From dbc537007d2a03ed524d023a35b20ee51466cd21 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 25 Nov 2019 09:30:26 +0000 Subject: [PATCH 001/788] First interface for auth --- auth/auth.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 auth/auth.go diff --git a/auth/auth.go b/auth/auth.go new file mode 100644 index 00000000..6c6f7e4f --- /dev/null +++ b/auth/auth.go @@ -0,0 +1,26 @@ +// Package auth provides authentication and authorization capability +package auth + +// Auth providers authentication and authorization +type Auth interface { + // Generate a new authorization token + Generate(u string) (*Token, error) + // Revoke an authorization token + Revoke(t *Token) error + // Verify a token + Verify(t *Token) error +} + +// Token providers by an auth provider +type Token struct { + // Unique token id + Id string `json: "id"` + // Time of token creation + Created time.Time `json:"created"` + // Time of token expiry + Expiry time.Time `json:"expiry"` + // Roles associated with the token + Roles []string `json:"roles"` + // Any other associated metadata + Metadata map[string]string `json:"metadata"` +} From 7013e7467fc5ccfb48c4d8fe43f55e9fe6f2fa1c Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 25 Nov 2019 09:33:30 +0000 Subject: [PATCH 002/788] Undefined time --- auth/auth.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/auth/auth.go b/auth/auth.go index 6c6f7e4f..d34bf1fb 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -1,6 +1,10 @@ // Package auth provides authentication and authorization capability package auth +import ( + "time" +) + // Auth providers authentication and authorization type Auth interface { // Generate a new authorization token From a957e90ca867d78376a2a156b54e726b7c65c6eb Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 5 Dec 2019 17:15:35 +0300 Subject: [PATCH 003/788] add RegisterCheck web server option for internal health checks Signed-off-by: Vasiliy Tolstov --- web/options.go | 14 ++++++++++++++ web/service.go | 7 +++++++ web/web.go | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/web/options.go b/web/options.go index 9a31f6d0..6f1233db 100644 --- a/web/options.go +++ b/web/options.go @@ -25,6 +25,9 @@ type Options struct { RegisterTTL time.Duration RegisterInterval time.Duration + // RegisterCheck runs a check function before registering the service + RegisterCheck func(context.Context) error + Server *http.Server Handler http.Handler @@ -62,6 +65,10 @@ func newOptions(opts ...Option) Options { o(&opt) } + if opt.RegisterCheck == nil { + opt.RegisterCheck = DefaultRegisterCheck + } + return opt } @@ -225,3 +232,10 @@ func StaticDir(d string) Option { o.StaticDir = d } } + +// RegisterCheck run func before registry service +func RegisterCheck(fn func(context.Context) error) Option { + return func(o *Options) { + o.RegisterCheck = fn + } +} diff --git a/web/service.go b/web/service.go index 49850d9e..e9d6801b 100644 --- a/web/service.go +++ b/web/service.go @@ -123,6 +123,13 @@ func (s *service) register() error { srv := s.genSrv() srv.Endpoints = s.srv.Endpoints s.srv = srv + + // use RegisterCheck func before register + if err := s.opts.RegisterCheck(s.opts.Context); err != nil { + log.Logf("Server %s-%s register check error: %s", s.opts.Name, s.opts.Id, err) + return err + } + return r.Register(s.srv, registry.RegisterTTL(s.opts.RegisterTTL)) } diff --git a/web/web.go b/web/web.go index f88e25ef..5c06c2ae 100644 --- a/web/web.go +++ b/web/web.go @@ -2,6 +2,7 @@ package web import ( + "context" "net/http" "time" @@ -32,7 +33,8 @@ var ( DefaultRegisterInterval = time.Second * 30 // static directory - DefaultStaticDir = "html" + DefaultStaticDir = "html" + DefaultRegisterCheck = func(context.Context) error { return nil } ) // NewService returns a new web.Service From 1c5a4c470f267a29461bb2289d269ae22e92f1d4 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 5 Dec 2019 19:37:03 +0300 Subject: [PATCH 004/788] add server Context option to pass own context Signed-off-by: Vasiliy Tolstov --- server/options.go | 9 +++++++++ web/options.go | 3 +++ 2 files changed, 12 insertions(+) diff --git a/server/options.go b/server/options.go index 110699ae..cbced938 100644 --- a/server/options.go +++ b/server/options.go @@ -136,6 +136,15 @@ func Codec(contentType string, c codec.NewCodec) Option { } } +// Context specifies a context for the service. +// Can be used to signal shutdown of the service +// Can be used for extra option values. +func Context(ctx context.Context) Option { + return func(o *Options) { + o.Context = ctx + } +} + // Registry used for discovery func Registry(r registry.Registry) Option { return func(o *Options) { diff --git a/web/options.go b/web/options.go index 9a31f6d0..05f7f615 100644 --- a/web/options.go +++ b/web/options.go @@ -126,18 +126,21 @@ func Context(ctx context.Context) Option { } } +// Registry used for discovery func Registry(r registry.Registry) Option { return func(o *Options) { o.Registry = r } } +// Register the service with a TTL func RegisterTTL(t time.Duration) Option { return func(o *Options) { o.RegisterTTL = t } } +// Register the service with at interval func RegisterInterval(t time.Duration) Option { return func(o *Options) { o.RegisterInterval = t From caa1bcf9fef1b87a35a33b68e12ebb15214fb519 Mon Sep 17 00:00:00 2001 From: Astone Date: Mon, 9 Dec 2019 11:08:21 +0800 Subject: [PATCH 005/788] named return value for error defer modify. --- server/grpc/subscriber.go | 3 +-- server/rpc_router.go | 3 +-- transport/grpc/handler.go | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/server/grpc/subscriber.go b/server/grpc/subscriber.go index 6d987974..9dd071c1 100644 --- a/server/grpc/subscriber.go +++ b/server/grpc/subscriber.go @@ -167,8 +167,7 @@ func validateSubscriber(sub server.Subscriber) error { } func (g *grpcServer) createSubHandler(sb *subscriber, opts server.Options) broker.Handler { - return func(p broker.Event) error { - var err error + return func(p broker.Event) (err error) { defer func() { if r := recover(); r != nil { diff --git a/server/rpc_router.go b/server/rpc_router.go index 19f672f4..d607f5f8 100644 --- a/server/rpc_router.go +++ b/server/rpc_router.go @@ -506,8 +506,7 @@ func (router *router) Subscribe(s Subscriber) error { return nil } -func (router *router) ProcessMessage(ctx context.Context, msg Message) error { - var err error +func (router *router) ProcessMessage(ctx context.Context, msg Message) (err error) { defer func() { // recover any panics diff --git a/transport/grpc/handler.go b/transport/grpc/handler.go index e02e1445..ce58a227 100644 --- a/transport/grpc/handler.go +++ b/transport/grpc/handler.go @@ -16,8 +16,7 @@ type microTransport struct { fn func(transport.Socket) } -func (m *microTransport) Stream(ts pb.Transport_StreamServer) error { - var err error +func (m *microTransport) Stream(ts pb.Transport_StreamServer) (err error) { sock := &grpcTransportSocket{ stream: ts, From 6e28e7a86f23ad603c09bfd9b97e0530f838aa8f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 11 Dec 2019 14:37:03 +0000 Subject: [PATCH 006/788] Save current state of the world --- network/default.go | 3 +- runtime/default.go | 2 +- tunnel/default.go | 88 +++++++++++++++++++++++++++++++--------------- tunnel/link.go | 38 +++++++++++++------- tunnel/options.go | 10 ++++++ 5 files changed, 97 insertions(+), 44 deletions(-) diff --git a/network/default.go b/network/default.go index dfc73bd2..c3c8d5db 100644 --- a/network/default.go +++ b/network/default.go @@ -1023,7 +1023,8 @@ func (n *network) sendTo(method, channel string, peer *node, msg proto.Message) if err != nil { return err } - c, err := n.tunnel.Dial(channel, tunnel.DialMode(tunnel.Multicast), tunnel.DialLink(peer.link)) + // Create a unicast connection to the peer but don't do the open/accept flow + c, err := n.tunnel.Dial(channel, tunnel.DialWait(false), tunnel.DialLink(peer.link)) if err != nil { return err } diff --git a/runtime/default.go b/runtime/default.go index 11ab7d32..e9318d46 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -143,7 +143,7 @@ func (r *runtime) run(events <-chan Event) { } } case <-r.closed: - log.Debugf("Runtime stopped.") + log.Debugf("Runtime stopped") return } } diff --git a/tunnel/default.go b/tunnel/default.go index a6cb08c9..8abad16b 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -73,10 +73,10 @@ func newTunnel(opts ...Option) *tun { // Init initializes tunnel options func (t *tun) Init(opts ...Option) error { t.Lock() - defer t.Unlock() for _, o := range opts { o(&t.options) } + t.Unlock() return nil } @@ -103,7 +103,6 @@ func (t *tun) delSession(channel, session string) { // listChannels returns a list of listening channels func (t *tun) listChannels() []string { t.RLock() - defer t.RUnlock() //nolint:prealloc var channels []string @@ -113,6 +112,9 @@ func (t *tun) listChannels() []string { } channels = append(channels, session.channel) } + + t.RUnlock() + return channels } @@ -244,53 +246,71 @@ func (t *tun) manageLink(link *link) { } // manageLinks is a function that can be called to immediately to link setup +// it purges dead links while generating new links for any nodes not connected func (t *tun) manageLinks() { - var delLinks []string + delLinks := make(map[*link]string) + connected := make(map[string]bool) t.RLock() + // get list of nodes from options + nodes := t.options.Nodes + // check the link status and purge dead links for node, link := range t.links { // check link status switch link.State() { - case "closed": - delLinks = append(delLinks, node) - case "error": - delLinks = append(delLinks, node) + case "closed", "error": + delLinks[link] = node + default: + connected[node] = true } } t.RUnlock() + // build a list of links to connect to + var connect []string + + for _, node := range nodes { + // check if we're connected + if _, ok := connected[node]; ok { + continue + } + // add nodes to connect o + connect = append(connect, node) + } + + // delete the dead links if len(delLinks) > 0 { t.Lock() - for _, node := range delLinks { + + for link, node := range delLinks { log.Debugf("Tunnel deleting dead link for %s", node) - if link, ok := t.links[node]; ok { - link.Close() + + // check if the link exists + l, ok := t.links[node] + if ok { + // close and delete + l.Close() delete(t.links, node) } + + // if the link does not match our own + if l != link { + // close our link just in case + link.Close() + } } + t.Unlock() } - // check current link status - var connect []string - - // build list of unknown nodes to connect to - t.RLock() - - for _, node := range t.options.Nodes { - if _, ok := t.links[node]; !ok { - connect = append(connect, node) - } - } - - t.RUnlock() - var wg sync.WaitGroup + // establish new links + for _, node := range connect { wg.Add(1) @@ -298,6 +318,7 @@ func (t *tun) manageLinks() { defer wg.Done() // create new link + // if we're using quic it should be a max 10 second handshake period link, err := t.setupLink(node) if err != nil { log.Debugf("Tunnel failed to setup node link to %s: %v", node, err) @@ -313,6 +334,7 @@ func (t *tun) manageLinks() { link.Close() return } + // save the link t.links[node] = link }(node) @@ -469,7 +491,6 @@ func (t *tun) process() { func (t *tun) delLink(remote string) { t.Lock() - defer t.Unlock() // get the link for id, link := range t.links { @@ -481,6 +502,8 @@ func (t *tun) delLink(remote string) { link.Close() delete(t.links, id) } + + t.Unlock() } // process incoming messages @@ -1035,6 +1058,7 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { // get opts options := DialOptions{ Timeout: DefaultDialTimeout, + Wait: true, } for _, o := range opts { @@ -1119,11 +1143,16 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { } // return early if its not unicast - // we will not call "open" for multicast + // we will not wait for "open" for multicast if c.mode != Unicast { return c, nil } + // if we're not told to wait + if !options.Wait { + return c, nil + } + // Note: we go no further for multicast or broadcast. // This is a unicast session so we call "open" and wait // for an "accept" @@ -1221,15 +1250,16 @@ func (t *tun) Listen(channel string, opts ...ListenOption) (Listener, error) { } func (t *tun) Links() []Link { - t.RLock() - defer t.RUnlock() - links := make([]Link, 0, len(t.links)) + t.RLock() + for _, link := range t.links { links = append(links, link) } + t.RUnlock() + return links } diff --git a/tunnel/link.go b/tunnel/link.go index a072a047..fe6ba83a 100644 --- a/tunnel/link.go +++ b/tunnel/link.go @@ -138,10 +138,10 @@ func (l *link) setRate(bits int64, delta time.Duration) { // setRTT sets a nanosecond based moving average roundtrip time for the link func (l *link) setRTT(d time.Duration) { l.Lock() - defer l.Unlock() if l.length <= 0 { l.length = d.Nanoseconds() + l.Unlock() return } @@ -149,6 +149,8 @@ func (l *link) setRTT(d time.Duration) { length := 0.8*float64(l.length) + 0.2*float64(d.Nanoseconds()) // set new length l.length = int64(length) + + l.Unlock() } func (l *link) delChannel(ch string) { @@ -159,8 +161,9 @@ func (l *link) delChannel(ch string) { func (l *link) getChannel(ch string) time.Time { l.RLock() - defer l.RUnlock() - return l.channels[ch] + t := l.channels[ch] + l.RUnlock() + return t } func (l *link) setChannel(channels ...string) { @@ -344,27 +347,31 @@ func (l *link) Delay() int64 { // Current transfer rate as bits per second (lower is better) func (l *link) Rate() float64 { l.RLock() - defer l.RUnlock() - return l.rate + r := l.rate + l.RUnlock() + return r } func (l *link) Loopback() bool { l.RLock() - defer l.RUnlock() - return l.loopback + lo := l.loopback + l.RUnlock() + return lo } // Length returns the roundtrip time as nanoseconds (lower is better). // Returns 0 where no measurement has been taken. func (l *link) Length() int64 { l.RLock() - defer l.RUnlock() - return l.length + length := l.length + l.RUnlock() + return length } func (l *link) Id() string { l.RLock() - defer l.RUnlock() + id := l.id + l.RUnlock() return l.id } @@ -413,11 +420,11 @@ func (l *link) Send(m *transport.Message) error { } l.Lock() - defer l.Unlock() // there's an error increment the counter and bail if err != nil { l.errCount++ + l.Unlock() return err } @@ -441,6 +448,8 @@ func (l *link) Send(m *transport.Message) error { l.setRate(int64(bits), time.Since(now)) } + l.Unlock() + return nil } @@ -476,10 +485,13 @@ func (l *link) State() string { return "closed" default: l.RLock() - defer l.RUnlock() - if l.errCount > 3 { + errCount := l.errCount + l.RUnlock() + + if lerrCount > 3 { return "error" } + return "connected" } } diff --git a/tunnel/options.go b/tunnel/options.go index 145db19f..262df797 100644 --- a/tunnel/options.go +++ b/tunnel/options.go @@ -38,6 +38,8 @@ type DialOptions struct { Link string // specify mode of the session Mode Mode + // Wait for connection to be accepted + Wait bool // the dial timeout Timeout time.Duration } @@ -124,6 +126,14 @@ func DialLink(id string) DialOption { } } +// DialWait specifies whether to wait for the connection +// to be accepted before returning the session +func DialWait(b bool) DialOption { + return func(o *DialOptions) { + o.Wait = b + } +} + // DefaultOptions returns router default options func DefaultOptions() Options { return Options{ From 27af221fd249a28fb2865d701f611b88bbe1e10f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 11 Dec 2019 15:23:08 +0000 Subject: [PATCH 007/788] batch metric updates --- tunnel/default.go | 1 - tunnel/link.go | 131 +++++++++++++++++++++++++++++++++------------- 2 files changed, 96 insertions(+), 36 deletions(-) diff --git a/tunnel/default.go b/tunnel/default.go index 8abad16b..ff66ea6f 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -281,7 +281,6 @@ func (t *tun) manageLinks() { connect = append(connect, node) } - // delete the dead links if len(delLinks) > 0 { t.Lock() diff --git a/tunnel/link.go b/tunnel/link.go index fe6ba83a..0f5b3980 100644 --- a/tunnel/link.go +++ b/tunnel/link.go @@ -22,6 +22,8 @@ type link struct { // stops the link closed chan bool + // metric used to track metrics + metric chan *metric // link state channel for testing link state chan *packet // send queue for sending packets @@ -65,6 +67,16 @@ type packet struct { err error } +// metric is used to record link rate +type metric struct { + // amount of data sent + data int + // time taken to send + duration time.Duration + // if an error occurred + status error +} + var ( // the 4 byte 0 packet sent to determine the link state linkRequest = []byte{0, 0, 0, 0} @@ -84,6 +96,7 @@ func newLink(s transport.Socket) *link { state: make(chan *packet, 64), sendQueue: make(chan *packet, 128), recvQueue: make(chan *packet, 128), + metric: make(chan *metric, 128), } // process inbound/outbound packets @@ -189,9 +202,11 @@ func (l *link) process() { m := new(transport.Message) err := l.recv(m) if err != nil { - l.Lock() - l.errCount++ - l.Unlock() + // record the metric + select { + case l.metric <- &metric{status: err}: + default: + } } // process new received message @@ -240,8 +255,12 @@ func (l *link) process() { // manage manages the link state including rtt packets and channel mapping expiry func (l *link) manage() { // tick over every minute to expire and fire rtt packets - t := time.NewTicker(time.Minute) - defer t.Stop() + t1 := time.NewTicker(time.Minute) + defer t1.Stop() + + // used to batch update link metrics + t2 := time.NewTicker(time.Second * 5) + defer t2.Stop() // get link id linkId := l.Id() @@ -290,7 +309,7 @@ func (l *link) manage() { // set the RTT l.setRTT(d) } - case <-t.C: + case <-t1.C: // drop any channel mappings older than 2 minutes var kill []string killTime := time.Minute * 2 @@ -318,10 +337,60 @@ func (l *link) manage() { // fire off a link state rtt packet now = time.Now() send(linkRequest) + case <-t2.C: + // get a batch of metrics + batch := l.batch() + + // skip if there's no metrics + if len(batch) == 0 { + continue + } + + // lock once to record a batch + l.Lock() + for _, metric := range batch { + l.record(metric) + } + l.Unlock() } } } +func (l *link) batch() []*metric { + var metrics []*metric + + // pull all the metrics + for { + select { + case m := <-l.metric: + metrics = append(metrics, m) + // non blocking return + default: + return metrics + } + } +} + +func (l *link) record(m *metric) { + // there's an error increment the counter and bail + if m.status != nil { + l.errCount++ + return + } + + // reset the counter + l.errCount = 0 + + // calculate based on data + if m.data > 0 { + // bit sent + bits := m.data * 1024 + + // set the rate + l.setRate(int64(bits), m.duration) + } +} + func (l *link) send(m *transport.Message) error { if m.Header == nil { m.Header = make(map[string]string) @@ -372,7 +441,7 @@ func (l *link) Id() string { l.RLock() id := l.id l.RUnlock() - return l.id + return id } func (l *link) Close() error { @@ -398,6 +467,14 @@ func (l *link) Send(m *transport.Message) error { status: make(chan error, 1), } + // calculate the data sent + dataSent := len(m.Body) + + // set header length + for k, v := range m.Header { + dataSent += (len(k) + len(v)) + } + // get time now now := time.Now() @@ -419,37 +496,21 @@ func (l *link) Send(m *transport.Message) error { case err = <-p.status: } - l.Lock() - - // there's an error increment the counter and bail - if err != nil { - l.errCount++ - l.Unlock() - return err + // create a metric with + // time taken, size of package, error status + mt := &metric{ + data: dataSent, + duration: time.Since(now), + status: err, } - // reset the counter - l.errCount = 0 - - // calculate the data sent - dataSent := len(m.Body) - - // set header length - for k, v := range m.Header { - dataSent += (len(k) + len(v)) + // pass back a metric + // do not block + select { + case l.metric <- mt: + default: } - // calculate based on data - if dataSent > 0 { - // bit sent - bits := dataSent * 1024 - - // set the rate - l.setRate(int64(bits), time.Since(now)) - } - - l.Unlock() - return nil } @@ -488,7 +549,7 @@ func (l *link) State() string { errCount := l.errCount l.RUnlock() - if lerrCount > 3 { + if errCount > 3 { return "error" } From e260cc4a2460198a049dd0e94989ed3346746cf7 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 12 Dec 2019 12:27:46 +0000 Subject: [PATCH 008/788] save cruft --- network/default.go | 23 +-- tunnel/default.go | 362 ++++++++++++++++++++++++++++++--------------- tunnel/listener.go | 19 --- 3 files changed, 255 insertions(+), 149 deletions(-) diff --git a/network/default.go b/network/default.go index c3c8d5db..a4fbd0b5 100644 --- a/network/default.go +++ b/network/default.go @@ -6,6 +6,7 @@ import ( "hash/fnv" "io" "math" + "math/rand" "sort" "sync" "time" @@ -88,6 +89,7 @@ type message struct { // newNetwork returns a new network node func newNetwork(opts ...Option) Network { + rand.Seed(time.Now().UnixNano()) options := DefaultOptions() for _, o := range opts { @@ -178,12 +180,11 @@ func newNetwork(opts ...Option) Network { func (n *network) Init(opts ...Option) error { n.Lock() - defer n.Unlock() - // TODO: maybe only allow reinit of certain opts for _, o := range opts { o(&n.options) } + n.Unlock() return nil } @@ -191,10 +192,8 @@ func (n *network) Init(opts ...Option) error { // Options returns network options func (n *network) Options() Options { n.RLock() - defer n.RUnlock() - options := n.options - + n.RUnlock() return options } @@ -332,8 +331,7 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { // someone requested the route n.sendTo("advert", ControlChannel, peer, msg) default: - // send to all since we can't get anything - n.sendMsg("advert", ControlChannel, msg) + // no one to send to } case <-n.closed: return @@ -498,12 +496,12 @@ func (n *network) getHopCount(rtr string) int { } // the route origin is our peer - if _, ok := n.peers[rtr]; ok { + if _, ok := n.node.peers[rtr]; ok { return 10 } // the route origin is the peer of our peer - for _, peer := range n.peers { + for _, peer := range n.node.peers { for id := range peer.peers { if rtr == id { return 100 @@ -944,6 +942,13 @@ func (n *network) manage() { case <-n.closed: return case <-announce.C: + // jitter + j := rand.Int63n(30) + time.Sleep(time.Duration(j) * time.Second) + + // TODO: intermittently flip between peer selection + // and full broadcast pick a random set of peers + msg := PeersToProto(n.node, MaxDepth) // advertise yourself to the network if err := n.sendMsg("peer", NetworkChannel, msg); err != nil { diff --git a/tunnel/default.go b/tunnel/default.go index ff66ea6f..aadd4870 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -14,7 +14,7 @@ import ( var ( // DiscoverTime sets the time at which we fire discover messages - DiscoverTime = 60 * time.Second + DiscoverTime = 30 * time.Second // KeepAliveTime defines time interval we send keepalive messages to outbound links KeepAliveTime = 30 * time.Second // ReconnectTime defines time interval we periodically attempt to reconnect dead links @@ -42,6 +42,9 @@ type tun struct { // close channel closed chan bool + // control channel to indicate link change + updated chan bool + // a map of sessions based on Micro-Tunnel-Channel sessions map[string]*session @@ -54,6 +57,7 @@ type tun struct { // create new tunnel on top of a link func newTunnel(opts ...Option) *tun { + rand.Seed(time.Now().UnixNano()) options := DefaultOptions() for _, o := range opts { o(&options) @@ -65,6 +69,7 @@ func newTunnel(opts ...Option) *tun { token: options.Token, send: make(chan *message, 128), closed: make(chan bool), + updated: make(chan bool, 3), sessions: make(map[string]*session), links: make(map[string]*link), } @@ -222,6 +227,12 @@ func (t *tun) manageLink(link *link) { discover := time.NewTicker(DiscoverTime) defer discover.Stop() + wait := func(d time.Duration) { + // jitter + j := rand.Int63n(int64(d / 2)) + time.Sleep(time.Duration(j) * time.Second) + } + for { select { case <-t.closed: @@ -229,18 +240,29 @@ func (t *tun) manageLink(link *link) { case <-link.closed: return case <-discover.C: - // send a discovery message to all links - if err := t.sendMsg("discover", link); err != nil { - log.Debugf("Tunnel failed to send discover to link %s: %v", link.Remote(), err) - } + go func() { + // wait half the discover time + wait(DiscoverTime) + + // send a discovery message to the link + log.Debugf("Tunnel sending discover to link: %v", link.Remote()) + if err := t.sendMsg("discover", link); err != nil { + log.Debugf("Tunnel failed to send discover to link %s: %v", link.Remote(), err) + } + }() case <-keepalive.C: - // send keepalive message - log.Debugf("Tunnel sending keepalive to link: %v", link.Remote()) - if err := t.sendMsg("keepalive", link); err != nil { - log.Debugf("Tunnel error sending keepalive to link %v: %v", link.Remote(), err) - t.delLink(link.Remote()) - return - } + go func() { + // wait half the keepalive time + wait(KeepAliveTime) + + // send keepalive message + log.Debugf("Tunnel sending keepalive to link: %v", link.Remote()) + if err := t.sendMsg("keepalive", link); err != nil { + log.Debugf("Tunnel error sending keepalive to link %v: %v", link.Remote(), err) + t.delLink(link.Remote()) + return + } + }() } } } @@ -248,6 +270,7 @@ func (t *tun) manageLink(link *link) { // manageLinks is a function that can be called to immediately to link setup // it purges dead links while generating new links for any nodes not connected func (t *tun) manageLinks() { + // if we need to notify of updates delLinks := make(map[*link]string) connected := make(map[string]bool) @@ -304,6 +327,9 @@ func (t *tun) manageLinks() { } t.Unlock() + + // links were deleted so notify + go t.notify() } var wg sync.WaitGroup @@ -324,18 +350,22 @@ func (t *tun) manageLinks() { return } - // save the link t.Lock() - defer t.Unlock() // just check nothing else was setup in the interim if _, ok := t.links[node]; ok { link.Close() + t.Unlock() return } // save the link t.links[node] = link + + t.Unlock() + + // notify ourselves of the change + go t.notify() }(node) } @@ -345,48 +375,37 @@ func (t *tun) manageLinks() { // process outgoing messages sent by all local sessions func (t *tun) process() { + // wait for the first update + <-t.updated + + // get the list of links + t.RLock() + var links []*link + for _, link := range t.links { + links = append(links, link) + } + t.RUnlock() + // manage the send buffer // all pseudo sessions throw everything down this for { select { case msg := <-t.send: - newMsg := &transport.Message{ - Header: make(map[string]string), - } - - // set the data - if msg.data != nil { - for k, v := range msg.data.Header { - newMsg.Header[k] = v - } - newMsg.Body = msg.data.Body - } - - // set message head - newMsg.Header["Micro-Tunnel"] = msg.typ - - // set the tunnel id on the outgoing message - newMsg.Header["Micro-Tunnel-Id"] = msg.tunnel - - // set the tunnel channel on the outgoing message - newMsg.Header["Micro-Tunnel-Channel"] = msg.channel - - // set the session id - newMsg.Header["Micro-Tunnel-Session"] = msg.session - - // send the message via the interface - t.RLock() - - if len(t.links) == 0 { + // no links yet + if len(links) == 0 { + // TODO: should we block here rather than throwing away messages... + // Or should we return an error? log.Debugf("No links to send message type: %s channel: %s", msg.typ, msg.channel) + time.Sleep(time.Millisecond * 100) + continue } - var sent bool - var err error + // build a list of links to send to var sendTo []*link + var err error // build the list of links ot send to - for node, link := range t.links { + for _, link := range links { // get the values we need link.RLock() id := link.id @@ -397,7 +416,7 @@ func (t *tun) process() { // if the link is not connected skip it if !connected { - log.Debugf("Link for node %s not connected", node) + log.Debugf("Link for node %s not connected", id) err = errors.New("link not connected") continue } @@ -406,7 +425,7 @@ func (t *tun) process() { // and the message is being sent outbound via // a dialled connection don't use this link if loopback && msg.outbound { - log.Tracef("Link for node %s is loopback", node) + log.Tracef("Link for node %s is loopback", id) err = errors.New("link is loopback") continue } @@ -414,7 +433,7 @@ func (t *tun) process() { // if the message was being returned by the loopback listener // send it back up the loopback link only if msg.loopback && !loopback { - log.Tracef("Link for message %s is loopback", node) + log.Tracef("Link for message %s is loopback", id) err = errors.New("link is not loopback") continue } @@ -439,55 +458,128 @@ func (t *tun) process() { sendTo = append(sendTo, link) } - t.RUnlock() - - // send the message - for _, link := range sendTo { - // send the message via the current link - log.Tracef("Tunnel sending %+v to %s", newMsg.Header, link.Remote()) - - if errr := link.Send(newMsg); errr != nil { - log.Debugf("Tunnel error sending %+v to %s: %v", newMsg.Header, link.Remote(), errr) - err = errors.New(errr.Error()) - t.delLink(link.Remote()) - continue - } - - // is sent - sent = true - - // keep sending broadcast messages - if msg.mode > Unicast { - continue - } - - // break on unicast - break - } - - var gerr error - - // set the error if not sent - if !sent { - gerr = err - } - - // skip if its not been set - if msg.errChan == nil { + // no links to send to + if len(sendTo) == 0 { + t.respond(msg, err) continue } - // return error non blocking - select { - case msg.errChan <- gerr: - default: + // send the message + t.sendTo(sendTo, msg) + case <-t.updated: + t.RLock() + var newLinks []*link + for _, link := range t.links { + newLinks = append(links, link) } + t.RUnlock() + // links were updated + links = newLinks case <-t.closed: return } } } +// send response back for a message to the caller +func (t *tun) respond(msg *message, err error) { + select { + case msg.errChan <- err: + default: + } +} + +// sendTo sends a message to the chosen links +func (t *tun) sendTo(links []*link, msg *message) error { + // the function that sends the actual message + send := func(link *link, msg *transport.Message) error { + if err := link.Send(msg); err != nil { + log.Debugf("Tunnel error sending %+v to %s: %v", msg.Header, link.Remote(), err) + t.delLink(link.Remote()) + return err + } + return nil + } + + newMsg := &transport.Message{ + Header: make(map[string]string), + } + + // set the data + if msg.data != nil { + for k, v := range msg.data.Header { + newMsg.Header[k] = v + } + newMsg.Body = msg.data.Body + } + + // set message head + newMsg.Header["Micro-Tunnel"] = msg.typ + // set the tunnel id on the outgoing message + newMsg.Header["Micro-Tunnel-Id"] = msg.tunnel + // set the tunnel channel on the outgoing message + newMsg.Header["Micro-Tunnel-Channel"] = msg.channel + // set the session id + newMsg.Header["Micro-Tunnel-Session"] = msg.session + + // error channel for call + errChan := make(chan error, len(links)) + + // send the message + for _, link := range links { + // send the message via the current link + log.Tracef("Tunnel sending %+v to %s", newMsg.Header, link.Remote()) + + // blast it in a go routine since its multicast/broadcast + if msg.mode > Unicast { + // make a copy + m := &transport.Message{ + Header: make(map[string]string), + } + copy(m.Body, newMsg.Body) + for k, v := range newMsg.Header { + m.Header[k] = v + } + + // execute in parallel + go func() { + errChan <- send(link, m) + }() + + continue + } + + // otherwise send as unicast + if err := send(link, newMsg); err != nil { + // put in the error chan if it failed + errChan <- err + continue + } + + // sent successfully so just return + t.respond(msg, nil) + return nil + } + + // either all unicast attempts failed or we're + // checking the multicast/broadcast attempts + + var err error + + // check all the errors + for i := 0; i < len(links); i++ { + err = <-errChan + // success + if err == nil { + break + } + } + + // return error. it's non blocking + t.respond(msg, err) + return err +} + func (t *tun) delLink(remote string) { t.Lock() @@ -502,9 +594,21 @@ func (t *tun) delLink(remote string) { delete(t.links, id) } + // let ourselves know of a link change + go t.notify() + t.Unlock() } +// notify ourselves of a link change +func (t *tun) notify() { + select { + case t.updated <- true: + // unblock after a second + case <-time.After(time.Second): + } +} + // process incoming messages func (t *tun) listen(link *link) { // remove the link on exit @@ -856,6 +960,9 @@ func (t *tun) setupLinks() { // wait for all threads to finish wg.Wait() + + // notify ourselves of the update + t.notify() } // connect the tunnel to all the nodes and listen for incoming tunnel connections @@ -1042,19 +1149,7 @@ func (t *tun) Close() error { // Dial an address func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { - log.Debugf("Tunnel dialing %s", channel) - c, ok := t.newSession(channel, t.newSessionId()) - if !ok { - return nil, errors.New("error dialing " + channel) - } - // set remote - c.remote = channel - // set local - c.local = "local" - // outbound session - c.outbound = true - - // get opts + // get the options options := DialOptions{ Timeout: DefaultDialTimeout, Wait: true, @@ -1064,12 +1159,28 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { o(&options) } - // set the multicast option + log.Debugf("Tunnel dialing %s", channel) + + // create a new session + c, ok := t.newSession(channel, t.newSessionId()) + if !ok { + return nil, errors.New("error dialing " + channel) + } + + // set remote + c.remote = channel + // set local + c.local = "local" + // outbound session + c.outbound = true + // set the mode of connection unicast/multicast/broadcast c.mode = options.Mode // set the dial timeout c.dialTimeout = options.Timeout // set read timeout set to never c.readTimeout = time.Duration(-1) + // set the link + c.link = options.Link var links []*link // did we measure the rtt @@ -1080,7 +1191,7 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { // non multicast so we need to find the link for _, link := range t.links { // use the link specified it its available - if id := options.Link; len(id) > 0 && link.id != id { + if len(c.link) > 0 && link.id != c.link { continue } @@ -1096,20 +1207,36 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { t.RUnlock() - // link not found and one was specified so error out - if len(links) == 0 && len(options.Link) > 0 { - // delete session and return error - t.delSession(c.channel, c.session) - log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, ErrLinkNotFound) - return nil, ErrLinkNotFound + // link option was specified to pick the link + if len(options.Link) > 0 { + // link not found and one was specified so error out + if len(links) == 0 { + // delete session and return error + t.delSession(c.channel, c.session) + log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, ErrLinkNotFound) + return nil, ErrLinkNotFound + } + + // assume discovered because we picked + c.discovered = true + + // link asked for and found and now + // we've been asked not to wait so return + if !options.Wait { + c.accepted = true + return c, nil + } } // discovered so set the link if not multicast if c.discovered && c.mode == Unicast { - // pickLink will pick the best link - link := t.pickLink(links) - // set the link - c.link = link.id + // pick a link if not specified + if len(c.link) == 0 { + // pickLink will pick the best link + link := t.pickLink(links) + // set the link + c.link = link.id + } } // if its not already discovered we need to attempt to do so @@ -1143,12 +1270,8 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { // return early if its not unicast // we will not wait for "open" for multicast - if c.mode != Unicast { - return c, nil - } - - // if we're not told to wait - if !options.Wait { + // and we will not wait it told not to + if c.mode != Unicast || !options.Wait { return c, nil } @@ -1241,9 +1364,6 @@ func (t *tun) Listen(channel string, opts ...ListenOption) (Listener, error) { // to the existign sessions go tl.process() - // announces the listener channel to others - go tl.announce() - // return the listener return tl, nil } diff --git a/tunnel/listener.go b/tunnel/listener.go index 6dbec5c8..16f37e35 100644 --- a/tunnel/listener.go +++ b/tunnel/listener.go @@ -2,7 +2,6 @@ package tunnel import ( "io" - "time" "github.com/micro/go-micro/util/log" ) @@ -24,24 +23,6 @@ type tunListener struct { delFunc func() } -// periodically announce self the channel being listened on -func (t *tunListener) announce() { - tick := time.NewTicker(time.Second * 30) - defer tick.Stop() - - // first announcement - t.session.Announce() - - for { - select { - case <-tick.C: - t.session.Announce() - case <-t.closed: - return - } - } -} - func (t *tunListener) process() { // our connection map for session conns := make(map[string]*session) From ae934c19f1c376eb8e97134d8bbd48d28557e315 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 12 Dec 2019 13:04:34 +0000 Subject: [PATCH 009/788] fix tunnel test --- tunnel/default.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tunnel/default.go b/tunnel/default.go index aadd4870..a418fcf1 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -433,7 +433,7 @@ func (t *tun) process() { // if the message was being returned by the loopback listener // send it back up the loopback link only if msg.loopback && !loopback { - log.Tracef("Link for message %s is loopback", id) + log.Tracef("Link for message from %s is loopback", id) err = errors.New("link is not loopback") continue } @@ -460,6 +460,7 @@ func (t *tun) process() { // no links to send to if len(sendTo) == 0 { + log.Log("no links") t.respond(msg, err) continue } @@ -683,6 +684,8 @@ func (t *tun) listen(link *link) { t.links[link.Remote()] = link t.Unlock() + // notify of link change + go t.notify() // send back an announcement of our channels discovery go t.announce("", "", link) // ask for the things on the other wise @@ -1076,6 +1079,11 @@ func (t *tun) pickLink(links []*link) *link { continue } + // skip the loopback + if link.Loopback() { + continue + } + // get the link state info d := float64(link.Delay()) l := float64(link.Length()) From df728aaddd3f4527f97edebd61604c3795690c9e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 12 Dec 2019 13:34:08 +0000 Subject: [PATCH 010/788] remove go routines from tunnel, fire network messages in go routines --- network/default.go | 53 +++++++++++++++++++++++++++++----------------- tunnel/default.go | 36 ++++++++++++++----------------- 2 files changed, 50 insertions(+), 39 deletions(-) diff --git a/network/default.go b/network/default.go index a4fbd0b5..a96efad2 100644 --- a/network/default.go +++ b/network/default.go @@ -765,22 +765,27 @@ func (n *network) processNetChan(listener tunnel.Listener) { // get node peers down to MaxDepth encoded in protobuf msg := PeersToProto(n.node, MaxDepth) - // advertise yourself to the network - if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { - log.Debugf("Network failed to advertise peers: %v", err) - } + go func() { + // advertise yourself to the network + if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { + log.Debugf("Network failed to advertise peers: %v", err) + } - // advertise all the routes when a new node has connected - if err := n.router.Solicit(); err != nil { - log.Debugf("Network failed to solicit routes: %s", err) - } + // wait for a second + <-time.After(time.Second) - // specify that we're soliciting - select { - case n.solicited <- peer: - default: - // don't block - } + // advertise all the routes when a new node has connected + if err := n.router.Solicit(); err != nil { + log.Debugf("Network failed to solicit routes: %s", err) + } + + // specify that we're soliciting + select { + case n.solicited <- peer: + default: + // don't block + } + }() case "peer": // mark the time the message has been received now := time.Now() @@ -818,10 +823,20 @@ func (n *network) processNetChan(listener tunnel.Listener) { Id: n.options.Id, } - // only solicit this peer - if err := n.sendTo("solicit", ControlChannel, peer, msg); err != nil { - log.Debugf("Network failed to send solicit message: %s", err) - } + go func() { + // advertise yourself to the peer + if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { + log.Debugf("Network failed to advertise peers: %v", err) + } + + // wait for a second + <-time.After(time.Second) + + // then solicit this peer + if err := n.sendTo("solicit", ControlChannel, peer, msg); err != nil { + log.Debugf("Network failed to send solicit message: %s", err) + } + }() continue // we're expecting any error to be ErrPeerExists @@ -943,7 +958,7 @@ func (n *network) manage() { return case <-announce.C: // jitter - j := rand.Int63n(30) + j := rand.Int63n(int64(AnnounceTime / 2)) time.Sleep(time.Duration(j) * time.Second) // TODO: intermittently flip between peer selection diff --git a/tunnel/default.go b/tunnel/default.go index a418fcf1..0b47007e 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -240,29 +240,25 @@ func (t *tun) manageLink(link *link) { case <-link.closed: return case <-discover.C: - go func() { - // wait half the discover time - wait(DiscoverTime) + // wait half the discover time + wait(DiscoverTime) - // send a discovery message to the link - log.Debugf("Tunnel sending discover to link: %v", link.Remote()) - if err := t.sendMsg("discover", link); err != nil { - log.Debugf("Tunnel failed to send discover to link %s: %v", link.Remote(), err) - } - }() + // send a discovery message to the link + log.Debugf("Tunnel sending discover to link: %v", link.Remote()) + if err := t.sendMsg("discover", link); err != nil { + log.Debugf("Tunnel failed to send discover to link %s: %v", link.Remote(), err) + } case <-keepalive.C: - go func() { - // wait half the keepalive time - wait(KeepAliveTime) + // wait half the keepalive time + wait(KeepAliveTime) - // send keepalive message - log.Debugf("Tunnel sending keepalive to link: %v", link.Remote()) - if err := t.sendMsg("keepalive", link); err != nil { - log.Debugf("Tunnel error sending keepalive to link %v: %v", link.Remote(), err) - t.delLink(link.Remote()) - return - } - }() + // send keepalive message + log.Debugf("Tunnel sending keepalive to link: %v", link.Remote()) + if err := t.sendMsg("keepalive", link); err != nil { + log.Debugf("Tunnel error sending keepalive to link %v: %v", link.Remote(), err) + t.delLink(link.Remote()) + return + } } } } From 7bd50cd25171d17f6b4d08a69fb6616d803ee31f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 12 Dec 2019 17:10:32 +0000 Subject: [PATCH 011/788] fix more broken cruft --- network/default.go | 6 ++++-- tunnel/crypto.go | 5 +++++ tunnel/default.go | 14 +++----------- tunnel/listener.go | 19 +++++++++++++++---- tunnel/tunnel.go | 2 ++ 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/network/default.go b/network/default.go index a96efad2..b7a61ec1 100644 --- a/network/default.go +++ b/network/default.go @@ -331,7 +331,9 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { // someone requested the route n.sendTo("advert", ControlChannel, peer, msg) default: - // no one to send to + if err := n.sendMsg("advert", ControlChannel, msg); err != nil { + log.Debugf("Network failed to advertise routes: %v", err) + } } case <-n.closed: return @@ -958,7 +960,7 @@ func (n *network) manage() { return case <-announce.C: // jitter - j := rand.Int63n(int64(AnnounceTime / 2)) + j := rand.Int63n(int64(AnnounceTime.Seconds() / 2.0)) time.Sleep(time.Duration(j) * time.Second) // TODO: intermittently flip between peer selection diff --git a/tunnel/crypto.go b/tunnel/crypto.go index ba0d5057..9f9f45af 100644 --- a/tunnel/crypto.go +++ b/tunnel/crypto.go @@ -60,6 +60,11 @@ func Decrypt(data []byte, key string) ([]byte, error) { } nonceSize := gcm.NonceSize() + + if len(data) < nonceSize { + return nil, ErrDecryptingData + } + // NOTE: we need to parse out nonce from the payload // we prepend the nonce to every encrypted payload nonce, ciphertext := data[:nonceSize], data[nonceSize:] diff --git a/tunnel/default.go b/tunnel/default.go index 0b47007e..36781b53 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -229,7 +229,7 @@ func (t *tun) manageLink(link *link) { wait := func(d time.Duration) { // jitter - j := rand.Int63n(int64(d / 2)) + j := rand.Int63n(int64(d.Seconds() / 2.0)) time.Sleep(time.Duration(j) * time.Second) } @@ -387,15 +387,6 @@ func (t *tun) process() { for { select { case msg := <-t.send: - // no links yet - if len(links) == 0 { - // TODO: should we block here rather than throwing away messages... - // Or should we return an error? - log.Debugf("No links to send message type: %s channel: %s", msg.typ, msg.channel) - time.Sleep(time.Millisecond * 100) - continue - } - // build a list of links to send to var sendTo []*link var err error @@ -456,7 +447,7 @@ func (t *tun) process() { // no links to send to if len(sendTo) == 0 { - log.Log("no links") + log.Debugf("No links to send message type: %s channel: %s", msg.typ, msg.channel) t.respond(msg, err) continue } @@ -532,6 +523,7 @@ func (t *tun) sendTo(links []*link, msg *message) error { // make a copy m := &transport.Message{ Header: make(map[string]string), + Body: make([]byte, len(newMsg.Body)), } copy(m.Body, newMsg.Body) for k, v := range newMsg.Header { diff --git a/tunnel/listener.go b/tunnel/listener.go index 16f37e35..052955cb 100644 --- a/tunnel/listener.go +++ b/tunnel/listener.go @@ -2,6 +2,7 @@ package tunnel import ( "io" + "sync" "github.com/micro/go-micro/util/log" ) @@ -13,14 +14,16 @@ type tunListener struct { token string // the accept channel accept chan *session - // the channel to close - closed chan bool // the tunnel closed channel tunClosed chan bool // the listener session session *session // del func to kill listener delFunc func() + + sync.RWMutex + // the channel to close + closed chan bool } func (t *tunListener) process() { @@ -49,7 +52,7 @@ func (t *tunListener) process() { var sessionId string var linkId string - switch m.mode { + switch t.session.mode { case Multicast: sessionId = "multicast" linkId = "multicast" @@ -87,7 +90,7 @@ func (t *tunListener) process() { // the link the message was received on link: linkId, // set the connection mode - mode: m.mode, + mode: t.session.mode, // close chan closed: make(chan bool), // recv called by the acceptor @@ -115,6 +118,11 @@ func (t *tunListener) process() { switch m.typ { case "close": + // don't close multicast sessions + if sess.mode > Unicast { + continue + } + // received a close message select { // check if the session is closed @@ -154,6 +162,9 @@ func (t *tunListener) Channel() string { // Close closes tunnel listener func (t *tunListener) Close() error { + t.Lock() + defer t.Unlock() + select { case <-t.closed: return nil diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 15ff6078..b59eb31d 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -28,6 +28,8 @@ var ( ErrLinkNotFound = errors.New("link not found") // ErrReadTimeout is a timeout on session.Recv ErrReadTimeout = errors.New("read timeout") + // ErrDecryptingData is for when theres a nonce error + ErrDecryptingData = errors.New("error decrypting data") ) // Mode of the session From 74c5102e4139fe10df3d2d8802a68264b714a321 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 12 Dec 2019 21:49:39 +0000 Subject: [PATCH 012/788] strip a couple things --- network/default.go | 3 --- tunnel/default.go | 15 ++++++--------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/network/default.go b/network/default.go index b7a61ec1..46cdcd4f 100644 --- a/network/default.go +++ b/network/default.go @@ -773,9 +773,6 @@ func (n *network) processNetChan(listener tunnel.Listener) { log.Debugf("Network failed to advertise peers: %v", err) } - // wait for a second - <-time.After(time.Second) - // advertise all the routes when a new node has connected if err := n.router.Solicit(); err != nil { log.Debugf("Network failed to solicit routes: %s", err) diff --git a/tunnel/default.go b/tunnel/default.go index 36781b53..83c85a64 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -375,8 +375,8 @@ func (t *tun) process() { <-t.updated // get the list of links - t.RLock() var links []*link + t.RLock() for _, link := range t.links { links = append(links, link) } @@ -412,7 +412,6 @@ func (t *tun) process() { // and the message is being sent outbound via // a dialled connection don't use this link if loopback && msg.outbound { - log.Tracef("Link for node %s is loopback", id) err = errors.New("link is loopback") continue } @@ -420,7 +419,6 @@ func (t *tun) process() { // if the message was being returned by the loopback listener // send it back up the loopback link only if msg.loopback && !loopback { - log.Tracef("Link for message from %s is loopback", id) err = errors.New("link is not loopback") continue } @@ -458,7 +456,7 @@ func (t *tun) process() { t.RLock() var newLinks []*link for _, link := range t.links { - newLinks = append(links, link) + newLinks = append(newLinks, link) } t.RUnlock() // links were updated @@ -583,10 +581,10 @@ func (t *tun) delLink(remote string) { delete(t.links, id) } + t.Unlock() + // let ourselves know of a link change go t.notify() - - t.Unlock() } // notify ourselves of a link change @@ -681,7 +679,6 @@ func (t *tun) listen(link *link) { // nothing more to do continue case "close": - log.Debugf("Tunnel link %s received close message", link.Remote()) // if there is no channel then we close the link // as its a signal from the other side to close the connection if len(channel) == 0 { @@ -689,6 +686,7 @@ func (t *tun) listen(link *link) { return } + log.Debugf("Tunnel link %s received close message for %s", link.Remote(), channel) // the entire listener was closed by the remote side so we need to // remove the channel mapping for it. should we also close sessions? if sessionId == "listener" { @@ -1365,9 +1363,8 @@ func (t *tun) Listen(channel string, opts ...ListenOption) (Listener, error) { } func (t *tun) Links() []Link { - links := make([]Link, 0, len(t.links)) - t.RLock() + links := make([]Link, 0, len(t.links)) for _, link := range t.links { links = append(links, link) From f6b4a9da1ca0bfc310614dff514ab256c30b04e9 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 12 Dec 2019 23:20:31 +0000 Subject: [PATCH 013/788] strip some code --- network/default.go | 25 ++++++++++++--------- tunnel/default.go | 55 ++++++---------------------------------------- 2 files changed, 22 insertions(+), 58 deletions(-) diff --git a/network/default.go b/network/default.go index 46cdcd4f..18baab4b 100644 --- a/network/default.go +++ b/network/default.go @@ -682,11 +682,6 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { log.Tracef("Network router flushing routes for: %s", pbRtrSolicit.Id) - // advertise all the routes when a new node has connected - if err := n.router.Solicit(); err != nil { - log.Debugf("Network failed to solicit routes: %s", err) - } - peer := &node{ id: pbRtrSolicit.Id, link: m.msg.Header["Micro-Link"], @@ -698,6 +693,11 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { default: // don't block } + + // advertise all the routes when a new node has connected + if err := n.router.Solicit(); err != nil { + log.Debugf("Network failed to solicit routes: %s", err) + } } case <-n.closed: return @@ -773,10 +773,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { log.Debugf("Network failed to advertise peers: %v", err) } - // advertise all the routes when a new node has connected - if err := n.router.Solicit(); err != nil { - log.Debugf("Network failed to solicit routes: %s", err) - } + <-time.After(time.Millisecond * 100) // specify that we're soliciting select { @@ -784,6 +781,12 @@ func (n *network) processNetChan(listener tunnel.Listener) { default: // don't block } + + // advertise all the routes when a new node has connected + if err := n.router.Solicit(); err != nil { + log.Debugf("Network failed to solicit routes: %s", err) + } + }() case "peer": // mark the time the message has been received @@ -829,7 +832,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { } // wait for a second - <-time.After(time.Second) + <-time.After(time.Millisecond * 100) // then solicit this peer if err := n.sendTo("solicit", ControlChannel, peer, msg); err != nil { @@ -1373,6 +1376,7 @@ func (n *network) Close() error { default: // TODO: send close message to the network channel close(n.closed) + // set connected to false n.connected = false @@ -1389,6 +1393,7 @@ func (n *network) Close() error { if err := n.sendMsg("close", NetworkChannel, msg); err != nil { log.Debugf("Network failed to send close message: %s", err) } + <-time.After(time.Millisecond * 100) } return n.close() diff --git a/tunnel/default.go b/tunnel/default.go index 83c85a64..c8927404 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -42,9 +42,6 @@ type tun struct { // close channel closed chan bool - // control channel to indicate link change - updated chan bool - // a map of sessions based on Micro-Tunnel-Channel sessions map[string]*session @@ -266,7 +263,6 @@ func (t *tun) manageLink(link *link) { // manageLinks is a function that can be called to immediately to link setup // it purges dead links while generating new links for any nodes not connected func (t *tun) manageLinks() { - // if we need to notify of updates delLinks := make(map[*link]string) connected := make(map[string]bool) @@ -323,9 +319,6 @@ func (t *tun) manageLinks() { } t.Unlock() - - // links were deleted so notify - go t.notify() } var wg sync.WaitGroup @@ -359,9 +352,6 @@ func (t *tun) manageLinks() { t.links[node] = link t.Unlock() - - // notify ourselves of the change - go t.notify() }(node) } @@ -371,17 +361,6 @@ func (t *tun) manageLinks() { // process outgoing messages sent by all local sessions func (t *tun) process() { - // wait for the first update - <-t.updated - - // get the list of links - var links []*link - t.RLock() - for _, link := range t.links { - links = append(links, link) - } - t.RUnlock() - // manage the send buffer // all pseudo sessions throw everything down this for { @@ -391,8 +370,10 @@ func (t *tun) process() { var sendTo []*link var err error + t.RLock() + // build the list of links ot send to - for _, link := range links { + for _, link := range t.links { // get the values we need link.RLock() id := link.id @@ -443,6 +424,8 @@ func (t *tun) process() { sendTo = append(sendTo, link) } + t.RUnlock() + // no links to send to if len(sendTo) == 0 { log.Debugf("No links to send message type: %s channel: %s", msg.typ, msg.channel) @@ -452,15 +435,6 @@ func (t *tun) process() { // send the message t.sendTo(sendTo, msg) - case <-t.updated: - t.RLock() - var newLinks []*link - for _, link := range t.links { - newLinks = append(newLinks, link) - } - t.RUnlock() - // links were updated - links = newLinks case <-t.closed: return } @@ -582,18 +556,6 @@ func (t *tun) delLink(remote string) { } t.Unlock() - - // let ourselves know of a link change - go t.notify() -} - -// notify ourselves of a link change -func (t *tun) notify() { - select { - case t.updated <- true: - // unblock after a second - case <-time.After(time.Second): - } } // process incoming messages @@ -670,8 +632,6 @@ func (t *tun) listen(link *link) { t.links[link.Remote()] = link t.Unlock() - // notify of link change - go t.notify() // send back an announcement of our channels discovery go t.announce("", "", link) // ask for the things on the other wise @@ -691,6 +651,8 @@ func (t *tun) listen(link *link) { // remove the channel mapping for it. should we also close sessions? if sessionId == "listener" { link.delChannel(channel) + // TODO: find all the non listener unicast sessions + // and close them. think aboud edge cases first continue } @@ -949,9 +911,6 @@ func (t *tun) setupLinks() { // wait for all threads to finish wg.Wait() - - // notify ourselves of the update - t.notify() } // connect the tunnel to all the nodes and listen for incoming tunnel connections From caa74d1b5ff2b61862927fbefef328097fe25e0b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 12 Dec 2019 23:29:44 +0000 Subject: [PATCH 014/788] fix build --- tunnel/default.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tunnel/default.go b/tunnel/default.go index c8927404..41e13c5f 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -66,7 +66,6 @@ func newTunnel(opts ...Option) *tun { token: options.Token, send: make(chan *message, 128), closed: make(chan bool), - updated: make(chan bool, 3), sessions: make(map[string]*session), links: make(map[string]*link), } From b0b6b8fce2bf070c9cda2c2088999f1e77a75501 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 13 Dec 2019 15:27:47 +0000 Subject: [PATCH 015/788] final updates --- network/default.go | 190 +++++++++++++++++++++++++++++++++++++-------- network/network.go | 4 +- network/node.go | 6 +- tunnel/default.go | 10 ++- 4 files changed, 169 insertions(+), 41 deletions(-) diff --git a/network/default.go b/network/default.go index 18baab4b..e8489f34 100644 --- a/network/default.go +++ b/network/default.go @@ -170,7 +170,7 @@ func newNetwork(opts ...Option) Network { tunClient: make(map[string]transport.Client), peerLinks: make(map[string]tunnel.Link), discovered: make(chan bool, 1), - solicited: make(chan *node, 1), + solicited: make(chan *node, 32), } network.node.network = network @@ -667,7 +667,7 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { log.Debugf("Network failed to process advert %s: %v", advert.Id, err) } case "solicit": - pbRtrSolicit := &pbRtr.Solicit{} + pbRtrSolicit := new(pbRtr.Solicit) if err := proto.Unmarshal(m.msg.Body, pbRtrSolicit); err != nil { log.Debugf("Network fail to unmarshal solicit message: %v", err) continue @@ -768,14 +768,19 @@ func (n *network) processNetChan(listener tunnel.Listener) { msg := PeersToProto(n.node, MaxDepth) go func() { - // advertise yourself to the network + // advertise yourself to the new node if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { log.Debugf("Network failed to advertise peers: %v", err) } <-time.After(time.Millisecond * 100) - // specify that we're soliciting + // ask for the new nodes routes + if err := n.sendTo("solicit", ControlChannel, peer, msg); err != nil { + log.Debugf("Network failed to send solicit message: %s", err) + } + + // now advertise our own routes select { case n.solicited <- peer: default: @@ -786,7 +791,6 @@ func (n *network) processNetChan(listener tunnel.Listener) { if err := n.router.Solicit(); err != nil { log.Debugf("Network failed to solicit routes: %s", err) } - }() case "peer": // mark the time the message has been received @@ -838,6 +842,18 @@ func (n *network) processNetChan(listener tunnel.Listener) { if err := n.sendTo("solicit", ControlChannel, peer, msg); err != nil { log.Debugf("Network failed to send solicit message: %s", err) } + + // now advertise our own routes + select { + case n.solicited <- peer: + default: + // don't block + } + + // advertise all the routes when a new node has connected + if err := n.router.Solicit(); err != nil { + log.Debugf("Network failed to solicit routes: %s", err) + } }() continue @@ -850,12 +866,15 @@ func (n *network) processNetChan(listener tunnel.Listener) { log.Tracef("Network peer exists, refreshing: %s", pbNetPeer.Node.Id) // update lastSeen time for the peer - if err := n.RefreshPeer(pbNetPeer.Node.Id, peer.link, now); err != nil { + if err := n.RefreshPeer(peer.id, peer.link, now); err != nil { log.Debugf("Network failed refreshing peer %s: %v", pbNetPeer.Node.Id, err) } // NOTE: we don't unpack MaxDepth toplogy peer = UnpackPeerTopology(pbNetPeer, now, MaxDepth-1) + // update the link + peer.link = m.msg.Header["Micro-Link"] + log.Tracef("Network updating topology of node: %s", n.node.id) if err := n.node.UpdatePeer(peer); err != nil { log.Debugf("Network failed to update peers: %v", err) @@ -954,22 +973,109 @@ func (n *network) manage() { resolve := time.NewTicker(ResolveTime) defer resolve.Stop() + // list of links we've sent to + links := make(map[string]time.Time) + for { select { case <-n.closed: return case <-announce.C: - // jitter - j := rand.Int63n(int64(AnnounceTime.Seconds() / 2.0)) - time.Sleep(time.Duration(j) * time.Second) + current := make(map[string]time.Time) - // TODO: intermittently flip between peer selection - // and full broadcast pick a random set of peers + // build link map of current links + for _, link := range n.tunnel.Links() { + if n.isLoopback(link) { + continue + } + // get an existing timestamp if it exists + current[link.Id()] = links[link.Id()] + } + // replace link map + // we do this because a growing map is not + // garbage collected + links = current + + n.RLock() + var i int + // create a list of peers to send to + var peers []*node + + // check peers to see if they need to be sent to + for _, peer := range n.peers { + if i >= 3 { + break + } + + // get last sent + lastSent := links[peer.link] + + // check when we last sent to the peer + // and send a peer message if we havent + if lastSent.IsZero() || time.Since(lastSent) > KeepAliveTime { + link := peer.link + id := peer.id + + // might not exist for some weird reason + if len(link) == 0 { + // set the link via peer links + l, ok := n.peerLinks[peer.address] + if ok { + log.Debugf("Network link not found for peer %s cannot announce", peer.id) + continue + } + link = l.Id() + } + + // add to the list of peers we're going to send to + peers = append(peers, &node{ + id: id, + link: link, + }) + + // increment our count + i++ + } + } + + n.RUnlock() + + // peers to proto msg := PeersToProto(n.node, MaxDepth) - // advertise yourself to the network - if err := n.sendMsg("peer", NetworkChannel, msg); err != nil { - log.Debugf("Network failed to advertise peers: %v", err) + + // we're only going to send to max 3 peers at any given tick + for _, peer := range peers { + + // advertise yourself to the network + if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { + log.Debugf("Network failed to advertise peer %s: %v", peer.id, err) + continue + } + + // update last sent time + links[peer.link] = time.Now() + } + + // now look at links we may not have sent to. this may occur + // where a connect message was lost + for link, lastSent := range links { + if !lastSent.IsZero() { + continue + } + + peer := &node{ + // unknown id of the peer + link: link, + } + + // unknown link and peer so lets do the connect flow + if err := n.sendTo("connect", NetworkChannel, peer, msg); err != nil { + log.Debugf("Network failed to advertise peer %s: %v", peer.id, err) + continue + } + + links[peer.link] = time.Now() } case <-prune.C: pruned := n.PruneStalePeers(PruneTime) @@ -1052,15 +1158,27 @@ func (n *network) sendTo(method, channel string, peer *node, msg proto.Message) } defer c.Close() - log.Debugf("Network sending %s message from: %s to %s", method, n.options.Id, peer.id) + id := peer.id - return c.Send(&transport.Message{ + if len(id) == 0 { + id = peer.link + } + + log.Debugf("Network sending %s message from: %s to %s", method, n.options.Id, id) + + tmsg := &transport.Message{ Header: map[string]string{ "Micro-Method": method, - "Micro-Peer": peer.id, }, Body: body, - }) + } + + // setting the peer header + if len(peer.id) > 0 { + tmsg.Header["Micro-Peer"] = peer.id + } + + return c.Send(tmsg) } // sendMsg sends a message to the tunnel channel @@ -1128,6 +1246,27 @@ func (n *network) updatePeerLinks(peer *node) error { return nil } +// isLoopback checks if a link is a loopback to ourselves +func (n *network) isLoopback(link tunnel.Link) bool { + // our advertise address + loopback := n.server.Options().Advertise + // actual address + address := n.tunnel.Address() + + // skip loopback + if link.Loopback() { + return true + } + + // if remote is ourselves + switch link.Remote() { + case loopback, address: + return true + } + + return false +} + // connect will wait for a link to be established and send the connect // message. We're trying to ensure convergence pretty quickly. So we want // to hear back. In the case we become completely disconnected we'll @@ -1137,11 +1276,6 @@ func (n *network) connect() { var discovered bool var attempts int - // our advertise address - loopback := n.server.Options().Advertise - // actual address - address := n.tunnel.Address() - for { // connected is used to define if the link is connected var connected bool @@ -1149,13 +1283,7 @@ func (n *network) connect() { // check the links state for _, link := range n.tunnel.Links() { // skip loopback - if link.Loopback() { - continue - } - - // if remote is ourselves - switch link.Remote() { - case loopback, address: + if n.isLoopback(link) { continue } @@ -1239,7 +1367,6 @@ func (n *network) Connect() error { netListener, err := n.tunnel.Listen( NetworkChannel, tunnel.ListenMode(tunnel.Multicast), - tunnel.ListenTimeout(AnnounceTime*2), ) if err != nil { return err @@ -1249,7 +1376,6 @@ func (n *network) Connect() error { ctrlListener, err := n.tunnel.Listen( ControlChannel, tunnel.ListenMode(tunnel.Multicast), - tunnel.ListenTimeout(router.AdvertiseTableTick*2), ) if err != nil { return err diff --git a/network/network.go b/network/network.go index e927241b..571deee1 100644 --- a/network/network.go +++ b/network/network.go @@ -16,7 +16,9 @@ var ( // ResolveTime defines time interval to periodically resolve network nodes ResolveTime = 1 * time.Minute // AnnounceTime defines time interval to periodically announce node neighbours - AnnounceTime = 30 * time.Second + AnnounceTime = 1 * time.Second + // KeepAliveTime is the time in which we want to have sent a message to a peer + KeepAliveTime = 30 * time.Second // PruneTime defines time interval to periodically check nodes that need to be pruned // due to their not announcing their presence within this time interval PruneTime = 90 * time.Second diff --git a/network/node.go b/network/node.go index 658c0964..0d79ffc5 100644 --- a/network/node.go +++ b/network/node.go @@ -140,10 +140,8 @@ func (n *node) RefreshPeer(id, link string, now time.Time) error { // set peer link peer.link = link - - if peer.lastSeen.Before(now) { - peer.lastSeen = now - } + // set last seen + peer.lastSeen = now return nil } diff --git a/tunnel/default.go b/tunnel/default.go index 41e13c5f..89de3dfb 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -484,6 +484,11 @@ func (t *tun) sendTo(links []*link, msg *message) error { // error channel for call errChan := make(chan error, len(links)) + // execute in parallel + sendTo := func(l *link, m *transport.Message, errChan chan error) { + errChan <- send(l, m) + } + // send the message for _, link := range links { // send the message via the current link @@ -501,10 +506,7 @@ func (t *tun) sendTo(links []*link, msg *message) error { m.Header[k] = v } - // execute in parallel - go func() { - errChan <- send(link, m) - }() + go sendTo(link, m, errChan) continue } From 5602b93d7a1ac8e20b02658b562f1f3d34a9b8fa Mon Sep 17 00:00:00 2001 From: gemantic Date: Sat, 14 Dec 2019 10:23:55 +0800 Subject: [PATCH 016/788] support ctx as input params, error as output for MockClient.Call --- client/mock/mock.go | 18 ++++++++++++++++-- client/mock/mock_test.go | 11 ++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/client/mock/mock.go b/client/mock/mock.go index 6ee8f1f8..ba182478 100644 --- a/client/mock/mock.go +++ b/client/mock/mock.go @@ -84,10 +84,24 @@ func (m *MockClient) Call(ctx context.Context, req client.Request, rsp interface response := r.Response if t := reflect.TypeOf(r.Response); t.Kind() == reflect.Func { var request []reflect.Value - if t.NumIn() == 1 { + switch t.NumIn() { + case 1: + // one input params: (req) request = append(request, reflect.ValueOf(req.Body())) + case 2: + // two input params: (ctx, req) + request = append(request, reflect.ValueOf(ctx), reflect.ValueOf(req.Body())) + } + + responseValue := reflect.ValueOf(r.Response).Call(request) + response = responseValue[0].Interface() + if len(responseValue) == 2 { + // make it possible to return error in response function + respErr, ok := responseValue[1].Interface().(error) + if ok && respErr != nil { + return respErr + } } - response = reflect.ValueOf(r.Response).Call(request)[0].Interface() } v.Set(reflect.ValueOf(response)) diff --git a/client/mock/mock_test.go b/client/mock/mock_test.go index 4f00f8a9..0730610f 100644 --- a/client/mock/mock_test.go +++ b/client/mock/mock_test.go @@ -2,6 +2,7 @@ package mock import ( "context" + "fmt" "testing" "github.com/micro/go-micro/errors" @@ -24,6 +25,12 @@ func TestClient(t *testing.T) { } return "wrong" }}, + {Endpoint: "Foo.FuncWithRequestContextAndResponse", Response: func(ctx context.Context, req interface{}) string { + return "something" + }}, + {Endpoint: "Foo.FuncWithRequestContextAndResponseError", Response: func(ctx context.Context, req interface{}) (string, error) { + return "something", fmt.Errorf("mock error") + }}, } c := NewClient(Response("go.mock", response)) @@ -35,7 +42,9 @@ func TestClient(t *testing.T) { err := c.Call(context.TODO(), req, &rsp) if err != r.Error { - t.Fatalf("Expecter error %v got %v", r.Error, err) + if r.Endpoint != "Foo.FuncWithRequestContextAndResponseError" { + t.Fatalf("Expecter error %v got %v", r.Error, err) + } } t.Log(rsp) From 572fe5831441e6a58071e3e17789f6d4f21444e1 Mon Sep 17 00:00:00 2001 From: jamsonzan <805373357@qq.com> Date: Sun, 15 Dec 2019 15:05:19 +0800 Subject: [PATCH 017/788] comment --- client/options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/options.go b/client/options.go index 5a7654a4..694a2fe9 100644 --- a/client/options.go +++ b/client/options.go @@ -160,7 +160,7 @@ func PoolSize(d int) Option { } } -// PoolSize sets the connection pool size +// PoolTTL sets the connection pool ttl func PoolTTL(d time.Duration) Option { return func(o *Options) { o.PoolTTL = d From 0131e9468f5e2f643e69edfb74e3f0da3f3648e0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 16 Dec 2019 12:13:18 +0000 Subject: [PATCH 018/788] change use of store namespace/prefix in sql store --- store/options.go | 9 ++++++ store/postgresql/postgresql.go | 37 ++++++++++++++++-------- store/service/service.go | 51 +++++++++++++++++++++++++++++----- 3 files changed, 79 insertions(+), 18 deletions(-) diff --git a/store/options.go b/store/options.go index 99014362..f5dbf7e2 100644 --- a/store/options.go +++ b/store/options.go @@ -4,6 +4,15 @@ import ( "github.com/micro/go-micro/config/options" ) +type Options struct { + // nodes to connect to + Nodes []string + // Namespace of the store + Namespace string + // Prefix of the keys used + Prefix string +} + // Nodes is a list of nodes used to back the store func Nodes(a ...string) options.Option { return options.WithValue("store.nodes", a) diff --git a/store/postgresql/postgresql.go b/store/postgresql/postgresql.go index 58fa935c..3cce21a6 100644 --- a/store/postgresql/postgresql.go +++ b/store/postgresql/postgresql.go @@ -17,18 +17,22 @@ import ( // DefaultNamespace is the namespace that the sql store // will use if no namespace is provided. -const DefaultNamespace = "micro" +var ( + DefaultNamespace = "micro" + DefaultPrefix = "micro" +) type sqlStore struct { db *sql.DB - table string + database string + table string options.Options } // List all the known records func (s *sqlStore) List() ([]*store.Record, error) { - q, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM micro.%s;", s.table)) + q, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s;", s.database, s.table)) if err != nil { return nil, err } @@ -73,7 +77,7 @@ func (s *sqlStore) List() ([]*store.Record, error) { // Read all records with keys func (s *sqlStore) Read(keys ...string) ([]*store.Record, error) { - q, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM micro.%s WHERE key = $1;", s.table)) + q, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key = $1;", s.database, s.table)) if err != nil { return nil, err } @@ -105,11 +109,11 @@ func (s *sqlStore) Read(keys ...string) ([]*store.Record, error) { // Write records func (s *sqlStore) Write(rec ...*store.Record) error { - q, err := s.db.Prepare(fmt.Sprintf(`INSERT INTO micro.%s(key, value, expiry) + q, err := s.db.Prepare(fmt.Sprintf(`INSERT INTO %s.%s(key, value, expiry) VALUES ($1, $2::bytea, $3) ON CONFLICT (key) DO UPDATE - SET value = EXCLUDED.value, expiry = EXCLUDED.expiry;`, s.table)) + SET value = EXCLUDED.value, expiry = EXCLUDED.expiry;`, s.database, s.table)) if err != nil { return err } @@ -130,7 +134,7 @@ func (s *sqlStore) Write(rec ...*store.Record) error { // Delete records with keys func (s *sqlStore) Delete(keys ...string) error { - q, err := s.db.Prepare(fmt.Sprintf("DELETE FROM micro.%s WHERE key = $1;", s.table)) + q, err := s.db.Prepare(fmt.Sprintf("DELETE FROM %s.%s WHERE key = $1;", s.database, s.table)) if err != nil { return err } @@ -151,10 +155,21 @@ func (s *sqlStore) initDB(options options.Options) error { // Get the store.namespace option, or use sql.DefaultNamespace namespaceOpt, found := options.Values().Get("store.namespace") if !found { - s.table = DefaultNamespace + s.database = DefaultNamespace } else { if namespace, ok := namespaceOpt.(string); ok { - s.table = namespace + s.database = namespace + } else { + return errors.New("store.namespace option must be a string") + } + } + // Get the store.namespace option, or use sql.DefaultNamespace + prefixOpt, found := options.Values().Get("store.prefix") + if !found { + s.table = DefaultPrefix + } else { + if prefix, ok := prefixOpt.(string); ok { + s.table = prefix } else { return errors.New("store.namespace option must be a string") } @@ -171,13 +186,13 @@ func (s *sqlStore) initDB(options options.Options) error { } // Create a table for the Store namespace - tableq, err := s.db.Prepare(fmt.Sprintf(`CREATE TABLE IF NOT EXISTS micro.%s + tableq, err := s.db.Prepare(fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s.%s ( key text COLLATE "default" NOT NULL, value bytea, expiry timestamp with time zone, CONSTRAINT %s_pkey PRIMARY KEY (key) - );`, s.table, s.table)) + );`, s.database, s.table, s.table)) if err != nil { return errors.Wrap(err, "SQL statement preparation failed") } diff --git a/store/service/service.go b/store/service/service.go index 1cb486bc..e0432016 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -8,6 +8,7 @@ import ( "github.com/micro/go-micro/client" "github.com/micro/go-micro/config/options" + "github.com/micro/go-micro/metadata" "github.com/micro/go-micro/store" pb "github.com/micro/go-micro/store/service/proto" ) @@ -15,16 +16,38 @@ import ( type serviceStore struct { options.Options + // Namespace to use + Namespace string + // Addresses of the nodes Nodes []string + // Prefix to use + Prefix string + // store service client Client pb.StoreService } +func (s *serviceStore) Context() context.Context { + ctx := context.Background() + + md := make(metadata.Metadata) + + if len(s.Namespace) > 0 { + md["Micro-Namespace"] = s.Namespace + } + + if len(s.Prefix) > 0 { + md["Micro-Prefix"] = s.Prefix + } + + return metadata.NewContext(ctx, md) +} + // Sync all the known records func (s *serviceStore) List() ([]*store.Record, error) { - stream, err := s.Client.List(context.Background(), &pb.ListRequest{}, client.WithAddress(s.Nodes...)) + stream, err := s.Client.List(s.Context(), &pb.ListRequest{}, client.WithAddress(s.Nodes...)) if err != nil { return nil, err } @@ -54,7 +77,7 @@ func (s *serviceStore) List() ([]*store.Record, error) { // Read a record with key func (s *serviceStore) Read(keys ...string) ([]*store.Record, error) { - rsp, err := s.Client.Read(context.Background(), &pb.ReadRequest{ + rsp, err := s.Client.Read(s.Context(), &pb.ReadRequest{ Keys: keys, }, client.WithAddress(s.Nodes...)) if err != nil { @@ -84,7 +107,7 @@ func (s *serviceStore) Write(recs ...*store.Record) error { }) } - _, err := s.Client.Write(context.Background(), &pb.WriteRequest{ + _, err := s.Client.Write(s.Context(), &pb.WriteRequest{ Records: records, }, client.WithAddress(s.Nodes...)) @@ -93,7 +116,7 @@ func (s *serviceStore) Write(recs ...*store.Record) error { // Delete a record with key func (s *serviceStore) Delete(keys ...string) error { - _, err := s.Client.Delete(context.Background(), &pb.DeleteRequest{ + _, err := s.Client.Delete(s.Context(), &pb.DeleteRequest{ Keys: keys, }, client.WithAddress(s.Nodes...)) return err @@ -104,16 +127,30 @@ func NewStore(opts ...options.Option) store.Store { options := options.NewOptions(opts...) var nodes []string + var namespace string + var prefix string n, ok := options.Values().Get("store.nodes") if ok { nodes = n.([]string) } + ns, ok := options.Values().Get("store.namespace") + if ok { + namespace = ns.(string) + } + + prx, ok := options.Values().Get("store.prefix") + if ok { + prefix = prx.(string) + } + service := &serviceStore{ - Options: options, - Nodes: nodes, - Client: pb.NewStoreService("go.micro.store", client.DefaultClient), + Options: options, + Namespace: namespace, + Prefix: prefix, + Nodes: nodes, + Client: pb.NewStoreService("go.micro.store", client.DefaultClient), } return service From e8e112144f2a9eb0b87da6199ddda6838927e4d1 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Mon, 16 Dec 2019 14:15:30 +0000 Subject: [PATCH 019/788] Create database should take the name of the database --- store/postgresql/postgresql.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/store/postgresql/postgresql.go b/store/postgresql/postgresql.go index 3cce21a6..4162e1e1 100644 --- a/store/postgresql/postgresql.go +++ b/store/postgresql/postgresql.go @@ -176,13 +176,13 @@ func (s *sqlStore) initDB(options options.Options) error { } // Create "micro" schema - schema, err := s.db.Prepare("CREATE SCHEMA IF NOT EXISTS micro ;") + schema, err := s.db.Prepare(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s ;", s.database)) if err != nil { return err } _, err = schema.Exec() if err != nil { - return errors.Wrap(err, "Couldn't create Schema") + return errors.Wrap(err, "Couldn't create database") } // Create a table for the Store namespace From 59751c02e663a717935dd6f4a2537c71a8df8219 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 16 Dec 2019 14:38:51 +0000 Subject: [PATCH 020/788] change store options --- store/cloudflare/cloudflare.go | 42 +++------ store/cloudflare/options.go | 57 ++++++++++-- store/etcd/etcd.go | 21 ++--- store/memory/memory.go | 12 ++- store/options.go | 24 +++-- store/postgresql/postgresql.go | 139 ++++++++++------------------ store/postgresql/postgresql_test.go | 5 +- store/service/service.go | 35 ++----- 8 files changed, 156 insertions(+), 179 deletions(-) diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index 3b9a5e8c..20ce2bac 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -17,7 +17,6 @@ import ( "strconv" "time" - "github.com/micro/go-micro/config/options" "github.com/micro/go-micro/store" "github.com/pkg/errors" ) @@ -27,7 +26,7 @@ const ( ) type workersKV struct { - options.Options + options store.Options // cf account id account string // cf api token @@ -291,38 +290,25 @@ func (w *workersKV) request(ctx context.Context, method, path string, body inter // CF_API_TOKEN to a cloudflare API token scoped to Workers KV. // CF_ACCOUNT_ID to contain a string with your cloudflare account ID. // KV_NAMESPACE_ID to contain the namespace UUID for your KV storage. -func NewStore(opts ...options.Option) store.Store { - // create new Options - options := options.NewOptions(opts...) +func NewStore(opts ...store.Option) store.Store { + var options store.Options + for _, o := range opts { + o(&options) + } - // get values from the environment + // get options from environment account, token, namespace := getOptions() - // set api token from options if exists - if apiToken, ok := options.Values().Get("CF_API_TOKEN"); ok { - tk, ok := apiToken.(string) - if !ok { - log.Fatal("Store: Option CF_API_TOKEN contains a non-string") - } - token = tk + if len(account) == 0 { + account = getAccount(options.Context) } - // set account id from options if exists - if accountID, ok := options.Values().Get("CF_ACCOUNT_ID"); ok { - id, ok := accountID.(string) - if !ok { - log.Fatal("Store: Option CF_ACCOUNT_ID contains a non-string") - } - account = id + if len(token) == 0 { + token = getToken(options.Context) } - // set namespace from options if exists - if uuid, ok := options.Values().Get("KV_NAMESPACE_ID"); ok { - ns, ok := uuid.(string) - if !ok { - log.Fatal("Store: Option KV_NAMESPACE_ID contains a non-string") - } - namespace = ns + if len(namespace) == 0 { + namespace = getNamespace(options.Context) } // validate options are not blank or log.Fatal @@ -332,7 +318,7 @@ func NewStore(opts ...options.Option) store.Store { account: account, namespace: namespace, token: token, - Options: options, + options: options, httpClient: &http.Client{}, } } diff --git a/store/cloudflare/options.go b/store/cloudflare/options.go index 36dc7c10..d9670ff4 100644 --- a/store/cloudflare/options.go +++ b/store/cloudflare/options.go @@ -1,23 +1,60 @@ package cloudflare import ( - "github.com/micro/go-micro/config/options" + "context" + + "github.com/micro/go-micro/store" ) +func getOption(ctx context.Context, key string) string { + if ctx == nil { + return "" + } + val, ok := ctx.Value(key).(string) + if !ok { + return "" + } + return val +} + +func getToken(ctx context.Context) string { + return getOption(ctx, "CF_API_TOKEN") +} + +func getAccount(ctx context.Context) string { + return getOption(ctx, "CF_ACCOUNT_ID") +} + +func getNamespace(ctx context.Context) string { + return getOption(ctx, "KV_NAMESPACE_ID") +} + // Token sets the cloudflare api token -func Token(t string) options.Option { - // TODO: change to store.cf.api_token - return options.WithValue("CF_API_TOKEN", t) +func Token(t string) store.Option { + return func(o *store.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, "CF_API_TOKEN", t) + } } // Account sets the cloudflare account id -func Account(id string) options.Option { - // TODO: change to store.cf.account_id - return options.WithValue("CF_ACCOUNT_ID", id) +func Account(id string) store.Option { + return func(o *store.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, "CF_ACCOUNT_ID", id) + } } // Namespace sets the KV namespace -func Namespace(ns string) options.Option { - // TODO: change to store.cf.namespace - return options.WithValue("KV_NAMESPACE_ID", ns) +func Namespace(ns string) store.Option { + return func(o *store.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, "KV_NAMESPACE_ID", ns) + } } diff --git a/store/etcd/etcd.go b/store/etcd/etcd.go index 8ffa2d7d..c9bc4047 100644 --- a/store/etcd/etcd.go +++ b/store/etcd/etcd.go @@ -7,13 +7,12 @@ import ( client "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/micro/go-micro/config/options" "github.com/micro/go-micro/store" ) type ekv struct { - options.Options - kv client.KV + options store.Options + kv client.KV } func (e *ekv) Read(keys ...string) ([]*store.Record, error) { @@ -91,15 +90,15 @@ func (e *ekv) String() string { return "etcd" } -func NewStore(opts ...options.Option) store.Store { - options := options.NewOptions(opts...) - - var endpoints []string - - if e, ok := options.Values().Get("store.nodes"); ok { - endpoints = e.([]string) +func NewStore(opts ...store.Option) store.Store { + var options store.Options + for _, o := range opts { + o(&options) } + // get the endpoints + endpoints := options.Nodes + if len(endpoints) == 0 { endpoints = []string{"http://127.0.0.1:2379"} } @@ -113,7 +112,7 @@ func NewStore(opts ...options.Option) store.Store { } return &ekv{ - Options: options, + options: options, kv: client.NewKV(c), } } diff --git a/store/memory/memory.go b/store/memory/memory.go index 01d1a44c..78e85e82 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -5,12 +5,11 @@ import ( "sync" "time" - "github.com/micro/go-micro/config/options" "github.com/micro/go-micro/store" ) type memoryStore struct { - options.Options + options store.Options sync.RWMutex values map[string]*memoryRecord @@ -110,11 +109,14 @@ func (m *memoryStore) Delete(keys ...string) error { } // NewStore returns a new store.Store -func NewStore(opts ...options.Option) store.Store { - options := options.NewOptions(opts...) +func NewStore(opts ...store.Option) store.Store { + var options store.Options + for _, o := range opts { + o(&options) + } return &memoryStore{ - Options: options, + options: options, values: make(map[string]*memoryRecord), } } diff --git a/store/options.go b/store/options.go index f5dbf7e2..0161ed20 100644 --- a/store/options.go +++ b/store/options.go @@ -1,7 +1,7 @@ package store import ( - "github.com/micro/go-micro/config/options" + "context" ) type Options struct { @@ -11,20 +11,30 @@ type Options struct { Namespace string // Prefix of the keys used Prefix string + // Alternative options + Context context.Context } +type Option func(o *Options) + // Nodes is a list of nodes used to back the store -func Nodes(a ...string) options.Option { - return options.WithValue("store.nodes", a) +func Nodes(a ...string) Option { + return func(o *Options) { + o.Nodes = a + } } // Prefix sets a prefix to any key ids used -func Prefix(p string) options.Option { - return options.WithValue("store.prefix", p) +func Prefix(p string) Option { + return func(o *Options) { + o.Prefix = p + } } // Namespace offers a way to have multiple isolated // stores in the same backend, if supported. -func Namespace(n string) options.Option { - return options.WithValue("store.namespace", n) +func Namespace(ns string) Option { + return func(o *Options) { + o.Namespace = ns + } } diff --git a/store/postgresql/postgresql.go b/store/postgresql/postgresql.go index 4162e1e1..84c07d58 100644 --- a/store/postgresql/postgresql.go +++ b/store/postgresql/postgresql.go @@ -4,15 +4,13 @@ package postgresql import ( "database/sql" "fmt" - "strings" "time" "unicode" "github.com/lib/pq" - "github.com/pkg/errors" - - "github.com/micro/go-micro/config/options" "github.com/micro/go-micro/store" + "github.com/micro/go-micro/util/log" + "github.com/pkg/errors" ) // DefaultNamespace is the namespace that the sql store @@ -27,7 +25,8 @@ type sqlStore struct { database string table string - options.Options + + options store.Options } // List all the known records @@ -151,38 +150,16 @@ func (s *sqlStore) Delete(keys ...string) error { return nil } -func (s *sqlStore) initDB(options options.Options) error { - // Get the store.namespace option, or use sql.DefaultNamespace - namespaceOpt, found := options.Values().Get("store.namespace") - if !found { - s.database = DefaultNamespace - } else { - if namespace, ok := namespaceOpt.(string); ok { - s.database = namespace - } else { - return errors.New("store.namespace option must be a string") - } - } - // Get the store.namespace option, or use sql.DefaultNamespace - prefixOpt, found := options.Values().Get("store.prefix") - if !found { - s.table = DefaultPrefix - } else { - if prefix, ok := prefixOpt.(string); ok { - s.table = prefix - } else { - return errors.New("store.namespace option must be a string") - } - } - +func (s *sqlStore) initDB() { // Create "micro" schema schema, err := s.db.Prepare(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s ;", s.database)) if err != nil { - return err + log.Fatal(err) } + _, err = schema.Exec() if err != nil { - return errors.Wrap(err, "Couldn't create database") + log.Fatal(errors.Wrap(err, "Couldn't create database")) } // Create a table for the Store namespace @@ -194,73 +171,59 @@ func (s *sqlStore) initDB(options options.Options) error { CONSTRAINT %s_pkey PRIMARY KEY (key) );`, s.database, s.table, s.table)) if err != nil { - return errors.Wrap(err, "SQL statement preparation failed") - } - _, err = tableq.Exec() - if err != nil { - return errors.Wrap(err, "Couldn't create table") + log.Fatal(errors.Wrap(err, "SQL statement preparation failed")) } - return nil + _, err = tableq.Exec() + if err != nil { + log.Fatal(errors.Wrap(err, "Couldn't create table")) + } } // New returns a new micro Store backed by sql -func New(opts ...options.Option) (store.Store, error) { - options := options.NewOptions(opts...) - driver, dataSourceName, err := validateOptions(options) +func New(opts ...store.Option) store.Store { + var options store.Options + for _, o := range opts { + o(&options) + } + + nodes := options.Nodes + if len(nodes) == 0 { + nodes = []string{"localhost:26257"} + } + + namespace := options.Namespace + if len(namespace) == 0 { + namespace = DefaultNamespace + } + + prefix := options.Prefix + if len(prefix) == 0 { + prefix = DefaultPrefix + } + + for _, r := range namespace { + if !unicode.IsLetter(r) { + log.Fatal("store.namespace must only contain letters") + } + } + + // create source from first node + source := fmt.Sprintf("host=%s", nodes[0]) + db, err := sql.Open("pq", source) if err != nil { - return nil, err - } - if !strings.Contains(dataSourceName, " ") { - dataSourceName = fmt.Sprintf("host=%s", dataSourceName) - } - db, err := sql.Open(driver, dataSourceName) - if err != nil { - return nil, err + log.Fatal(err) } + if err := db.Ping(); err != nil { - return nil, err + log.Fatal(err) } + s := &sqlStore{ - db: db, + db: db, + database: namespace, + table: prefix, } - return s, s.initDB(options) -} - -// validateOptions checks whether the provided options are valid, then returns the driver -// and data source name. -func validateOptions(options options.Options) (driver, dataSourceName string, err error) { - driverOpt, found := options.Values().Get("store.sql.driver") - if !found { - return "", "", errors.New("No store.sql.driver option specified") - } - nodesOpt, found := options.Values().Get("store.nodes") - if !found { - return "", "", errors.New("No store.nodes option specified (expected a database connection string)") - } - driver, ok := driverOpt.(string) - if !ok { - return "", "", errors.New("store.sql.driver option must be a string") - } - nodes, ok := nodesOpt.([]string) - if !ok { - return "", "", errors.New("store.nodes option must be a []string") - } - if len(nodes) != 1 { - return "", "", errors.New("expected only 1 store.nodes option") - } - namespaceOpt, found := options.Values().Get("store.namespace") - if found { - namespace, ok := namespaceOpt.(string) - if !ok { - return "", "", errors.New("store.namespace must me a string") - } - for _, r := range namespace { - if !unicode.IsLetter(r) { - return "", "", errors.New("store.namespace must only contain letters") - } - } - } - return driver, nodes[0], nil + return s } diff --git a/store/postgresql/postgresql_test.go b/store/postgresql/postgresql_test.go index fffc974e..692aebeb 100644 --- a/store/postgresql/postgresql_test.go +++ b/store/postgresql/postgresql_test.go @@ -27,13 +27,10 @@ func TestSQL(t *testing.T) { } db.Close() - sqlStore, err := New( + sqlStore := New( store.Namespace("testsql"), store.Nodes(connection), ) - if err != nil { - t.Fatal(err.Error()) - } records, err := sqlStore.List() if err != nil { diff --git a/store/service/service.go b/store/service/service.go index e0432016..37a7a030 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -7,14 +7,13 @@ import ( "time" "github.com/micro/go-micro/client" - "github.com/micro/go-micro/config/options" "github.com/micro/go-micro/metadata" "github.com/micro/go-micro/store" pb "github.com/micro/go-micro/store/service/proto" ) type serviceStore struct { - options.Options + options store.Options // Namespace to use Namespace string @@ -123,33 +122,17 @@ func (s *serviceStore) Delete(keys ...string) error { } // NewStore returns a new store service implementation -func NewStore(opts ...options.Option) store.Store { - options := options.NewOptions(opts...) - - var nodes []string - var namespace string - var prefix string - - n, ok := options.Values().Get("store.nodes") - if ok { - nodes = n.([]string) - } - - ns, ok := options.Values().Get("store.namespace") - if ok { - namespace = ns.(string) - } - - prx, ok := options.Values().Get("store.prefix") - if ok { - prefix = prx.(string) +func NewStore(opts ...store.Option) store.Store { + var options store.Options + for _, o := range opts { + o(&options) } service := &serviceStore{ - Options: options, - Namespace: namespace, - Prefix: prefix, - Nodes: nodes, + options: options, + Namespace: options.Namespace, + Prefix: options.Prefix, + Nodes: options.Nodes, Client: pb.NewStoreService("go.micro.store", client.DefaultClient), } From 03700ae6c0154651ddd9430ebe391c6234310bb3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 16 Dec 2019 14:55:47 +0000 Subject: [PATCH 021/788] Replace proxy options --- proxy/grpc/grpc.go | 26 ++++++++--------------- proxy/http/http.go | 20 ++++++++---------- proxy/mucp/mucp.go | 50 +++++++++++++++++---------------------------- proxy/options.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++ proxy/proxy.go | 36 -------------------------------- 5 files changed, 88 insertions(+), 95 deletions(-) create mode 100644 proxy/options.go diff --git a/proxy/grpc/grpc.go b/proxy/grpc/grpc.go index 571822ea..2a401c0c 100644 --- a/proxy/grpc/grpc.go +++ b/proxy/grpc/grpc.go @@ -9,7 +9,6 @@ import ( "github.com/micro/go-micro/client" "github.com/micro/go-micro/client/grpc" "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/config/options" "github.com/micro/go-micro/proxy" "github.com/micro/go-micro/server" ) @@ -19,7 +18,7 @@ import ( // If the service matches the Name it will use the server.DefaultRouter. type Proxy struct { // The proxy options - options.Options + options proxy.Options // Endpoint specified the fixed endpoint to call. Endpoint string @@ -138,22 +137,15 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server } // NewProxy returns a new grpc proxy server -func NewProxy(opts ...options.Option) proxy.Proxy { +func NewProxy(opts ...proxy.Option) proxy.Proxy { + var options proxy.Options + for _, o := range opts { + o(&options) + } + p := new(Proxy) - p.Options = options.NewOptions(opts...) - p.Options.Init(options.WithString("grpc")) - - // get endpoint - ep, ok := p.Options.Values().Get("proxy.endpoint") - if ok { - p.Endpoint = ep.(string) - } - - // get client - c, ok := p.Options.Values().Get("proxy.client") - if ok { - p.Client = c.(client.Client) - } + p.Endpoint = options.Endpoint + p.Client = options.Client return p } diff --git a/proxy/http/http.go b/proxy/http/http.go index 64b4384b..9b8b9188 100644 --- a/proxy/http/http.go +++ b/proxy/http/http.go @@ -10,7 +10,6 @@ import ( "net/url" "path" - "github.com/micro/go-micro/config/options" "github.com/micro/go-micro/errors" "github.com/micro/go-micro/proxy" "github.com/micro/go-micro/server" @@ -18,7 +17,7 @@ import ( // Proxy will proxy rpc requests as http POST requests. It is a server.Proxy type Proxy struct { - options.Options + options proxy.Options // The http backend to call Endpoint string @@ -197,16 +196,15 @@ func NewSingleHostProxy(url string) proxy.Proxy { } // NewProxy returns a new proxy which will route using a http client -func NewProxy(opts ...options.Option) proxy.Proxy { - p := new(Proxy) - p.Options = options.NewOptions(opts...) - p.Options.Init(options.WithString("http")) - - // get endpoint - ep, ok := p.Options.Values().Get("proxy.endpoint") - if ok { - p.Endpoint = ep.(string) +func NewProxy(opts ...proxy.Option) proxy.Proxy { + var options proxy.Options + for _, o := range opts { + o(&options) } + p := new(Proxy) + p.Endpoint = options.Endpoint + p.options = options + return p } diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index d565d47a..98a3b7b6 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -14,7 +14,6 @@ import ( "github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/codec" "github.com/micro/go-micro/codec/bytes" - "github.com/micro/go-micro/config/options" "github.com/micro/go-micro/errors" "github.com/micro/go-micro/metadata" "github.com/micro/go-micro/proxy" @@ -27,7 +26,7 @@ import ( // If no endpoint is specified it will call a service using the client. type Proxy struct { // embed options - options.Options + options proxy.Options // Endpoint specifies the fixed service endpoint to call. Endpoint string @@ -525,54 +524,43 @@ func (p *Proxy) serveRequest(ctx context.Context, link client.Client, service, e // NewSingleHostProxy returns a proxy which sends requests to a single backend func NewSingleHostProxy(endpoint string) *Proxy { return &Proxy{ - Options: options.NewOptions(), Endpoint: endpoint, } } // NewProxy returns a new proxy which will route based on mucp headers -func NewProxy(opts ...options.Option) proxy.Proxy { +func NewProxy(opts ...proxy.Option) proxy.Proxy { + var options proxy.Options + for _, o := range opts { + o(&options) + } + p := new(Proxy) p.Links = map[string]client.Client{} - p.Options = options.NewOptions(opts...) - p.Options.Init(options.WithString("mucp")) + p.Routes = make(map[string]map[uint64]router.Route) + p.options = options // get endpoint - ep, ok := p.Options.Values().Get("proxy.endpoint") - if ok { - p.Endpoint = ep.(string) - } - - // get client - c, ok := p.Options.Values().Get("proxy.client") - if ok { - p.Client = c.(client.Client) - } + p.Endpoint = options.Endpoint + // set the client + p.Client = options.Client + // get router + p.Router = options.Router // set the default client if p.Client == nil { p.Client = client.DefaultClient } - // get client - links, ok := p.Options.Values().Get("proxy.links") - if ok { - p.Links = links.(map[string]client.Client) - } - - // get router - r, ok := p.Options.Values().Get("proxy.router") - if ok { - p.Router = r.(router.Router) - } - // create default router and start it if p.Router == nil { p.Router = router.DefaultRouter } - - // routes cache - p.Routes = make(map[string]map[uint64]router.Route) + // set the links + if options.Links != nil { + // get client + p.Links = options.Links + } go func() { // continuously attempt to watch routes diff --git a/proxy/options.go b/proxy/options.go new file mode 100644 index 00000000..20ca9c4d --- /dev/null +++ b/proxy/options.go @@ -0,0 +1,51 @@ +// Package proxy is a transparent proxy built on the go-micro/server +package proxy + +import ( + "github.com/micro/go-micro/client" + "github.com/micro/go-micro/router" +) + +type Options struct { + // Specific endpoint to always call + Endpoint string + // The default client to use + Client client.Client + // The default router to use + Router router.Router + // Extra links for different clients + Links map[string]client.Client +} + +type Option func(o *Options) + +// WithEndpoint sets a proxy endpoint +func WithEndpoint(e string) Option { + return func(o *Options) { + o.Endpoint = e + } +} + +// WithClient sets the client +func WithClient(c client.Client) Option { + return func(o *Options) { + o.Client = c + } +} + +// WithRouter specifies the router to use +func WithRouter(r router.Router) Option { + return func(o *Options) { + o.Router = r + } +} + +// WithLink sets a link for outbound requests +func WithLink(name string, c client.Client) Option { + return func(o *Options) { + if o.Links == nil { + o.Links = make(map[string]client.Client) + } + o.Links[name] = c + } +} diff --git a/proxy/proxy.go b/proxy/proxy.go index e08926e9..7fabae76 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -4,15 +4,11 @@ package proxy import ( "context" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/config/options" - "github.com/micro/go-micro/router" "github.com/micro/go-micro/server" ) // Proxy can be used as a proxy server for go-micro services type Proxy interface { - options.Options // ProcessMessage handles inbound messages ProcessMessage(context.Context, server.Message) error // ServeRequest handles inbound requests @@ -22,35 +18,3 @@ type Proxy interface { var ( DefaultEndpoint = "localhost:9090" ) - -// WithEndpoint sets a proxy endpoint -func WithEndpoint(e string) options.Option { - return options.WithValue("proxy.endpoint", e) -} - -// WithClient sets the client -func WithClient(c client.Client) options.Option { - return options.WithValue("proxy.client", c) -} - -// WithRouter specifies the router to use -func WithRouter(r router.Router) options.Option { - return options.WithValue("proxy.router", r) -} - -// WithLink sets a link for outbound requests -func WithLink(name string, c client.Client) options.Option { - return func(o *options.Values) error { - var links map[string]client.Client - v, ok := o.Get("proxy.links") - if ok { - links = v.(map[string]client.Client) - } else { - links = map[string]client.Client{} - } - links[name] = c - // save the links - o.Set("proxy.links", links) - return nil - } -} From 303adca500489d12a4cf9f0350cf8031667e1a08 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 16 Dec 2019 15:09:59 +0000 Subject: [PATCH 022/788] rename postgres to cockroach --- .../postgresql.go => cockroach/cockroach.go} | 12 ++++++++---- .../cockroach_test.go} | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) rename store/{postgresql/postgresql.go => cockroach/cockroach.go} (95%) rename store/{postgresql/postgresql_test.go => cockroach/cockroach_test.go} (98%) diff --git a/store/postgresql/postgresql.go b/store/cockroach/cockroach.go similarity index 95% rename from store/postgresql/postgresql.go rename to store/cockroach/cockroach.go index 84c07d58..0467954f 100644 --- a/store/postgresql/postgresql.go +++ b/store/cockroach/cockroach.go @@ -1,9 +1,10 @@ -// Package postgresql implements a micro Store backed by sql -package postgresql +// Package cockroach implements the cockroach store +package cockroach import ( "database/sql" "fmt" + "strings" "time" "unicode" @@ -208,9 +209,12 @@ func New(opts ...store.Option) store.Store { } } + source := nodes[0] + if !strings.Contains(source, " ") { + source = fmt.Sprintf("host=%s", source) + } // create source from first node - source := fmt.Sprintf("host=%s", nodes[0]) - db, err := sql.Open("pq", source) + db, err := sql.Open("postgres", source) if err != nil { log.Fatal(err) } diff --git a/store/postgresql/postgresql_test.go b/store/cockroach/cockroach_test.go similarity index 98% rename from store/postgresql/postgresql_test.go rename to store/cockroach/cockroach_test.go index 692aebeb..45948634 100644 --- a/store/postgresql/postgresql_test.go +++ b/store/cockroach/cockroach_test.go @@ -1,4 +1,4 @@ -package postgresql +package cockroach import ( "database/sql" From 1ea6390eaedd0d144cb5d0d98531504b27fe7bbf Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 16 Dec 2019 15:18:20 +0000 Subject: [PATCH 023/788] Add proxy string method --- proxy/grpc/grpc.go | 4 ++++ proxy/http/http.go | 4 ++++ proxy/mucp/mucp.go | 4 ++++ proxy/proxy.go | 2 ++ 4 files changed, 14 insertions(+) diff --git a/proxy/grpc/grpc.go b/proxy/grpc/grpc.go index 2a401c0c..0caea36a 100644 --- a/proxy/grpc/grpc.go +++ b/proxy/grpc/grpc.go @@ -136,6 +136,10 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server } } +func (p *Proxy) String() string { + return "grpc" +} + // NewProxy returns a new grpc proxy server func NewProxy(opts ...proxy.Option) proxy.Proxy { var options proxy.Options diff --git a/proxy/http/http.go b/proxy/http/http.go index 9b8b9188..d01bf038 100644 --- a/proxy/http/http.go +++ b/proxy/http/http.go @@ -188,6 +188,10 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server } } +func (p *Proxy) String() string { + return "http" +} + // NewSingleHostProxy returns a router which sends requests to a single http backend func NewSingleHostProxy(url string) proxy.Proxy { return &Proxy{ diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index 98a3b7b6..0b059da3 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -521,6 +521,10 @@ func (p *Proxy) serveRequest(ctx context.Context, link client.Client, service, e } } +func (p *Proxy) String() string { + return "mucp" +} + // NewSingleHostProxy returns a proxy which sends requests to a single backend func NewSingleHostProxy(endpoint string) *Proxy { return &Proxy{ diff --git a/proxy/proxy.go b/proxy/proxy.go index 7fabae76..982ad3c6 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -13,6 +13,8 @@ type Proxy interface { ProcessMessage(context.Context, server.Message) error // ServeRequest handles inbound requests ServeRequest(context.Context, server.Request, server.Response) error + // Name of the proxy protocol + String() string } var ( From 56619f274553fa7425fbc84c039384f64f5f3124 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Mon, 16 Dec 2019 17:11:13 +0000 Subject: [PATCH 024/788] Fix cockroachdb store implemetation --- store/cockroach/cockroach.go | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 0467954f..97123a98 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -32,13 +32,9 @@ type sqlStore struct { // List all the known records func (s *sqlStore) List() ([]*store.Record, error) { - q, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s;", s.database, s.table)) - if err != nil { - return nil, err - } + rows, err := s.db.Query(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s;", s.database, s.table)) var records []*store.Record var timehelper pq.NullTime - rows, err := q.Query() if err != nil { if err == sql.ErrNoRows { return records, nil @@ -47,6 +43,7 @@ func (s *sqlStore) List() ([]*store.Record, error) { } defer rows.Close() for rows.Next() { + println("next!") record := &store.Record{} if err := rows.Scan(&record.Key, &record.Value, &timehelper); err != nil { return records, err @@ -152,30 +149,25 @@ func (s *sqlStore) Delete(keys ...string) error { } func (s *sqlStore) initDB() { - // Create "micro" schema - schema, err := s.db.Prepare(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s ;", s.database)) + // Create the namespace's database + _, err := s.db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s ;", s.database)) if err != nil { log.Fatal(err) } - _, err = schema.Exec() + _, err = s.db.Exec(fmt.Sprintf("SET DATABASE = %s ;", s.database)) if err != nil { - log.Fatal(errors.Wrap(err, "Couldn't create database")) + log.Fatal(errors.Wrap(err, "Couldn't set database")) } - // Create a table for the Store namespace - tableq, err := s.db.Prepare(fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s.%s + // Create a table for the namespace's prefix + _, err = s.db.Exec(fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s ( - key text COLLATE "default" NOT NULL, + key text NOT NULL, value bytea, expiry timestamp with time zone, CONSTRAINT %s_pkey PRIMARY KEY (key) - );`, s.database, s.table, s.table)) - if err != nil { - log.Fatal(errors.Wrap(err, "SQL statement preparation failed")) - } - - _, err = tableq.Exec() + );`, s.table, s.table)) if err != nil { log.Fatal(errors.Wrap(err, "Couldn't create table")) } @@ -228,6 +220,6 @@ func New(opts ...store.Option) store.Store { database: namespace, table: prefix, } - + s.initDB() return s } From 55f5937c8b4f78edbdfc64033edf91676cdcb5ba Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Mon, 16 Dec 2019 17:16:10 +0000 Subject: [PATCH 025/788] Remove debug --- store/cockroach/cockroach.go | 1 - 1 file changed, 1 deletion(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 97123a98..31ec7d0c 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -43,7 +43,6 @@ func (s *sqlStore) List() ([]*store.Record, error) { } defer rows.Close() for rows.Next() { - println("next!") record := &store.Record{} if err := rows.Scan(&record.Key, &record.Value, &timehelper); err != nil { return records, err From cb15fadceea6d0653c6f055675777507e9bbaf49 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 16 Dec 2019 17:36:47 +0000 Subject: [PATCH 026/788] go fmt --- proxy/grpc/grpc.go | 2 +- proxy/http/http.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/grpc/grpc.go b/proxy/grpc/grpc.go index 0caea36a..e8a28877 100644 --- a/proxy/grpc/grpc.go +++ b/proxy/grpc/grpc.go @@ -137,7 +137,7 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server } func (p *Proxy) String() string { - return "grpc" + return "grpc" } // NewProxy returns a new grpc proxy server diff --git a/proxy/http/http.go b/proxy/http/http.go index d01bf038..dd666763 100644 --- a/proxy/http/http.go +++ b/proxy/http/http.go @@ -189,7 +189,7 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server } func (p *Proxy) String() string { - return "http" + return "http" } // NewSingleHostProxy returns a router which sends requests to a single http backend From 01f0e702139911331fcf55bc6d7720009a629792 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 16 Dec 2019 17:37:11 +0000 Subject: [PATCH 027/788] add some commented out stuff --- micro.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/micro.go b/micro.go index 295c08c5..a8cb7368 100644 --- a/micro.go +++ b/micro.go @@ -42,8 +42,29 @@ type Function interface { Subscribe(topic string, v interface{}) error } -// Publisher is syntactic sugar for publishing +/* +// Type Event is a future type for acting on asynchronous events +type Event interface { + // Publish publishes a message to the event topic + Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error + // Subscribe to the event + Subscribe(ctx context.Context, v in +} + +// Resource is a future type for defining dependencies +type Resource interface { + // Name of the resource + Name() string + // Type of resource + Type() string + // Method of creation + Create() error +} +*/ + +// Publisher is uses to publish messages to a topic type Publisher interface { + // Publish publishes a message to the event topic Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error } From 6027a81f06bb23ded819761d73f8239078fa0d14 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 08:28:45 +0000 Subject: [PATCH 028/788] Update router comments --- router/router.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/router/router.go b/router/router.go index 7758817c..fc6f18c2 100644 --- a/router/router.go +++ b/router/router.go @@ -24,11 +24,11 @@ type Router interface { Options() Options // The routing table Table() Table - // Advertise advertises routes to the network + // Advertise advertises routes Advertise() (<-chan *Advert, error) // Process processes incoming adverts Process(*Advert) error - // Solicit advertises the whole routing table to the network + // Solicit advertises the whole routing table Solicit() error // Lookup queries routes in the routing table Lookup(...QueryOption) ([]Route, error) From e95f44d3f8558dfb6522947c4c8d99a34465c19d Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 17 Dec 2019 11:32:38 +0000 Subject: [PATCH 029/788] Move runtime/kubernetes/client to util/kubernetes/client --- runtime/kubernetes/kubernetes.go | 2 +- runtime/kubernetes/service.go | 2 +- {runtime => util}/kubernetes/client/api/api_test.go | 0 {runtime => util}/kubernetes/client/api/request.go | 0 {runtime => util}/kubernetes/client/api/response.go | 0 {runtime => util}/kubernetes/client/client.go | 2 +- {runtime => util}/kubernetes/client/kubernetes.go | 0 {runtime => util}/kubernetes/client/templates.go | 0 {runtime => util}/kubernetes/client/types.go | 0 {runtime => util}/kubernetes/client/util.go | 0 {runtime => util}/kubernetes/client/util_test.go | 0 11 files changed, 3 insertions(+), 3 deletions(-) rename {runtime => util}/kubernetes/client/api/api_test.go (100%) rename {runtime => util}/kubernetes/client/api/request.go (100%) rename {runtime => util}/kubernetes/client/api/response.go (100%) rename {runtime => util}/kubernetes/client/client.go (98%) rename {runtime => util}/kubernetes/client/kubernetes.go (100%) rename {runtime => util}/kubernetes/client/templates.go (100%) rename {runtime => util}/kubernetes/client/types.go (100%) rename {runtime => util}/kubernetes/client/util.go (100%) rename {runtime => util}/kubernetes/client/util_test.go (100%) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index d451254a..9c5d9089 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -7,7 +7,7 @@ import ( "time" "github.com/micro/go-micro/runtime" - "github.com/micro/go-micro/runtime/kubernetes/client" + "github.com/micro/go-micro/util/kubernetes/client" "github.com/micro/go-micro/util/log" ) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index ec837682..704aafcf 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -5,7 +5,7 @@ import ( "time" "github.com/micro/go-micro/runtime" - "github.com/micro/go-micro/runtime/kubernetes/client" + "github.com/micro/go-micro/util/kubernetes/client" "github.com/micro/go-micro/util/log" ) diff --git a/runtime/kubernetes/client/api/api_test.go b/util/kubernetes/client/api/api_test.go similarity index 100% rename from runtime/kubernetes/client/api/api_test.go rename to util/kubernetes/client/api/api_test.go diff --git a/runtime/kubernetes/client/api/request.go b/util/kubernetes/client/api/request.go similarity index 100% rename from runtime/kubernetes/client/api/request.go rename to util/kubernetes/client/api/request.go diff --git a/runtime/kubernetes/client/api/response.go b/util/kubernetes/client/api/response.go similarity index 100% rename from runtime/kubernetes/client/api/response.go rename to util/kubernetes/client/api/response.go diff --git a/runtime/kubernetes/client/client.go b/util/kubernetes/client/client.go similarity index 98% rename from runtime/kubernetes/client/client.go rename to util/kubernetes/client/client.go index 4637a9d8..3680863f 100644 --- a/runtime/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -9,7 +9,7 @@ import ( "os" "path" - "github.com/micro/go-micro/runtime/kubernetes/client/api" + "github.com/micro/go-micro/util/kubernetes/client/api" "github.com/micro/go-micro/util/log" ) diff --git a/runtime/kubernetes/client/kubernetes.go b/util/kubernetes/client/kubernetes.go similarity index 100% rename from runtime/kubernetes/client/kubernetes.go rename to util/kubernetes/client/kubernetes.go diff --git a/runtime/kubernetes/client/templates.go b/util/kubernetes/client/templates.go similarity index 100% rename from runtime/kubernetes/client/templates.go rename to util/kubernetes/client/templates.go diff --git a/runtime/kubernetes/client/types.go b/util/kubernetes/client/types.go similarity index 100% rename from runtime/kubernetes/client/types.go rename to util/kubernetes/client/types.go diff --git a/runtime/kubernetes/client/util.go b/util/kubernetes/client/util.go similarity index 100% rename from runtime/kubernetes/client/util.go rename to util/kubernetes/client/util.go diff --git a/runtime/kubernetes/client/util_test.go b/util/kubernetes/client/util_test.go similarity index 100% rename from runtime/kubernetes/client/util_test.go rename to util/kubernetes/client/util_test.go From 0415ead50470706bd77741a8800ad5d1847057de Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 17 Dec 2019 12:11:26 +0000 Subject: [PATCH 030/788] First commit for Kubernetes logger --- debug/log/kubernetes/kubernetes.go | 23 +++++++++++++ debug/log/kubernetes/kubernetes_test.go | 44 +++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 debug/log/kubernetes/kubernetes.go create mode 100644 debug/log/kubernetes/kubernetes_test.go diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go new file mode 100644 index 00000000..65841ef8 --- /dev/null +++ b/debug/log/kubernetes/kubernetes.go @@ -0,0 +1,23 @@ +// Package kubernetes is a logger implementing (github.com/micro/go-micro/debug/log).Log +package kubernetes + +import ( + "github.com/micro/go-micro/debug/log" +) + +type klog struct{} + +func (k *klog) Read(...log.ReadOption) []log.Record { return nil } + +func (k *klog) Write(log.Record) {} + +func (k *klog) Stream(stop chan bool) <-chan log.Record { + c := make(chan log.Record) + go close(c) + return c +} + +// New returns a configured Kubernetes logger +func New() log.Log { + return &klog{} +} diff --git a/debug/log/kubernetes/kubernetes_test.go b/debug/log/kubernetes/kubernetes_test.go new file mode 100644 index 00000000..af9ce9b3 --- /dev/null +++ b/debug/log/kubernetes/kubernetes_test.go @@ -0,0 +1,44 @@ +package kubernetes + +import ( + "bytes" + "io" + "os" + "testing" + "time" + + "github.com/micro/go-micro/debug/log" + "github.com/stretchr/testify/assert" +) + +func TestKubernetes(t *testing.T) { + k := New() + r, w, err := os.Pipe() + if err != nil { + t.Fatal(err) + } + s := os.Stderr + os.Stderr = w + meta := make(map[string]string) + meta["foo"] = "bar" + k.Write(log.Record{ + Timestamp: time.Unix(0, 0), + Value: "Test log entry", + Metadata: meta, + }) + b := &bytes.Buffer{} + w.Close() + io.Copy(b, r) + os.Stderr = s + assert.Equal(t, "Test log entry", b.String(), "Write was not equal") + + assert.Nil(t, k.Read(), "Read should be unimplemented") + + stream := k.Stream(make(chan bool)) + records := []log.Record{} + for s := range stream { + records = append(records, s) + } + assert.Equal(t, 0, len(records), "Stream should be unimplemented") + +} From bc30efcf709168a6f6d501c988d707c8f7578957 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 15:38:03 +0000 Subject: [PATCH 031/788] Decruft the debug logger interface --- debug/log/default.go | 17 ++--- debug/log/log.go | 2 +- debug/service/handler/debug.go | 23 +++--- debug/service/log.go | 81 ++++++++++++++++++++++ debug/service/service.go | 20 +++--- debug/stats/default.go | 6 +- {debug/buffer => util/ring}/buffer.go | 61 +++++++++------- {debug/buffer => util/ring}/buffer_test.go | 2 +- 8 files changed, 150 insertions(+), 62 deletions(-) create mode 100644 debug/service/log.go rename {debug/buffer => util/ring}/buffer.go (72%) rename {debug/buffer => util/ring}/buffer_test.go (98%) diff --git a/debug/log/default.go b/debug/log/default.go index 6f7bddab..3d79bdc9 100644 --- a/debug/log/default.go +++ b/debug/log/default.go @@ -4,17 +4,17 @@ import ( "fmt" golog "log" - "github.com/micro/go-micro/debug/buffer" + "github.com/micro/go-micro/util/ring" ) var ( // DefaultSize of the logger buffer - DefaultSize = 1000 + DefaultSize = 1024 ) // defaultLog is default micro log type defaultLog struct { - *buffer.Buffer + *ring.Buffer } // NewLog returns default Logger with @@ -28,7 +28,7 @@ func NewLog(opts ...Option) Log { } return &defaultLog{ - Buffer: buffer.New(options.Size), + Buffer: ring.New(options.Size), } } @@ -46,7 +46,7 @@ func (l *defaultLog) Read(opts ...ReadOption) []Record { o(&options) } - var entries []*buffer.Entry + var entries []*ring.Entry // if Since options ha sbeen specified we honor it if !options.Since.IsZero() { entries = l.Buffer.Since(options.Since) @@ -82,9 +82,10 @@ func (l *defaultLog) Read(opts ...ReadOption) []Record { } // Stream returns channel for reading log records -func (l *defaultLog) Stream(stop chan bool) <-chan Record { +// along with a stop channel, close it when done +func (l *defaultLog) Stream() (<-chan Record, chan bool) { // get stream channel from ring buffer - stream := l.Buffer.Stream(stop) + stream, stop := l.Buffer.Stream() // make a buffered channel records := make(chan Record, 128) // get last 10 records @@ -110,5 +111,5 @@ func (l *defaultLog) Stream(stop chan bool) <-chan Record { } }() - return records + return records, stop } diff --git a/debug/log/log.go b/debug/log/log.go index 42a8f558..9425ff19 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -23,7 +23,7 @@ type Log interface { // Write writes records to log Write(Record) // Stream log records - Stream(chan bool) <-chan Record + Stream() (<-chan Record, chan bool) } // Record is log record entry diff --git a/debug/service/handler/debug.go b/debug/service/handler/debug.go index ee24b27a..7f2f16e4 100644 --- a/debug/service/handler/debug.go +++ b/debug/service/handler/debug.go @@ -1,4 +1,4 @@ -// Pacjage handler implements service debug handler +// Package handler implements service debug handler embedded in go-micro services package handler import ( @@ -66,26 +66,27 @@ func (d *Debug) Log(ctx context.Context, stream server.Stream) error { } if req.Stream { - stop := make(chan bool) - defer close(stop) - - // TODO: we need to figure out how to close ithe log stream + // TODO: we need to figure out how to close the log stream // It seems like when a client disconnects, // the connection stays open until some timeout expires // or something like that; that means the map of streams // might end up leaking memory if not cleaned up properly - records := d.log.Stream(stop) + records, stop := d.log.Stream() + defer close(stop) + for record := range records { if err := d.sendRecord(record, stream); err != nil { return err } } + // done streaming, return return nil } // get the log records records := d.log.Read(options...) + // send all the logs downstream for _, record := range records { if err := d.sendRecord(record, stream); err != nil { @@ -102,15 +103,9 @@ func (d *Debug) sendRecord(record log.Record, stream server.Stream) error { metadata[k] = v } - pbRecord := &proto.Record{ + return stream.Send(&proto.Record{ Timestamp: record.Timestamp.Unix(), Value: record.Value.(string), Metadata: metadata, - } - - if err := stream.Send(pbRecord); err != nil { - return err - } - - return nil + }) } diff --git a/debug/service/log.go b/debug/service/log.go new file mode 100644 index 00000000..7a9aabc5 --- /dev/null +++ b/debug/service/log.go @@ -0,0 +1,81 @@ +package service + +import ( + "context" + "fmt" + "time" + + "github.com/micro/go-micro/client" + "github.com/micro/go-micro/debug/log" + pb "github.com/micro/go-micro/debug/service/proto" +) + +type serviceLog struct { + Client *debugClient +} + +// Read reads log entries from the logger +func (s *serviceLog) Read(opts ...log.ReadOption) []log.Record { + // TODO: parse opts + stream, err := s.Client.Log(opts...) + if err != nil { + return nil + } + // stream the records until nothing is left + var records []log.Record + for _, record := range stream { + records = append(records, record) + } + return records +} + +// There is no write support +func (s *serviceLog) Write(r log.Record) { + return +} + +// Stream log records +func (s *serviceLog) Stream(ch chan bool) (<-chan log.Record, chan bool) { + stop := make(chan bool) + stream, err := s.Client.Log(log.Stream(true)) + if err != nil { + // return a closed stream + stream = make(chan log.Record) + close(stream) + return stream, stop + } + + // stream the records until nothing is left + go func() { + var records []log.Record + for _, record := range stream { + select { + case stream <- record: + case <-stop: + return + } + } + }() + + // return the stream + return stream, stop +} + +// NewLog returns a new log interface +func NewLog(opts ...log.Option) log.Log { + var options log.Options + for _, o := range opts { + o(&options) + } + + name := options.Name + + // set the default name + if len(name) == 0 { + name = debug.DefaultName + } + + return serviceLog{ + Client: newDebugClient(name), + } +} diff --git a/debug/service/service.go b/debug/service/service.go index d48b0a3d..7527127a 100644 --- a/debug/service/service.go +++ b/debug/service/service.go @@ -1,3 +1,4 @@ +// Package service provides the service log package service import ( @@ -12,23 +13,23 @@ import ( ) // Debug provides debug service client -type Debug struct { - dbg pb.DebugService +type debugClient struct { + Client pb.DebugService } // NewDebug provides Debug service implementation -func NewDebug(name string) *Debug { +func newDebugClient(name string) *debug { // create default client cli := client.DefaultClient - return &Debug{ - dbg: pb.NewDebugService(name, cli), + return &debugClient{ + Client: pb.NewDebugService(name, cli), } } // Logs queries the service logs and returns a channel to read the logs from -func (d *Debug) Log(opts ...log.ReadOption) (<-chan log.Record, error) { - options := log.ReadOptions{} +func (d *debugClient) Log(opts ...log.ReadOption) (<-chan log.Record, error) { + var options log.ReadOptions // initialize the read options for _, o := range opts { o(&options) @@ -46,20 +47,21 @@ func (d *Debug) Log(opts ...log.ReadOption) (<-chan log.Record, error) { req.Stream = options.Stream // get the log stream - stream, err := d.dbg.Log(context.Background(), req) + stream, err := d.Client.Log(context.Background(), req) if err != nil { return nil, fmt.Errorf("failed getting log stream: %s", err) } // log channel for streaming logs logChan := make(chan log.Record) + // go stream logs go d.streamLogs(logChan, stream) return logChan, nil } -func (d *Debug) streamLogs(logChan chan log.Record, stream pb.Debug_LogService) { +func (d *debugClient) streamLogs(logChan chan log.Record, stream pb.Debug_LogService) { defer stream.Close() for { diff --git a/debug/stats/default.go b/debug/stats/default.go index b2d78fce..357d6303 100644 --- a/debug/stats/default.go +++ b/debug/stats/default.go @@ -1,11 +1,11 @@ package stats import ( - "github.com/micro/go-micro/debug/buffer" + "github.com/micro/go-micro/util/ring" ) type stats struct { - buffer *buffer.Buffer + buffer *ring.Buffer } func (s *stats) Read() ([]*Stat, error) { @@ -33,6 +33,6 @@ func (s *stats) Write(stat *Stat) error { // TODO add options func NewStats() Stats { return &stats{ - buffer: buffer.New(1024), + buffer: ring.New(1024), } } diff --git a/debug/buffer/buffer.go b/util/ring/buffer.go similarity index 72% rename from debug/buffer/buffer.go rename to util/ring/buffer.go index 007293aa..bb8febcf 100644 --- a/debug/buffer/buffer.go +++ b/util/ring/buffer.go @@ -1,5 +1,5 @@ -// Package buffer provides a simple ring buffer for storing local data -package buffer +// Package ring provides a simple ring buffer for storing local data +package ring import ( "sync" @@ -8,18 +8,13 @@ import ( "github.com/google/uuid" ) -type stream struct { - id string - entries chan *Entry - stop chan bool -} - // Buffer is ring buffer type Buffer struct { size int + sync.RWMutex vals []*Entry - streams map[string]stream + streams map[string]*Stream } // Entry is ring buffer data entry @@ -28,12 +23,14 @@ type Entry struct { Timestamp time.Time } -// New returns a new buffer of the given size -func New(i int) *Buffer { - return &Buffer{ - size: i, - streams: make(map[string]stream), - } +// Stream is used to stream the buffer +type Stream struct { + // Id of the stream + Id string + // Buffered entries + Entries chan *Entry + // Stop channel + Stop chan bool } // Put adds a new value to ring buffer @@ -53,13 +50,13 @@ func (b *Buffer) Put(v interface{}) { b.vals = b.vals[1:] } - // TODO: this is fucking ugly + // send to every stream for _, stream := range b.streams { select { - case <-stream.stop: - delete(b.streams, stream.id) - close(stream.entries) - case stream.entries <- entry: + case <-stream.Stop: + delete(b.streams, stream.Id) + close(stream.Entries) + case stream.Entries <- entry: } } } @@ -115,22 +112,34 @@ func (b *Buffer) Since(t time.Time) []*Entry { } // Stream logs from the buffer -func (b *Buffer) Stream(stop chan bool) <-chan *Entry { +// Close the channel when you want to stop +func (b *Buffer) Stream() (<-chan *Entry, chan bool) { b.Lock() defer b.Unlock() entries := make(chan *Entry, 128) id := uuid.New().String() - b.streams[id] = stream{ - id: id, - entries: entries, - stop: stop, + stop := make(chan bool) + + b.streams[id] = &Stream{ + Id: id, + Entries: entries, + Stop: stop, } - return entries + return entries, stop } // Size returns the size of the ring buffer func (b *Buffer) Size() int { return b.size } + +// New returns a new buffer of the given size +func New(i int) *Buffer { + return &Buffer{ + size: i, + streams: make(map[string]*Stream), + } +} + diff --git a/debug/buffer/buffer_test.go b/util/ring/buffer_test.go similarity index 98% rename from debug/buffer/buffer_test.go rename to util/ring/buffer_test.go index 3a107923..0c9b5378 100644 --- a/debug/buffer/buffer_test.go +++ b/util/ring/buffer_test.go @@ -1,4 +1,4 @@ -package buffer +package ring import ( "testing" From d502e2f58abf344c50ceb4dc421cb9b248344b2b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 15:46:09 +0000 Subject: [PATCH 032/788] fix breaks --- debug/log/log.go | 2 +- debug/log/options.go | 9 +++++++++ debug/service/log.go | 31 +++++++++++++------------------ debug/service/service.go | 2 +- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/debug/log/log.go b/debug/log/log.go index 9425ff19..918d0c55 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -174,6 +174,6 @@ func SetPrefix(p string) { } // Set service name -func Name(name string) { +func SetName(name string) { prefix = fmt.Sprintf("[%s]", name) } diff --git a/debug/log/options.go b/debug/log/options.go index 03dece38..0d83394b 100644 --- a/debug/log/options.go +++ b/debug/log/options.go @@ -7,10 +7,19 @@ type Option func(*Options) // Options are logger options type Options struct { + // Name of the log + Name string // Size is the size of ring buffer Size int } +// Name of the log +func Name(n string) Option { + return func(o *Options) { + o.Name = n + } +} + // Size sets the size of the ring buffer func Size(s int) Option { return func(o *Options) { diff --git a/debug/service/log.go b/debug/service/log.go index 7a9aabc5..3508874c 100644 --- a/debug/service/log.go +++ b/debug/service/log.go @@ -1,13 +1,8 @@ package service import ( - "context" - "fmt" - "time" - - "github.com/micro/go-micro/client" + "github.com/micro/go-micro/debug" "github.com/micro/go-micro/debug/log" - pb "github.com/micro/go-micro/debug/service/proto" ) type serviceLog struct { @@ -23,7 +18,7 @@ func (s *serviceLog) Read(opts ...log.ReadOption) []log.Record { } // stream the records until nothing is left var records []log.Record - for _, record := range stream { + for record := range stream { records = append(records, record) } return records @@ -35,30 +30,30 @@ func (s *serviceLog) Write(r log.Record) { } // Stream log records -func (s *serviceLog) Stream(ch chan bool) (<-chan log.Record, chan bool) { +func (s *serviceLog) Stream() (<-chan log.Record, chan bool) { stop := make(chan bool) stream, err := s.Client.Log(log.Stream(true)) if err != nil { // return a closed stream - stream = make(chan log.Record) - close(stream) - return stream, stop + deadStream := make(chan log.Record) + close(deadStream) + return deadStream, stop } - // stream the records until nothing is left + newStream := make(chan log.Record, 128) + go func() { - var records []log.Record - for _, record := range stream { + for { select { - case stream <- record: + case rec := <-stream: + newStream <- rec case <-stop: return } } }() - // return the stream - return stream, stop + return newStream, stop } // NewLog returns a new log interface @@ -75,7 +70,7 @@ func NewLog(opts ...log.Option) log.Log { name = debug.DefaultName } - return serviceLog{ + return &serviceLog{ Client: newDebugClient(name), } } diff --git a/debug/service/service.go b/debug/service/service.go index 7527127a..7d73c753 100644 --- a/debug/service/service.go +++ b/debug/service/service.go @@ -18,7 +18,7 @@ type debugClient struct { } // NewDebug provides Debug service implementation -func newDebugClient(name string) *debug { +func newDebugClient(name string) *debugClient { // create default client cli := client.DefaultClient From b35dfb1086004dd862c29ec225244d1594e440fe Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 15:56:49 +0000 Subject: [PATCH 033/788] fix further breaks --- debug/service/log.go | 2 +- debug/service/service.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/debug/service/log.go b/debug/service/log.go index 3508874c..647b349a 100644 --- a/debug/service/log.go +++ b/debug/service/log.go @@ -71,6 +71,6 @@ func NewLog(opts ...log.Option) log.Log { } return &serviceLog{ - Client: newDebugClient(name), + Client: NewClient(name), } } diff --git a/debug/service/service.go b/debug/service/service.go index 7d73c753..1da11c6e 100644 --- a/debug/service/service.go +++ b/debug/service/service.go @@ -17,8 +17,8 @@ type debugClient struct { Client pb.DebugService } -// NewDebug provides Debug service implementation -func newDebugClient(name string) *debugClient { +// NewClient provides a debug client +func NewClient(name string) *debugClient { // create default client cli := client.DefaultClient From 53ca742c66bf696f6edc01c8e962ac0ef59a03b1 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 17 Dec 2019 16:09:51 +0000 Subject: [PATCH 034/788] Update the util/kubernetes client to retrieve logs --- debug/log/kubernetes/kubernetes.go | 4 +++- debug/log/kubernetes/kubernetes_test.go | 15 +++++++++++---- debug/log/kubernetes/log.go | 15 +++++++++++++++ debug/log/log.go | 8 ++++---- util/kubernetes/client/api/api_test.go | 11 +++++++++++ util/kubernetes/client/api/request.go | 25 +++++++++++++++++++++++++ util/kubernetes/client/client.go | 16 ++++++++++++++++ 7 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 debug/log/kubernetes/log.go diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go index 65841ef8..529b5d7c 100644 --- a/debug/log/kubernetes/kubernetes.go +++ b/debug/log/kubernetes/kubernetes.go @@ -9,7 +9,9 @@ type klog struct{} func (k *klog) Read(...log.ReadOption) []log.Record { return nil } -func (k *klog) Write(log.Record) {} +func (k *klog) Write(l log.Record) { + write(l) +} func (k *klog) Stream(stop chan bool) <-chan log.Record { c := make(chan log.Record) diff --git a/debug/log/kubernetes/kubernetes_test.go b/debug/log/kubernetes/kubernetes_test.go index af9ce9b3..c1eca93d 100644 --- a/debug/log/kubernetes/kubernetes_test.go +++ b/debug/log/kubernetes/kubernetes_test.go @@ -2,6 +2,7 @@ package kubernetes import ( "bytes" + "encoding/json" "io" "os" "testing" @@ -13,6 +14,7 @@ import ( func TestKubernetes(t *testing.T) { k := New() + r, w, err := os.Pipe() if err != nil { t.Fatal(err) @@ -20,17 +22,22 @@ func TestKubernetes(t *testing.T) { s := os.Stderr os.Stderr = w meta := make(map[string]string) - meta["foo"] = "bar" - k.Write(log.Record{ + write := log.Record{ Timestamp: time.Unix(0, 0), Value: "Test log entry", Metadata: meta, - }) + } + meta["foo"] = "bar" + k.Write(write) b := &bytes.Buffer{} w.Close() io.Copy(b, r) os.Stderr = s - assert.Equal(t, "Test log entry", b.String(), "Write was not equal") + var read log.Record + if err := json.Unmarshal(b.Bytes(), &read); err != nil { + t.Fatalf("json.Unmarshal failed: %s", err.Error()) + } + assert.Equal(t, write, read, "Write was not equal") assert.Nil(t, k.Read(), "Read should be unimplemented") diff --git a/debug/log/kubernetes/log.go b/debug/log/kubernetes/log.go new file mode 100644 index 00000000..ea352165 --- /dev/null +++ b/debug/log/kubernetes/log.go @@ -0,0 +1,15 @@ +package kubernetes + +import "github.com/micro/go-micro/debug/log" + +import ( + "encoding/json" + "fmt" + "os" +) + +func write(l log.Record) { + if m, err := json.Marshal(l); err == nil { + fmt.Fprintf(os.Stderr, "%s", m) + } +} diff --git a/debug/log/log.go b/debug/log/log.go index 42a8f558..f4ad0d76 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -29,14 +29,14 @@ type Log interface { // Record is log record entry type Record struct { // Timestamp of logged event - Timestamp time.Time + Timestamp time.Time `json:"time"` // Value contains log entry - Value interface{} + Value interface{} `json:"value"` // Metadata to enrich log record - Metadata map[string]string + Metadata map[string]string `json:"metadata"` } -// level is a log level +// Level is a log level type Level int const ( diff --git a/util/kubernetes/client/api/api_test.go b/util/kubernetes/client/api/api_test.go index 474dff55..f1f45fdd 100644 --- a/util/kubernetes/client/api/api_test.go +++ b/util/kubernetes/client/api/api_test.go @@ -111,6 +111,17 @@ var tests = []testcase{ URI: "/apis/apps/v1/namespaces/default/deployments/baz", Header: map[string]string{"foo": "bar"}, }, + testcase{ + ReqFn: func(opts *Options) *Request { + return NewRequest(opts). + Get(). + Resource("pod"). + SubResource("log"). + Name("foolog") + }, + Method: "GET", + URI: "/api/v1/namespaces/default/pods/foolog/log", + }, } var wrappedHandler = func(test *testcase, t *testing.T) http.HandlerFunc { diff --git a/util/kubernetes/client/api/request.go b/util/kubernetes/client/api/request.go index 1b454c00..53d57195 100644 --- a/util/kubernetes/client/api/request.go +++ b/util/kubernetes/client/api/request.go @@ -23,6 +23,7 @@ type Request struct { resource string resourceName *string + subResource *string body io.Reader err error @@ -79,6 +80,13 @@ func (r *Request) Resource(s string) *Request { return r } +// SubResource sets a subresource on a resource, +// e.g. pods/log for pod logs +func (r *Request) SubResource(s string) *Request { + r.subResource = &s + return r +} + // Name is for targeting a specific resource by id func (r *Request) Name(s string) *Request { r.resourceName = &s @@ -154,6 +162,9 @@ func (r *Request) request() (*http.Request, error) { // append resourceName if it is present if r.resourceName != nil { url += *r.resourceName + if r.subResource != nil { + url += "/" + *r.subResource + } } // append any query params @@ -202,6 +213,20 @@ func (r *Request) Do() *Response { return newResponse(res, err) } +// Raw performs a Raw HTTP request to the Kubernetes API +func (r *Request) Raw() (*http.Response, error) { + req, err := r.request() + if err != nil { + return nil, err + } + + res, err := r.client.Do(req) + if err != nil { + return nil, err + } + return res, nil +} + // Options ... type Options struct { Host string diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 3680863f..821ee3da 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/tls" "errors" + "io" "io/ioutil" "net/http" "os" @@ -116,6 +117,21 @@ func (c *client) Get(r *Resource, labels map[string]string) error { Into(r.Value) } +// Logs returns logs for a pod +func (c *client) Logs(podName string) (io.ReadCloser, error) { + req := api.NewRequest(c.opts). + Get(). + Resource("pod"). + SubResource("log"). + Name(podName) + + resp, err := req.Raw() + if err != nil { + return nil, err + } + return resp.Body, nil +} + // Update updates API object func (c *client) Update(r *Resource) error { req := api.NewRequest(c.opts). From c3607c23e728f87aa28d02185d3c5ce210392afe Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 17 Dec 2019 16:27:17 +0000 Subject: [PATCH 035/788] Fix after merge --- debug/log/kubernetes/kubernetes.go | 6 +++--- debug/log/kubernetes/kubernetes_test.go | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go index 529b5d7c..df8e2a6d 100644 --- a/debug/log/kubernetes/kubernetes.go +++ b/debug/log/kubernetes/kubernetes.go @@ -13,10 +13,10 @@ func (k *klog) Write(l log.Record) { write(l) } -func (k *klog) Stream(stop chan bool) <-chan log.Record { - c := make(chan log.Record) +func (k *klog) Stream() (<-chan log.Record, chan bool) { + c, s := make(chan log.Record), make(chan bool) go close(c) - return c + return c, s } // New returns a configured Kubernetes logger diff --git a/debug/log/kubernetes/kubernetes_test.go b/debug/log/kubernetes/kubernetes_test.go index c1eca93d..8fac8c08 100644 --- a/debug/log/kubernetes/kubernetes_test.go +++ b/debug/log/kubernetes/kubernetes_test.go @@ -41,11 +41,12 @@ func TestKubernetes(t *testing.T) { assert.Nil(t, k.Read(), "Read should be unimplemented") - stream := k.Stream(make(chan bool)) + stream, stop := k.Stream() records := []log.Record{} for s := range stream { records = append(records, s) } + close(stop) assert.Equal(t, 0, len(records), "Stream should be unimplemented") } From 51f4bc6d56fece260d9ffaeea937c1200afc53e8 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 17 Dec 2019 16:30:09 +0000 Subject: [PATCH 036/788] Add logs to Interface --- util/kubernetes/client/kubernetes.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/kubernetes/client/kubernetes.go b/util/kubernetes/client/kubernetes.go index a9d3a653..8e30c923 100644 --- a/util/kubernetes/client/kubernetes.go +++ b/util/kubernetes/client/kubernetes.go @@ -2,6 +2,7 @@ package client import ( + "io" "strings" "github.com/micro/go-micro/util/log" @@ -24,6 +25,8 @@ type Kubernetes interface { Delete(*Resource) error // List lists API resources List(*Resource) error + // Logs gets logs from a pod + Logs(string) (io.ReadCloser, error) } // NewService returns default micro kubernetes service definition From d2a3fd0b0407a36603e67a9e671d2e74752339ec Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 16:56:55 +0000 Subject: [PATCH 037/788] Move stream to interface --- debug/log/default.go | 14 +-- debug/log/default_test.go | 2 +- debug/log/level.go | 35 ++++++++ debug/log/log.go | 151 ++------------------------------- debug/log/logger.go | 120 ++++++++++++++++++++++++++ debug/log/options.go | 7 -- debug/log/stream.go | 20 +++++ debug/service/handler/debug.go | 14 ++- debug/service/log.go | 54 +++++------- debug/service/service.go | 44 +++++----- debug/service/stream.go | 25 ++++++ 11 files changed, 269 insertions(+), 217 deletions(-) create mode 100644 debug/log/level.go create mode 100644 debug/log/logger.go create mode 100644 debug/log/stream.go create mode 100644 debug/service/stream.go diff --git a/debug/log/default.go b/debug/log/default.go index 3d79bdc9..428941f0 100644 --- a/debug/log/default.go +++ b/debug/log/default.go @@ -33,13 +33,14 @@ func NewLog(opts ...Option) Log { } // Write writes logs into logger -func (l *defaultLog) Write(r Record) { +func (l *defaultLog) Write(r Record) error { golog.Print(r.Value) l.Buffer.Put(fmt.Sprint(r.Value)) + return nil } // Read reads logs and returns them -func (l *defaultLog) Read(opts ...ReadOption) []Record { +func (l *defaultLog) Read(opts ...ReadOption) ([]Record, error) { options := ReadOptions{} // initialize the read options for _, o := range opts { @@ -78,12 +79,12 @@ func (l *defaultLog) Read(opts ...ReadOption) []Record { records = append(records, record) } - return records + return records, nil } // Stream returns channel for reading log records // along with a stop channel, close it when done -func (l *defaultLog) Stream() (<-chan Record, chan bool) { +func (l *defaultLog) Stream() (Stream, error) { // get stream channel from ring buffer stream, stop := l.Buffer.Stream() // make a buffered channel @@ -111,5 +112,8 @@ func (l *defaultLog) Stream() (<-chan Record, chan bool) { } }() - return records, stop + return &logStream{ + stream: records, + stop: stop, + }, nil } diff --git a/debug/log/default_test.go b/debug/log/default_test.go index e0f08a7c..7f5c84e8 100644 --- a/debug/log/default_test.go +++ b/debug/log/default_test.go @@ -23,7 +23,7 @@ func TestLogger(t *testing.T) { // Check if the logs are stored in the logger ring buffer expected := []string{"foobar", "foo bar"} - entries := DefaultLog.Read(Count(len(expected))) + entries, _ := DefaultLog.Read(Count(len(expected))) for i, entry := range entries { if !reflect.DeepEqual(entry.Value, expected[i]) { t.Errorf("expected %s, got %s", expected[i], entry.Value) diff --git a/debug/log/level.go b/debug/log/level.go new file mode 100644 index 00000000..2f8b425c --- /dev/null +++ b/debug/log/level.go @@ -0,0 +1,35 @@ +// Package log provides debug logging +package log + +import ( + "os" +) + +// level is a log level +type Level int + +const ( + LevelFatal Level = iota + LevelError + LevelInfo + LevelWarn + LevelDebug + LevelTrace +) + +func init() { + switch os.Getenv("MICRO_LOG_LEVEL") { + case "trace": + DefaultLevel = LevelTrace + case "debug": + DefaultLevel = LevelDebug + case "warn": + DefaultLevel = LevelWarn + case "info": + DefaultLevel = LevelInfo + case "error": + DefaultLevel = LevelError + case "fatal": + DefaultLevel = LevelFatal + } +} diff --git a/debug/log/log.go b/debug/log/log.go index 918d0c55..81a088c6 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -2,8 +2,6 @@ package log import ( - "fmt" - "os" "time" ) @@ -19,11 +17,11 @@ var ( // Log is event log type Log interface { // Read reads log entries from the logger - Read(...ReadOption) []Record + Read(...ReadOption) ([]Record, error) // Write writes records to log - Write(Record) + Write(Record) error // Stream log records - Stream() (<-chan Record, chan bool) + Stream() (Stream, error) } // Record is log record entry @@ -36,144 +34,7 @@ type Record struct { Metadata map[string]string } -// level is a log level -type Level int - -const ( - LevelFatal Level = iota - LevelError - LevelInfo - LevelWarn - LevelDebug - LevelTrace -) - -func init() { - switch os.Getenv("MICRO_LOG_LEVEL") { - case "trace": - DefaultLevel = LevelTrace - case "debug": - DefaultLevel = LevelDebug - case "warn": - DefaultLevel = LevelWarn - case "info": - DefaultLevel = LevelInfo - case "error": - DefaultLevel = LevelError - case "fatal": - DefaultLevel = LevelFatal - } -} - -func log(v ...interface{}) { - if len(prefix) > 0 { - DefaultLog.Write(Record{Value: fmt.Sprint(append([]interface{}{prefix, " "}, v...)...)}) - return - } - DefaultLog.Write(Record{Value: fmt.Sprint(v...)}) -} - -func logf(format string, v ...interface{}) { - if len(prefix) > 0 { - format = prefix + " " + format - } - DefaultLog.Write(Record{Value: fmt.Sprintf(format, v...)}) -} - -// WithLevel logs with the level specified -func WithLevel(l Level, v ...interface{}) { - if l > DefaultLevel { - return - } - log(v...) -} - -// WithLevel logs with the level specified -func WithLevelf(l Level, format string, v ...interface{}) { - if l > DefaultLevel { - return - } - logf(format, v...) -} - -// Trace provides trace level logging -func Trace(v ...interface{}) { - WithLevel(LevelTrace, v...) -} - -// Tracef provides trace level logging -func Tracef(format string, v ...interface{}) { - WithLevelf(LevelTrace, format, v...) -} - -// Debug provides debug level logging -func Debug(v ...interface{}) { - WithLevel(LevelDebug, v...) -} - -// Debugf provides debug level logging -func Debugf(format string, v ...interface{}) { - WithLevelf(LevelDebug, format, v...) -} - -// Warn provides warn level logging -func Warn(v ...interface{}) { - WithLevel(LevelWarn, v...) -} - -// Warnf provides warn level logging -func Warnf(format string, v ...interface{}) { - WithLevelf(LevelWarn, format, v...) -} - -// Info provides info level logging -func Info(v ...interface{}) { - WithLevel(LevelInfo, v...) -} - -// Infof provides info level logging -func Infof(format string, v ...interface{}) { - WithLevelf(LevelInfo, format, v...) -} - -// Error provides warn level logging -func Error(v ...interface{}) { - WithLevel(LevelError, v...) -} - -// Errorf provides warn level logging -func Errorf(format string, v ...interface{}) { - WithLevelf(LevelError, format, v...) -} - -// Fatal logs with Log and then exits with os.Exit(1) -func Fatal(v ...interface{}) { - WithLevel(LevelFatal, v...) - os.Exit(1) -} - -// Fatalf logs with Logf and then exits with os.Exit(1) -func Fatalf(format string, v ...interface{}) { - WithLevelf(LevelFatal, format, v...) - os.Exit(1) -} - -// SetLevel sets the log level -func SetLevel(l Level) { - DefaultLevel = l -} - -// GetLevel returns the current level -func GetLevel() Level { - return DefaultLevel -} - -// Set a prefix for the logger -func SetPrefix(p string) { - prefix = p -} - -// Set service name -func SetName(name string) { - prefix = fmt.Sprintf("[%s]", name) +type Stream interface { + Chan() <-chan Record + Stop() error } diff --git a/debug/log/logger.go b/debug/log/logger.go new file mode 100644 index 00000000..912defc2 --- /dev/null +++ b/debug/log/logger.go @@ -0,0 +1,120 @@ +// Package log provides debug logging +package log + +import ( + "fmt" + "os" +) + +func log(v ...interface{}) { + if len(prefix) > 0 { + DefaultLog.Write(Record{Value: fmt.Sprint(append([]interface{}{prefix, " "}, v...)...)}) + return + } + DefaultLog.Write(Record{Value: fmt.Sprint(v...)}) +} + +func logf(format string, v ...interface{}) { + if len(prefix) > 0 { + format = prefix + " " + format + } + DefaultLog.Write(Record{Value: fmt.Sprintf(format, v...)}) +} + +// WithLevel logs with the level specified +func WithLevel(l Level, v ...interface{}) { + if l > DefaultLevel { + return + } + log(v...) +} + +// WithLevel logs with the level specified +func WithLevelf(l Level, format string, v ...interface{}) { + if l > DefaultLevel { + return + } + logf(format, v...) +} + +// Trace provides trace level logging +func Trace(v ...interface{}) { + WithLevel(LevelTrace, v...) +} + +// Tracef provides trace level logging +func Tracef(format string, v ...interface{}) { + WithLevelf(LevelTrace, format, v...) +} + +// Debug provides debug level logging +func Debug(v ...interface{}) { + WithLevel(LevelDebug, v...) +} + +// Debugf provides debug level logging +func Debugf(format string, v ...interface{}) { + WithLevelf(LevelDebug, format, v...) +} + +// Warn provides warn level logging +func Warn(v ...interface{}) { + WithLevel(LevelWarn, v...) +} + +// Warnf provides warn level logging +func Warnf(format string, v ...interface{}) { + WithLevelf(LevelWarn, format, v...) +} + +// Info provides info level logging +func Info(v ...interface{}) { + WithLevel(LevelInfo, v...) +} + +// Infof provides info level logging +func Infof(format string, v ...interface{}) { + WithLevelf(LevelInfo, format, v...) +} + +// Error provides warn level logging +func Error(v ...interface{}) { + WithLevel(LevelError, v...) +} + +// Errorf provides warn level logging +func Errorf(format string, v ...interface{}) { + WithLevelf(LevelError, format, v...) +} + +// Fatal logs with Log and then exits with os.Exit(1) +func Fatal(v ...interface{}) { + WithLevel(LevelFatal, v...) + os.Exit(1) +} + +// Fatalf logs with Logf and then exits with os.Exit(1) +func Fatalf(format string, v ...interface{}) { + WithLevelf(LevelFatal, format, v...) + os.Exit(1) +} + +// SetLevel sets the log level +func SetLevel(l Level) { + DefaultLevel = l +} + +// GetLevel returns the current level +func GetLevel() Level { + return DefaultLevel +} + +// Set a prefix for the logger +func SetPrefix(p string) { + prefix = p +} + +// Set service name +func SetName(name string) { + prefix = fmt.Sprintf("[%s]", name) +} diff --git a/debug/log/options.go b/debug/log/options.go index 0d83394b..b17c2f43 100644 --- a/debug/log/options.go +++ b/debug/log/options.go @@ -60,10 +60,3 @@ func Count(c int) ReadOption { o.Count = c } } - -// Stream requests continuous log stream -func Stream(s bool) ReadOption { - return func(o *ReadOptions) { - o.Stream = s - } -} diff --git a/debug/log/stream.go b/debug/log/stream.go new file mode 100644 index 00000000..0effe358 --- /dev/null +++ b/debug/log/stream.go @@ -0,0 +1,20 @@ +package log + +type logStream struct { + stream <-chan Record + stop chan bool +} + +func (l *logStream) Chan() <-chan Record { + return l.stream +} + +func (l *logStream) Stop() error { + select { + case <-l.stop: + return nil + default: + close(l.stop) + } + return nil +} diff --git a/debug/service/handler/debug.go b/debug/service/handler/debug.go index 7f2f16e4..c0e26c5e 100644 --- a/debug/service/handler/debug.go +++ b/debug/service/handler/debug.go @@ -71,10 +71,13 @@ func (d *Debug) Log(ctx context.Context, stream server.Stream) error { // the connection stays open until some timeout expires // or something like that; that means the map of streams // might end up leaking memory if not cleaned up properly - records, stop := d.log.Stream() - defer close(stop) + lgStream, err := d.log.Stream() + if err != nil { + return err + } + defer lgStream.Stop() - for record := range records { + for record := range lgStream.Chan() { if err := d.sendRecord(record, stream); err != nil { return err } @@ -85,7 +88,10 @@ func (d *Debug) Log(ctx context.Context, stream server.Stream) error { } // get the log records - records := d.log.Read(options...) + records, err := d.log.Read(options...) + if err != nil { + return err + } // send all the logs downstream for _, record := range records { diff --git a/debug/service/log.go b/debug/service/log.go index 647b349a..95ad0f3c 100644 --- a/debug/service/log.go +++ b/debug/service/log.go @@ -1,6 +1,8 @@ package service import ( + "time" + "github.com/micro/go-micro/debug" "github.com/micro/go-micro/debug/log" ) @@ -10,50 +12,36 @@ type serviceLog struct { } // Read reads log entries from the logger -func (s *serviceLog) Read(opts ...log.ReadOption) []log.Record { - // TODO: parse opts - stream, err := s.Client.Log(opts...) - if err != nil { - return nil +func (s *serviceLog) Read(opts ...log.ReadOption) ([]log.Record, error) { + var options log.ReadOptions + for _, o := range opts { + o(&options) } + + stream, err := s.Client.Log(options.Since, options.Count, false) + if err != nil { + return nil, err + } + defer stream.Stop() + // stream the records until nothing is left var records []log.Record - for record := range stream { + + for record := range stream.Chan() { records = append(records, record) } - return records + + return records, nil } // There is no write support -func (s *serviceLog) Write(r log.Record) { - return +func (s *serviceLog) Write(r log.Record) error { + return nil } // Stream log records -func (s *serviceLog) Stream() (<-chan log.Record, chan bool) { - stop := make(chan bool) - stream, err := s.Client.Log(log.Stream(true)) - if err != nil { - // return a closed stream - deadStream := make(chan log.Record) - close(deadStream) - return deadStream, stop - } - - newStream := make(chan log.Record, 128) - - go func() { - for { - select { - case rec := <-stream: - newStream <- rec - case <-stop: - return - } - } - }() - - return newStream, stop +func (s *serviceLog) Stream() (log.Stream, error) { + return s.Client.Log(time.Time{}, 0, true) } // NewLog returns a new log interface diff --git a/debug/service/service.go b/debug/service/service.go index 1da11c6e..805a84a3 100644 --- a/debug/service/service.go +++ b/debug/service/service.go @@ -27,42 +27,40 @@ func NewClient(name string) *debugClient { } } -// Logs queries the service logs and returns a channel to read the logs from -func (d *debugClient) Log(opts ...log.ReadOption) (<-chan log.Record, error) { - var options log.ReadOptions - // initialize the read options - for _, o := range opts { - o(&options) - } - +// Logs queries the services logs and returns a channel to read the logs from +func (d *debugClient) Log(since time.Time, count int, stream bool) (log.Stream, error) { req := &pb.LogRequest{} - if !options.Since.IsZero() { - req.Since = options.Since.Unix() + if !since.IsZero() { + req.Since = since.Unix() } - if options.Count > 0 { - req.Count = int64(options.Count) + if count > 0 { + req.Count = int64(count) } - req.Stream = options.Stream + // set whether to stream + req.Stream = stream // get the log stream - stream, err := d.Client.Log(context.Background(), req) + serverStream, err := d.Client.Log(context.Background(), req) if err != nil { return nil, fmt.Errorf("failed getting log stream: %s", err) } - // log channel for streaming logs - logChan := make(chan log.Record) + lg := &logStream{ + stream: make(chan log.Record), + stop: make(chan bool), + } // go stream logs - go d.streamLogs(logChan, stream) + go d.streamLogs(lg, serverStream) - return logChan, nil + return lg, nil } -func (d *debugClient) streamLogs(logChan chan log.Record, stream pb.Debug_LogService) { +func (d *debugClient) streamLogs(lg *logStream, stream pb.Debug_LogService) { defer stream.Close() + defer lg.Stop() for { resp, err := stream.Recv() @@ -81,8 +79,10 @@ func (d *debugClient) streamLogs(logChan chan log.Record, stream pb.Debug_LogSer Metadata: metadata, } - logChan <- record + select { + case <-lg.stop: + return + case lg.stream <- record: + } } - - close(logChan) } diff --git a/debug/service/stream.go b/debug/service/stream.go new file mode 100644 index 00000000..d7bd9765 --- /dev/null +++ b/debug/service/stream.go @@ -0,0 +1,25 @@ +package service + +import ( + "github.com/micro/go-micro/debug/log" +) + +type logStream struct { + stream chan log.Record + stop chan bool +} + +func (l *logStream) Chan() <-chan log.Record { + return l.stream +} + +func (l *logStream) Stop() error { + select { + case <-l.stop: + return nil + default: + close(l.stream) + close(l.stop) + } + return nil +} From c2b307e5bbde51459ba6e4fa07b95a22cec3466b Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 17 Dec 2019 17:08:31 +0000 Subject: [PATCH 038/788] Merge branch master of https://github.com/micro/go-micro into kubernetes-logging --- debug/log/log.go | 143 ----------------------------------------------- 1 file changed, 143 deletions(-) diff --git a/debug/log/log.go b/debug/log/log.go index 27e5193d..fdce331f 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -34,150 +34,7 @@ type Record struct { Metadata map[string]string `json:"metadata"` } -<<<<<<< HEAD -// Level is a log level -type Level int - -const ( - LevelFatal Level = iota - LevelError - LevelInfo - LevelWarn - LevelDebug - LevelTrace -) - -func init() { - switch os.Getenv("MICRO_LOG_LEVEL") { - case "trace": - DefaultLevel = LevelTrace - case "debug": - DefaultLevel = LevelDebug - case "warn": - DefaultLevel = LevelWarn - case "info": - DefaultLevel = LevelInfo - case "error": - DefaultLevel = LevelError - case "fatal": - DefaultLevel = LevelFatal - } -} - -func log(v ...interface{}) { - if len(prefix) > 0 { - DefaultLog.Write(Record{Value: fmt.Sprint(append([]interface{}{prefix, " "}, v...)...)}) - return - } - DefaultLog.Write(Record{Value: fmt.Sprint(v...)}) -} - -func logf(format string, v ...interface{}) { - if len(prefix) > 0 { - format = prefix + " " + format - } - DefaultLog.Write(Record{Value: fmt.Sprintf(format, v...)}) -} - -// WithLevel logs with the level specified -func WithLevel(l Level, v ...interface{}) { - if l > DefaultLevel { - return - } - log(v...) -} - -// WithLevel logs with the level specified -func WithLevelf(l Level, format string, v ...interface{}) { - if l > DefaultLevel { - return - } - logf(format, v...) -} - -// Trace provides trace level logging -func Trace(v ...interface{}) { - WithLevel(LevelTrace, v...) -} - -// Tracef provides trace level logging -func Tracef(format string, v ...interface{}) { - WithLevelf(LevelTrace, format, v...) -} - -// Debug provides debug level logging -func Debug(v ...interface{}) { - WithLevel(LevelDebug, v...) -} - -// Debugf provides debug level logging -func Debugf(format string, v ...interface{}) { - WithLevelf(LevelDebug, format, v...) -} - -// Warn provides warn level logging -func Warn(v ...interface{}) { - WithLevel(LevelWarn, v...) -} - -// Warnf provides warn level logging -func Warnf(format string, v ...interface{}) { - WithLevelf(LevelWarn, format, v...) -} - -// Info provides info level logging -func Info(v ...interface{}) { - WithLevel(LevelInfo, v...) -} - -// Infof provides info level logging -func Infof(format string, v ...interface{}) { - WithLevelf(LevelInfo, format, v...) -} - -// Error provides warn level logging -func Error(v ...interface{}) { - WithLevel(LevelError, v...) -} - -// Errorf provides warn level logging -func Errorf(format string, v ...interface{}) { - WithLevelf(LevelError, format, v...) -} - -// Fatal logs with Log and then exits with os.Exit(1) -func Fatal(v ...interface{}) { - WithLevel(LevelFatal, v...) - os.Exit(1) -} - -// Fatalf logs with Logf and then exits with os.Exit(1) -func Fatalf(format string, v ...interface{}) { - WithLevelf(LevelFatal, format, v...) - os.Exit(1) -} - -// SetLevel sets the log level -func SetLevel(l Level) { - DefaultLevel = l -} - -// GetLevel returns the current level -func GetLevel() Level { - return DefaultLevel -} - -// Set a prefix for the logger -func SetPrefix(p string) { - prefix = p -} - -// Set service name -func SetName(name string) { - prefix = fmt.Sprintf("[%s]", name) -======= type Stream interface { Chan() <-chan Record Stop() error ->>>>>>> 50d5c6402b1e2bea64476a969b613b7c685d6f8e } From 46fd205eda49b2c527083eb78c282d2addaef54e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 17:08:38 +0000 Subject: [PATCH 039/788] rename files --- debug/service/client.go | 88 ++++++++++++++++++++++++++++++++ debug/service/log.go | 64 ----------------------- debug/service/service.go | 106 +++++++++++++++------------------------ 3 files changed, 129 insertions(+), 129 deletions(-) create mode 100644 debug/service/client.go delete mode 100644 debug/service/log.go diff --git a/debug/service/client.go b/debug/service/client.go new file mode 100644 index 00000000..805a84a3 --- /dev/null +++ b/debug/service/client.go @@ -0,0 +1,88 @@ +// Package service provides the service log +package service + +import ( + "context" + "fmt" + "time" + + "github.com/micro/go-micro/client" + + "github.com/micro/go-micro/debug/log" + pb "github.com/micro/go-micro/debug/service/proto" +) + +// Debug provides debug service client +type debugClient struct { + Client pb.DebugService +} + +// NewClient provides a debug client +func NewClient(name string) *debugClient { + // create default client + cli := client.DefaultClient + + return &debugClient{ + Client: pb.NewDebugService(name, cli), + } +} + +// Logs queries the services logs and returns a channel to read the logs from +func (d *debugClient) Log(since time.Time, count int, stream bool) (log.Stream, error) { + req := &pb.LogRequest{} + if !since.IsZero() { + req.Since = since.Unix() + } + + if count > 0 { + req.Count = int64(count) + } + + // set whether to stream + req.Stream = stream + + // get the log stream + serverStream, err := d.Client.Log(context.Background(), req) + if err != nil { + return nil, fmt.Errorf("failed getting log stream: %s", err) + } + + lg := &logStream{ + stream: make(chan log.Record), + stop: make(chan bool), + } + + // go stream logs + go d.streamLogs(lg, serverStream) + + return lg, nil +} + +func (d *debugClient) streamLogs(lg *logStream, stream pb.Debug_LogService) { + defer stream.Close() + defer lg.Stop() + + for { + resp, err := stream.Recv() + if err != nil { + break + } + + metadata := make(map[string]string) + for k, v := range resp.Metadata { + metadata[k] = v + } + + record := log.Record{ + Timestamp: time.Unix(resp.Timestamp, 0), + Value: resp.Value, + Metadata: metadata, + } + + select { + case <-lg.stop: + return + case lg.stream <- record: + } + } +} diff --git a/debug/service/log.go b/debug/service/log.go deleted file mode 100644 index 95ad0f3c..00000000 --- a/debug/service/log.go +++ /dev/null @@ -1,64 +0,0 @@ -package service - -import ( - "time" - - "github.com/micro/go-micro/debug" - "github.com/micro/go-micro/debug/log" -) - -type serviceLog struct { - Client *debugClient -} - -// Read reads log entries from the logger -func (s *serviceLog) Read(opts ...log.ReadOption) ([]log.Record, error) { - var options log.ReadOptions - for _, o := range opts { - o(&options) - } - - stream, err := s.Client.Log(options.Since, options.Count, false) - if err != nil { - return nil, err - } - defer stream.Stop() - - // stream the records until nothing is left - var records []log.Record - - for record := range stream.Chan() { - records = append(records, record) - } - - return records, nil -} - -// There is no write support -func (s *serviceLog) Write(r log.Record) error { - return nil -} - -// Stream log records -func (s *serviceLog) Stream() (log.Stream, error) { - return s.Client.Log(time.Time{}, 0, true) -} - -// NewLog returns a new log interface -func NewLog(opts ...log.Option) log.Log { - var options log.Options - for _, o := range opts { - o(&options) - } - - name := options.Name - - // set the default name - if len(name) == 0 { - name = debug.DefaultName - } - - return &serviceLog{ - Client: NewClient(name), - } -} diff --git a/debug/service/service.go b/debug/service/service.go index 805a84a3..95ad0f3c 100644 --- a/debug/service/service.go +++ b/debug/service/service.go @@ -1,88 +1,64 @@ -// Package service provides the service log package service import ( - "context" - "fmt" "time" - "github.com/micro/go-micro/client" - + "github.com/micro/go-micro/debug" "github.com/micro/go-micro/debug/log" - pb "github.com/micro/go-micro/debug/service/proto" ) -// Debug provides debug service client -type debugClient struct { - Client pb.DebugService +type serviceLog struct { + Client *debugClient } -// NewClient provides a debug client -func NewClient(name string) *debugClient { - // create default client - cli := client.DefaultClient - - return &debugClient{ - Client: pb.NewDebugService(name, cli), - } -} - -// Logs queries the services logs and returns a channel to read the logs from -func (d *debugClient) Log(since time.Time, count int, stream bool) (log.Stream, error) { - req := &pb.LogRequest{} - if !since.IsZero() { - req.Since = since.Unix() +// Read reads log entries from the logger +func (s *serviceLog) Read(opts ...log.ReadOption) ([]log.Record, error) { + var options log.ReadOptions + for _, o := range opts { + o(&options) } - if count > 0 { - req.Count = int64(count) - } - - // set whether to stream - req.Stream = stream - - // get the log stream - serverStream, err := d.Client.Log(context.Background(), req) + stream, err := s.Client.Log(options.Since, options.Count, false) if err != nil { - return nil, fmt.Errorf("failed getting log stream: %s", err) + return nil, err + } + defer stream.Stop() + + // stream the records until nothing is left + var records []log.Record + + for record := range stream.Chan() { + records = append(records, record) } - lg := &logStream{ - stream: make(chan log.Record), - stop: make(chan bool), - } - - // go stream logs - go d.streamLogs(lg, serverStream) - - return lg, nil + return records, nil } -func (d *debugClient) streamLogs(lg *logStream, stream pb.Debug_LogService) { - defer stream.Close() - defer lg.Stop() +// There is no write support +func (s *serviceLog) Write(r log.Record) error { + return nil +} - for { - resp, err := stream.Recv() - if err != nil { - break - } +// Stream log records +func (s *serviceLog) Stream() (log.Stream, error) { + return s.Client.Log(time.Time{}, 0, true) +} - metadata := make(map[string]string) - for k, v := range resp.Metadata { - metadata[k] = v - } +// NewLog returns a new log interface +func NewLog(opts ...log.Option) log.Log { + var options log.Options + for _, o := range opts { + o(&options) + } - record := log.Record{ - Timestamp: time.Unix(resp.Timestamp, 0), - Value: resp.Value, - Metadata: metadata, - } + name := options.Name - select { - case <-lg.stop: - return - case lg.stream <- record: - } + // set the default name + if len(name) == 0 { + name = debug.DefaultName + } + + return &serviceLog{ + Client: NewClient(name), } } From 81e7edd666252a25df6536055924bdf9ad396c9d Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 17 Dec 2019 17:24:01 +0000 Subject: [PATCH 040/788] Adhere to new interfaces --- debug/log/kubernetes/kubernetes.go | 18 ++++++++++-------- debug/log/kubernetes/kubernetes_test.go | 14 +++++++++----- debug/log/kubernetes/log.go | 25 ++++++++++++++++++++++--- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go index df8e2a6d..56770a6e 100644 --- a/debug/log/kubernetes/kubernetes.go +++ b/debug/log/kubernetes/kubernetes.go @@ -2,21 +2,23 @@ package kubernetes import ( + "errors" + "github.com/micro/go-micro/debug/log" ) type klog struct{} -func (k *klog) Read(...log.ReadOption) []log.Record { return nil } - -func (k *klog) Write(l log.Record) { - write(l) +func (k *klog) Read(...log.ReadOption) ([]log.Record, error) { + return nil, errors.New("not implemented") } -func (k *klog) Stream() (<-chan log.Record, chan bool) { - c, s := make(chan log.Record), make(chan bool) - go close(c) - return c, s +func (k *klog) Write(l log.Record) error { + return write(l) +} + +func (k *klog) Stream() (log.Stream, error) { + return &klogStreamer{}, nil } // New returns a configured Kubernetes logger diff --git a/debug/log/kubernetes/kubernetes_test.go b/debug/log/kubernetes/kubernetes_test.go index 8fac8c08..3ba1cec3 100644 --- a/debug/log/kubernetes/kubernetes_test.go +++ b/debug/log/kubernetes/kubernetes_test.go @@ -39,14 +39,18 @@ func TestKubernetes(t *testing.T) { } assert.Equal(t, write, read, "Write was not equal") - assert.Nil(t, k.Read(), "Read should be unimplemented") + _, err = k.Read() + assert.Error(t, err, "Read should be unimplemented") - stream, stop := k.Stream() + stream, err := k.Stream() + if err != nil { + t.Error(err) + } records := []log.Record{} - for s := range stream { + go stream.Stop() + for s := range stream.Chan() { records = append(records, s) } - close(stop) - assert.Equal(t, 0, len(records), "Stream should be unimplemented") + assert.Equal(t, 0, len(records), "Stream should return nothing") } diff --git a/debug/log/kubernetes/log.go b/debug/log/kubernetes/log.go index ea352165..ad5740ea 100644 --- a/debug/log/kubernetes/log.go +++ b/debug/log/kubernetes/log.go @@ -8,8 +8,27 @@ import ( "os" ) -func write(l log.Record) { - if m, err := json.Marshal(l); err == nil { - fmt.Fprintf(os.Stderr, "%s", m) +func write(l log.Record) error { + m, err := json.Marshal(l) + if err == nil { + _, err := fmt.Fprintf(os.Stderr, "%s", m) + return err } + return err +} + +type klogStreamer struct { + streamChan chan log.Record +} + +func (k *klogStreamer) Chan() <-chan log.Record { + if k.streamChan == nil { + k.streamChan = make(chan log.Record) + } + return k.streamChan +} + +func (k *klogStreamer) Stop() error { + close(k.streamChan) + return nil } From f95bccce841aeb1b437a7144e3a4e60cefae75b2 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 17 Dec 2019 17:36:01 +0000 Subject: [PATCH 041/788] Use UTC in tests --- debug/log/kubernetes/kubernetes_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug/log/kubernetes/kubernetes_test.go b/debug/log/kubernetes/kubernetes_test.go index 3ba1cec3..70f2ea46 100644 --- a/debug/log/kubernetes/kubernetes_test.go +++ b/debug/log/kubernetes/kubernetes_test.go @@ -23,7 +23,7 @@ func TestKubernetes(t *testing.T) { os.Stderr = w meta := make(map[string]string) write := log.Record{ - Timestamp: time.Unix(0, 0), + Timestamp: time.Unix(0, 0).UTC(), Value: "Test log entry", Metadata: meta, } From c2d59c1f4dec13c3310512b93e9a7481a8534a21 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 18:16:45 +0000 Subject: [PATCH 042/788] Move logger --- debug/log/log.go | 2 + debug/log/{default.go => memory/memory.go} | 34 +++---- .../memory_test.go} | 18 ++-- debug/log/{ => memory}/stream.go | 10 +- debug/log/os.go | 97 +++++++++++++++++++ 5 files changed, 132 insertions(+), 29 deletions(-) rename debug/log/{default.go => memory/memory.go} (76%) rename debug/log/{default_test.go => memory/memory_test.go} (59%) rename debug/log/{ => memory}/stream.go (56%) create mode 100644 debug/log/os.go diff --git a/debug/log/log.go b/debug/log/log.go index fdce331f..b5801bac 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -10,6 +10,8 @@ var ( DefaultLog = NewLog() // DefaultLevel is default log level DefaultLevel = LevelInfo + // Default buffer size if any + DefaultSize = 1024 // prefix for all messages prefix string ) diff --git a/debug/log/default.go b/debug/log/memory/memory.go similarity index 76% rename from debug/log/default.go rename to debug/log/memory/memory.go index 428941f0..1083f480 100644 --- a/debug/log/default.go +++ b/debug/log/memory/memory.go @@ -1,9 +1,10 @@ -package log +// Package memory provides an in memory log buffer +package memory import ( "fmt" - golog "log" + "github.com/micro/go-micro/debug/log" "github.com/micro/go-micro/util/ring" ) @@ -12,36 +13,35 @@ var ( DefaultSize = 1024 ) -// defaultLog is default micro log -type defaultLog struct { +// memoryLog is default micro log +type memoryLog struct { *ring.Buffer } // NewLog returns default Logger with -func NewLog(opts ...Option) Log { +func NewLog(opts ...log.Option) log.Log { // get default options - options := DefaultOptions() + options := log.DefaultOptions() // apply requested options for _, o := range opts { o(&options) } - return &defaultLog{ + return &memoryLog{ Buffer: ring.New(options.Size), } } // Write writes logs into logger -func (l *defaultLog) Write(r Record) error { - golog.Print(r.Value) +func (l *memoryLog) Write(r log.Record) error { l.Buffer.Put(fmt.Sprint(r.Value)) return nil } // Read reads logs and returns them -func (l *defaultLog) Read(opts ...ReadOption) ([]Record, error) { - options := ReadOptions{} +func (l *memoryLog) Read(opts ...log.ReadOption) ([]log.Record, error) { + options := log.ReadOptions{} // initialize the read options for _, o := range opts { o(&options) @@ -70,9 +70,9 @@ func (l *defaultLog) Read(opts ...ReadOption) ([]Record, error) { } } - records := make([]Record, 0, len(entries)) + records := make([]log.Record, 0, len(entries)) for _, entry := range entries { - record := Record{ + record := log.Record{ Timestamp: entry.Timestamp, Value: entry.Value, } @@ -84,11 +84,11 @@ func (l *defaultLog) Read(opts ...ReadOption) ([]Record, error) { // Stream returns channel for reading log records // along with a stop channel, close it when done -func (l *defaultLog) Stream() (Stream, error) { +func (l *memoryLog) Stream() (log.Stream, error) { // get stream channel from ring buffer stream, stop := l.Buffer.Stream() // make a buffered channel - records := make(chan Record, 128) + records := make(chan log.Record, 128) // get last 10 records last10 := l.Buffer.Get(10) @@ -96,7 +96,7 @@ func (l *defaultLog) Stream() (Stream, error) { go func() { // first send last 10 records for _, entry := range last10 { - records <- Record{ + records <- log.Record{ Timestamp: entry.Timestamp, Value: entry.Value, Metadata: make(map[string]string), @@ -104,7 +104,7 @@ func (l *defaultLog) Stream() (Stream, error) { } // now stream continuously for entry := range stream { - records <- Record{ + records <- log.Record{ Timestamp: entry.Timestamp, Value: entry.Value, Metadata: make(map[string]string), diff --git a/debug/log/default_test.go b/debug/log/memory/memory_test.go similarity index 59% rename from debug/log/default_test.go rename to debug/log/memory/memory_test.go index 7f5c84e8..470eb2bb 100644 --- a/debug/log/default_test.go +++ b/debug/log/memory/memory_test.go @@ -1,29 +1,29 @@ -package log +package memory import ( "reflect" "testing" + + "github.com/micro/go-micro/debug/log" ) func TestLogger(t *testing.T) { // set size to some value size := 100 // override the global logger - DefaultLog = NewLog(Size(size)) + lg := NewLog(log.Size(size)) // make sure we have the right size of the logger ring buffer - if DefaultLog.(*defaultLog).Size() != size { - t.Errorf("expected buffer size: %d, got: %d", size, DefaultLog.(*defaultLog).Size()) + if lg.(*memoryLog).Size() != size { + t.Errorf("expected buffer size: %d, got: %d", size, lg.(*memoryLog).Size()) } // Log some cruft - Info("foobar") - // increase the log level - DefaultLevel = LevelDebug - Debugf("foo %s", "bar") + lg.Write(log.Record{Value: "foobar"}) + lg.Write(log.Record{Value: "foo bar"}) // Check if the logs are stored in the logger ring buffer expected := []string{"foobar", "foo bar"} - entries, _ := DefaultLog.Read(Count(len(expected))) + entries, _ := lg.Read(log.Count(len(expected))) for i, entry := range entries { if !reflect.DeepEqual(entry.Value, expected[i]) { t.Errorf("expected %s, got %s", expected[i], entry.Value) diff --git a/debug/log/stream.go b/debug/log/memory/stream.go similarity index 56% rename from debug/log/stream.go rename to debug/log/memory/stream.go index 0effe358..a7992230 100644 --- a/debug/log/stream.go +++ b/debug/log/memory/stream.go @@ -1,11 +1,15 @@ -package log +package memory + +import ( + "github.com/micro/go-micro/debug/log" +) type logStream struct { - stream <-chan Record + stream <-chan log.Record stop chan bool } -func (l *logStream) Chan() <-chan Record { +func (l *logStream) Chan() <-chan log.Record { return l.stream } diff --git a/debug/log/os.go b/debug/log/os.go new file mode 100644 index 00000000..458c4bdc --- /dev/null +++ b/debug/log/os.go @@ -0,0 +1,97 @@ +package log + +import ( + "bufio" + "encoding/json" + "os" + "time" +) + +// Should stream from OS +type osLog struct{} + +type osStream struct { + stream chan Record + scanner *bufio.Reader + stop chan bool +} + +// Read reads log entries from the logger +func (o *osLog) Read(...ReadOption) ([]Record, error) { + return []Record{}, nil +} + +// Write writes records to log +func (o *osLog) Write(r Record) error { + b, _ := json.Marshal(r) + _, err := os.Stderr.Write(b) + return err +} + +// Stream log records +func (o *osLog) Stream() (Stream, error) { + // read from standard error + scanner := bufio.NewReader(os.Stderr) + stream := make(chan Record, 128) + stop := make(chan bool) + + go func() { + for { + select { + case <-stop: + return + default: + // read the line + line, err := scanner.ReadString('\n') + if err != nil { + return + } + // check if the line exists + if len(line) == 0 { + continue + } + // parse the record + var r Record + if line[0] == '{' { + json.Unmarshal([]byte(line), &r) + } else { + r = Record{ + Timestamp: time.Now(), + Value: line, + Metadata: make(map[string]string), + } + } + // send to stream + select { + case <-stop: + return + case stream <- r: + } + } + } + }() + + return &osStream{ + stream: stream, + scanner: scanner, + stop: stop, + }, nil +} + +func (o *osStream) Chan() <-chan Record { + return o.stream +} + +func (o *osStream) Stop() error { + select { + case <-o.stop: + return nil + default: + close(o.stop) + } + return nil +} + +func NewLog(opts ...Option) Log { + return &osLog{} +} From c61e12d5ee04bba0899bf3159be8eeddc6a5862d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 18:17:32 +0000 Subject: [PATCH 043/788] add event proto for runtiem --- runtime/service/proto/runtime.pb.go | 154 ++++++++++++++++++++-------- runtime/service/proto/runtime.proto | 7 ++ 2 files changed, 117 insertions(+), 44 deletions(-) diff --git a/runtime/service/proto/runtime.pb.go b/runtime/service/proto/runtime.pb.go index 9d82b555..0e389f5c 100644 --- a/runtime/service/proto/runtime.pb.go +++ b/runtime/service/proto/runtime.pb.go @@ -87,6 +87,69 @@ func (m *Service) GetMetadata() map[string]string { return nil } +type Event struct { + Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` + Timestamp int64 `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Service string `protobuf:"bytes,3,opt,name=service,proto3" json:"service,omitempty"` + Version string `protobuf:"bytes,4,opt,name=version,proto3" json:"version,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Event) Reset() { *m = Event{} } +func (m *Event) String() string { return proto.CompactTextString(m) } +func (*Event) ProtoMessage() {} +func (*Event) Descriptor() ([]byte, []int) { + return fileDescriptor_4bc91a8efec81434, []int{1} +} + +func (m *Event) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Event.Unmarshal(m, b) +} +func (m *Event) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Event.Marshal(b, m, deterministic) +} +func (m *Event) XXX_Merge(src proto.Message) { + xxx_messageInfo_Event.Merge(m, src) +} +func (m *Event) XXX_Size() int { + return xxx_messageInfo_Event.Size(m) +} +func (m *Event) XXX_DiscardUnknown() { + xxx_messageInfo_Event.DiscardUnknown(m) +} + +var xxx_messageInfo_Event proto.InternalMessageInfo + +func (m *Event) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *Event) GetTimestamp() int64 { + if m != nil { + return m.Timestamp + } + return 0 +} + +func (m *Event) GetService() string { + if m != nil { + return m.Service + } + return "" +} + +func (m *Event) GetVersion() string { + if m != nil { + return m.Version + } + return "" +} + type CreateOptions struct { // command to pass in Command []string `protobuf:"bytes,1,rep,name=command,proto3" json:"command,omitempty"` @@ -103,7 +166,7 @@ func (m *CreateOptions) Reset() { *m = CreateOptions{} } func (m *CreateOptions) String() string { return proto.CompactTextString(m) } func (*CreateOptions) ProtoMessage() {} func (*CreateOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{1} + return fileDescriptor_4bc91a8efec81434, []int{2} } func (m *CreateOptions) XXX_Unmarshal(b []byte) error { @@ -157,7 +220,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{2} + return fileDescriptor_4bc91a8efec81434, []int{3} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -202,7 +265,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{3} + return fileDescriptor_4bc91a8efec81434, []int{4} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -239,7 +302,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{4} + return fileDescriptor_4bc91a8efec81434, []int{5} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -292,7 +355,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{5} + return fileDescriptor_4bc91a8efec81434, []int{6} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -331,7 +394,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{6} + return fileDescriptor_4bc91a8efec81434, []int{7} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -370,7 +433,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{7} + return fileDescriptor_4bc91a8efec81434, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -408,7 +471,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{8} + return fileDescriptor_4bc91a8efec81434, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -440,7 +503,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{9} + return fileDescriptor_4bc91a8efec81434, []int{10} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -478,7 +541,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{10} + return fileDescriptor_4bc91a8efec81434, []int{11} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -509,7 +572,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{11} + return fileDescriptor_4bc91a8efec81434, []int{12} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -541,7 +604,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{12} + return fileDescriptor_4bc91a8efec81434, []int{13} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -572,6 +635,7 @@ func (m *ListResponse) GetServices() []*Service { func init() { proto.RegisterType((*Service)(nil), "go.micro.runtime.Service") proto.RegisterMapType((map[string]string)(nil), "go.micro.runtime.Service.MetadataEntry") + proto.RegisterType((*Event)(nil), "go.micro.runtime.Event") proto.RegisterType((*CreateOptions)(nil), "go.micro.runtime.CreateOptions") proto.RegisterType((*CreateRequest)(nil), "go.micro.runtime.CreateRequest") proto.RegisterType((*CreateResponse)(nil), "go.micro.runtime.CreateResponse") @@ -591,36 +655,38 @@ func init() { } var fileDescriptor_4bc91a8efec81434 = []byte{ - // 492 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0xae, 0xe3, 0x10, 0xb7, 0x63, 0x8c, 0xa2, 0x15, 0x42, 0xa6, 0x12, 0x10, 0xf9, 0x42, 0x2f, - 0x38, 0x92, 0x2b, 0xc4, 0xdf, 0xb1, 0x29, 0x5c, 0x88, 0x90, 0x5c, 0xf5, 0x01, 0x96, 0x64, 0x54, - 0x59, 0xd4, 0x5e, 0xb3, 0xbb, 0x8e, 0x94, 0x13, 0x57, 0x5e, 0x8f, 0x37, 0x42, 0xfb, 0x97, 0xd8, - 0xa9, 0xdd, 0x4b, 0x6e, 0x33, 0xbb, 0xb3, 0xdf, 0x7c, 0x3f, 0x96, 0x21, 0x2b, 0x8b, 0x15, 0x67, - 0xf3, 0x3b, 0xf6, 0xce, 0x14, 0xbc, 0xa9, 0x64, 0x51, 0xe2, 0x5c, 0x20, 0xdf, 0x14, 0x2b, 0x9c, - 0xd7, 0x9c, 0xc9, 0xdd, 0x69, 0xaa, 0x3b, 0x32, 0xbd, 0x63, 0xa9, 0x9e, 0x4e, 0xed, 0x79, 0xf2, - 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x2f, 0xbd, 0xfc, 0x1f, - 0x00, 0x00, 0xff, 0xff, 0x14, 0x09, 0x5e, 0x98, 0x81, 0x05, 0x00, 0x00, + // 526 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x4b, 0x6b, 0xdb, 0x40, + 0x10, 0x8e, 0x2d, 0xc7, 0x4e, 0x46, 0x55, 0x31, 0x4b, 0x29, 0x6a, 0xe8, 0xc3, 0xe8, 0xd2, 0x5c, + 0x2a, 0x83, 0x42, 0xe9, 0xeb, 0x18, 0xbb, 0xbd, 0xd4, 0x14, 0x14, 0xf2, 0x03, 0xb6, 0xf6, 0x10, + 0x44, 0x23, 0xad, 0xaa, 0x5d, 0x09, 0x7c, 0xea, 0xb5, 0x7f, 0xaf, 0xff, 0xa8, 0xec, 0x4b, 0x0f, + 0x47, 0xca, 0xc5, 0xb7, 0x99, 0xd9, 0xd9, 0x4f, 0xdf, 0x63, 0x11, 0x44, 0x69, 0xb2, 0x2d, 0xd8, + 0xf2, 0x8e, 0xbd, 0xd3, 0x45, 0x51, 0x66, 0x22, 0x49, 0x71, 0xc9, 0xb1, 0xa8, 0x92, 0x2d, 0x2e, + 0xf3, 0x82, 0x89, 0x7a, 0x1a, 0xaa, 0x8e, 0xcc, 0xef, 0x58, 0xa8, 0xb6, 0x43, 0x33, 0x0f, 0xfe, + 0x8d, 0x60, 0x76, 0xa3, 0x6f, 0x10, 0x02, 0x93, 0x8c, 0xa6, 0xe8, 0x8f, 0x16, 0xa3, 0xcb, 0xf3, + 0x58, 0xd5, 0xc4, 0x87, 0x59, 0x85, 0x05, 0x4f, 0x58, 0xe6, 0x8f, 0xd5, 0xd8, 0xb6, 0xe4, 0x39, + 0x4c, 0x39, 0x2b, 0x8b, 0x2d, 0xfa, 0x8e, 0x3a, 0x30, 0x1d, 0xb9, 0x86, 0xb3, 0x14, 0x05, 0xdd, + 0x51, 0x41, 0x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xca, 0x36, 0xa1, 0x7e, 0xab, 0x0e, + 0xde, 0x8c, 0x0d, 0xc4, 0x69, 0x02, 0x09, 0xbe, 0x6a, 0x58, 0xab, 0xf3, 0x43, 0x43, 0x59, 0xeb, + 0x7c, 0xf5, 0x90, 0x72, 0x8b, 0x46, 0x43, 0x78, 0x0d, 0x4f, 0x34, 0x8e, 0xa6, 0x4b, 0xde, 0xc3, + 0x99, 0x21, 0xc4, 0x55, 0x0c, 0x8f, 0x3a, 0x56, 0xaf, 0x06, 0x2b, 0xf0, 0x56, 0x78, 0x8f, 0xc7, + 0x19, 0x2f, 0xdd, 0xb3, 0x28, 0xc6, 0xbd, 0x15, 0x78, 0xb7, 0xf9, 0x8e, 0x1e, 0x8f, 0x6b, 0x51, + 0x0c, 0xae, 0x07, 0xee, 0xf7, 0x84, 0x0b, 0x83, 0x2a, 0x5d, 0xd0, 0xed, 0x51, 0x2e, 0x44, 0x7f, + 0x1d, 0x98, 0xc5, 0xfa, 0x94, 0x6c, 0x60, 0xaa, 0x5f, 0x02, 0x19, 0x7c, 0x3d, 0xe6, 0xeb, 0x17, + 0x8b, 0xe1, 0x05, 0x43, 0xf7, 0x84, 0x7c, 0x83, 0x89, 0xcc, 0x89, 0x0c, 0xe4, 0x6a, 0xa1, 0x5e, + 0x0f, 0x1d, 0xd7, 0x40, 0x1b, 0x98, 0x6a, 0x8f, 0xfb, 0x78, 0x75, 0x32, 0xec, 0xe3, 0x75, 0x10, + 0x8f, 0x82, 0xd3, 0xd6, 0xf6, 0xc1, 0x75, 0xa2, 0xeb, 0x83, 0x3b, 0x48, 0x45, 0xc9, 0x94, 0x41, + 0xf4, 0xc9, 0x6c, 0xe5, 0xd5, 0x27, 0xb3, 0x9d, 0x5f, 0x70, 0xf2, 0x73, 0xaa, 0x7e, 0xdd, 0x57, + 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0xcd, 0x8e, 0xbb, 0xe1, 0xf0, 0x05, 0x00, 0x00, } diff --git a/runtime/service/proto/runtime.proto b/runtime/service/proto/runtime.proto index 3da3b17d..a292c88b 100644 --- a/runtime/service/proto/runtime.proto +++ b/runtime/service/proto/runtime.proto @@ -21,6 +21,13 @@ message Service { map metadata = 4; } +message Event { + string type = 1; + int64 timestamp = 2; + string service = 3; + string version = 4; +} + message CreateOptions { // command to pass in repeated string command = 1; From 5a52593e66a9b66408ebd50665da851876d8264d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 18:24:00 +0000 Subject: [PATCH 044/788] go fmt --- debug/service/client.go | 20 ++++++++++---------- util/ring/buffer.go | 5 ++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/debug/service/client.go b/debug/service/client.go index 805a84a3..44da0568 100644 --- a/debug/service/client.go +++ b/debug/service/client.go @@ -17,16 +17,6 @@ type debugClient struct { Client pb.DebugService } -// NewClient provides a debug client -func NewClient(name string) *debugClient { - // create default client - cli := client.DefaultClient - - return &debugClient{ - Client: pb.NewDebugService(name, cli), - } -} - // Logs queries the services logs and returns a channel to read the logs from func (d *debugClient) Log(since time.Time, count int, stream bool) (log.Stream, error) { req := &pb.LogRequest{} @@ -86,3 +76,13 @@ func (d *debugClient) streamLogs(lg *logStream, stream pb.Debug_LogService) { } } } + +// NewClient provides a debug client +func NewClient(name string) *debugClient { + // create default client + cli := client.DefaultClient + + return &debugClient{ + Client: pb.NewDebugService(name, cli), + } +} diff --git a/util/ring/buffer.go b/util/ring/buffer.go index bb8febcf..e49f1312 100644 --- a/util/ring/buffer.go +++ b/util/ring/buffer.go @@ -26,11 +26,11 @@ type Entry struct { // Stream is used to stream the buffer type Stream struct { // Id of the stream - Id string + Id string // Buffered entries Entries chan *Entry // Stop channel - Stop chan bool + Stop chan bool } // Put adds a new value to ring buffer @@ -142,4 +142,3 @@ func New(i int) *Buffer { streams: make(map[string]*Stream), } } - From e9efcbe8dc8ba671ed3be81ec14e0815ca777431 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 18:34:21 +0000 Subject: [PATCH 045/788] strip logger --- debug/log/kubernetes/kubernetes.go | 5 +- debug/log/kubernetes/{log.go => stream.go} | 14 ++- debug/log/level.go | 35 ------ debug/log/log.go | 11 +- debug/log/logger.go | 120 --------------------- 5 files changed, 18 insertions(+), 167 deletions(-) rename debug/log/kubernetes/{log.go => stream.go} (75%) delete mode 100644 debug/log/level.go delete mode 100644 debug/log/logger.go diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go index 56770a6e..06ecf790 100644 --- a/debug/log/kubernetes/kubernetes.go +++ b/debug/log/kubernetes/kubernetes.go @@ -18,7 +18,10 @@ func (k *klog) Write(l log.Record) error { } func (k *klog) Stream() (log.Stream, error) { - return &klogStreamer{}, nil + return &klogStreamer{ + streamChan: make(chan log.Record), + stop: make(chan bool), + }, nil } // New returns a configured Kubernetes logger diff --git a/debug/log/kubernetes/log.go b/debug/log/kubernetes/stream.go similarity index 75% rename from debug/log/kubernetes/log.go rename to debug/log/kubernetes/stream.go index ad5740ea..b62434a0 100644 --- a/debug/log/kubernetes/log.go +++ b/debug/log/kubernetes/stream.go @@ -18,17 +18,23 @@ func write(l log.Record) error { } type klogStreamer struct { + // the k8s log stream streamChan chan log.Record + // the stop chan + stop chan bool } func (k *klogStreamer) Chan() <-chan log.Record { - if k.streamChan == nil { - k.streamChan = make(chan log.Record) - } return k.streamChan } func (k *klogStreamer) Stop() error { - close(k.streamChan) + select { + case <-k.stop: + return nil + default: + close(k.stop) + close(k.streamChan) + } return nil } diff --git a/debug/log/level.go b/debug/log/level.go deleted file mode 100644 index 2f8b425c..00000000 --- a/debug/log/level.go +++ /dev/null @@ -1,35 +0,0 @@ -// Package log provides debug logging -package log - -import ( - "os" -) - -// level is a log level -type Level int - -const ( - LevelFatal Level = iota - LevelError - LevelInfo - LevelWarn - LevelDebug - LevelTrace -) - -func init() { - switch os.Getenv("MICRO_LOG_LEVEL") { - case "trace": - DefaultLevel = LevelTrace - case "debug": - DefaultLevel = LevelDebug - case "warn": - DefaultLevel = LevelWarn - case "info": - DefaultLevel = LevelInfo - case "error": - DefaultLevel = LevelError - case "fatal": - DefaultLevel = LevelFatal - } -} diff --git a/debug/log/log.go b/debug/log/log.go index b5801bac..a9689da6 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -6,17 +6,13 @@ import ( ) var ( - // DefaultLog logger - DefaultLog = NewLog() - // DefaultLevel is default log level - DefaultLevel = LevelInfo // Default buffer size if any DefaultSize = 1024 - // prefix for all messages - prefix string + // DefaultLog logger + DefaultLog = NewLog() ) -// Log is event log +// Log is debug log interface for reading and writing logs type Log interface { // Read reads log entries from the logger Read(...ReadOption) ([]Record, error) @@ -36,6 +32,7 @@ type Record struct { Metadata map[string]string `json:"metadata"` } +// Stream returns a log stream type Stream interface { Chan() <-chan Record Stop() error diff --git a/debug/log/logger.go b/debug/log/logger.go deleted file mode 100644 index 912defc2..00000000 --- a/debug/log/logger.go +++ /dev/null @@ -1,120 +0,0 @@ -// Package log provides debug logging -package log - -import ( - "fmt" - "os" -) - -func log(v ...interface{}) { - if len(prefix) > 0 { - DefaultLog.Write(Record{Value: fmt.Sprint(append([]interface{}{prefix, " "}, v...)...)}) - return - } - DefaultLog.Write(Record{Value: fmt.Sprint(v...)}) -} - -func logf(format string, v ...interface{}) { - if len(prefix) > 0 { - format = prefix + " " + format - } - DefaultLog.Write(Record{Value: fmt.Sprintf(format, v...)}) -} - -// WithLevel logs with the level specified -func WithLevel(l Level, v ...interface{}) { - if l > DefaultLevel { - return - } - log(v...) -} - -// WithLevel logs with the level specified -func WithLevelf(l Level, format string, v ...interface{}) { - if l > DefaultLevel { - return - } - logf(format, v...) -} - -// Trace provides trace level logging -func Trace(v ...interface{}) { - WithLevel(LevelTrace, v...) -} - -// Tracef provides trace level logging -func Tracef(format string, v ...interface{}) { - WithLevelf(LevelTrace, format, v...) -} - -// Debug provides debug level logging -func Debug(v ...interface{}) { - WithLevel(LevelDebug, v...) -} - -// Debugf provides debug level logging -func Debugf(format string, v ...interface{}) { - WithLevelf(LevelDebug, format, v...) -} - -// Warn provides warn level logging -func Warn(v ...interface{}) { - WithLevel(LevelWarn, v...) -} - -// Warnf provides warn level logging -func Warnf(format string, v ...interface{}) { - WithLevelf(LevelWarn, format, v...) -} - -// Info provides info level logging -func Info(v ...interface{}) { - WithLevel(LevelInfo, v...) -} - -// Infof provides info level logging -func Infof(format string, v ...interface{}) { - WithLevelf(LevelInfo, format, v...) -} - -// Error provides warn level logging -func Error(v ...interface{}) { - WithLevel(LevelError, v...) -} - -// Errorf provides warn level logging -func Errorf(format string, v ...interface{}) { - WithLevelf(LevelError, format, v...) -} - -// Fatal logs with Log and then exits with os.Exit(1) -func Fatal(v ...interface{}) { - WithLevel(LevelFatal, v...) - os.Exit(1) -} - -// Fatalf logs with Logf and then exits with os.Exit(1) -func Fatalf(format string, v ...interface{}) { - WithLevelf(LevelFatal, format, v...) - os.Exit(1) -} - -// SetLevel sets the log level -func SetLevel(l Level) { - DefaultLevel = l -} - -// GetLevel returns the current level -func GetLevel() Level { - return DefaultLevel -} - -// Set a prefix for the logger -func SetPrefix(p string) { - prefix = p -} - -// Set service name -func SetName(name string) { - prefix = fmt.Sprintf("[%s]", name) -} From 515014fbeb5eb68268feea878c64552c324209f5 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 21:27:05 +0000 Subject: [PATCH 046/788] update with resource --- auth/auth.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index d34bf1fb..57286a85 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -7,12 +7,20 @@ import ( // Auth providers authentication and authorization type Auth interface { - // Generate a new authorization token - Generate(u string) (*Token, error) + // Generate a new auth token + Generate(string) (*Token, error) // Revoke an authorization token - Revoke(t *Token) error - // Verify a token - Verify(t *Token) error + Revoke(*Token) error + // Grant access to a resource + Grant(*Token, *Resource) error + // Verify a token can access a resource + Verify(*Token, *Resource) error +} + +// Resource is some thing to provide access to +type Resource struct { + // Name of the resource + Name string } // Token providers by an auth provider From ebae497a7251006b535008dabe21295dba8cf451 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 21:37:20 +0000 Subject: [PATCH 047/788] use service rather than resource --- auth/auth.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 57286a85..109019c4 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -12,15 +12,17 @@ type Auth interface { // Revoke an authorization token Revoke(*Token) error // Grant access to a resource - Grant(*Token, *Resource) error + Grant(*Token, *Service) error // Verify a token can access a resource - Verify(*Token, *Resource) error + Verify(*Token, *Service) error } -// Resource is some thing to provide access to -type Resource struct { +// Service is some thing to provide access to +type Service struct { // Name of the resource Name string + // Endpoint is the specific endpoint + Endpoint string } // Token providers by an auth provider From cb9c4c3aeff85b25275f472ac89ff861e7a57ff8 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 17 Dec 2019 23:05:46 +0000 Subject: [PATCH 048/788] publisher => event --- event.go | 16 ++++++++++++++++ micro.go | 18 +++++++++++++----- publisher.go | 16 ---------------- 3 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 event.go delete mode 100644 publisher.go diff --git a/event.go b/event.go new file mode 100644 index 00000000..5301c747 --- /dev/null +++ b/event.go @@ -0,0 +1,16 @@ +package micro + +import ( + "context" + + "github.com/micro/go-micro/client" +) + +type event struct { + c client.Client + topic string +} + +func (e *event) Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error { + return e.c.Publish(ctx, e.c.NewMessage(e.topic, msg), opts...) +} diff --git a/micro.go b/micro.go index a8cb7368..6dc43848 100644 --- a/micro.go +++ b/micro.go @@ -62,12 +62,15 @@ type Resource interface { } */ -// Publisher is uses to publish messages to a topic -type Publisher interface { +// Event is used to publish messages to a topic +type Event interface { // Publish publishes a message to the event topic Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error } +// Type alias to satisfy the deprecation +type Publisher = Event + type Option func(*Options) var ( @@ -95,12 +98,17 @@ func NewFunction(opts ...Option) Function { return newFunction(opts...) } -// NewPublisher returns a new Publisher -func NewPublisher(topic string, c client.Client) Publisher { +// NewEvent creates a new event publisher +func NewEvent(topic string, c client.Client) Event { if c == nil { c = client.NewClient() } - return &publisher{c, topic} + return &event{c, topic} +} + +// Deprecated: NewPublisher returns a new Publisher +func NewPublisher(topic string, c client.Client) Event { + return NewEvent(topic, c) } // RegisterHandler is syntactic sugar for registering a handler diff --git a/publisher.go b/publisher.go deleted file mode 100644 index c3bfbff3..00000000 --- a/publisher.go +++ /dev/null @@ -1,16 +0,0 @@ -package micro - -import ( - "context" - - "github.com/micro/go-micro/client" -) - -type publisher struct { - c client.Client - topic string -} - -func (p *publisher) Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error { - return p.c.Publish(ctx, p.c.NewMessage(p.topic, msg), opts...) -} From 7c21a1b92ac1f43f55fa28cc8d65e45a393fff95 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 18 Dec 2019 15:06:02 +0000 Subject: [PATCH 049/788] go fmt --- auth/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/auth.go b/auth/auth.go index 109019c4..a7750745 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -21,7 +21,7 @@ type Auth interface { type Service struct { // Name of the resource Name string - // Endpoint is the specific endpoint + // Endpoint is the specific endpoint Endpoint string } From 5d7254e79a43165c16d841b1e0252362a422fc1b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 18 Dec 2019 15:06:25 +0000 Subject: [PATCH 050/788] fix the os logger --- debug/log/os.go | 172 ++++++++++++++++++++++++++++++++++-------------- go.mod | 2 +- go.sum | 2 + 3 files changed, 126 insertions(+), 50 deletions(-) diff --git a/debug/log/os.go b/debug/log/os.go index 458c4bdc..60f47d05 100644 --- a/debug/log/os.go +++ b/debug/log/os.go @@ -3,17 +3,117 @@ package log import ( "bufio" "encoding/json" + "io" "os" + "sync" "time" + + "github.com/google/uuid" ) // Should stream from OS -type osLog struct{} +type osLog struct { + sync.RWMutex + subs map[string]*osStream +} type osStream struct { - stream chan Record - scanner *bufio.Reader - stop chan bool + stream chan Record + stop chan bool +} + +// watch io stream +func (o *osLog) run() { + // save outputs + stdout := *os.Stdout + stderr := *os.Stderr + + // new os pipe + r, w := io.Pipe() + + // create new iopipes + r1, w1, _ := os.Pipe() + r2, w2, _ := os.Pipe() + + // create tea readers + tee1 := io.TeeReader(r1, &stdout) + tee2 := io.TeeReader(r2, &stderr) + + // start copying + go io.Copy(w, tee1) + go io.Copy(w, tee2) + + // set default go log output + //log.SetOutput(w2) + + // replace os stdout and os stderr + *os.Stdout = *w1 + *os.Stderr = *w2 + + // this should short circuit everything + defer func() { + // reset stdout and stderr + *os.Stdout = stdout + *os.Stderr = stderr + //log.SetOutput(stderr) + + // close all the outputs + r.Close() + r1.Close() + r2.Close() + w.Close() + w1.Close() + w2.Close() + }() + + // read from standard error + scanner := bufio.NewReader(r) + + for { + // read the line + line, err := scanner.ReadString('\n') + if err != nil { + return + } + // check if the line exists + if len(line) == 0 { + continue + } + // parse the record + var r Record + if line[0] == '{' { + json.Unmarshal([]byte(line), &r) + } else { + r = Record{ + Timestamp: time.Now(), + Value: line, + Metadata: make(map[string]string), + } + } + + o.Lock() + + // bail if there's no subscribers + if len(o.subs) == 0 { + o.Unlock() + return + } + + // check subs and send to stream + for id, sub := range o.subs { + // send to stream + select { + case <-sub.stop: + delete(o.subs, id) + case sub.stream <- r: + // send to stream + default: + // do not block + } + } + + o.Unlock() + } } // Read reads log entries from the logger @@ -30,52 +130,24 @@ func (o *osLog) Write(r Record) error { // Stream log records func (o *osLog) Stream() (Stream, error) { - // read from standard error - scanner := bufio.NewReader(os.Stderr) - stream := make(chan Record, 128) - stop := make(chan bool) + o.Lock() + defer o.Unlock() - go func() { - for { - select { - case <-stop: - return - default: - // read the line - line, err := scanner.ReadString('\n') - if err != nil { - return - } - // check if the line exists - if len(line) == 0 { - continue - } - // parse the record - var r Record - if line[0] == '{' { - json.Unmarshal([]byte(line), &r) - } else { - r = Record{ - Timestamp: time.Now(), - Value: line, - Metadata: make(map[string]string), - } - } - // send to stream - select { - case <-stop: - return - case stream <- r: - } - } - } - }() + // start stream watcher + if len(o.subs) == 0 { + go o.run() + } - return &osStream{ - stream: stream, - scanner: scanner, - stop: stop, - }, nil + // create stream + st := &osStream{ + stream: make(chan Record, 128), + stop: make(chan bool), + } + + // save stream + o.subs[uuid.New().String()] = st + + return st, nil } func (o *osStream) Chan() <-chan Record { @@ -93,5 +165,7 @@ func (o *osStream) Stop() error { } func NewLog(opts ...Option) Log { - return &osLog{} + return &osLog{ + subs: make(map[string]*osStream), + } } diff --git a/go.mod b/go.mod index 5e442a33..498f4f3f 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/fsouza/go-dockerclient v1.6.0 github.com/ghodss/yaml v1.0.0 github.com/go-acme/lego/v3 v3.1.0 - github.com/go-log/log v0.1.0 + github.com/go-log/log v0.2.0 github.com/go-playground/locales v0.13.0 // indirect github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 diff --git a/go.sum b/go.sum index 8a137787..469bfba7 100644 --- a/go.sum +++ b/go.sum @@ -129,6 +129,8 @@ github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3I github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-log/log v0.1.0 h1:wudGTNsiGzrD5ZjgIkVZ517ugi2XRe9Q/xRCzwEO4/U= github.com/go-log/log v0.1.0/go.mod h1:4mBwpdRMFLiuXZDCwU2lKQFsoSCo72j3HqBK9d81N2M= +github.com/go-log/log v0.2.0 h1:z8i91GBudxD5L3RmF0KVpetCbcGWAV7q1Tw1eRwQM9Q= +github.com/go-log/log v0.2.0/go.mod h1:xzCnwajcues/6w7lne3yK2QU7DBPW7kqbgPGG5AF65U= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= From a82af19d43c236982bdc5aa56b7f4897d45c1863 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 18 Dec 2019 15:19:20 +0000 Subject: [PATCH 051/788] strip newline --- debug/log/os.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/debug/log/os.go b/debug/log/os.go index 60f47d05..1404a5b2 100644 --- a/debug/log/os.go +++ b/debug/log/os.go @@ -5,6 +5,7 @@ import ( "encoding/json" "io" "os" + "strings" "sync" "time" @@ -86,7 +87,7 @@ func (o *osLog) run() { } else { r = Record{ Timestamp: time.Now(), - Value: line, + Value: strings.TrimSuffix(line, "\n"), Metadata: make(map[string]string), } } From f0e841595c5088ab0c5c398e4fceadf412cd1aa4 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 18 Dec 2019 16:02:11 +0000 Subject: [PATCH 052/788] move to structured logging --- debug/log/kubernetes/kubernetes_test.go | 2 +- debug/log/log.go | 6 +- debug/log/memory/memory.go | 8 +-- debug/log/memory/memory_test.go | 8 +-- debug/log/os.go | 4 +- debug/service/client.go | 2 +- debug/service/handler/debug.go | 2 +- debug/service/proto/debug.pb.go | 79 +++++++++++++------------ debug/service/proto/debug.proto | 6 +- util/log/log.go | 56 ++++++++++++++---- 10 files changed, 102 insertions(+), 71 deletions(-) diff --git a/debug/log/kubernetes/kubernetes_test.go b/debug/log/kubernetes/kubernetes_test.go index 70f2ea46..27c3a6d9 100644 --- a/debug/log/kubernetes/kubernetes_test.go +++ b/debug/log/kubernetes/kubernetes_test.go @@ -24,7 +24,7 @@ func TestKubernetes(t *testing.T) { meta := make(map[string]string) write := log.Record{ Timestamp: time.Unix(0, 0).UTC(), - Value: "Test log entry", + Message: "Test log entry", Metadata: meta, } meta["foo"] = "bar" diff --git a/debug/log/log.go b/debug/log/log.go index a9689da6..a5958ad3 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -25,11 +25,11 @@ type Log interface { // Record is log record entry type Record struct { // Timestamp of logged event - Timestamp time.Time `json:"time"` - // Value contains log entry - Value interface{} `json:"value"` + Timestamp time.Time `json:"timestamp"` // Metadata to enrich log record Metadata map[string]string `json:"metadata"` + // Value contains log entry + Message interface{} `json:"message"` } // Stream returns a log stream diff --git a/debug/log/memory/memory.go b/debug/log/memory/memory.go index 1083f480..18215701 100644 --- a/debug/log/memory/memory.go +++ b/debug/log/memory/memory.go @@ -35,7 +35,7 @@ func NewLog(opts ...log.Option) log.Log { // Write writes logs into logger func (l *memoryLog) Write(r log.Record) error { - l.Buffer.Put(fmt.Sprint(r.Value)) + l.Buffer.Put(fmt.Sprint(r.Message)) return nil } @@ -74,7 +74,7 @@ func (l *memoryLog) Read(opts ...log.ReadOption) ([]log.Record, error) { for _, entry := range entries { record := log.Record{ Timestamp: entry.Timestamp, - Value: entry.Value, + Message: entry.Value, } records = append(records, record) } @@ -98,7 +98,7 @@ func (l *memoryLog) Stream() (log.Stream, error) { for _, entry := range last10 { records <- log.Record{ Timestamp: entry.Timestamp, - Value: entry.Value, + Message: entry.Value, Metadata: make(map[string]string), } } @@ -106,7 +106,7 @@ func (l *memoryLog) Stream() (log.Stream, error) { for entry := range stream { records <- log.Record{ Timestamp: entry.Timestamp, - Value: entry.Value, + Message: entry.Value, Metadata: make(map[string]string), } } diff --git a/debug/log/memory/memory_test.go b/debug/log/memory/memory_test.go index 470eb2bb..db907f75 100644 --- a/debug/log/memory/memory_test.go +++ b/debug/log/memory/memory_test.go @@ -18,15 +18,15 @@ func TestLogger(t *testing.T) { } // Log some cruft - lg.Write(log.Record{Value: "foobar"}) - lg.Write(log.Record{Value: "foo bar"}) + lg.Write(log.Record{Message: "foobar"}) + lg.Write(log.Record{Message: "foo bar"}) // Check if the logs are stored in the logger ring buffer expected := []string{"foobar", "foo bar"} entries, _ := lg.Read(log.Count(len(expected))) for i, entry := range entries { - if !reflect.DeepEqual(entry.Value, expected[i]) { - t.Errorf("expected %s, got %s", expected[i], entry.Value) + if !reflect.DeepEqual(entry.Message, expected[i]) { + t.Errorf("expected %s, got %s", expected[i], entry.Message) } } } diff --git a/debug/log/os.go b/debug/log/os.go index 1404a5b2..bae3662e 100644 --- a/debug/log/os.go +++ b/debug/log/os.go @@ -87,7 +87,7 @@ func (o *osLog) run() { } else { r = Record{ Timestamp: time.Now(), - Value: strings.TrimSuffix(line, "\n"), + Message: strings.TrimSuffix(line, "\n"), Metadata: make(map[string]string), } } @@ -125,7 +125,7 @@ func (o *osLog) Read(...ReadOption) ([]Record, error) { // Write writes records to log func (o *osLog) Write(r Record) error { b, _ := json.Marshal(r) - _, err := os.Stderr.Write(b) + _, err := os.Stderr.Write(append(b, byte('\n'))) return err } diff --git a/debug/service/client.go b/debug/service/client.go index 44da0568..e7d14fda 100644 --- a/debug/service/client.go +++ b/debug/service/client.go @@ -65,7 +65,7 @@ func (d *debugClient) streamLogs(lg *logStream, stream pb.Debug_LogService) { record := log.Record{ Timestamp: time.Unix(resp.Timestamp, 0), - Value: resp.Value, + Message: resp.Message, Metadata: metadata, } diff --git a/debug/service/handler/debug.go b/debug/service/handler/debug.go index c0e26c5e..7d2f40f5 100644 --- a/debug/service/handler/debug.go +++ b/debug/service/handler/debug.go @@ -111,7 +111,7 @@ func (d *Debug) sendRecord(record log.Record, stream server.Stream) error { return stream.Send(&proto.Record{ Timestamp: record.Timestamp.Unix(), - Value: record.Value.(string), + Message: record.Message.(string), Metadata: metadata, }) } diff --git a/debug/service/proto/debug.pb.go b/debug/service/proto/debug.pb.go index f76bbba3..4ea6ae42 100644 --- a/debug/service/proto/debug.pb.go +++ b/debug/service/proto/debug.pb.go @@ -299,13 +299,13 @@ func (m *LogRequest) GetSince() int64 { type Record struct { // timestamp of log record Timestamp int64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - // record value - Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` // record metadata - Metadata map[string]string `protobuf:"bytes,3,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Metadata map[string]string `protobuf:"bytes,2,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + // message + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Record) Reset() { *m = Record{} } @@ -340,13 +340,6 @@ func (m *Record) GetTimestamp() int64 { return 0 } -func (m *Record) GetValue() string { - if m != nil { - return m.Value - } - return "" -} - func (m *Record) GetMetadata() map[string]string { if m != nil { return m.Metadata @@ -354,6 +347,13 @@ func (m *Record) GetMetadata() map[string]string { return nil } +func (m *Record) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + func init() { proto.RegisterType((*HealthRequest)(nil), "HealthRequest") proto.RegisterType((*HealthResponse)(nil), "HealthResponse") @@ -369,30 +369,31 @@ func init() { } var fileDescriptor_dea322649cde1ef2 = []byte{ - // 399 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0xc1, 0x6e, 0xd4, 0x30, - 0x10, 0xdd, 0xac, 0x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xdd, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xea, 0xdf, 0xa5, 0x1d, 0xf7, 0x02, 0x00, 0x00, + // 407 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcf, 0x6e, 0x13, 0x31, + 0x10, 0xc6, 0xb3, 0xbb, 0xcd, 0xb6, 0x99, 0x92, 0x80, 0x2c, 0x40, 0x56, 0x84, 0x44, 0xe5, 0xd3, + 0x22, 0x84, 0x03, 0xe5, 0x82, 0xe0, 0x0a, 0x12, 0x87, 0x72, 0x31, 0x4f, 0xe0, 0xee, 0x8e, 0xb6, + 0x81, 0x3a, 0x0e, 0xf6, 0x6c, 0xa5, 0x9c, 0x78, 0x16, 0xde, 0x80, 0x47, 0x44, 0xfe, 0xb3, 0xb4, + 0xab, 0x1e, 0x7a, 0xf3, 0xef, 0xf3, 0xe7, 0xd1, 0xcc, 0xf8, 0x03, 0x69, 0xb6, 0xad, 0xb3, 0x9b, + 0xde, 0xbe, 0x49, 0x87, 0x0e, 0x2f, 0x87, 0x7e, 0xe3, 0xd1, 0xdd, 0x6c, 0x5b, 0xdc, 0xec, 0x9d, + 0xa5, 0xac, 0xc9, 0x78, 0x16, 0xaf, 0x60, 0xf9, 0x15, 0xf5, 0x35, 0x5d, 0x29, 0xfc, 0x35, 0xa0, + 0x27, 0xc6, 0xe1, 0x38, 0xbb, 0x79, 0x71, 0x56, 0x34, 0x0b, 0x35, 0xa2, 0x68, 0x60, 0x35, 0x5a, + 0xfd, 0xde, 0xee, 0x3c, 0xb2, 0xe7, 0x50, 0x7b, 0xd2, 0x34, 0xf8, 0x6c, 0xcd, 0x24, 0x1a, 0x78, + 0xf4, 0x9d, 0x34, 0xf9, 0x87, 0x6b, 0xfe, 0x29, 0x60, 0x99, 0xad, 0xb9, 0xe6, 0x0b, 0x58, 0xd0, + 0xd6, 0xa0, 0x27, 0x6d, 0xf6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, 0x27, 0x99, 0x5a, 0x3f, 0x96, + 0xd3, 0xe0, 0x88, 0x19, 0x6b, 0x60, 0x1e, 0xff, 0x9d, 0x2d, 0xe5, 0xdd, 0xa8, 0xac, 0x57, 0x72, + 0x12, 0x07, 0x31, 0x63, 0x2f, 0xa1, 0xba, 0xb0, 0x3d, 0x3b, 0x95, 0xb7, 0x9f, 0xb0, 0x3e, 0xce, + 0xb3, 0x8a, 0xd9, 0xdb, 0xe2, 0xb2, 0x8e, 0x49, 0x7e, 0xff, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x4e, + 0xd3, 0x4c, 0xce, 0xfb, 0x02, 0x00, 0x00, } diff --git a/debug/service/proto/debug.proto b/debug/service/proto/debug.proto index 4f639245..4b803152 100644 --- a/debug/service/proto/debug.proto +++ b/debug/service/proto/debug.proto @@ -54,8 +54,8 @@ message LogRequest { message Record { // timestamp of log record int64 timestamp = 1; - // record value - string value = 2; // record metadata - map metadata = 3; + map metadata = 2; + // message + string message = 3; } diff --git a/util/log/log.go b/util/log/log.go index 52184c5e..360f8039 100644 --- a/util/log/log.go +++ b/util/log/log.go @@ -4,9 +4,9 @@ package log import ( "fmt" "os" + "time" - "github.com/go-log/log" - golog "github.com/go-log/log/log" + "github.com/micro/go-micro/debug/log" ) // level is a log level @@ -23,7 +23,7 @@ const ( var ( // the local logger - logger log.Logger = golog.New() + logger log.Log = log.DefaultLog // default log level is info level = LevelInfo @@ -49,21 +49,51 @@ func init() { } } -// Log makes use of github.com/go-log/log.Log -func Log(v ...interface{}) { - if len(prefix) > 0 { - logger.Log(append([]interface{}{prefix, " "}, v...)...) - return +func (l Level) String() string { + switch l { + case LevelTrace: + return "trace" + case LevelDebug: + return "debug" + case LevelWarn: + return "warn" + case LevelInfo: + return "info" + case LevelError: + return "error" + case LevelFatal: + return "fatal" + default: + return "unknown" } - logger.Log(v...) } -// Logf makes use of github.com/go-log/log.Logf +// Log makes use of github.com/micro/debug/log +func Log(v ...interface{}) { + if len(prefix) > 0 { + v = append([]interface{}{prefix, " "}, v...) + } + logger.Write(log.Record{ + Timestamp: time.Now(), + Message: fmt.Sprint(v...), + Metadata: map[string]string{ + "level": level.String(), + }, + }) +} + +// Logf makes use of github.com/micro/debug/log func Logf(format string, v ...interface{}) { if len(prefix) > 0 { format = prefix + " " + format } - logger.Logf(format, v...) + logger.Write(log.Record{ + Timestamp: time.Now(), + Message: fmt.Sprintf(format, v...), + Metadata: map[string]string{ + "level": level.String(), + }, + }) } // WithLevel logs with the level specified @@ -145,12 +175,12 @@ func Fatalf(format string, v ...interface{}) { } // SetLogger sets the local logger -func SetLogger(l log.Logger) { +func SetLogger(l log.Log) { logger = l } // GetLogger returns the local logger -func GetLogger() log.Logger { +func GetLogger() log.Log { return logger } From 2338e7c9d20a2d71da9af4bf1b97d4c7d6ab7738 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 18 Dec 2019 16:12:25 +0000 Subject: [PATCH 053/788] Cleanup go mod --- broker/http_broker_test.go | 6 +-- debug/log/noop/noop.go | 23 +++++++++++ go.mod | 23 ++++++++++- go.sum | 78 ++++++++++++++++++++++++-------------- service_test.go | 4 +- util/log/README.md | 6 +-- 6 files changed, 100 insertions(+), 40 deletions(-) create mode 100644 debug/log/noop/noop.go diff --git a/broker/http_broker_test.go b/broker/http_broker_test.go index 3b9653fa..3312a7f3 100644 --- a/broker/http_broker_test.go +++ b/broker/http_broker_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - glog "github.com/go-log/log" "github.com/google/uuid" + "github.com/micro/go-micro/debug/log/noop" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry/memory" "github.com/micro/go-micro/util/log" @@ -18,7 +18,7 @@ func newTestRegistry() registry.Registry { func sub(be *testing.B, c int) { // set no op logger - log.SetLogger(glog.DefaultLogger) + log.SetLogger(noop.NewLog()) be.StopTimer() m := newTestRegistry() @@ -81,7 +81,7 @@ func sub(be *testing.B, c int) { func pub(be *testing.B, c int) { // set no op logger - log.SetLogger(glog.DefaultLogger) + log.SetLogger(noop.NewLog()) be.StopTimer() m := newTestRegistry() diff --git a/debug/log/noop/noop.go b/debug/log/noop/noop.go new file mode 100644 index 00000000..2d8a40da --- /dev/null +++ b/debug/log/noop/noop.go @@ -0,0 +1,23 @@ +package noop + +import ( + "github.com/micro/go-micro/debug/log" +) + +type noop struct{} + +func (n *noop) Read(...log.ReadOption) ([]log.Record, error) { + return nil, nil +} + +func (n *noop) Write(log.Record) error { + return nil +} + +func (n *noop) Stream() (log.Stream, error) { + return nil, nil +} + +func NewLog(opts ...log.Option) log.Log { + return new(noop) +} diff --git a/go.mod b/go.mod index 498f4f3f..9735d98f 100644 --- a/go.mod +++ b/go.mod @@ -6,21 +6,31 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/beevik/ntp v0.2.0 github.com/bitly/go-simplejson v0.5.0 + github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect github.com/bwmarrin/discordgo v0.20.1 + github.com/coreos/bbolt v1.3.3 // indirect github.com/coreos/etcd v3.3.17+incompatible + github.com/coreos/go-semver v0.3.0 // indirect + github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect + github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c github.com/fsnotify/fsnotify v1.4.7 github.com/fsouza/go-dockerclient v1.6.0 github.com/ghodss/yaml v1.0.0 github.com/go-acme/lego/v3 v3.1.0 - github.com/go-log/log v0.2.0 github.com/go-playground/locales v0.13.0 // indirect + github.com/go-playground/universal-translator v0.16.0 // indirect + github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect + github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc // indirect github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/websocket v1.4.1 + github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect + github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/hashicorp/hcl v1.0.0 github.com/imdario/mergo v0.3.8 + github.com/jonboulle/clockwork v0.1.0 // indirect github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 github.com/json-iterator/go v1.1.8 github.com/kr/pretty v0.1.0 @@ -30,19 +40,28 @@ require ( github.com/mholt/certmagic v0.8.3 github.com/micro/cli v0.2.0 github.com/micro/mdns v0.3.0 - github.com/micro/protoc-gen-micro v1.0.0 // indirect github.com/miekg/dns v1.1.22 github.com/mitchellh/hashstructure v1.0.0 + github.com/nats-io/nats-server/v2 v2.1.0 // indirect github.com/nats-io/nats.go v1.9.1 github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/pkg/errors v0.8.1 + github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 + github.com/technoweenie/multipartstreamer v1.0.1 // indirect + github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect + github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect + go.etcd.io/bbolt v1.3.3 // indirect go.uber.org/zap v1.12.0 golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a golang.org/x/net v0.0.0-20191109021931-daa7c04131f5 + golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 // indirect + google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a // indirect google.golang.org/grpc v1.25.1 + gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/validator.v9 v9.30.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 + sigs.k8s.io/yaml v1.1.0 // indirect ) diff --git a/go.sum b/go.sum index 469bfba7..ce46a0ba 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,7 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= contrib.go.opencensus.io/exporter/ocagent v0.4.12/go.mod h1:450APlNTSR6FrvC3CTRqYosuDstRB9un7SOx2k/9ckA= github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-autorest/autorest v0.1.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg= github.com/Azure/go-autorest/autorest v0.5.0/go.mod h1:9HLKlQjVBH6U3oDfsXOeVc56THsLPw1L03yban4xThw= @@ -18,22 +19,26 @@ github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6L github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvdeRAgDr0izn4z5Ij88= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= +github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 h1:ygIc8M6trr62pF5DucadTWGdEB4mEyvzi0e2nbcmcyA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= -github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg= +github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/akamai/AkamaiOPEN-edgegrid-golang v0.9.0/go.mod h1:zpDJeKyp9ScW4NNrbdr+Eyxvry3ilGPewKoXw3XGN1k= +github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75 h1:3ILjVyslFbc4jl1w5TWuvvslFD/nDfR2H8tVaMVLrEY= github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75/go.mod h1:uAXEEpARkRhCZfEvy/y0Jcc888f9tHCc1W7/UeEtreE= +github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190808125512-07798873deee/go.mod h1:myCDvQSzCW+wB1WAlocEru4wMGJxy+vlxHdhegi1CDQ= github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= +github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aws/aws-sdk-go v1.23.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= @@ -41,12 +46,13 @@ github.com/beevik/ntp v0.2.0 h1:sGsd+kAXzT0bfVfzJfce04g+dSRfrs+tbQW8lweuYgw= github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y= github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= -github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/bwmarrin/discordgo v0.20.1 h1:Ihh3/mVoRwy3otmaoPDUioILBJq4fdWkpsi83oj2Lmk= github.com/bwmarrin/discordgo v0.20.1/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= @@ -63,16 +69,17 @@ github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0 h1:xjvXQWABwS2uiv3TWgQt5Uth60Gu86LTGZXMJkjc7rY= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= -github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVlf61smEIq1nwLLAjQVEK2EADoW3CX9AuT+8= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3/go.mod h1:IV7qH3hrUgRmyYrtgEeGWJfWbgcHL9CSRruz2Vqcph0= github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDGpgqzQIzDW1TphrGLssLDZp2GuS+X5DkEJB8o= github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= +github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.17+incompatible h1:f/Z3EoDSx1yjaIjLQGo1diYUlQYSBrrAQ5vP8NjwXwo= github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= @@ -87,13 +94,13 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/decker502/dnspod-go v0.2.0/go.mod h1:qsurYu1FgxcDwfSwXJdLt4kRsBLZeosEb9uq4Sy+08g= +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= github.com/dnsimple/dnsimple-go v0.30.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v1.4.2-0.20190710153559-aa8249ae1b8b/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23 h1:oqgGT9O61YAYvI41EBsLePOr+LE6roB0xY4gpkZuFSE= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= @@ -109,36 +116,32 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= +github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXju1m8W4lnEeIqTHPOzhTUO81a7yknM/xQR4= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsouza/go-dockerclient v1.4.4/go.mod h1:PrwszSL5fbmsESocROrOGq/NULMXRw+bajY0ltzD6MA= github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4GGn3Hig= github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= -github.com/go-acme/lego v2.7.2+incompatible h1:ThhpPBgf6oa9X/vRd0kEmWOsX7+vmYdckmGZSb+FEp0= github.com/go-acme/lego/v3 v3.1.0 h1:yanYFoYW8azFkCvJfIk7edWWfjkYkhDxe45ZsxoW4Xk= github.com/go-acme/lego/v3 v3.1.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-log/log v0.1.0 h1:wudGTNsiGzrD5ZjgIkVZ517ugi2XRe9Q/xRCzwEO4/U= -github.com/go-log/log v0.1.0/go.mod h1:4mBwpdRMFLiuXZDCwU2lKQFsoSCo72j3HqBK9d81N2M= -github.com/go-log/log v0.2.0 h1:z8i91GBudxD5L3RmF0KVpetCbcGWAV7q1Tw1eRwQM9Q= -github.com/go-log/log v0.2.0/go.mod h1:xzCnwajcues/6w7lne3yK2QU7DBPW7kqbgPGG5AF65U= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM= github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU= github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM= github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= @@ -147,9 +150,12 @@ github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc h1:55rEp52jU6bkyslZ1+C/7NGfpQsEc6pxGLAGDOctqbw= github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= @@ -157,9 +163,11 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -181,8 +189,11 @@ github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg= github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.8.5 h1:2+KSC78XiO6Qy0hIjfc1OD9H+hsaJdJlb8Kqsd41CTE= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -192,15 +203,16 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= -github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd/go.mod h1:3LVOLeyx9XVvwPgrt2be44XgSqndprz1G18rSk8KD84= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 h1:lnrOS18wZBYrzdDmnUeg1OVk+kQ3rxG8mZWU89DpMIA= github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1/go.mod h1:DFXrEwSRX0p/aSvxE21319menCBFeQO0jXpRj7LEZUA= @@ -220,6 +232,7 @@ github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/kolo/xmlrpc v0.0.0-20190717152603-07c4ee3fd181/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -230,37 +243,31 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= -github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ= -github.com/lucas-clemente/quic-go v0.12.1/go.mod h1:UXJJPE4RfFef/xPO5wQm0tITK8gNfqwTxjbE7s3Vb8s= github.com/lucas-clemente/quic-go v0.13.1 h1:CxtJTXQIh2aboCPk0M6vf530XOov6DZjVBiSE3nSj8s= github.com/lucas-clemente/quic-go v0.13.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ= github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE= github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= -github.com/marten-seemann/qtls v0.3.2/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mholt/certmagic v0.7.5/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= github.com/mholt/certmagic v0.8.3 h1:JOUiX9IAZbbgyjNP2GY6v/6lorH+9GkZsc7ktMpGCSo= github.com/mholt/certmagic v0.8.3/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= -github.com/micro/go-micro v1.16.0/go.mod h1:A0F58bHLh2m0LAI9QyhvmbN8c1cxhAZo3cM6s+iDsrM= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= -github.com/micro/protoc-gen-micro v1.0.0 h1:qKh5S3I1RfenhIs5mqDFJLwRlRDlgin7XWiUKZbpwLM= -github.com/micro/protoc-gen-micro v1.0.0/go.mod h1:C8ij4DJhapBmypcT00AXdb0cZ675/3PqUO02buWWqbE= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15 h1:CSSIDtllwGLMoA6zjdKnaE6Tx6eVUxQ29LUgGetiDCI= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= @@ -284,6 +291,7 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= github.com/nats-io/jwt v0.3.0 h1:xdnzwFETV++jNc4W1mw//qFyJGb2ABOombmZJQS4+Qo= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= +github.com/nats-io/nats-server/v2 v2.1.0 h1:Yi0+ZhRPtPAGeIxFn5erIeJIV9wXA+JznfSxK621Fbk= github.com/nats-io/nats-server/v2 v2.1.0/go.mod h1:r5y0WgCag0dTj/qiHkHrXAcKQ/f5GMOZaEGdoxxnJ4I= github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= @@ -294,8 +302,6 @@ github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= -github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA= -github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= @@ -303,7 +309,9 @@ github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2 github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= @@ -331,18 +339,22 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.1.0 h1:BQ53HtBmfOitExawJ6LokA4x8ov/z0SYYb0+HxJfRI8= github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= +github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKcyumwBO6qip7RNQ5r77yrssm9bfCowcLEBcU5IA= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= @@ -361,6 +373,7 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= @@ -376,6 +389,7 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= @@ -388,7 +402,9 @@ github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2 github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= @@ -399,10 +415,10 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.2.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.12.0 h1:dySoUQPFBGj6xwjmBzageVL8jGi8uxc6bEmJQjA06bw= @@ -414,7 +430,6 @@ golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -423,7 +438,6 @@ golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a h1:R/qVym5WAxsZWQqZCwDY/8sdVKV1m1WgU4/S5IRQAzc= golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -432,6 +446,7 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/net v0.0.0-20180611182652-db08ff08e862/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -453,7 +468,6 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191109021931-daa7c04131f5 h1:bHNaocaoJxYBo5cw41UyTMLjYlb8wPY7+WFrnklbHOM= golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -476,14 +490,12 @@ golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -515,6 +527,7 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= @@ -539,14 +552,16 @@ google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= google.golang.org/grpc v1.25.1 h1:wdKvqQk7IttEw92GoRyKG2IDrUIpgpj6H6m81yfeMW0= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/go-playground/validator.v9 v9.30.0 h1:Wk0Z37oBmKj9/n+tPyBHZmeL19LaCoK3Qq48VwYENss= gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= @@ -560,11 +575,13 @@ gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4 gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg= gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= +gopkg.in/src-d/go-git-fixtures.v3 v3.5.0 h1:ivZFOIltbce2Mo8IjzUHAFoq/IylO9WHhNOAJK+LsJg= gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE= gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= gopkg.in/telegram-bot-api.v4 v4.6.4 h1:hpHWhzn4jTCsAJZZ2loNKfy2QWyPDRJVl3aTFXeMW8g= gopkg.in/telegram-bot-api.v4 v4.6.4/go.mod h1:5DpGO5dbumb40px+dXcwCpcjmeHNYLpk0bp3XRNvWDM= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= @@ -572,12 +589,15 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= +sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/service_test.go b/service_test.go index 79b4872c..c2a7c33b 100644 --- a/service_test.go +++ b/service_test.go @@ -6,8 +6,8 @@ import ( "sync" "testing" - glog "github.com/go-log/log" "github.com/micro/go-micro/client" + "github.com/micro/go-micro/debug/log/noop" proto "github.com/micro/go-micro/debug/service/proto" "github.com/micro/go-micro/registry/memory" "github.com/micro/go-micro/util/log" @@ -25,7 +25,7 @@ func testShutdown(wg *sync.WaitGroup, cancel func()) { func testService(ctx context.Context, wg *sync.WaitGroup, name string) Service { // set no op logger - log.SetLogger(glog.DefaultLogger) + log.SetLogger(noop.NewLog()) // add self wg.Add(1) diff --git a/util/log/README.md b/util/log/README.md index 6e26ad79..b5b9c5df 100644 --- a/util/log/README.md +++ b/util/log/README.md @@ -1,8 +1,6 @@ # Log -This is the global logger for all micro based libraries which makes use of [github.com/go-log/log](https://github.com/go-log/log). - -It defaults the logger to the stdlib log implementation. +This is the global logger for all micro based libraries. ## Set Logger @@ -12,6 +10,6 @@ Set the logger for micro libraries // import go-micro/util/log import "github.com/micro/go-micro/util/log" -// SetLogger expects github.com/go-log/log.Logger interface +// SetLogger expects github.com/micro/go-micro/debug/log.Log interface log.SetLogger(mylogger) ``` From d4bec24eb73a94053bcf5698b10516d07f97e7d0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 18 Dec 2019 17:06:29 +0000 Subject: [PATCH 054/788] Add os log buffer --- debug/log/os.go | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/debug/log/os.go b/debug/log/os.go index bae3662e..53ae60c5 100644 --- a/debug/log/os.go +++ b/debug/log/os.go @@ -10,12 +10,14 @@ import ( "time" "github.com/google/uuid" + "github.com/micro/go-micro/util/ring" ) // Should stream from OS type osLog struct { sync.RWMutex - subs map[string]*osStream + buffer *ring.Buffer + subs map[string]*osStream } type osStream struct { @@ -94,11 +96,8 @@ func (o *osLog) run() { o.Lock() - // bail if there's no subscribers - if len(o.subs) == 0 { - o.Unlock() - return - } + // write to the buffer + o.buffer.Put(r) // check subs and send to stream for id, sub := range o.subs { @@ -119,7 +118,14 @@ func (o *osLog) run() { // Read reads log entries from the logger func (o *osLog) Read(...ReadOption) ([]Record, error) { - return []Record{}, nil + var records []Record + + // read the last 100 records + for _, v := range o.buffer.Get(100) { + records = append(records, v.Value.(Record)) + } + + return records, nil } // Write writes records to log @@ -134,11 +140,6 @@ func (o *osLog) Stream() (Stream, error) { o.Lock() defer o.Unlock() - // start stream watcher - if len(o.subs) == 0 { - go o.run() - } - // create stream st := &osStream{ stream: make(chan Record, 128), @@ -166,7 +167,12 @@ func (o *osStream) Stop() error { } func NewLog(opts ...Option) Log { - return &osLog{ - subs: make(map[string]*osStream), + l := &osLog{ + buffer: ring.New(1024), + subs: make(map[string]*osStream), } + + go l.run() + + return l } From d52a1117356334a6736239870b483a083c09415e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 18 Dec 2019 18:36:42 +0000 Subject: [PATCH 055/788] add requests/errors to stats --- debug/log/os.go | 16 ++++++- debug/service/handler/debug.go | 74 ++++++++++++++++++++------------ debug/service/proto/debug.pb.go | 75 +++++++++++++++++++++------------ debug/service/proto/debug.proto | 4 ++ debug/stats/default.go | 55 +++++++++++++++++++++++- debug/stats/stats.go | 10 +++++ service.go | 4 ++ util/wrapper/wrapper.go | 18 ++++++++ 8 files changed, 197 insertions(+), 59 deletions(-) diff --git a/debug/log/os.go b/debug/log/os.go index 53ae60c5..fe0612a0 100644 --- a/debug/log/os.go +++ b/debug/log/os.go @@ -15,6 +15,8 @@ import ( // Should stream from OS type osLog struct { + once sync.Once + sync.RWMutex buffer *ring.Buffer subs map[string]*osStream @@ -118,6 +120,10 @@ func (o *osLog) run() { // Read reads log entries from the logger func (o *osLog) Read(...ReadOption) ([]Record, error) { + o.once.Do(func() { + go o.run() + }) + var records []Record // read the last 100 records @@ -130,6 +136,10 @@ func (o *osLog) Read(...ReadOption) ([]Record, error) { // Write writes records to log func (o *osLog) Write(r Record) error { + o.once.Do(func() { + go o.run() + }) + b, _ := json.Marshal(r) _, err := os.Stderr.Write(append(b, byte('\n'))) return err @@ -137,6 +147,10 @@ func (o *osLog) Write(r Record) error { // Stream log records func (o *osLog) Stream() (Stream, error) { + o.once.Do(func() { + go o.run() + }) + o.Lock() defer o.Unlock() @@ -172,7 +186,5 @@ func NewLog(opts ...Option) Log { subs: make(map[string]*osStream), } - go l.run() - return l } diff --git a/debug/service/handler/debug.go b/debug/service/handler/debug.go index 7d2f40f5..7fd42632 100644 --- a/debug/service/handler/debug.go +++ b/debug/service/handler/debug.go @@ -3,11 +3,11 @@ package handler import ( "context" - "runtime" "time" "github.com/micro/go-micro/debug/log" proto "github.com/micro/go-micro/debug/service/proto" + "github.com/micro/go-micro/debug/stats" "github.com/micro/go-micro/server" ) @@ -17,15 +17,18 @@ var ( ) type Debug struct { - started int64 + // must honour the debug handler proto.DebugHandler + // the logger for retrieving logs log log.Log + // the stats collector + stats stats.Stats } func newDebug() *Debug { return &Debug{ - started: time.Now().Unix(), - log: log.DefaultLog, + log: log.DefaultLog, + stats: stats.DefaultStats, } } @@ -35,15 +38,25 @@ func (d *Debug) Health(ctx context.Context, req *proto.HealthRequest, rsp *proto } func (d *Debug) Stats(ctx context.Context, req *proto.StatsRequest, rsp *proto.StatsResponse) error { - var mstat runtime.MemStats - runtime.ReadMemStats(&mstat) + stats, err := d.stats.Read() + if err != nil { + return err + } + + if len(stats) == 0 { + return nil + } + + // write the response values + rsp.Timestamp = uint64(stats[0].Timestamp) + rsp.Started = uint64(stats[0].Started) + rsp.Uptime = uint64(stats[0].Uptime) + rsp.Memory = stats[0].Memory + rsp.Gc = stats[0].GC + rsp.Threads = stats[0].Threads + rsp.Requests = stats[0].Requests + rsp.Errors = stats[0].Errors - rsp.Timestamp = uint64(time.Now().Unix()) - rsp.Started = uint64(d.started) - rsp.Uptime = uint64(time.Now().Unix() - d.started) - rsp.Memory = mstat.Alloc - rsp.Gc = mstat.PauseTotalNs - rsp.Threads = uint64(runtime.NumGoroutine()) return nil } @@ -78,7 +91,17 @@ func (d *Debug) Log(ctx context.Context, stream server.Stream) error { defer lgStream.Stop() for record := range lgStream.Chan() { - if err := d.sendRecord(record, stream); err != nil { + // copy metadata + metadata := make(map[string]string) + for k, v := range record.Metadata { + metadata[k] = v + } + // send record + if err := stream.Send(&proto.Record{ + Timestamp: record.Timestamp.Unix(), + Message: record.Message.(string), + Metadata: metadata, + }); err != nil { return err } } @@ -95,23 +118,20 @@ func (d *Debug) Log(ctx context.Context, stream server.Stream) error { // send all the logs downstream for _, record := range records { - if err := d.sendRecord(record, stream); err != nil { + // copy metadata + metadata := make(map[string]string) + for k, v := range record.Metadata { + metadata[k] = v + } + // send record + if err := stream.Send(&proto.Record{ + Timestamp: record.Timestamp.Unix(), + Message: record.Message.(string), + Metadata: metadata, + }); err != nil { return err } } return nil } - -func (d *Debug) sendRecord(record log.Record, stream server.Stream) error { - metadata := make(map[string]string) - for k, v := range record.Metadata { - metadata[k] = v - } - - return stream.Send(&proto.Record{ - Timestamp: record.Timestamp.Unix(), - Message: record.Message.(string), - Metadata: metadata, - }) -} diff --git a/debug/service/proto/debug.pb.go b/debug/service/proto/debug.pb.go index 4ea6ae42..263f21ec 100644 --- a/debug/service/proto/debug.pb.go +++ b/debug/service/proto/debug.pb.go @@ -152,7 +152,11 @@ type StatsResponse struct { // num threads Threads uint64 `protobuf:"varint,5,opt,name=threads,proto3" json:"threads,omitempty"` // total gc in nanoseconds - Gc uint64 `protobuf:"varint,6,opt,name=gc,proto3" json:"gc,omitempty"` + Gc uint64 `protobuf:"varint,6,opt,name=gc,proto3" json:"gc,omitempty"` + // total number of requests + Requests uint64 `protobuf:"varint,7,opt,name=requests,proto3" json:"requests,omitempty"` + // total number of errors + Errors uint64 `protobuf:"varint,8,opt,name=errors,proto3" json:"errors,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -225,6 +229,20 @@ func (m *StatsResponse) GetGc() uint64 { return 0 } +func (m *StatsResponse) GetRequests() uint64 { + if m != nil { + return m.Requests + } + return 0 +} + +func (m *StatsResponse) GetErrors() uint64 { + if m != nil { + return m.Errors + } + return 0 +} + // LogRequest requests service logs type LogRequest struct { // service to request logs for @@ -369,31 +387,32 @@ func init() { } var fileDescriptor_dea322649cde1ef2 = []byte{ - // 407 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcf, 0x6e, 0x13, 0x31, - 0x10, 0xc6, 0xb3, 0xbb, 0xcd, 0xb6, 0x99, 0x92, 0x80, 0x2c, 0x40, 0x56, 0x84, 0x44, 0xe5, 0xd3, - 0x22, 0x84, 0x03, 0xe5, 0x82, 0xe0, 0x0a, 0x12, 0x87, 0x72, 0x31, 0x4f, 0xe0, 0xee, 0x8e, 0xb6, - 0x81, 0x3a, 0x0e, 0xf6, 0x6c, 0xa5, 0x9c, 0x78, 0x16, 0xde, 0x80, 0x47, 0x44, 0xfe, 0xb3, 0xb4, - 0xab, 0x1e, 0x7a, 0xf3, 0xef, 0xf3, 0xe7, 0xd1, 0xcc, 0xf8, 0x03, 0x69, 0xb6, 0xad, 0xb3, 0x9b, - 0xde, 0xbe, 0x49, 0x87, 0x0e, 0x2f, 0x87, 0x7e, 0xe3, 0xd1, 0xdd, 0x6c, 0x5b, 0xdc, 0xec, 0x9d, - 0xa5, 0xac, 0xc9, 0x78, 0x16, 0xaf, 0x60, 0xf9, 0x15, 0xf5, 0x35, 0x5d, 0x29, 0xfc, 0x35, 0xa0, - 0x27, 0xc6, 0xe1, 0x38, 0xbb, 0x79, 0x71, 0x56, 0x34, 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a, 0xa8, - 0x11, 0xd7, 0x9f, 0x60, 0x39, 0x79, 0xc4, 0x9e, 0x40, 0xf5, 0x13, 0x0f, 0x79, 0xc0, 0x70, 0x0c, - 0xed, 0xde, 0xe8, 0xeb, 0x01, 0xe3, 0x6c, 0x0b, 0x95, 0xe0, 0x63, 0xf9, 0xa1, 0x38, 0xff, 0x0d, - 0xf3, 0xcf, 0x21, 0x50, 0xec, 0x35, 0xd4, 0x29, 0x1f, 0x6c, 0x25, 0x27, 0x99, 0x5a, 0x3f, 0x96, - 0xd3, 0xe0, 0x88, 0x19, 0x6b, 0x60, 0x1e, 0xff, 0x9d, 0x2d, 0xe5, 0xdd, 0xa8, 0xac, 0x57, 0x72, - 0x12, 0x07, 0x31, 0x63, 0x2f, 0xa1, 0xba, 0xb0, 0x3d, 0x3b, 0x95, 0xb7, 0x9f, 0xb0, 0x3e, 0xce, - 0xb3, 0x8a, 0xd9, 0xdb, 0xe2, 0xb2, 0x8e, 0x49, 0x7e, 0xff, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x4e, - 0xd3, 0x4c, 0xce, 0xfb, 0x02, 0x00, 0x00, + // 427 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcd, 0x6e, 0x13, 0x31, + 0x14, 0x85, 0x33, 0x33, 0xcd, 0x24, 0xb9, 0x25, 0x01, 0x59, 0x80, 0xac, 0x11, 0x12, 0x95, 0x57, + 0x83, 0x10, 0x0e, 0x94, 0x0d, 0x82, 0x2d, 0x48, 0x2c, 0xca, 0xc6, 0x3c, 0x81, 0x3b, 0x73, 0x35, + 0x0d, 0xd4, 0x71, 0xb0, 0xef, 0x54, 0xca, 0x8a, 0x57, 0xe2, 0x65, 0x78, 0x1f, 0xe4, 0x9f, 0xb4, + 0x8d, 0x58, 0x74, 0xe7, 0xef, 0xcc, 0xf5, 0x91, 0xcf, 0x9d, 0x03, 0xd2, 0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67, 0xc7, 0x2d, 0xc5, 0x30, 0x95, 0x4a, 0x10, 0x54, 0xbf, 0xd9, 0x76, 0x18, 0xa3, + 0x54, 0x2a, 0x81, 0xf8, 0x53, 0x40, 0xad, 0xb0, 0xb3, 0xae, 0xff, 0x7f, 0x79, 0xd5, 0xfd, 0xe5, + 0xbd, 0x83, 0xb9, 0x41, 0xd2, 0xbd, 0x26, 0xcd, 0xcb, 0xb3, 0xaa, 0x3d, 0x3d, 0x7f, 0x26, 0xd3, + 0x45, 0xf9, 0x2d, 0xeb, 0x5f, 0xb6, 0xe4, 0xf6, 0xea, 0x76, 0x2c, 0xbc, 0xdc, 0xa0, 0xf7, 0x7a, + 0x48, 0x6b, 0x5d, 0xa8, 0x03, 0x36, 0x9f, 0x60, 0x79, 0x74, 0x89, 0x3d, 0x81, 0xea, 0x27, 0xee, + 0x73, 0xc0, 0x70, 0x0c, 0xcf, 0xbd, 0xd1, 0xd7, 0x23, 0xc6, 0x6c, 0x0b, 0x95, 0xe0, 0x63, 0xf9, + 0xa1, 0x38, 0xff, 0x0d, 0xd3, 0xcf, 0xa1, 0x84, 0xec, 0x35, 0xd4, 0xa9, 0x53, 0x6c, 0x25, 0x8f, + 0x7a, 0xd8, 0x3c, 0x96, 0xc7, 0x65, 0x13, 0x13, 0xd6, 0xc2, 0x34, 0x76, 0x85, 0x2d, 0xe5, 0xfd, + 0x7a, 0x35, 0x2b, 0x79, 0x54, 0x21, 0x31, 0x61, 0x2f, 0xa1, 0xba, 0xb0, 0x03, 0x3b, 0x95, 0x77, + 0x3f, 0xa1, 0x99, 0xe5, 0xac, 0x62, 0xf2, 0xb6, 0xb8, 0xac, 0x63, 0xfb, 0xdf, 0xff, 0x0b, 0x00, + 0x00, 0xff, 0xff, 0x69, 0xc0, 0x33, 0x21, 0x2f, 0x03, 0x00, 0x00, } diff --git a/debug/service/proto/debug.proto b/debug/service/proto/debug.proto index 4b803152..54358608 100644 --- a/debug/service/proto/debug.proto +++ b/debug/service/proto/debug.proto @@ -34,6 +34,10 @@ message StatsResponse { uint64 threads = 5; // total gc in nanoseconds uint64 gc = 6; + // total number of requests + uint64 requests = 7; + // total number of errors + uint64 errors = 8; } // LogRequest requests service logs diff --git a/debug/stats/default.go b/debug/stats/default.go index 357d6303..d4ffc23e 100644 --- a/debug/stats/default.go +++ b/debug/stats/default.go @@ -1,18 +1,50 @@ package stats import ( + "runtime" + "sync" + "time" + "github.com/micro/go-micro/util/ring" ) type stats struct { + // used to store past stats buffer *ring.Buffer + + sync.RWMutex + started int64 + requests uint64 + errors uint64 +} + +func (s *stats) snapshot() *Stat { + s.RLock() + defer s.RUnlock() + + var mstat runtime.MemStats + runtime.ReadMemStats(&mstat) + + now := time.Now().Unix() + + return &Stat{ + Timestamp: now, + Started: s.started, + Uptime: now - s.started, + Memory: mstat.Alloc, + GC: mstat.PauseTotalNs, + Threads: uint64(runtime.NumGoroutine()), + Requests: s.requests, + Errors: s.errors, + } } func (s *stats) Read() ([]*Stat, error) { // TODO adjustable size and optional read values - buf := s.buffer.Get(1) + buf := s.buffer.Get(60) var stats []*Stat + // get a value from the buffer if it exists for _, b := range buf { stat, ok := b.Value.(*Stat) if !ok { @@ -21,6 +53,9 @@ func (s *stats) Read() ([]*Stat, error) { stats = append(stats, stat) } + // get a snapshot + stats = append(stats, s.snapshot()) + return stats, nil } @@ -29,10 +64,26 @@ func (s *stats) Write(stat *Stat) error { return nil } +func (s *stats) Record(err error) error { + s.Lock() + defer s.Unlock() + + // increment the total request count + s.requests++ + + // increment the error count + if err != nil { + s.errors++ + } + + return nil +} + // NewStats returns a new in memory stats buffer // TODO add options func NewStats() Stats { return &stats{ - buffer: ring.New(1024), + started: time.Now().Unix(), + buffer: ring.New(60), } } diff --git a/debug/stats/stats.go b/debug/stats/stats.go index c24bfc42..6cbf4b16 100644 --- a/debug/stats/stats.go +++ b/debug/stats/stats.go @@ -7,6 +7,8 @@ type Stats interface { Read() ([]*Stat, error) // Write a stat snapshot Write(*Stat) error + // Record a request + Record(error) error } // A runtime stat @@ -23,4 +25,12 @@ type Stat struct { Threads uint64 // Garbage collection in nanoseconds GC uint64 + // Total requests + Requests uint64 + // Total errors + Errors uint64 } + +var ( + DefaultStats = NewStats() +) diff --git a/service.go b/service.go index 0245bfd6..69376e68 100644 --- a/service.go +++ b/service.go @@ -14,6 +14,7 @@ import ( "github.com/micro/go-micro/debug/profile/http" "github.com/micro/go-micro/debug/profile/pprof" "github.com/micro/go-micro/debug/service/handler" + "github.com/micro/go-micro/debug/stats" "github.com/micro/go-micro/plugin" "github.com/micro/go-micro/server" "github.com/micro/go-micro/util/log" @@ -35,6 +36,9 @@ func newService(opts ...Option) Service { // wrap client to inject From-Service header on any calls options.Client = wrapper.FromService(serviceName, options.Client) + // wrap the server to provide handler stats + options.Server.Init(server.WrapHandler(wrapper.HandlerStats(stats.DefaultStats))) + return &service{ opts: options, } diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index cf198435..371bcb66 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -4,7 +4,9 @@ import ( "context" "github.com/micro/go-micro/client" + "github.com/micro/go-micro/debug/stats" "github.com/micro/go-micro/metadata" + "github.com/micro/go-micro/server" ) type clientWrapper struct { @@ -55,3 +57,19 @@ func FromService(name string, c client.Client) client.Client { }, } } + +// HandlerStats wraps a server handler to generate request/error stats +func HandlerStats(stats stats.Stats) server.HandlerWrapper { + // return a handler wrapper + return func(h server.HandlerFunc) server.HandlerFunc { + // return a function that returns a function + return func(ctx context.Context, req server.Request, rsp interface{}) error { + // execute the handler + err := h(ctx, req, rsp) + // record the stats + stats.Record(err) + // return the error + return err + } + } +} From 2bcfb8561343292efabd0224da7e9a8d3c7c6c04 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 19 Dec 2019 12:20:33 +0000 Subject: [PATCH 056/788] Add log Format option --- debug/log/log.go | 5 +++++ debug/log/options.go | 8 ++++++++ debug/log/os.go | 16 +++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/debug/log/log.go b/debug/log/log.go index a5958ad3..374023b1 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -10,6 +10,8 @@ var ( DefaultSize = 1024 // DefaultLog logger DefaultLog = NewLog() + // Default formatter + DefaultFormat = func(r Record) string { return r.Message.(string) } ) // Log is debug log interface for reading and writing logs @@ -37,3 +39,6 @@ type Stream interface { Chan() <-chan Record Stop() error } + +// Format is a function which formats the output +type FormatFunc func(Record) string diff --git a/debug/log/options.go b/debug/log/options.go index b17c2f43..63281857 100644 --- a/debug/log/options.go +++ b/debug/log/options.go @@ -11,6 +11,8 @@ type Options struct { Name string // Size is the size of ring buffer Size int + // Format specifies the output format + Format FormatFunc } // Name of the log @@ -27,6 +29,12 @@ func Size(s int) Option { } } +func Format(f FormatFunc) Option { + return func(o *Options) { + o.Format = f + } +} + // DefaultOptions returns default options func DefaultOptions() Options { return Options{ diff --git a/debug/log/os.go b/debug/log/os.go index fe0612a0..ed96668d 100644 --- a/debug/log/os.go +++ b/debug/log/os.go @@ -15,7 +15,8 @@ import ( // Should stream from OS type osLog struct { - once sync.Once + format FormatFunc + once sync.Once sync.RWMutex buffer *ring.Buffer @@ -140,8 +141,9 @@ func (o *osLog) Write(r Record) error { go o.run() }) - b, _ := json.Marshal(r) - _, err := os.Stderr.Write(append(b, byte('\n'))) + // generate output + out := o.format(r) + "\n" + _, err := os.Stderr.Write([]byte(out)) return err } @@ -181,7 +183,15 @@ func (o *osStream) Stop() error { } func NewLog(opts ...Option) Log { + options := Options{ + Format: DefaultFormat, + } + for _, o := range opts { + o(&options) + } + l := &osLog{ + format: options.Format, buffer: ring.New(1024), subs: make(map[string]*osStream), } From 95ae2688a2645d2c87911767af32a89505c65f56 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 19 Dec 2019 12:29:03 +0000 Subject: [PATCH 057/788] add formatters --- debug/log/log.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/debug/log/log.go b/debug/log/log.go index 374023b1..3d2a123b 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -2,6 +2,7 @@ package log import ( + "encoding/json" "time" ) @@ -11,7 +12,7 @@ var ( // DefaultLog logger DefaultLog = NewLog() // Default formatter - DefaultFormat = func(r Record) string { return r.Message.(string) } + DefaultFormat = TextFormat ) // Log is debug log interface for reading and writing logs @@ -42,3 +43,14 @@ type Stream interface { // Format is a function which formats the output type FormatFunc func(Record) string + +// TextFormat returns text format +func TextFormat(r Record) string { + return r.Message.(string) +} + +// JSONFormat is a json Format func +func JSONFormat(r Record) string { + b, _ := json.Marshal(r) + return string(b) +} From ae12fd1021f712b2a41b340b84ae2bf718ec2d59 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 19 Dec 2019 18:25:22 +0000 Subject: [PATCH 058/788] update crap logging --- debug/log/log.go | 4 +++- debug/service/client.go | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/debug/log/log.go b/debug/log/log.go index 3d2a123b..bf90a999 100644 --- a/debug/log/log.go +++ b/debug/log/log.go @@ -3,6 +3,7 @@ package log import ( "encoding/json" + "fmt" "time" ) @@ -46,7 +47,8 @@ type FormatFunc func(Record) string // TextFormat returns text format func TextFormat(r Record) string { - return r.Message.(string) + t := r.Timestamp.Format("2006-01-02 15:04:05") + return fmt.Sprintf("%s %v", t, r.Message) } // JSONFormat is a json Format func diff --git a/debug/service/client.go b/debug/service/client.go index e7d14fda..89209955 100644 --- a/debug/service/client.go +++ b/debug/service/client.go @@ -3,7 +3,6 @@ package service import ( "context" - "fmt" "time" "github.com/micro/go-micro/client" @@ -34,7 +33,7 @@ func (d *debugClient) Log(since time.Time, count int, stream bool) (log.Stream, // get the log stream serverStream, err := d.Client.Log(context.Background(), req) if err != nil { - return nil, fmt.Errorf("failed getting log stream: %s", err) + return nil, err } lg := &logStream{ From ce33e3b072bbd983de4662e366e269544a7f6248 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Fri, 20 Dec 2019 23:16:05 +0000 Subject: [PATCH 059/788] Kubernetes logging (#1054) * wip * Implementation of Kubernetes Logger * Missing file * Skip test in Travis --- debug/log/kubernetes/kubernetes.go | 152 ++++++++++++++++++++++-- debug/log/kubernetes/kubernetes_test.go | 12 +- debug/log/kubernetes/util.go | 15 +++ util/kubernetes/client/api/request.go | 4 + util/kubernetes/client/client.go | 35 +++++- util/kubernetes/client/kubernetes.go | 2 +- util/kubernetes/client/logoptions.go | 13 ++ util/kubernetes/client/types.go | 6 +- 8 files changed, 224 insertions(+), 15 deletions(-) create mode 100644 debug/log/kubernetes/util.go create mode 100644 util/kubernetes/client/logoptions.go diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go index 06ecf790..ff727a3b 100644 --- a/debug/log/kubernetes/kubernetes.go +++ b/debug/log/kubernetes/kubernetes.go @@ -2,15 +2,62 @@ package kubernetes import ( - "errors" + "bufio" + "encoding/json" + "fmt" + "os" + "sort" + "strconv" + "time" "github.com/micro/go-micro/debug/log" + "github.com/micro/go-micro/util/kubernetes/client" ) -type klog struct{} +type klog struct { + client client.Kubernetes -func (k *klog) Read(...log.ReadOption) ([]log.Record, error) { - return nil, errors.New("not implemented") + log.Options +} + +func (k *klog) Read(options ...log.ReadOption) ([]log.Record, error) { + opts := &log.ReadOptions{} + for _, o := range options { + o(opts) + } + + logsToGet, err := k.getMatchingPods() + if err != nil { + return nil, err + } + records := []log.Record{} + + for _, l := range logsToGet { + logParams := make(map[string]string) + if !opts.Since.Equal(time.Time{}) { + logParams["sinceSeconds"] = strconv.Itoa(int(time.Since(opts.Since).Seconds())) + } + if opts.Count != 0 { + logParams["tailLines"] = strconv.Itoa(opts.Count) + } + if opts.Stream == true { + logParams["follow"] = "true" + } + logs, err := k.client.Logs(l, client.AdditionalParams(logParams)) + if err != nil { + return nil, err + } + defer logs.Close() + s := bufio.NewScanner(logs) + for s.Scan() { + record := k.parse(s.Text()) + record.Metadata["pod"] = l + records = append(records, record) + } + } + + sort.Sort(byTimestamp(records)) + return records, nil } func (k *klog) Write(l log.Record) error { @@ -18,13 +65,102 @@ func (k *klog) Write(l log.Record) error { } func (k *klog) Stream() (log.Stream, error) { - return &klogStreamer{ + return k.stream() +} + +func (k *klog) stream() (log.Stream, error) { + pods, err := k.getMatchingPods() + if err != nil { + return nil, err + } + logStreamer := &klogStreamer{ streamChan: make(chan log.Record), stop: make(chan bool), - }, nil + } + errorChan := make(chan error) + go func(stopChan <-chan bool) { + for { + select { + case <-stopChan: + return + case err := <-errorChan: + fmt.Fprintf(os.Stderr, err.Error()) + } + } + }(logStreamer.stop) + for _, pod := range pods { + go k.individualPodLogStreamer(pod, logStreamer.streamChan, errorChan, logStreamer.stop) + } + return logStreamer, nil +} + +func (k *klog) individualPodLogStreamer(podName string, recordChan chan<- log.Record, errorChan chan<- error, stopChan <-chan bool) { + p := make(map[string]string) + p["follow"] = "true" + body, err := k.client.Logs(podName, client.AdditionalParams(p)) + if err != nil { + errorChan <- err + return + } + s := bufio.NewScanner(body) + defer body.Close() + for { + select { + case <-stopChan: + return + default: + if s.Scan() { + record := k.parse(s.Text()) + recordChan <- record + } else { + time.Sleep(time.Second) + } + } + } } // New returns a configured Kubernetes logger -func New() log.Log { - return &klog{} +func New(opts ...log.Option) log.Log { + klog := &klog{} + for _, o := range opts { + o(&klog.Options) + } + + if len(os.Getenv("KUBERNETES_SERVICE_HOST")) > 0 { + klog.client = client.NewClientInCluster() + } else { + klog.client = client.NewLocalDevClient() + } + return klog +} + +func (k *klog) getMatchingPods() ([]string, error) { + r := &client.Resource{ + Kind: "pod", + Value: new(client.PodList), + } + l := make(map[string]string) + l["micro"] = "runtime" + if err := k.client.Get(r, l); err != nil { + return nil, err + } + + var matches []string + for _, p := range r.Value.(*client.PodList).Items { + if p.Metadata.Labels["name"] == k.Options.Name { + matches = append(matches, p.Metadata.Name) + } + } + return matches, nil +} + +func (k *klog) parse(line string) log.Record { + record := log.Record{} + if err := json.Unmarshal([]byte(line), &record); err != nil { + record.Timestamp = time.Now().UTC() + record.Message = line + record.Metadata = make(map[string]string) + } + record.Metadata["service"] = k.Options.Name + return record } diff --git a/debug/log/kubernetes/kubernetes_test.go b/debug/log/kubernetes/kubernetes_test.go index 27c3a6d9..aabe97f3 100644 --- a/debug/log/kubernetes/kubernetes_test.go +++ b/debug/log/kubernetes/kubernetes_test.go @@ -13,7 +13,10 @@ import ( ) func TestKubernetes(t *testing.T) { - k := New() + if os.Getenv("IN_TRAVIS_CI") == "yes" { + t.Skip("In Travis CI") + } + k := New(log.Name("micro-network")) r, w, err := os.Pipe() if err != nil { @@ -39,14 +42,15 @@ func TestKubernetes(t *testing.T) { } assert.Equal(t, write, read, "Write was not equal") - _, err = k.Read() - assert.Error(t, err, "Read should be unimplemented") + records, err := k.Read() + assert.Nil(t, err, "Read should not error") + assert.NotNil(t, records, "Read should return records") stream, err := k.Stream() if err != nil { t.Error(err) } - records := []log.Record{} + records = []log.Record{} go stream.Stop() for s := range stream.Chan() { records = append(records, s) diff --git a/debug/log/kubernetes/util.go b/debug/log/kubernetes/util.go new file mode 100644 index 00000000..9b259e6e --- /dev/null +++ b/debug/log/kubernetes/util.go @@ -0,0 +1,15 @@ +package kubernetes + +import "github.com/micro/go-micro/debug/log" + +// ByTimestamp lets you sort log records by Timestamp (implements Sort.Sort) +type byTimestamp []log.Record + +// Len returns the number of Log records (implements Sort.Sort) +func (b byTimestamp) Len() int { return len(b) } + +// Swap swaps 2 Log records (implements Sort.Sort) +func (b byTimestamp) Swap(i, j int) { b[i], b[j] = b[j], b[i] } + +// Less checks if a record was before another record (implements Sort.Sort) +func (b byTimestamp) Less(i, j int) bool { return b[i].Timestamp.Before(b[j].Timestamp) } diff --git a/util/kubernetes/client/api/request.go b/util/kubernetes/client/api/request.go index 53d57195..de314dca 100644 --- a/util/kubernetes/client/api/request.go +++ b/util/kubernetes/client/api/request.go @@ -34,6 +34,7 @@ type Request struct { type Params struct { LabelSelector map[string]string Annotations map[string]string + Additional map[string]string } // verb sets method @@ -136,6 +137,9 @@ func (r *Request) Params(p *Params) *Request { // set and overwrite the value r.params.Set("labelSelector", value) } + for k, v := range p.Additional { + r.params.Set(k, v) + } return r } diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 821ee3da..ff82f837 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "path" + "strconv" "github.com/micro/go-micro/util/kubernetes/client/api" "github.com/micro/go-micro/util/log" @@ -26,6 +27,26 @@ type client struct { opts *api.Options } +// NewLocalDevClient returns a client that can be used with `kubectl proxy` on an optional port +func NewLocalDevClient(port ...int) *client { + var p int + if len(port) > 1 { + log.Fatal("Expected 0 or 1 port parameters") + } + if len(port) == 0 { + p = 8001 + } else { + p = port[0] + } + return &client{ + opts: &api.Options{ + Client: http.DefaultClient, + Host: "http://localhost:" + strconv.Itoa(p), + Namespace: "default", + }, + } +} + // NewClientInCluster creates a Kubernetes client for use from within a k8s pod. func NewClientInCluster() *client { host := "https://" + os.Getenv("KUBERNETES_SERVICE_HOST") + ":" + os.Getenv("KUBERNETES_SERVICE_PORT") @@ -118,17 +139,29 @@ func (c *client) Get(r *Resource, labels map[string]string) error { } // Logs returns logs for a pod -func (c *client) Logs(podName string) (io.ReadCloser, error) { +func (c *client) Logs(podName string, options ...LogOption) (io.ReadCloser, error) { + opts := &LogOptions{} + for _, o := range options { + o(opts) + } req := api.NewRequest(c.opts). Get(). Resource("pod"). SubResource("log"). Name(podName) + if opts.AdditionalParams != nil { + req.Params(&api.Params{Additional: opts.AdditionalParams}) + } + resp, err := req.Raw() if err != nil { return nil, err } + if resp.StatusCode < 200 || resp.StatusCode >= 300 { + resp.Body.Close() + return nil, errors.New(resp.Request.URL.String() + ": " + resp.Status) + } return resp.Body, nil } diff --git a/util/kubernetes/client/kubernetes.go b/util/kubernetes/client/kubernetes.go index 8e30c923..761602ac 100644 --- a/util/kubernetes/client/kubernetes.go +++ b/util/kubernetes/client/kubernetes.go @@ -26,7 +26,7 @@ type Kubernetes interface { // List lists API resources List(*Resource) error // Logs gets logs from a pod - Logs(string) (io.ReadCloser, error) + Logs(string, ...LogOption) (io.ReadCloser, error) } // NewService returns default micro kubernetes service definition diff --git a/util/kubernetes/client/logoptions.go b/util/kubernetes/client/logoptions.go new file mode 100644 index 00000000..349d0c59 --- /dev/null +++ b/util/kubernetes/client/logoptions.go @@ -0,0 +1,13 @@ +package client + +type LogOptions struct { + AdditionalParams map[string]string +} + +type LogOption func(*LogOptions) + +func AdditionalParams(p map[string]string) LogOption { + return func(l *LogOptions) { + l.AdditionalParams = p + } +} diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index b9bfa4a3..588f9e40 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -79,7 +79,7 @@ type Container struct { Ports []ContainerPort `json:"ports,omitempty"` } -// PodSpec +// PodSpec is a pod type PodSpec struct { Containers []Container `json:"containers"` } @@ -131,3 +131,7 @@ type Deployment struct { type DeploymentList struct { Items []Deployment `json:"items"` } + +type PodList struct { + Items []Template `json:"items"` +} From 847a01df82b3c1d5c9d76413e64f401ec64ea39d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 20 Dec 2019 23:34:08 +0000 Subject: [PATCH 060/788] Cleanup k8s logs --- debug/log/kubernetes/kubernetes.go | 171 +++++++++++++----------- debug/log/kubernetes/kubernetes_test.go | 20 ++- debug/log/kubernetes/stream.go | 16 +-- debug/log/kubernetes/util.go | 15 --- 4 files changed, 118 insertions(+), 104 deletions(-) delete mode 100644 debug/log/kubernetes/util.go diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go index ff727a3b..027175dd 100644 --- a/debug/log/kubernetes/kubernetes.go +++ b/debug/log/kubernetes/kubernetes.go @@ -20,6 +20,78 @@ type klog struct { log.Options } +func (k *klog) podLogStream(podName string, stream *kubeStream) { + p := make(map[string]string) + p["follow"] = "true" + + body, err := k.client.Logs(podName, client.AdditionalParams(p)) + if err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + return + } + + s := bufio.NewScanner(body) + defer body.Close() + + for { + select { + case <-stream.stop: + return + default: + if s.Scan() { + record := k.parse(s.Text()) + stream.stream <- record + } else { + // TODO: is there a blocking call + // rather than a sleep loop? + time.Sleep(time.Second) + } + } + } +} + +func (k *klog) getMatchingPods() ([]string, error) { + r := &client.Resource{ + Kind: "pod", + Value: new(client.PodList), + } + + l := make(map[string]string) + + l["name"] = client.Format(k.Options.Name) + // TODO: specify micro:service + // l["micro"] = "service" + + if err := k.client.Get(r, l); err != nil { + return nil, err + } + + var matches []string + + for _, p := range r.Value.(*client.PodList).Items { + // find labels that match the name + if p.Metadata.Labels["name"] == client.Format(k.Options.Name) { + matches = append(matches, p.Metadata.Name) + } + } + + return matches, nil +} + +func (k *klog) parse(line string) log.Record { + record := log.Record{} + + if err := json.Unmarshal([]byte(line), &record); err != nil { + record.Timestamp = time.Now().UTC() + record.Message = line + record.Metadata = make(map[string]string) + } + + record.Metadata["service"] = k.Options.Name + + return record +} + func (k *klog) Read(options ...log.ReadOption) ([]log.Record, error) { opts := &log.ReadOptions{} for _, o := range options { @@ -30,25 +102,32 @@ func (k *klog) Read(options ...log.ReadOption) ([]log.Record, error) { if err != nil { return nil, err } - records := []log.Record{} + + var records []log.Record for _, l := range logsToGet { logParams := make(map[string]string) + if !opts.Since.Equal(time.Time{}) { logParams["sinceSeconds"] = strconv.Itoa(int(time.Since(opts.Since).Seconds())) } + if opts.Count != 0 { logParams["tailLines"] = strconv.Itoa(opts.Count) } + if opts.Stream == true { logParams["follow"] = "true" } + logs, err := k.client.Logs(l, client.AdditionalParams(logParams)) if err != nil { return nil, err } defer logs.Close() + s := bufio.NewScanner(logs) + for s.Scan() { record := k.parse(s.Text()) record.Metadata["pod"] = l @@ -56,7 +135,9 @@ func (k *klog) Read(options ...log.ReadOption) ([]log.Record, error) { } } - sort.Sort(byTimestamp(records)) + // sort the records + sort.Slice(records, func(i, j int) bool { return records[i].Timestamp.Before(records[j].Timestamp) }) + return records, nil } @@ -65,58 +146,23 @@ func (k *klog) Write(l log.Record) error { } func (k *klog) Stream() (log.Stream, error) { - return k.stream() -} - -func (k *klog) stream() (log.Stream, error) { + // find the matching pods pods, err := k.getMatchingPods() if err != nil { return nil, err } - logStreamer := &klogStreamer{ - streamChan: make(chan log.Record), - stop: make(chan bool), - } - errorChan := make(chan error) - go func(stopChan <-chan bool) { - for { - select { - case <-stopChan: - return - case err := <-errorChan: - fmt.Fprintf(os.Stderr, err.Error()) - } - } - }(logStreamer.stop) - for _, pod := range pods { - go k.individualPodLogStreamer(pod, logStreamer.streamChan, errorChan, logStreamer.stop) - } - return logStreamer, nil -} -func (k *klog) individualPodLogStreamer(podName string, recordChan chan<- log.Record, errorChan chan<- error, stopChan <-chan bool) { - p := make(map[string]string) - p["follow"] = "true" - body, err := k.client.Logs(podName, client.AdditionalParams(p)) - if err != nil { - errorChan <- err - return + stream := &kubeStream{ + stream: make(chan log.Record), + stop: make(chan bool), } - s := bufio.NewScanner(body) - defer body.Close() - for { - select { - case <-stopChan: - return - default: - if s.Scan() { - record := k.parse(s.Text()) - recordChan <- record - } else { - time.Sleep(time.Second) - } - } + + // stream from the individual pods + for _, pod := range pods { + go k.podLogStream(pod, stream) } + + return stream, nil } // New returns a configured Kubernetes logger @@ -133,34 +179,3 @@ func New(opts ...log.Option) log.Log { } return klog } - -func (k *klog) getMatchingPods() ([]string, error) { - r := &client.Resource{ - Kind: "pod", - Value: new(client.PodList), - } - l := make(map[string]string) - l["micro"] = "runtime" - if err := k.client.Get(r, l); err != nil { - return nil, err - } - - var matches []string - for _, p := range r.Value.(*client.PodList).Items { - if p.Metadata.Labels["name"] == k.Options.Name { - matches = append(matches, p.Metadata.Name) - } - } - return matches, nil -} - -func (k *klog) parse(line string) log.Record { - record := log.Record{} - if err := json.Unmarshal([]byte(line), &record); err != nil { - record.Timestamp = time.Now().UTC() - record.Message = line - record.Metadata = make(map[string]string) - } - record.Metadata["service"] = k.Options.Name - return record -} diff --git a/debug/log/kubernetes/kubernetes_test.go b/debug/log/kubernetes/kubernetes_test.go index aabe97f3..c9546798 100644 --- a/debug/log/kubernetes/kubernetes_test.go +++ b/debug/log/kubernetes/kubernetes_test.go @@ -13,33 +13,44 @@ import ( ) func TestKubernetes(t *testing.T) { + // TODO: fix local test running + return + if os.Getenv("IN_TRAVIS_CI") == "yes" { t.Skip("In Travis CI") } + k := New(log.Name("micro-network")) r, w, err := os.Pipe() if err != nil { t.Fatal(err) } + s := os.Stderr os.Stderr = w meta := make(map[string]string) + write := log.Record{ Timestamp: time.Unix(0, 0).UTC(), Message: "Test log entry", Metadata: meta, } + meta["foo"] = "bar" + k.Write(write) b := &bytes.Buffer{} w.Close() io.Copy(b, r) os.Stderr = s + var read log.Record + if err := json.Unmarshal(b.Bytes(), &read); err != nil { t.Fatalf("json.Unmarshal failed: %s", err.Error()) } + assert.Equal(t, write, read, "Write was not equal") records, err := k.Read() @@ -48,13 +59,16 @@ func TestKubernetes(t *testing.T) { stream, err := k.Stream() if err != nil { - t.Error(err) + t.Fatal(err) } - records = []log.Record{} + + records = nil + go stream.Stop() + for s := range stream.Chan() { records = append(records, s) } - assert.Equal(t, 0, len(records), "Stream should return nothing") + assert.Equal(t, 0, len(records), "Stream should return nothing") } diff --git a/debug/log/kubernetes/stream.go b/debug/log/kubernetes/stream.go index b62434a0..eed76d3e 100644 --- a/debug/log/kubernetes/stream.go +++ b/debug/log/kubernetes/stream.go @@ -1,11 +1,11 @@ package kubernetes -import "github.com/micro/go-micro/debug/log" - import ( "encoding/json" "fmt" "os" + + "github.com/micro/go-micro/debug/log" ) func write(l log.Record) error { @@ -17,24 +17,24 @@ func write(l log.Record) error { return err } -type klogStreamer struct { +type kubeStream struct { // the k8s log stream - streamChan chan log.Record + stream chan log.Record // the stop chan stop chan bool } -func (k *klogStreamer) Chan() <-chan log.Record { - return k.streamChan +func (k *kubeStream) Chan() <-chan log.Record { + return k.stream } -func (k *klogStreamer) Stop() error { +func (k *kubeStream) Stop() error { select { case <-k.stop: return nil default: close(k.stop) - close(k.streamChan) + close(k.stream) } return nil } diff --git a/debug/log/kubernetes/util.go b/debug/log/kubernetes/util.go deleted file mode 100644 index 9b259e6e..00000000 --- a/debug/log/kubernetes/util.go +++ /dev/null @@ -1,15 +0,0 @@ -package kubernetes - -import "github.com/micro/go-micro/debug/log" - -// ByTimestamp lets you sort log records by Timestamp (implements Sort.Sort) -type byTimestamp []log.Record - -// Len returns the number of Log records (implements Sort.Sort) -func (b byTimestamp) Len() int { return len(b) } - -// Swap swaps 2 Log records (implements Sort.Sort) -func (b byTimestamp) Swap(i, j int) { b[i], b[j] = b[j], b[i] } - -// Less checks if a record was before another record (implements Sort.Sort) -func (b byTimestamp) Less(i, j int) bool { return b[i].Timestamp.Before(b[j].Timestamp) } From 45208992b52049c40ba00748386b0d67c5b8200a Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 20 Dec 2019 23:36:16 +0000 Subject: [PATCH 061/788] NewLog --- debug/log/kubernetes/kubernetes.go | 4 ++-- debug/log/kubernetes/kubernetes_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go index 027175dd..187a7ca3 100644 --- a/debug/log/kubernetes/kubernetes.go +++ b/debug/log/kubernetes/kubernetes.go @@ -165,8 +165,8 @@ func (k *klog) Stream() (log.Stream, error) { return stream, nil } -// New returns a configured Kubernetes logger -func New(opts ...log.Option) log.Log { +// NewLog returns a configured Kubernetes logger +func NewLog(opts ...log.Option) log.Log { klog := &klog{} for _, o := range opts { o(&klog.Options) diff --git a/debug/log/kubernetes/kubernetes_test.go b/debug/log/kubernetes/kubernetes_test.go index c9546798..955e5d46 100644 --- a/debug/log/kubernetes/kubernetes_test.go +++ b/debug/log/kubernetes/kubernetes_test.go @@ -20,7 +20,7 @@ func TestKubernetes(t *testing.T) { t.Skip("In Travis CI") } - k := New(log.Name("micro-network")) + k := NewLog(log.Name("micro-network")) r, w, err := os.Pipe() if err != nil { From 17815429646fcafdf1f350594a397fcff1a59d56 Mon Sep 17 00:00:00 2001 From: shikbupt Date: Mon, 23 Dec 2019 15:29:13 +0800 Subject: [PATCH 062/788] fix etcd LogConfig bug (#1056) --- registry/etcd/options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/etcd/options.go b/registry/etcd/options.go index bc69b23b..611e119f 100644 --- a/registry/etcd/options.go +++ b/registry/etcd/options.go @@ -32,6 +32,6 @@ func LogConfig(config *zap.Config) registry.Option { if o.Context == nil { o.Context = context.Background() } - o.Context = context.WithValue(o.Context, authKey{}, config) + o.Context = context.WithValue(o.Context, logConfigKey{}, config) } } From ef95b28e3d721ded376cd6c383e5e59b61f05bc5 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 23 Dec 2019 08:42:57 +0000 Subject: [PATCH 063/788] add Write method to config source --- config/source/cli/cli.go | 5 +++++ config/source/env/env.go | 4 ++++ config/source/etcd/etcd.go | 4 ++++ config/source/file/file.go | 4 ++++ config/source/flag/flag.go | 4 ++++ config/source/memory/memory.go | 4 ++++ config/source/source.go | 1 + 7 files changed, 26 insertions(+) diff --git a/config/source/cli/cli.go b/config/source/cli/cli.go index 362ea79f..6d6a8fbb 100644 --- a/config/source/cli/cli.go +++ b/config/source/cli/cli.go @@ -78,6 +78,11 @@ func (c *cliSource) Watch() (source.Watcher, error) { return source.NewNoopWatcher() } +// Write is unsupported +func (c *cliSource) Write(cs *source.ChangeSet) error { + return nil +} + func (c *cliSource) String() string { return "cli" } diff --git a/config/source/env/env.go b/config/source/env/env.go index 62dbf8b2..c971945c 100644 --- a/config/source/env/env.go +++ b/config/source/env/env.go @@ -105,6 +105,10 @@ func (e *env) Watch() (source.Watcher, error) { return newWatcher() } +func (e *env) Write(cs *source.ChangeSet) error { + return nil +} + func (e *env) String() string { return "env" } diff --git a/config/source/etcd/etcd.go b/config/source/etcd/etcd.go index 7c8edba9..9dc0c0c2 100644 --- a/config/source/etcd/etcd.go +++ b/config/source/etcd/etcd.go @@ -76,6 +76,10 @@ func (c *etcd) Watch() (source.Watcher, error) { return newWatcher(c.prefix, c.stripPrefix, c.client.Watcher, cs, c.opts) } +func (c *etcd) Write(cs *source.ChangeSet) error { + return nil +} + func NewSource(opts ...source.Option) source.Source { options := source.NewOptions(opts...) diff --git a/config/source/file/file.go b/config/source/file/file.go index 8a4b720d..15b9b860 100644 --- a/config/source/file/file.go +++ b/config/source/file/file.go @@ -54,6 +54,10 @@ func (f *file) Watch() (source.Watcher, error) { return newWatcher(f) } +func (f *file) Write(cs *source.ChangeSet) error { + return nil +} + func NewSource(opts ...source.Option) source.Source { options := source.NewOptions(opts...) path := DefaultPath diff --git a/config/source/flag/flag.go b/config/source/flag/flag.go index 04483d5b..98ff4d91 100644 --- a/config/source/flag/flag.go +++ b/config/source/flag/flag.go @@ -77,6 +77,10 @@ func (fs *flagsrc) Watch() (source.Watcher, error) { return source.NewNoopWatcher() } +func (fs *flagsrc) Write(cs *source.ChangeSet) error { + return nil +} + func (fs *flagsrc) String() string { return "flag" } diff --git a/config/source/memory/memory.go b/config/source/memory/memory.go index 78e26d3f..e6a25d2a 100644 --- a/config/source/memory/memory.go +++ b/config/source/memory/memory.go @@ -41,6 +41,10 @@ func (s *memory) Watch() (source.Watcher, error) { return w, nil } +func (m *memory) Write(cs *source.ChangeSet) error { + return nil +} + // Update allows manual updates of the config data. func (s *memory) Update(c *source.ChangeSet) { // don't process nil diff --git a/config/source/source.go b/config/source/source.go index c6d961be..6d0605bc 100644 --- a/config/source/source.go +++ b/config/source/source.go @@ -15,6 +15,7 @@ var ( type Source interface { Read() (*ChangeSet, error) Watch() (Watcher, error) + Write(*ChangeSet) error String() string } From 81e20160f562de120e8a79f139e18fda0c669e56 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 23 Dec 2019 08:49:53 +0000 Subject: [PATCH 064/788] reorder --- config/source/source.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/source/source.go b/config/source/source.go index 6d0605bc..0cf8b9fb 100644 --- a/config/source/source.go +++ b/config/source/source.go @@ -14,8 +14,8 @@ var ( // Source is the source from which config is loaded type Source interface { Read() (*ChangeSet, error) - Watch() (Watcher, error) Write(*ChangeSet) error + Watch() (Watcher, error) String() string } From 5c8d1ae2b974803ed27d75246ede8f8fc1dc7c06 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 24 Dec 2019 17:33:05 +0000 Subject: [PATCH 065/788] Update k8s log options --- debug/log/kubernetes/kubernetes.go | 19 ++++++++++++++----- util/kubernetes/client/client.go | 19 ++++++++++--------- util/kubernetes/client/kubernetes.go | 4 ++-- util/kubernetes/client/logoptions.go | 13 ------------- util/kubernetes/client/options.go | 14 ++++++++++++++ 5 files changed, 40 insertions(+), 29 deletions(-) delete mode 100644 util/kubernetes/client/logoptions.go create mode 100644 util/kubernetes/client/options.go diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go index 187a7ca3..317d0952 100644 --- a/debug/log/kubernetes/kubernetes.go +++ b/debug/log/kubernetes/kubernetes.go @@ -24,7 +24,12 @@ func (k *klog) podLogStream(podName string, stream *kubeStream) { p := make(map[string]string) p["follow"] = "true" - body, err := k.client.Logs(podName, client.AdditionalParams(p)) + // get the logs for the pod + body, err := k.client.Log(&client.Resource{ + Name: podName, + Kind: "pod", + }, client.LogParams(p)) + if err != nil { fmt.Fprintf(os.Stderr, err.Error()) return @@ -98,14 +103,14 @@ func (k *klog) Read(options ...log.ReadOption) ([]log.Record, error) { o(opts) } - logsToGet, err := k.getMatchingPods() + pods, err := k.getMatchingPods() if err != nil { return nil, err } var records []log.Record - for _, l := range logsToGet { + for _, pod := range pods { logParams := make(map[string]string) if !opts.Since.Equal(time.Time{}) { @@ -120,7 +125,11 @@ func (k *klog) Read(options ...log.ReadOption) ([]log.Record, error) { logParams["follow"] = "true" } - logs, err := k.client.Logs(l, client.AdditionalParams(logParams)) + logs, err := k.client.Log(&client.Resource{ + Name: pod, + Kind: "pod", + }, client.LogParams(logParams)) + if err != nil { return nil, err } @@ -130,7 +139,7 @@ func (k *klog) Read(options ...log.ReadOption) ([]log.Record, error) { for s.Scan() { record := k.parse(s.Text()) - record.Metadata["pod"] = l + record.Metadata["pod"] = pod records = append(records, record) } } diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index ff82f837..2ae295e3 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -138,20 +138,21 @@ func (c *client) Get(r *Resource, labels map[string]string) error { Into(r.Value) } -// Logs returns logs for a pod -func (c *client) Logs(podName string, options ...LogOption) (io.ReadCloser, error) { - opts := &LogOptions{} - for _, o := range options { - o(opts) +// Log returns logs for a pod +func (c *client) Log(r *Resource, opts ...LogOption) (io.ReadCloser, error) { + var options LogOptions + for _, o := range opts { + o(&options) } + req := api.NewRequest(c.opts). Get(). - Resource("pod"). + Resource(r.Kind). SubResource("log"). - Name(podName) + Name(r.Name) - if opts.AdditionalParams != nil { - req.Params(&api.Params{Additional: opts.AdditionalParams}) + if options.Params != nil { + req.Params(&api.Params{Additional: options.Params}) } resp, err := req.Raw() diff --git a/util/kubernetes/client/kubernetes.go b/util/kubernetes/client/kubernetes.go index 761602ac..bbb22949 100644 --- a/util/kubernetes/client/kubernetes.go +++ b/util/kubernetes/client/kubernetes.go @@ -25,8 +25,8 @@ type Kubernetes interface { Delete(*Resource) error // List lists API resources List(*Resource) error - // Logs gets logs from a pod - Logs(string, ...LogOption) (io.ReadCloser, error) + // Log gets log for a pod + Log(*Resource, ...LogOption) (io.ReadCloser, error) } // NewService returns default micro kubernetes service definition diff --git a/util/kubernetes/client/logoptions.go b/util/kubernetes/client/logoptions.go deleted file mode 100644 index 349d0c59..00000000 --- a/util/kubernetes/client/logoptions.go +++ /dev/null @@ -1,13 +0,0 @@ -package client - -type LogOptions struct { - AdditionalParams map[string]string -} - -type LogOption func(*LogOptions) - -func AdditionalParams(p map[string]string) LogOption { - return func(l *LogOptions) { - l.AdditionalParams = p - } -} diff --git a/util/kubernetes/client/options.go b/util/kubernetes/client/options.go new file mode 100644 index 00000000..a5309b87 --- /dev/null +++ b/util/kubernetes/client/options.go @@ -0,0 +1,14 @@ +package client + +type LogOptions struct { + Params map[string]string +} + +type LogOption func(*LogOptions) + +// LogParams provides additional params for logs +func LogParams(p map[string]string) LogOption { + return func(l *LogOptions) { + l.Params = p + } +} From 361fdfba0465b0a7a287bc3bc85ff02b014405ed Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 24 Dec 2019 17:42:22 +0000 Subject: [PATCH 066/788] move around k8s api --- util/kubernetes/{client => }/api/api_test.go | 0 util/kubernetes/{client => }/api/request.go | 8 -------- util/kubernetes/{client => }/api/response.go | 9 +++------ util/kubernetes/client/client.go | 2 +- 4 files changed, 4 insertions(+), 15 deletions(-) rename util/kubernetes/{client => }/api/api_test.go (100%) rename util/kubernetes/{client => }/api/request.go (96%) rename util/kubernetes/{client => }/api/response.go (89%) diff --git a/util/kubernetes/client/api/api_test.go b/util/kubernetes/api/api_test.go similarity index 100% rename from util/kubernetes/client/api/api_test.go rename to util/kubernetes/api/api_test.go diff --git a/util/kubernetes/client/api/request.go b/util/kubernetes/api/request.go similarity index 96% rename from util/kubernetes/client/api/request.go rename to util/kubernetes/api/request.go index de314dca..b0f12ef7 100644 --- a/util/kubernetes/client/api/request.go +++ b/util/kubernetes/api/request.go @@ -8,8 +8,6 @@ import ( "io" "net/http" "net/url" - - "github.com/micro/go-micro/util/log" ) // Request is used to construct a http request for the k8s API. @@ -103,7 +101,6 @@ func (r *Request) Body(in interface{}) *Request { r.err = err return r } - log.Debugf("Request body: %v", b) r.body = b return r } @@ -120,7 +117,6 @@ func (r *Request) Body(in interface{}) *Request { return r } - log.Debugf("Request body: %v", b) r.body = b return r } @@ -202,8 +198,6 @@ func (r *Request) Do() *Response { } } - log.Debugf("kubernetes api request: %v", req) - res, err := r.client.Do(req) if err != nil { return &Response{ @@ -211,8 +205,6 @@ func (r *Request) Do() *Response { } } - log.Debugf("kubernetes api response: %v", res) - // return res, err return newResponse(res, err) } diff --git a/util/kubernetes/client/api/response.go b/util/kubernetes/api/response.go similarity index 89% rename from util/kubernetes/client/api/response.go rename to util/kubernetes/api/response.go index ceed48db..4f74e41d 100644 --- a/util/kubernetes/client/api/response.go +++ b/util/kubernetes/api/response.go @@ -5,8 +5,6 @@ import ( "errors" "io/ioutil" "net/http" - - "github.com/micro/go-micro/util/log" ) // Errors ... @@ -82,13 +80,12 @@ func newResponse(res *http.Response, err error) *Response { return r } - log.Logf("kubernetes: request failed with code %v", r.res.StatusCode) - b, err := ioutil.ReadAll(r.res.Body) if err == nil { - log.Log("kubernetes: request failed with body:") - log.Log(string(b)) + r.err = errors.New(string(b)) + return r } + r.err = ErrUnknown return r diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 2ae295e3..1c8b91b3 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -11,7 +11,7 @@ import ( "path" "strconv" - "github.com/micro/go-micro/util/kubernetes/client/api" + "github.com/micro/go-micro/util/kubernetes/api" "github.com/micro/go-micro/util/log" ) From 14c9c412cda76c2852dfbbd4f6008ee5bfd709ce Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 24 Dec 2019 17:45:17 +0000 Subject: [PATCH 067/788] Move and rename --- util/kubernetes/client/client.go | 245 ++++++++++++++++++++------- util/kubernetes/client/kubernetes.go | 125 -------------- 2 files changed, 180 insertions(+), 190 deletions(-) delete mode 100644 util/kubernetes/client/kubernetes.go diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 1c8b91b3..911e885c 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -1,3 +1,4 @@ +// Package client provides an implementation of a restricted subset of kubernetes API client package client import ( @@ -10,6 +11,7 @@ import ( "os" "path" "strconv" + "strings" "github.com/micro/go-micro/util/kubernetes/api" "github.com/micro/go-micro/util/log" @@ -20,6 +22,8 @@ var ( serviceAccountPath = "/var/run/secrets/kubernetes.io/serviceaccount" // ErrReadNamespace is returned when the names could not be read from service account ErrReadNamespace = errors.New("Could not read namespace from service account secret") + // DefaultImage is default micro image + DefaultImage = "micro/go-micro" ) // Client ... @@ -27,71 +31,20 @@ type client struct { opts *api.Options } -// NewLocalDevClient returns a client that can be used with `kubectl proxy` on an optional port -func NewLocalDevClient(port ...int) *client { - var p int - if len(port) > 1 { - log.Fatal("Expected 0 or 1 port parameters") - } - if len(port) == 0 { - p = 8001 - } else { - p = port[0] - } - return &client{ - opts: &api.Options{ - Client: http.DefaultClient, - Host: "http://localhost:" + strconv.Itoa(p), - Namespace: "default", - }, - } -} - -// NewClientInCluster creates a Kubernetes client for use from within a k8s pod. -func NewClientInCluster() *client { - host := "https://" + os.Getenv("KUBERNETES_SERVICE_HOST") + ":" + os.Getenv("KUBERNETES_SERVICE_PORT") - - s, err := os.Stat(serviceAccountPath) - if err != nil { - log.Fatal(err) - } - if s == nil || !s.IsDir() { - log.Fatal(errors.New("service account not found")) - } - - token, err := ioutil.ReadFile(path.Join(serviceAccountPath, "token")) - if err != nil { - log.Fatal(err) - } - t := string(token) - - ns, err := detectNamespace() - if err != nil { - log.Fatal(err) - } - - crt, err := CertPoolFromFile(path.Join(serviceAccountPath, "ca.crt")) - if err != nil { - log.Fatal(err) - } - - c := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{ - RootCAs: crt, - }, - DisableCompression: true, - }, - } - - return &client{ - opts: &api.Options{ - Client: c, - Host: host, - Namespace: ns, - BearerToken: &t, - }, - } +// Kubernetes client +type Client interface { + // Create creates new API resource + Create(*Resource) error + // Get queries API resrouces + Get(*Resource, map[string]string) error + // Update patches existing API object + Update(*Resource) error + // Delete deletes API resource + Delete(*Resource) error + // List lists API resources + List(*Resource) error + // Log gets log for a pod + Log(*Resource, ...LogOption) (io.ReadCloser, error) } func detectNamespace() (string, error) { @@ -203,3 +156,165 @@ func (c *client) List(r *Resource) error { } return c.Get(r, labels) } + +// NewService returns default micro kubernetes service definition +func NewService(name, version, typ string) *Service { + log.Tracef("kubernetes default service: name: %s, version: %s", name, version) + + Labels := map[string]string{ + "name": name, + "version": version, + "micro": typ, + } + + svcName := name + if len(version) > 0 { + // API service object name joins name and version over "-" + svcName = strings.Join([]string{name, version}, "-") + } + + Metadata := &Metadata{ + Name: svcName, + Namespace: "default", + Version: version, + Labels: Labels, + } + + Spec := &ServiceSpec{ + Type: "ClusterIP", + Selector: Labels, + Ports: []ServicePort{{ + "service-port", 9090, "", + }}, + } + + return &Service{ + Metadata: Metadata, + Spec: Spec, + } +} + +// NewService returns default micro kubernetes deployment definition +func NewDeployment(name, version, typ string) *Deployment { + log.Tracef("kubernetes default deployment: name: %s, version: %s", name, version) + + Labels := map[string]string{ + "name": name, + "version": version, + "micro": typ, + } + + depName := name + if len(version) > 0 { + // API deployment object name joins name and version over "-" + depName = strings.Join([]string{name, version}, "-") + } + + Metadata := &Metadata{ + Name: depName, + Namespace: "default", + Version: version, + Labels: Labels, + Annotations: map[string]string{}, + } + + // enable go modules by default + env := EnvVar{ + Name: "GO111MODULE", + Value: "on", + } + + Spec := &DeploymentSpec{ + Replicas: 1, + Selector: &LabelSelector{ + MatchLabels: Labels, + }, + Template: &Template{ + Metadata: Metadata, + PodSpec: &PodSpec{ + Containers: []Container{{ + Name: name, + Image: DefaultImage, + Env: []EnvVar{env}, + Command: []string{"go", "run", "main.go"}, + Ports: []ContainerPort{{ + Name: "service-port", + ContainerPort: 8080, + }}, + }}, + }, + }, + } + + return &Deployment{ + Metadata: Metadata, + Spec: Spec, + } +} + +// NewLocalDevClient returns a client that can be used with `kubectl proxy` on an optional port +func NewLocalDevClient(port ...int) *client { + var p int + if len(port) > 1 { + log.Fatal("Expected 0 or 1 port parameters") + } + if len(port) == 0 { + p = 8001 + } else { + p = port[0] + } + return &client{ + opts: &api.Options{ + Client: http.DefaultClient, + Host: "http://localhost:" + strconv.Itoa(p), + Namespace: "default", + }, + } +} + +// NewClientInCluster creates a Kubernetes client for use from within a k8s pod. +func NewClientInCluster() *client { + host := "https://" + os.Getenv("KUBERNETES_SERVICE_HOST") + ":" + os.Getenv("KUBERNETES_SERVICE_PORT") + + s, err := os.Stat(serviceAccountPath) + if err != nil { + log.Fatal(err) + } + if s == nil || !s.IsDir() { + log.Fatal(errors.New("service account not found")) + } + + token, err := ioutil.ReadFile(path.Join(serviceAccountPath, "token")) + if err != nil { + log.Fatal(err) + } + t := string(token) + + ns, err := detectNamespace() + if err != nil { + log.Fatal(err) + } + + crt, err := CertPoolFromFile(path.Join(serviceAccountPath, "ca.crt")) + if err != nil { + log.Fatal(err) + } + + c := &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + RootCAs: crt, + }, + DisableCompression: true, + }, + } + + return &client{ + opts: &api.Options{ + Client: c, + Host: host, + Namespace: ns, + BearerToken: &t, + }, + } +} diff --git a/util/kubernetes/client/kubernetes.go b/util/kubernetes/client/kubernetes.go deleted file mode 100644 index bbb22949..00000000 --- a/util/kubernetes/client/kubernetes.go +++ /dev/null @@ -1,125 +0,0 @@ -// Package client provides an implementation of a restricted subset of kubernetes API client -package client - -import ( - "io" - "strings" - - "github.com/micro/go-micro/util/log" -) - -var ( - // DefaultImage is default micro image - DefaultImage = "micro/go-micro" -) - -// Kubernetes client -type Kubernetes interface { - // Create creates new API resource - Create(*Resource) error - // Get queries API resrouces - Get(*Resource, map[string]string) error - // Update patches existing API object - Update(*Resource) error - // Delete deletes API resource - Delete(*Resource) error - // List lists API resources - List(*Resource) error - // Log gets log for a pod - Log(*Resource, ...LogOption) (io.ReadCloser, error) -} - -// NewService returns default micro kubernetes service definition -func NewService(name, version, typ string) *Service { - log.Tracef("kubernetes default service: name: %s, version: %s", name, version) - - Labels := map[string]string{ - "name": name, - "version": version, - "micro": typ, - } - - svcName := name - if len(version) > 0 { - // API service object name joins name and version over "-" - svcName = strings.Join([]string{name, version}, "-") - } - - Metadata := &Metadata{ - Name: svcName, - Namespace: "default", - Version: version, - Labels: Labels, - } - - Spec := &ServiceSpec{ - Type: "ClusterIP", - Selector: Labels, - Ports: []ServicePort{{ - "service-port", 9090, "", - }}, - } - - return &Service{ - Metadata: Metadata, - Spec: Spec, - } -} - -// NewService returns default micro kubernetes deployment definition -func NewDeployment(name, version, typ string) *Deployment { - log.Tracef("kubernetes default deployment: name: %s, version: %s", name, version) - - Labels := map[string]string{ - "name": name, - "version": version, - "micro": typ, - } - - depName := name - if len(version) > 0 { - // API deployment object name joins name and version over "-" - depName = strings.Join([]string{name, version}, "-") - } - - Metadata := &Metadata{ - Name: depName, - Namespace: "default", - Version: version, - Labels: Labels, - Annotations: map[string]string{}, - } - - // enable go modules by default - env := EnvVar{ - Name: "GO111MODULE", - Value: "on", - } - - Spec := &DeploymentSpec{ - Replicas: 1, - Selector: &LabelSelector{ - MatchLabels: Labels, - }, - Template: &Template{ - Metadata: Metadata, - PodSpec: &PodSpec{ - Containers: []Container{{ - Name: name, - Image: DefaultImage, - Env: []EnvVar{env}, - Command: []string{"go", "run", "main.go"}, - Ports: []ContainerPort{{ - Name: "service-port", - ContainerPort: 8080, - }}, - }}, - }, - }, - } - - return &Deployment{ - Metadata: Metadata, - Spec: Spec, - } -} From 2fe64001c0f7a98aefc4efd4a02266a20eb4ed7b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 24 Dec 2019 17:51:30 +0000 Subject: [PATCH 068/788] Start runtime services inline --- debug/log/kubernetes/kubernetes.go | 2 +- runtime/default.go | 14 ++++--- runtime/kubernetes/kubernetes.go | 66 +++--------------------------- runtime/kubernetes/service.go | 6 +-- 4 files changed, 18 insertions(+), 70 deletions(-) diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go index 317d0952..6fd8aa7d 100644 --- a/debug/log/kubernetes/kubernetes.go +++ b/debug/log/kubernetes/kubernetes.go @@ -15,7 +15,7 @@ import ( ) type klog struct { - client client.Kubernetes + client client.Client log.Options } diff --git a/runtime/default.go b/runtime/default.go index e9318d46..1f40380e 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -167,12 +167,16 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error { return errors.New("missing exec command") } - // save service - r.services[s.Name] = newService(s, options) + // create new service + service := newService(s, options) - // push into start queue - log.Debugf("Runtime creating service %s", s.Name) - r.start <- r.services[s.Name] + // start the service + if err := service.Start(); err != nil { + return err + } + + // save service + r.services[s.Name] = service return nil } diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 9c5d9089..6ba29df8 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -20,24 +20,16 @@ const ( stop ) -// task is queued into runtime queue -type task struct { - action action - service *service -} - type kubernetes struct { sync.RWMutex // options configure runtime options runtime.Options // indicates if we're running running bool - // task queue for kubernetes services - queue chan *task // used to stop the runtime closed chan bool // client is kubernetes client - client client.Kubernetes + client client.Client } // getService queries kubernetes for micro service @@ -163,30 +155,6 @@ func (k *kubernetes) run(events <-chan runtime.Event) { case <-t.C: // TODO: figure out what to do here // - do we even need the ticker for k8s services? - case task := <-k.queue: - // The task queue is used to take actions e.g (CRUD - R) - switch task.action { - case start: - log.Debugf("Runtime starting new service: %s", task.service.Name) - if err := task.service.Start(k.client); err != nil { - log.Debugf("Runtime failed to start service %s: %v", task.service.Name, err) - continue - } - case stop: - log.Debugf("Runtime stopping service: %s", task.service.Name) - if err := task.service.Stop(k.client); err != nil { - log.Debugf("Runtime failed to stop service %s: %v", task.service.Name, err) - continue - } - case update: - log.Debugf("Runtime updating service: %s", task.service.Name) - if err := task.service.Update(k.client); err != nil { - log.Debugf("Runtime failed to update service %s: %v", task.service.Name, err) - continue - } - default: - log.Debugf("Runtime received unknown action for service: %s", task.service.Name) - } case event := <-events: // NOTE: we only handle Update events for now log.Debugf("Runtime received notification event: %v", event) @@ -299,15 +267,8 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er // create new kubernetes micro service service := newService(s, options) - log.Debugf("Runtime queueing service %s version %s for start action", service.Name, service.Version) - - // push into start queue - k.queue <- &task{ - action: start, - service: service, - } - - return nil + // start the service + return service.Start(k.client) } // Read returns all instances of given service @@ -365,15 +326,7 @@ func (k *kubernetes) Update(s *runtime.Service) error { // update build time annotation service.kdeploy.Spec.Template.Metadata.Annotations["build"] = time.Now().Format(time.RFC3339) - log.Debugf("Runtime queueing service %s for update action", service.Name) - - // queue service for removal - k.queue <- &task{ - action: update, - service: service, - } - - return nil + return service.Update(k.client) } // Delete removes a service @@ -386,15 +339,7 @@ func (k *kubernetes) Delete(s *runtime.Service) error { Type: k.options.Type, }) - log.Debugf("Runtime queueing service %s for delete action", service.Name) - - // queue service for removal - k.queue <- &task{ - action: stop, - service: service, - } - - return nil + return service.Stop(k.client) } // Start starts the runtime @@ -475,7 +420,6 @@ func NewRuntime(opts ...runtime.Option) runtime.Runtime { return &kubernetes{ options: options, closed: make(chan bool), - queue: make(chan *task, 128), client: client, } } diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 704aafcf..b74eb7f2 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -85,7 +85,7 @@ func serviceResource(s *client.Service) *client.Resource { } // Start starts the Kubernetes service. It creates new kubernetes deployment and service API objects -func (s *service) Start(k client.Kubernetes) error { +func (s *service) Start(k client.Client) error { // create deployment first; if we fail, we dont create service if err := k.Create(deploymentResource(s.kdeploy)); err != nil { log.Debugf("Runtime failed to create deployment: %v", err) @@ -100,7 +100,7 @@ func (s *service) Start(k client.Kubernetes) error { return nil } -func (s *service) Stop(k client.Kubernetes) error { +func (s *service) Stop(k client.Client) error { // first attempt to delete service if err := k.Delete(serviceResource(s.kservice)); err != nil { log.Debugf("Runtime failed to delete service: %v", err) @@ -115,7 +115,7 @@ func (s *service) Stop(k client.Kubernetes) error { return nil } -func (s *service) Update(k client.Kubernetes) error { +func (s *service) Update(k client.Client) error { if err := k.Update(deploymentResource(s.kdeploy)); err != nil { log.Debugf("Runtime failed to update deployment: %v", err) return err From a09b6729cc1725df98ad4145997dbc243737a6b0 Mon Sep 17 00:00:00 2001 From: Eagle Wu Date: Fri, 27 Dec 2019 18:53:11 +0800 Subject: [PATCH 069/788] Fix missing recover while occur panic in handler (#1063) --- server/rpc_server.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/rpc_server.go b/server/rpc_server.go index d23401c8..a7426059 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -374,6 +374,12 @@ func (s *rpcServer) ServeConn(sock transport.Socket) { pool.Release(psock) // signal we're done wg.Done() + + // recover any panics for outbound process + if r := recover(); r != nil { + log.Log("panic recovered: ", r) + log.Log(string(debug.Stack())) + } }() for { @@ -400,6 +406,12 @@ func (s *rpcServer) ServeConn(sock transport.Socket) { pool.Release(psock) // signal we're done wg.Done() + + // recover any panics for call handler + if r := recover(); r != nil { + log.Log("panic recovered: ", r) + log.Log(string(debug.Stack())) + } }() // serve the actual request using the request router From 22aa7d14b369331c5fff7a92db5a58ef57f71a2b Mon Sep 17 00:00:00 2001 From: jamsonzan <31194068+jamsonzan@users.noreply.github.com> Date: Fri, 27 Dec 2019 20:25:58 +0800 Subject: [PATCH 070/788] support streams pool for grpc (#1062) * Update grpc_pool.go * Update options.go * Update grpc.go * Update grpc_pool_test.go * streams pool for grpc * use busy list to speed up allocate while pool is very busy * fix idle bug --- client/grpc/grpc.go | 24 ++++- client/grpc/grpc_pool.go | 172 +++++++++++++++++++++++++++------- client/grpc/grpc_pool_test.go | 10 +- client/grpc/options.go | 31 ++++++ 4 files changed, 199 insertions(+), 38 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index a593b690..792563d7 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -244,6 +244,28 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client }, nil } +func (g *grpcClient) poolMaxStreams() int { + if g.opts.Context == nil { + return DefaultPoolMaxStreams + } + v := g.opts.Context.Value(poolMaxStreams{}) + if v == nil { + return DefaultPoolMaxStreams + } + return v.(int) +} + +func (g *grpcClient) poolMaxIdle() int { + if g.opts.Context == nil { + return DefaultPoolMaxIdle + } + v := g.opts.Context.Value(poolMaxIdle{}) + if v == nil { + return DefaultPoolMaxIdle + } + return v.(int) +} + func (g *grpcClient) maxRecvMsgSizeValue() int { if g.opts.Context == nil { return DefaultMaxRecvMsgSize @@ -639,8 +661,8 @@ func newClient(opts ...client.Option) client.Client { rc := &grpcClient{ once: sync.Once{}, opts: options, - pool: newPool(options.PoolSize, options.PoolTTL), } + rc.pool = newPool(options.PoolSize, options.PoolTTL, rc.poolMaxIdle(), rc.poolMaxStreams()) c := client.Client(rc) diff --git a/client/grpc/grpc_pool.go b/client/grpc/grpc_pool.go index ea084e74..ba076b2a 100644 --- a/client/grpc/grpc_pool.go +++ b/client/grpc/grpc_pool.go @@ -10,74 +10,182 @@ import ( type pool struct { size int ttl int64 + + // max streams on a *poolConn + maxStreams int + // max idle conns + maxIdle int sync.Mutex - conns map[string][]*poolConn + conns map[string]*streamsPool +} + +type streamsPool struct { + // head of list + head *poolConn + // busy conns list + busy *poolConn + // the siza of list + count int + // idle conn + idle int } type poolConn struct { + // grpc conn *grpc.ClientConn + err error + addr string + + // pool and streams pool + pool *pool + sp *streamsPool + streams int created int64 + + // list + pre *poolConn + next *poolConn + in bool } -func newPool(size int, ttl time.Duration) *pool { +func newPool(size int, ttl time.Duration, idle int, ms int) *pool { + if ms <= 0 { + ms = 1 + } + if idle < 0 { + idle = 0 + } return &pool{ size: size, ttl: int64(ttl.Seconds()), - conns: make(map[string][]*poolConn), + maxStreams: ms, + maxIdle: idle, + conns: make(map[string]*streamsPool), } } func (p *pool) getConn(addr string, opts ...grpc.DialOption) (*poolConn, error) { - p.Lock() - conns := p.conns[addr] now := time.Now().Unix() - - // while we have conns check age and then return one - // otherwise we'll create a new conn - for len(conns) > 0 { - conn := conns[len(conns)-1] - conns = conns[:len(conns)-1] - p.conns[addr] = conns - - // if conn is old kill it and move on - if d := now - conn.created; d > p.ttl { - conn.ClientConn.Close() + p.Lock() + sp, ok := p.conns[addr] + if !ok { + sp = &streamsPool{head:&poolConn{}, busy:&poolConn{}, count:0, idle:0} + p.conns[addr] = sp + } + // while we have conns check streams and then return one + // otherwise we'll create a new conn + conn := sp.head.next + for conn != nil { + // a old conn + if now-conn.created > p.ttl { + next := conn.next + if conn.streams == 0 { + removeConn(conn) + conn.ClientConn.Close() + sp.idle-- + } + conn = next continue } - - // we got a good conn, lets unlock and return it + // a busy conn + if conn.streams >= p.maxStreams { + next := conn.next + removeConn(conn) + addConnAfter(conn, sp.busy) + conn = next + continue + } + // a idle conn + if conn.streams == 0 { + sp.idle-- + } + // a good conn + conn.streams++ p.Unlock() - return conn, nil } - p.Unlock() - // create new conn + // create new conn cc, err := grpc.Dial(addr, opts...) if err != nil { return nil, err } + conn = &poolConn{cc,nil,addr,p,sp,1,time.Now().Unix(), nil, nil, false} - return &poolConn{cc, time.Now().Unix()}, nil + // add conn to streams pool + p.Lock() + if sp.count < p.size { + addConnAfter(conn, sp.head) + } + p.Unlock() + + return conn, nil } func (p *pool) release(addr string, conn *poolConn, err error) { - // don't store the conn if it has errored - if err != nil { - conn.ClientConn.Close() - return - } - - // otherwise put it back for reuse p.Lock() - conns := p.conns[addr] - if len(conns) >= p.size { + p, sp, created := conn.pool, conn.sp, conn.created + // try to add conn + if !conn.in && sp.count < p.size { + addConnAfter(conn, sp.head) + } + if !conn.in { p.Unlock() conn.ClientConn.Close() return } - p.conns[addr] = append(conns, conn) + // a busy conn + if conn.streams >= p.maxStreams { + removeConn(conn) + addConnAfter(conn, sp.head) + } + conn.streams-- + // if streams == 0, we can do something + if conn.streams == 0 { + // 1. it has errored + // 2. too many idle conn or + // 3. conn is too old + now := time.Now().Unix() + if err != nil || sp.idle >= p.maxIdle || now-created > p.ttl { + removeConn(conn) + p.Unlock() + conn.ClientConn.Close() + return + } + sp.idle++ + } p.Unlock() + return +} + +func (conn *poolConn)Close() { + conn.pool.release(conn.addr, conn, conn.err) +} + +func removeConn(conn *poolConn) { + if conn.pre != nil { + conn.pre.next = conn.next + } + if conn.next != nil { + conn.next.pre = conn.pre + } + conn.pre = nil + conn.next = nil + conn.in = false + conn.sp.count-- + return +} + +func addConnAfter(conn *poolConn, after *poolConn) { + conn.next = after.next + conn.pre = after + if after.next != nil { + after.next.pre = conn + } + after.next = conn + conn.in = true + conn.sp.count++ + return } diff --git a/client/grpc/grpc_pool_test.go b/client/grpc/grpc_pool_test.go index d5c1fdb0..aa087ae0 100644 --- a/client/grpc/grpc_pool_test.go +++ b/client/grpc/grpc_pool_test.go @@ -11,7 +11,7 @@ import ( pb "google.golang.org/grpc/examples/helloworld/helloworld" ) -func testPool(t *testing.T, size int, ttl time.Duration) { +func testPool(t *testing.T, size int, ttl time.Duration, idle int, ms int) { // setup server l, err := net.Listen("tcp", ":0") if err != nil { @@ -26,7 +26,7 @@ func testPool(t *testing.T, size int, ttl time.Duration) { defer s.Stop() // zero pool - p := newPool(size, ttl) + p := newPool(size, ttl, idle, ms) for i := 0; i < 10; i++ { // get a conn @@ -50,7 +50,7 @@ func testPool(t *testing.T, size int, ttl time.Duration) { p.release(l.Addr().String(), cc, nil) p.Lock() - if i := len(p.conns[l.Addr().String()]); i > size { + if i := p.conns[l.Addr().String()].count; i > size { p.Unlock() t.Fatalf("pool size %d is greater than expected %d", i, size) } @@ -59,6 +59,6 @@ func testPool(t *testing.T, size int, ttl time.Duration) { } func TestGRPCPool(t *testing.T) { - testPool(t, 0, time.Minute) - testPool(t, 2, time.Minute) + testPool(t, 0, time.Minute, 10, 2) + testPool(t, 2, time.Minute, 10, 1) } diff --git a/client/grpc/options.go b/client/grpc/options.go index e7f2fceb..8384c48a 100644 --- a/client/grpc/options.go +++ b/client/grpc/options.go @@ -11,6 +11,14 @@ import ( ) var ( + // DefaultPoolMaxStreams maximum streams on a connectioin + // (20) + DefaultPoolMaxStreams = 20 + + // DefaultPoolMaxIdle maximum idle conns of a pool + // (50) + DefaultPoolMaxIdle = 50 + // DefaultMaxRecvMsgSize maximum message that client can receive // (4 MB). DefaultMaxRecvMsgSize = 1024 * 1024 * 4 @@ -20,6 +28,8 @@ var ( DefaultMaxSendMsgSize = 1024 * 1024 * 4 ) +type poolMaxStreams struct {} +type poolMaxIdle struct {} type codecsKey struct{} type tlsAuth struct{} type maxRecvMsgSizeKey struct{} @@ -27,6 +37,26 @@ type maxSendMsgSizeKey struct{} type grpcDialOptions struct{} type grpcCallOptions struct{} +// maximum streams on a connectioin +func PoolMaxStreams(n int) client.Option { + return func(o *client.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, poolMaxStreams{}, n) + } +} + +// maximum idle conns of a pool +func PoolMaxIdle(d int) client.Option { + return func(o *client.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, poolMaxIdle{}, d) + } +} + // gRPC Codec to be used to encode/decode requests for a given content type func Codec(contentType string, c encoding.Codec) client.Option { return func(o *client.Options) { @@ -99,3 +129,4 @@ func CallOptions(opts ...grpc.CallOption) client.CallOption { o.Context = context.WithValue(o.Context, grpcCallOptions{}, opts) } } + From 61cde4a9f4de145fd409ad6a5a5971b3cb98d5b9 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 27 Dec 2019 20:08:46 +0000 Subject: [PATCH 071/788] Kubernetes Registry (#1064) * add teh k8s registry * add k8s reg config/cmd * go mod update --- config/cmd/cmd.go | 2 + debug/log/kubernetes/kubernetes.go | 4 +- go.mod | 49 ++--- go.sum | 142 ++++---------- registry/kubernetes/README.md | 66 +++++++ registry/kubernetes/kubernetes.go | 289 +++++++++++++++++++++++++++++ registry/kubernetes/watcher.go | 261 ++++++++++++++++++++++++++ runtime/kubernetes/kubernetes.go | 2 +- util/kubernetes/api/request.go | 16 +- util/kubernetes/api/response.go | 4 + util/kubernetes/client/client.go | 53 ++++-- util/kubernetes/client/options.go | 12 ++ util/kubernetes/client/types.go | 164 ++++++++-------- util/kubernetes/client/watch.go | 122 ++++++++++++ 14 files changed, 950 insertions(+), 236 deletions(-) create mode 100644 registry/kubernetes/README.md create mode 100644 registry/kubernetes/kubernetes.go create mode 100644 registry/kubernetes/watcher.go create mode 100644 util/kubernetes/client/watch.go diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index f436ab18..ca02b6dd 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -29,6 +29,7 @@ import ( "github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry/etcd" "github.com/micro/go-micro/registry/mdns" + kreg "github.com/micro/go-micro/registry/kubernetes" rmem "github.com/micro/go-micro/registry/memory" regSrv "github.com/micro/go-micro/registry/service" @@ -211,6 +212,7 @@ var ( "etcd": etcd.NewRegistry, "mdns": mdns.NewRegistry, "memory": rmem.NewRegistry, + "kubernetes": kreg.NewRegistry, } DefaultSelectors = map[string]func(...selector.Option) selector.Selector{ diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go index 6fd8aa7d..861dbc46 100644 --- a/debug/log/kubernetes/kubernetes.go +++ b/debug/log/kubernetes/kubernetes.go @@ -182,9 +182,9 @@ func NewLog(opts ...log.Option) log.Log { } if len(os.Getenv("KUBERNETES_SERVICE_HOST")) > 0 { - klog.client = client.NewClientInCluster() + klog.client = client.NewClusterClient() } else { - klog.client = client.NewLocalDevClient() + klog.client = client.NewLocalClient() } return klog } diff --git a/go.mod b/go.mod index 9735d98f..58b17fb5 100644 --- a/go.mod +++ b/go.mod @@ -6,62 +6,43 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/beevik/ntp v0.2.0 github.com/bitly/go-simplejson v0.5.0 - github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect - github.com/bwmarrin/discordgo v0.20.1 - github.com/coreos/bbolt v1.3.3 // indirect - github.com/coreos/etcd v3.3.17+incompatible - github.com/coreos/go-semver v0.3.0 // indirect - github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect + github.com/bwmarrin/discordgo v0.20.2 + github.com/coreos/etcd v3.3.18+incompatible github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c github.com/fsnotify/fsnotify v1.4.7 github.com/fsouza/go-dockerclient v1.6.0 github.com/ghodss/yaml v1.0.0 - github.com/go-acme/lego/v3 v3.1.0 - github.com/go-playground/locales v0.13.0 // indirect - github.com/go-playground/universal-translator v0.16.0 // indirect - github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect - github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc // indirect + github.com/go-acme/lego/v3 v3.2.0 + github.com/go-playground/universal-translator v0.17.0 // indirect github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/websocket v1.4.1 - github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect - github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/hashicorp/hcl v1.0.0 github.com/imdario/mergo v0.3.8 - github.com/jonboulle/clockwork v0.1.0 // indirect github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 - github.com/json-iterator/go v1.1.8 + github.com/json-iterator/go v1.1.9 github.com/kr/pretty v0.1.0 github.com/leodido/go-urn v1.2.0 // indirect - github.com/lib/pq v1.2.0 - github.com/lucas-clemente/quic-go v0.13.1 - github.com/mholt/certmagic v0.8.3 + github.com/lib/pq v1.3.0 + github.com/lucas-clemente/quic-go v0.14.1 + github.com/mholt/certmagic v0.9.0 github.com/micro/cli v0.2.0 github.com/micro/mdns v0.3.0 - github.com/miekg/dns v1.1.22 + github.com/miekg/dns v1.1.26 github.com/mitchellh/hashstructure v1.0.0 - github.com/nats-io/nats-server/v2 v2.1.0 // indirect github.com/nats-io/nats.go v1.9.1 - github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 + github.com/nlopes/slack v0.6.0 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/pkg/errors v0.8.1 - github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 github.com/technoweenie/multipartstreamer v1.0.1 // indirect - github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect - github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect - go.etcd.io/bbolt v1.3.3 // indirect - go.uber.org/zap v1.12.0 - golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a - golang.org/x/net v0.0.0-20191109021931-daa7c04131f5 - golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 // indirect - google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a // indirect - google.golang.org/grpc v1.25.1 - gopkg.in/go-playground/assert.v1 v1.2.1 // indirect - gopkg.in/go-playground/validator.v9 v9.30.0 + go.uber.org/zap v1.13.0 + golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 + golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 + google.golang.org/grpc v1.26.0 + gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 - sigs.k8s.io/yaml v1.1.0 // indirect ) diff --git a/go.sum b/go.sum index ce46a0ba..71f5b50f 100644 --- a/go.sum +++ b/go.sum @@ -3,7 +3,6 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= contrib.go.opencensus.io/exporter/ocagent v0.4.12/go.mod h1:450APlNTSR6FrvC3CTRqYosuDstRB9un7SOx2k/9ckA= github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-autorest/autorest v0.1.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg= github.com/Azure/go-autorest/autorest v0.5.0/go.mod h1:9HLKlQjVBH6U3oDfsXOeVc56THsLPw1L03yban4xThw= @@ -19,26 +18,20 @@ github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6L github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvdeRAgDr0izn4z5Ij88= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 h1:ygIc8M6trr62pF5DucadTWGdEB4mEyvzi0e2nbcmcyA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= -github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/akamai/AkamaiOPEN-edgegrid-golang v0.9.0/go.mod h1:zpDJeKyp9ScW4NNrbdr+Eyxvry3ilGPewKoXw3XGN1k= -github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75 h1:3ILjVyslFbc4jl1w5TWuvvslFD/nDfR2H8tVaMVLrEY= github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75/go.mod h1:uAXEEpARkRhCZfEvy/y0Jcc888f9tHCc1W7/UeEtreE= -github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190808125512-07798873deee/go.mod h1:myCDvQSzCW+wB1WAlocEru4wMGJxy+vlxHdhegi1CDQ= github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= -github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= -github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aws/aws-sdk-go v1.23.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= @@ -46,15 +39,12 @@ github.com/beevik/ntp v0.2.0 h1:sGsd+kAXzT0bfVfzJfce04g+dSRfrs+tbQW8lweuYgw= github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y= github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= -github.com/bwmarrin/discordgo v0.20.1 h1:Ihh3/mVoRwy3otmaoPDUioILBJq4fdWkpsi83oj2Lmk= -github.com/bwmarrin/discordgo v0.20.1/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= +github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= +github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -75,16 +65,10 @@ github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3/go.mod h1:IV7qH3hrUgRmyYrtgEeGWJfWbgcHL9CSRruz2Vqcph0= github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDGpgqzQIzDW1TphrGLssLDZp2GuS+X5DkEJB8o= github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= -github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= -github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/etcd v3.3.17+incompatible h1:f/Z3EoDSx1yjaIjLQGo1diYUlQYSBrrAQ5vP8NjwXwo= -github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= +github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c= -github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpu/goacmedns v0.0.1/go.mod h1:sesf/pNnCYwUevQEQfEwY0Y3DydlQWSGZbaMElOWxok= @@ -94,7 +78,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/decker502/dnspod-go v0.2.0/go.mod h1:qsurYu1FgxcDwfSwXJdLt4kRsBLZeosEb9uq4Sy+08g= -github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= @@ -112,11 +95,10 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1 github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= -github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXju1m8W4lnEeIqTHPOzhTUO81a7yknM/xQR4= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= @@ -126,10 +108,11 @@ github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4 github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= -github.com/go-acme/lego/v3 v3.1.0 h1:yanYFoYW8azFkCvJfIk7edWWfjkYkhDxe45ZsxoW4Xk= +github.com/go-acme/lego v2.7.2+incompatible h1:ThhpPBgf6oa9X/vRd0kEmWOsX7+vmYdckmGZSb+FEp0= github.com/go-acme/lego/v3 v3.1.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= +github.com/go-acme/lego/v3 v3.2.0 h1:z0zvNlL1niv/1qA06V5X1BRC5PeLoGKAlVaWthXQz9c= +github.com/go-acme/lego/v3 v3.2.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= @@ -138,11 +121,9 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM= -github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU= -github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM= github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -150,12 +131,8 @@ github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc h1:55rEp52jU6bkyslZ1+C/7NGfpQsEc6pxGLAGDOctqbw= -github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= @@ -163,11 +140,9 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -189,11 +164,6 @@ github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg= -github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.8.5 h1:2+KSC78XiO6Qy0hIjfc1OD9H+hsaJdJlb8Kqsd41CTE= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -203,7 +173,6 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= @@ -212,15 +181,13 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= -github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= -github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 h1:lnrOS18wZBYrzdDmnUeg1OVk+kQ3rxG8mZWU89DpMIA= github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1/go.mod h1:DFXrEwSRX0p/aSvxE21319menCBFeQO0jXpRj7LEZUA= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46Ok= -github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= @@ -232,7 +199,6 @@ github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/kolo/xmlrpc v0.0.0-20190717152603-07c4ee3fd181/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -245,12 +211,12 @@ github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HK github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0= -github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= +github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ= -github.com/lucas-clemente/quic-go v0.13.1 h1:CxtJTXQIh2aboCPk0M6vf530XOov6DZjVBiSE3nSj8s= -github.com/lucas-clemente/quic-go v0.13.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= +github.com/lucas-clemente/quic-go v0.14.1 h1:c1aKoBZKOPA+49q96B1wGkibyPP0AxYh45WuAoq+87E= +github.com/lucas-clemente/quic-go v0.14.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ= github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE= github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= @@ -260,19 +226,17 @@ github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= -github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mholt/certmagic v0.8.3 h1:JOUiX9IAZbbgyjNP2GY6v/6lorH+9GkZsc7ktMpGCSo= -github.com/mholt/certmagic v0.8.3/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= +github.com/mholt/certmagic v0.9.0 h1:dYh9sZPDBTcIiPhYM/Qtv3V623/zFH34FmpbrQTpMAc= +github.com/mholt/certmagic v0.9.0/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/miekg/dns v1.1.15 h1:CSSIDtllwGLMoA6zjdKnaE6Tx6eVUxQ29LUgGetiDCI= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/miekg/dns v1.1.22 h1:Jm64b3bO9kP43ddLjL2EY3Io6bmy1qGb9Xxz6TqS6rc= -github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= +github.com/miekg/dns v1.1.26 h1:gPxPSwALAeHJSjarOs00QjVdV9QoBvc1D2ujQUr5BzU= +github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed/go.mod h1:3rdaFaCv4AyBgu5ALFM0+tSuHrBh6v692nyQe3ikrq0= @@ -291,27 +255,21 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= github.com/nats-io/jwt v0.3.0 h1:xdnzwFETV++jNc4W1mw//qFyJGb2ABOombmZJQS4+Qo= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= -github.com/nats-io/nats-server/v2 v2.1.0 h1:Yi0+ZhRPtPAGeIxFn5erIeJIV9wXA+JznfSxK621Fbk= -github.com/nats-io/nats-server/v2 v2.1.0/go.mod h1:r5y0WgCag0dTj/qiHkHrXAcKQ/f5GMOZaEGdoxxnJ4I= -github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= -github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4= github.com/nats-io/nkeys v0.1.0 h1:qMd4+pRHgdr1nAClu+2h/2a5F2TmKcCzjCDazVgRoX4= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= -github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= -github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= +github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA= +github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2SwKQ= github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= @@ -323,7 +281,6 @@ github.com/opencontainers/runc v0.1.1 h1:GlxAyO6x8rfZYN9Tt0Kti5a/cP41iuiO2yYT0IJ github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/runtime-tools v0.0.0-20181011054405-1d69bd0f9c39/go.mod h1:r3f7wjNzSs2extwzU3Y+6pKfobzPh+kKFJ3ofN+3nfs= -github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/oracle/oci-go-sdk v7.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014/go.mod h1:joRatxRJaZBsY3JAOEMcoOp05CnZzsx4scTxi95DHyQ= @@ -339,22 +296,18 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.1.0 h1:BQ53HtBmfOitExawJ6LokA4x8ov/z0SYYb0+HxJfRI8= github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= -github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKcyumwBO6qip7RNQ5r77yrssm9bfCowcLEBcU5IA= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= @@ -373,8 +326,6 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= -github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -389,8 +340,6 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= @@ -402,31 +351,22 @@ github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2 github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= -go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.12.0 h1:dySoUQPFBGj6xwjmBzageVL8jGi8uxc6bEmJQjA06bw= -go.uber.org/zap v1.12.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= +go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -438,15 +378,14 @@ golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a h1:R/qVym5WAxsZWQqZCwDY/8sdVKV1m1WgU4/S5IRQAzc= -golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 h1:sKJQZMuxjOAR/Uo2LBfU90onWEf1dF4C+0hPJCc9Mpc= +golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/net v0.0.0-20180611182652-db08ff08e862/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -468,8 +407,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191109021931-daa7c04131f5 h1:bHNaocaoJxYBo5cw41UyTMLjYlb8wPY7+WFrnklbHOM= -golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -499,12 +438,10 @@ golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3 h1:7TYNF4UdlohbFwpNH04CoPMp1cHUZgO1Ebq5r2hIjfo= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 h1:Hynbrlo6LbYI3H1IqXpkVDOcX/3HiPdhVEuyj5a59RM= -golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= @@ -527,7 +464,6 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= @@ -544,27 +480,21 @@ google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a h1:Ob5/580gVHBJZgXnff1cZDbG+xLtMVE5mDRTe+nIsX4= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1 h1:wdKvqQk7IttEw92GoRyKG2IDrUIpgpj6H6m81yfeMW0= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= -gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= -gopkg.in/go-playground/validator.v9 v9.30.0 h1:Wk0Z37oBmKj9/n+tPyBHZmeL19LaCoK3Qq48VwYENss= -gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= +gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= @@ -575,13 +505,11 @@ gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4 gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg= gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= -gopkg.in/src-d/go-git-fixtures.v3 v3.5.0 h1:ivZFOIltbce2Mo8IjzUHAFoq/IylO9WHhNOAJK+LsJg= gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE= gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= gopkg.in/telegram-bot-api.v4 v4.6.4 h1:hpHWhzn4jTCsAJZZ2loNKfy2QWyPDRJVl3aTFXeMW8g= gopkg.in/telegram-bot-api.v4 v4.6.4/go.mod h1:5DpGO5dbumb40px+dXcwCpcjmeHNYLpk0bp3XRNvWDM= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= @@ -589,15 +517,11 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= -sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= -sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/registry/kubernetes/README.md b/registry/kubernetes/README.md new file mode 100644 index 00000000..80282db4 --- /dev/null +++ b/registry/kubernetes/README.md @@ -0,0 +1,66 @@ +# Kubernetes Registry Plugin for micro +This is a plugin for go-micro that allows you to use Kubernetes as a registry. + + +## Overview +This registry plugin makes use of Annotations and Labels on a Kubernetes pod +to build a service discovery mechanism. + + +## RBAC +If your Kubernetes cluster has RBAC enabled, a role and role binding +will need to be created to allow this plugin to `list` and `patch` pods. + +A cluster role can be used to specify the `list` and `patch` +requirements, while a role binding per namespace can be used to apply +the cluster role. The example RBAC configs below assume your Micro-based +services are running in the `test` namespace, and the pods that contain +the services are using the `micro-services` service account. + +``` +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: micro-registry +rules: +- apiGroups: + - "" + resources: + - pods + verbs: + - list + - patch + - watch +``` + +``` +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: micro-registry +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: micro-registry +subjects: +- kind: ServiceAccount + name: micro-services + namespace: test +``` + + +## Gotchas +* Registering/Deregistering relies on the HOSTNAME Environment Variable, which inside a pod +is the place where it can be retrieved from. (This needs improving) + + +## Connecting to the Kubernetes API +### Within a pod +If the `--registry_address` flag is omitted, the plugin will securely connect to +the Kubernetes API using the pods "Service Account". No extra configuration is necessary. + +Find out more about service accounts here. http://kubernetes.io/docs/user-guide/accessing-the-cluster/ + +### Outside of Kubernetes +Some functions of the plugin should work, but its not been heavily tested. +Currently no TLS support. diff --git a/registry/kubernetes/kubernetes.go b/registry/kubernetes/kubernetes.go new file mode 100644 index 00000000..ccc22f1b --- /dev/null +++ b/registry/kubernetes/kubernetes.go @@ -0,0 +1,289 @@ +// Package kubernetes provides a kubernetes registry +package kubernetes + +import ( + "encoding/json" + "errors" + "fmt" + "os" + "regexp" + "strings" + "time" + + "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/util/kubernetes/client" +) + +type kregistry struct { + client client.Client + timeout time.Duration + options registry.Options +} + +var ( + // used on pods as labels & services to select + // eg: svcSelectorPrefix+"svc.name" + servicePrefix = "micro/service/" + serviceValue = "service" + + labelTypeKey = "micro" + labelTypeValue = "service" + + // used on k8s services to scope a serialised + // micro service by pod name + annotationPrefix = "micro/service/" + + // Pod status + podRunning = "Running" + + // label name regex + labelRe = regexp.MustCompilePOSIX("[-A-Za-z0-9_.]") +) + +// podSelector +var podSelector = map[string]string{ + labelTypeKey: labelTypeValue, +} + +func configure(k *kregistry, opts ...registry.Option) error { + for _, o := range opts { + o(&k.options) + } + + // get first host + var host string + if len(k.options.Addrs) > 0 && len(k.options.Addrs[0]) > 0 { + host = k.options.Addrs[0] + } + + if k.options.Timeout == 0 { + k.options.Timeout = time.Second * 1 + } + + // if no hosts setup, assume InCluster + var c client.Client + + if len(host) > 0 { + c = client.NewLocalClient(host) + } else { + c = client.NewClusterClient() + } + + k.client = c + k.timeout = k.options.Timeout + + return nil +} + +// serviceName generates a valid service name for k8s labels +func serviceName(name string) string { + aname := make([]byte, len(name)) + + for i, r := range []byte(name) { + if !labelRe.Match([]byte{r}) { + aname[i] = '_' + continue + } + aname[i] = r + } + + return string(aname) +} + +// Init allows reconfig of options +func (c *kregistry) Init(opts ...registry.Option) error { + return configure(c, opts...) +} + +// Options returns the registry Options +func (c *kregistry) Options() registry.Options { + return c.options +} + +// Register sets a service selector label and an annotation with a +// serialised version of the service passed in. +func (c *kregistry) Register(s *registry.Service, opts ...registry.RegisterOption) error { + if len(s.Nodes) == 0 { + return errors.New("no nodes") + } + + // TODO: grab podname from somewhere better than this. + podName := os.Getenv("HOSTNAME") + svcName := s.Name + + // encode micro service + b, err := json.Marshal(s) + if err != nil { + return err + } + /// marshalled service + svc := string(b) + + pod := &client.Pod{ + Metadata: &client.Metadata{ + Labels: map[string]string{ + // micro: service + labelTypeKey: labelTypeValue, + // micro/service/name: service + servicePrefix + serviceName(svcName): serviceValue, + }, + Annotations: map[string]string{ + // micro/service/name: definition + annotationPrefix + serviceName(svcName): svc, + }, + }, + } + + return c.client.Update(&client.Resource{ + Name: podName, + Kind: "pod", + Value: pod, + }) +} + +// Deregister nils out any things set in Register +func (c *kregistry) Deregister(s *registry.Service) error { + if len(s.Nodes) == 0 { + return errors.New("you must deregister at least one node") + } + + // TODO: grab podname from somewhere better than this. + podName := os.Getenv("HOSTNAME") + svcName := s.Name + + pod := &client.Pod{ + Metadata: &client.Metadata{ + Labels: map[string]string{ + servicePrefix + serviceName(svcName): "", + }, + Annotations: map[string]string{ + annotationPrefix + serviceName(svcName): "", + }, + }, + } + + return c.client.Update(&client.Resource{ + Name: podName, + Kind: "pod", + Value: pod, + }) +} + +// GetService will get all the pods with the given service selector, +// and build services from the annotations. +func (c *kregistry) GetService(name string) ([]*registry.Service, error) { + var pods client.PodList + + if err := c.client.Get(&client.Resource{ + Kind: "pod", + Value: &pods, + }, map[string]string{ + servicePrefix + serviceName(name): serviceValue, + }); err != nil { + return nil, err + } + + if len(pods.Items) == 0 { + return nil, registry.ErrNotFound + } + + // svcs mapped by version + svcs := make(map[string]*registry.Service) + + // loop through items + for _, pod := range pods.Items { + if pod.Status.Phase != podRunning { + continue + } + + // get serialised service from annotation + svcStr, ok := pod.Metadata.Annotations[annotationPrefix+serviceName(name)] + if !ok { + continue + } + + // unmarshal service string + var svc registry.Service + + if err := json.Unmarshal([]byte(svcStr), &svc); err != nil { + return nil, fmt.Errorf("could not unmarshal service '%s' from pod annotation", name) + } + + // merge up pod service & ip with versioned service. + vs, ok := svcs[svc.Version] + if !ok { + svcs[svc.Version] = &svc + continue + } + + vs.Nodes = append(vs.Nodes, svc.Nodes...) + } + + list := make([]*registry.Service, 0, len(svcs)) + for _, val := range svcs { + list = append(list, val) + } + return list, nil +} + +// ListServices will list all the service names +func (c *kregistry) ListServices() ([]*registry.Service, error) { + var pods client.PodList + + if err := c.client.Get(&client.Resource{ + Kind: "pod", + Value: &pods, + }, podSelector); err != nil { + return nil, err + } + + // svcs mapped by name + svcs := make(map[string]bool) + + for _, pod := range pods.Items { + if pod.Status.Phase != podRunning { + continue + } + for k, v := range pod.Metadata.Annotations { + if !strings.HasPrefix(k, annotationPrefix) { + continue + } + + // we have to unmarshal the annotation itself since the + // key is encoded to match the regex restriction. + var svc registry.Service + + if err := json.Unmarshal([]byte(v), &svc); err != nil { + continue + } + + svcs[svc.Name] = true + } + } + + var list []*registry.Service + + for val := range svcs { + list = append(list, ®istry.Service{Name: val}) + } + + return list, nil +} + +// Watch returns a kubernetes watcher +func (c *kregistry) Watch(opts ...registry.WatchOption) (registry.Watcher, error) { + return newWatcher(c, opts...) +} + +func (c *kregistry) String() string { + return "kubernetes" +} + +// NewRegistry creates a kubernetes registry +func NewRegistry(opts ...registry.Option) registry.Registry { + k := &kregistry{ + options: registry.Options{}, + } + configure(k, opts...) + return k +} diff --git a/registry/kubernetes/watcher.go b/registry/kubernetes/watcher.go new file mode 100644 index 00000000..c51d4fc8 --- /dev/null +++ b/registry/kubernetes/watcher.go @@ -0,0 +1,261 @@ +package kubernetes + +import ( + "encoding/json" + "errors" + "strings" + "sync" + + "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/util/kubernetes/client" + "github.com/micro/go-micro/util/log" +) + +type k8sWatcher struct { + registry *kregistry + watcher client.Watcher + next chan *registry.Result + stop chan bool + + sync.RWMutex + pods map[string]*client.Pod +} + +// build a cache of pods when the watcher starts. +func (k *k8sWatcher) updateCache() ([]*registry.Result, error) { + var pods client.PodList + + if err := k.registry.client.Get(&client.Resource{ + Kind: "pod", + Value: &pods, + }, podSelector); err != nil { + return nil, err + } + + var results []*registry.Result + + for _, pod := range pods.Items { + rslts := k.buildPodResults(&pod, nil) + + for _, r := range rslts { + results = append(results, r) + } + + k.Lock() + k.pods[pod.Metadata.Name] = &pod + k.Unlock() + } + + return results, nil +} + +// look through pod annotations, compare against cache if present +// and return a list of results to send down the wire. +func (k *k8sWatcher) buildPodResults(pod *client.Pod, cache *client.Pod) []*registry.Result { + var results []*registry.Result + ignore := make(map[string]bool) + + if pod.Metadata != nil { + for ak, av := range pod.Metadata.Annotations { + // check this annotation kv is a service notation + if !strings.HasPrefix(ak, annotationPrefix) { + continue + } + + if len(av) == 0 { + continue + } + + // ignore when we check the cached annotations + // as we take care of it here + ignore[ak] = true + + // compare aginst cache. + var cacheExists bool + var cav string + + if cache != nil && cache.Metadata != nil { + cav, cacheExists = cache.Metadata.Annotations[ak] + if cacheExists && len(cav) > 0 && cav == av { + // service notation exists and is identical - + // no change result required. + continue + } + } + + rslt := ®istry.Result{} + if cacheExists { + rslt.Action = "update" + } else { + rslt.Action = "create" + } + + // unmarshal service notation from annotation value + err := json.Unmarshal([]byte(av), &rslt.Service) + if err != nil { + continue + } + + results = append(results, rslt) + } + } + + // loop through cache annotations to find services + // not accounted for above, and "delete" them. + if cache != nil && cache.Metadata != nil { + for ak, av := range cache.Metadata.Annotations { + if ignore[ak] { + continue + } + + // check this annotation kv is a service notation + if !strings.HasPrefix(ak, annotationPrefix) { + continue + } + + rslt := ®istry.Result{Action: "delete"} + // unmarshal service notation from annotation value + err := json.Unmarshal([]byte(av), &rslt.Service) + if err != nil { + continue + } + + results = append(results, rslt) + } + } + + return results +} + +// handleEvent will taken an event from the k8s pods API and do the correct +// things with the result, based on the local cache. +func (k *k8sWatcher) handleEvent(event client.Event) { + var pod client.Pod + if err := json.Unmarshal([]byte(event.Object), &pod); err != nil { + log.Log("K8s Watcher: Couldnt unmarshal event object from pod") + return + } + + switch event.Type { + case client.Modified: + // Pod was modified + + k.RLock() + cache := k.pods[pod.Metadata.Name] + k.RUnlock() + + // service could have been added, edited or removed. + var results []*registry.Result + + if pod.Status.Phase == podRunning { + results = k.buildPodResults(&pod, cache) + } else { + // passing in cache might not return all results + results = k.buildPodResults(&pod, nil) + } + + for _, result := range results { + // pod isnt running + if pod.Status.Phase != podRunning { + result.Action = "delete" + } + + select { + case k.next <- result: + case <-k.stop: + return + } + } + + k.Lock() + k.pods[pod.Metadata.Name] = &pod + k.Unlock() + return + + case client.Deleted: + // Pod was deleted + // passing in cache might not return all results + results := k.buildPodResults(&pod, nil) + + for _, result := range results { + result.Action = "delete" + select { + case k.next <- result: + case <-k.stop: + return + } + } + + k.Lock() + delete(k.pods, pod.Metadata.Name) + k.Unlock() + return + } + +} + +// Next will block until a new result comes in +func (k *k8sWatcher) Next() (*registry.Result, error) { + select { + case r := <-k.next: + return r, nil + case <-k.stop: + return nil, errors.New("watcher stopped") + } +} + +// Stop will cancel any requests, and close channels +func (k *k8sWatcher) Stop() { + select { + case <-k.stop: + return + default: + k.watcher.Stop() + close(k.stop) + } +} + +func newWatcher(kr *kregistry, opts ...registry.WatchOption) (registry.Watcher, error) { + var wo registry.WatchOptions + for _, o := range opts { + o(&wo) + } + + selector := podSelector + if len(wo.Service) > 0 { + selector = map[string]string{ + servicePrefix + serviceName(wo.Service): serviceValue, + } + } + + // Create watch request + watcher, err := kr.client.Watch(&client.Resource{ + Kind: "pod", + }, client.WatchParams(selector)) + if err != nil { + return nil, err + } + + k := &k8sWatcher{ + registry: kr, + watcher: watcher, + next: make(chan *registry.Result), + stop: make(chan bool), + pods: make(map[string]*client.Pod), + } + + // update cache, but dont emit changes + if _, err := k.updateCache(); err != nil { + return nil, err + } + + // range over watch request changes, and invoke + // the update event + go func() { + for event := range watcher.Chan() { + k.handleEvent(event) + } + }() + + return k, nil +} diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 6ba29df8..33cebb1d 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -415,7 +415,7 @@ func NewRuntime(opts ...runtime.Option) runtime.Runtime { } // kubernetes client - client := client.NewClientInCluster() + client := client.NewClusterClient() return &kubernetes{ options: options, diff --git a/util/kubernetes/api/request.go b/util/kubernetes/api/request.go index b0f12ef7..89b429b7 100644 --- a/util/kubernetes/api/request.go +++ b/util/kubernetes/api/request.go @@ -2,6 +2,7 @@ package api import ( "bytes" + "context" "encoding/json" "errors" "fmt" @@ -12,6 +13,8 @@ import ( // Request is used to construct a http request for the k8s API. type Request struct { + // the request context + context context.Context client *http.Client header http.Header params url.Values @@ -41,6 +44,10 @@ func (r *Request) verb(method string) *Request { return r } +func (r *Request) Context(ctx context.Context) { + r.context = ctx +} + // Get request func (r *Request) Get() *Request { return r.verb("GET") @@ -172,8 +179,15 @@ func (r *Request) request() (*http.Request, error) { url += "?" + r.params.Encode() } + var req *http.Request + var err error + // build request - req, err := http.NewRequest(r.method, url, r.body) + if r.context != nil { + req, err = http.NewRequestWithContext(r.context, r.method, url, r.body) + } else { + req, err = http.NewRequest(r.method, url, r.body) + } if err != nil { return nil, err } diff --git a/util/kubernetes/api/response.go b/util/kubernetes/api/response.go index 4f74e41d..6185a880 100644 --- a/util/kubernetes/api/response.go +++ b/util/kubernetes/api/response.go @@ -58,6 +58,10 @@ func (r *Response) Into(data interface{}) error { return r.err } +func (r *Response) Close() error { + return r.res.Body.Close() +} + func newResponse(res *http.Response, err error) *Response { r := &Response{ res: res, diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 911e885c..a71d8bab 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -10,7 +10,6 @@ import ( "net/http" "os" "path" - "strconv" "strings" "github.com/micro/go-micro/util/kubernetes/api" @@ -45,6 +44,8 @@ type Client interface { List(*Resource) error // Log gets log for a pod Log(*Resource, ...LogOption) (io.ReadCloser, error) + // Watch for events + Watch(*Resource, ...WatchOption) (Watcher, error) } func detectNamespace() (string, error) { @@ -132,6 +133,8 @@ func (c *client) Update(r *Resource) error { req.Body(r.Value.(*Service)) case "deployment": req.Body(r.Value.(*Deployment)) + case "pod": + req.Body(r.Value.(*Pod)) default: return errors.New("unsupported resource") } @@ -157,6 +160,34 @@ func (c *client) List(r *Resource) error { return c.Get(r, labels) } +// Watch returns an event stream +func (c *client) Watch(r *Resource, opts ...WatchOption) (Watcher, error) { + var options WatchOptions + for _, o := range opts { + o(&options) + } + + // set the watch param + params := &api.Params{Additional: map[string]string{ + "watch": "true", + }} + + // get options params + if options.Params != nil { + for k, v := range options.Params { + params.Additional[k] = v + } + } + + req := api.NewRequest(c.opts). + Get(). + Resource(r.Kind). + Name(r.Name). + Params(params) + + return newWatcher(req) +} + // NewService returns default micro kubernetes service definition func NewService(name, version, typ string) *Service { log.Tracef("kubernetes default service: name: %s, version: %s", name, version) @@ -252,28 +283,22 @@ func NewDeployment(name, version, typ string) *Deployment { } } -// NewLocalDevClient returns a client that can be used with `kubectl proxy` on an optional port -func NewLocalDevClient(port ...int) *client { - var p int - if len(port) > 1 { - log.Fatal("Expected 0 or 1 port parameters") - } - if len(port) == 0 { - p = 8001 - } else { - p = port[0] +// NewLocalClient returns a client that can be used with `kubectl proxy` +func NewLocalClient(hosts ...string) *client { + if len(hosts) == 0 { + hosts[0] = "http://localhost:8001" } return &client{ opts: &api.Options{ Client: http.DefaultClient, - Host: "http://localhost:" + strconv.Itoa(p), + Host: hosts[0], Namespace: "default", }, } } -// NewClientInCluster creates a Kubernetes client for use from within a k8s pod. -func NewClientInCluster() *client { +// NewClusterClient creates a Kubernetes client for use from within a k8s pod. +func NewClusterClient() *client { host := "https://" + os.Getenv("KUBERNETES_SERVICE_HOST") + ":" + os.Getenv("KUBERNETES_SERVICE_PORT") s, err := os.Stat(serviceAccountPath) diff --git a/util/kubernetes/client/options.go b/util/kubernetes/client/options.go index a5309b87..0e293522 100644 --- a/util/kubernetes/client/options.go +++ b/util/kubernetes/client/options.go @@ -4,7 +4,12 @@ type LogOptions struct { Params map[string]string } +type WatchOptions struct { + Params map[string]string +} + type LogOption func(*LogOptions) +type WatchOption func(*WatchOptions) // LogParams provides additional params for logs func LogParams(p map[string]string) LogOption { @@ -12,3 +17,10 @@ func LogParams(p map[string]string) LogOption { l.Params = p } } + +// WatchParams used for watch params +func WatchParams(p map[string]string) WatchOption { + return func(w *WatchOptions) { + w.Params = p + } +} diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index 588f9e40..b3ce9a72 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -1,61 +1,5 @@ package client -// Resource is API resource -type Resource struct { - Name string - Kind string - Value interface{} -} - -// Metadata defines api object metadata -type Metadata struct { - Name string `json:"name,omitempty"` - Namespace string `json:"namespace,omitempty"` - Version string `json:"version,omitempty"` - Labels map[string]string `json:"labels,omitempty"` - Annotations map[string]string `json:"annotations,omitempty"` -} - -// ServicePort configures service ports -type ServicePort struct { - Name string `json:"name,omitempty"` - Port int `json:"port"` - Protocol string `json:"protocol,omitempty"` -} - -// ServiceSpec provides service configuration -type ServiceSpec struct { - Type string `json:"type,omitempty"` - Selector map[string]string `json:"selector,omitempty"` - Ports []ServicePort `json:"ports,omitempty"` -} - -type LoadBalancerIngress struct { - IP string `json:"ip,omitempty"` - Hostname string `json:"hostname,omitempty"` -} - -type LoadBalancerStatus struct { - Ingress []LoadBalancerIngress `json:"ingress,omitempty"` -} - -// ServiceStatus -type ServiceStatus struct { - LoadBalancer LoadBalancerStatus `json:"loadBalancer,omitempty"` -} - -// Service is kubernetes service -type Service struct { - Metadata *Metadata `json:"metadata"` - Spec *ServiceSpec `json:"spec,omitempty"` - Status *ServiceStatus `json:"status,omitempty"` -} - -// ServiceList -type ServiceList struct { - Items []Service `json:"items"` -} - // ContainerPort type ContainerPort struct { Name string `json:"name,omitempty"` @@ -79,23 +23,6 @@ type Container struct { Ports []ContainerPort `json:"ports,omitempty"` } -// PodSpec is a pod -type PodSpec struct { - Containers []Container `json:"containers"` -} - -// Template is micro deployment template -type Template struct { - Metadata *Metadata `json:"metadata,omitempty"` - PodSpec *PodSpec `json:"spec,omitempty"` -} - -// LabelSelector is a label query over a set of resources -// NOTE: we do not support MatchExpressions at the moment -type LabelSelector struct { - MatchLabels map[string]string `json:"matchLabels,omitempty"` -} - // DeploymentSpec defines micro deployment spec type DeploymentSpec struct { Replicas int `json:"replicas,omitempty"` @@ -132,6 +59,93 @@ type DeploymentList struct { Items []Deployment `json:"items"` } -type PodList struct { - Items []Template `json:"items"` +// LabelSelector is a label query over a set of resources +// NOTE: we do not support MatchExpressions at the moment +type LabelSelector struct { + MatchLabels map[string]string `json:"matchLabels,omitempty"` +} + +type LoadBalancerIngress struct { + IP string `json:"ip,omitempty"` + Hostname string `json:"hostname,omitempty"` +} + +type LoadBalancerStatus struct { + Ingress []LoadBalancerIngress `json:"ingress,omitempty"` +} + +// Metadata defines api object metadata +type Metadata struct { + Name string `json:"name,omitempty"` + Namespace string `json:"namespace,omitempty"` + Version string `json:"version,omitempty"` + Labels map[string]string `json:"labels,omitempty"` + Annotations map[string]string `json:"annotations,omitempty"` +} + +// PodSpec is a pod +type PodSpec struct { + Containers []Container `json:"containers"` +} + +// PodList +type PodList struct { + Items []Pod `json:"items"` +} + +// Pod is the top level item for a pod +type Pod struct { + Metadata *Metadata `json:"metadata"` + Spec *PodSpec `json:"spec,omitempty"` + Status *PodStatus `json:"status"` +} + +// PodStatus +type PodStatus struct { + PodIP string `json:"podIP"` + Phase string `json:"phase"` +} + +// Resource is API resource +type Resource struct { + Name string + Kind string + Value interface{} +} + +// ServicePort configures service ports +type ServicePort struct { + Name string `json:"name,omitempty"` + Port int `json:"port"` + Protocol string `json:"protocol,omitempty"` +} + +// ServiceSpec provides service configuration +type ServiceSpec struct { + Type string `json:"type,omitempty"` + Selector map[string]string `json:"selector,omitempty"` + Ports []ServicePort `json:"ports,omitempty"` +} + +// ServiceStatus +type ServiceStatus struct { + LoadBalancer LoadBalancerStatus `json:"loadBalancer,omitempty"` +} + +// Service is kubernetes service +type Service struct { + Metadata *Metadata `json:"metadata"` + Spec *ServiceSpec `json:"spec,omitempty"` + Status *ServiceStatus `json:"status,omitempty"` +} + +// ServiceList +type ServiceList struct { + Items []Service `json:"items"` +} + +// Template is micro deployment template +type Template struct { + Metadata *Metadata `json:"metadata,omitempty"` + PodSpec *PodSpec `json:"spec,omitempty"` } diff --git a/util/kubernetes/client/watch.go b/util/kubernetes/client/watch.go new file mode 100644 index 00000000..a734db93 --- /dev/null +++ b/util/kubernetes/client/watch.go @@ -0,0 +1,122 @@ +package client + +import ( + "bufio" + "context" + "encoding/json" + "errors" + "net/http" + + "github.com/micro/go-micro/util/kubernetes/api" +) + +const ( + // EventTypes used + Added EventType = "ADDED" + Modified EventType = "MODIFIED" + Deleted EventType = "DELETED" + Error EventType = "ERROR" +) + +// Watcher is used to watch for events +type Watcher interface { + // A channel of events + Chan() <-chan Event + // Stop the watcher + Stop() +} + +// EventType defines the possible types of events. +type EventType string + +// Event represents a single event to a watched resource. +type Event struct { + Type EventType `json:"type"` + Object json.RawMessage `json:"object"` +} + +// bodyWatcher scans the body of a request for chunks +type bodyWatcher struct { + results chan Event + cancel func() + stop chan bool + res *http.Response + req *api.Request +} + +// Changes returns the results channel +func (wr *bodyWatcher) Chan() <-chan Event { + return wr.results +} + +// Stop cancels the request +func (wr *bodyWatcher) Stop() { + select { + case <-wr.stop: + return + default: + // cancel the request + wr.cancel() + // stop the watcher + close(wr.stop) + } +} + +func (wr *bodyWatcher) stream() { + reader := bufio.NewReader(wr.res.Body) + + go func() { + for { + // read a line + b, err := reader.ReadBytes('\n') + if err != nil { + return + } + + // send the event + var event Event + if err := json.Unmarshal(b, &event); err != nil { + continue + } + + select { + case <-wr.stop: + return + case wr.results <- event: + } + } + }() +} + +// newWatcher creates a k8s body watcher for +// a given http request +func newWatcher(req *api.Request) (Watcher, error) { + // set request context so we can cancel the request + ctx, cancel := context.WithCancel(context.Background()) + req.Context(ctx) + + // do the raw request + res, err := req.Raw() + if err != nil { + return nil, err + } + + if res.StatusCode < 200 || res.StatusCode >= 300 { + // close the response body + res.Body.Close() + // return an error + return nil, errors.New(res.Request.URL.String() + ": " + res.Status) + } + + wr := &bodyWatcher{ + results: make(chan Event), + stop: make(chan bool), + cancel: cancel, + req: req, + res: res, + } + + go wr.stream() + + return wr, nil +} From 943445270f5f7b2599719815cff1cd0f60dcc79a Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 28 Dec 2019 14:11:46 +0300 Subject: [PATCH 072/788] fix registry check issue (#1067) fix #1066 Signed-off-by: Vasiliy Tolstov --- server/rpc_server.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/server/rpc_server.go b/server/rpc_server.go index a7426059..7d1642ff 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -835,16 +835,19 @@ func (s *rpcServer) Start() error { s.RLock() registered := s.registered s.RUnlock() - if err = s.opts.RegisterCheck(s.opts.Context); err != nil && registered { + rerr := s.opts.RegisterCheck(s.opts.Context) + if rerr != nil && registered { log.Logf("Server %s-%s register check error: %s, deregister it", config.Name, config.Id, err) // deregister self in case of error if err := s.Deregister(); err != nil { log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err) } - } else { - if err := s.Register(); err != nil { - log.Logf("Server %s-%s register error: %s", config.Name, config.Id, err) - } + } else if rerr != nil && !registered { + log.Logf("Server %s-%s register check error: %s", config.Name, config.Id, err) + continue + } + if err := s.Register(); err != nil { + log.Logf("Server %s-%s register error: %s", config.Name, config.Id, err) } // wait for exit case ch = <-s.exit: @@ -854,9 +857,14 @@ func (s *rpcServer) Start() error { } } - // deregister self - if err := s.Deregister(); err != nil { - log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err) + s.RLock() + registered := s.registered + s.RUnlock() + if registered { + // deregister self + if err := s.Deregister(); err != nil { + log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err) + } } s.Lock() From c145f355ddb18a49c6b68deb9fb6e5c5c48a70ac Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 29 Dec 2019 21:07:55 +0000 Subject: [PATCH 073/788] Moving to gRPC by default (#1069) * Step 1 * Fix the test panics --- client/grpc/grpc.go | 36 ++-------- client/grpc/grpc_pool.go | 52 +++++++------- client/grpc/options.go | 5 +- client/options.go | 42 ++++------- client/options_test.go | 4 +- client/rpc_client.go | 2 +- config/cmd/cmd.go | 6 +- options.go | 2 - server/grpc/grpc.go | 2 +- service/grpc/README.md | 28 -------- service/grpc/README_cn.md | 25 ------- service/grpc/grpc.go | 148 +++++++++++++++++++++++++++----------- service/grpc/grpc_test.go | 62 +++------------- service/grpc/options.go | 6 +- service/mucp/mucp.go | 110 ++++++++++++++++++++++++++-- service/options.go | 2 +- 16 files changed, 273 insertions(+), 259 deletions(-) delete mode 100644 service/grpc/README.md delete mode 100644 service/grpc/README_cn.md diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 792563d7..e8e23a36 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -12,12 +12,10 @@ import ( "github.com/micro/go-micro/broker" "github.com/micro/go-micro/client" "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/codec" raw "github.com/micro/go-micro/codec/bytes" "github.com/micro/go-micro/errors" "github.com/micro/go-micro/metadata" "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/transport" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -623,45 +621,19 @@ func (g *grpcClient) getGrpcCallOptions() []grpc.CallOption { } func newClient(opts ...client.Option) client.Client { - options := client.Options{ - Codecs: make(map[string]codec.NewCodec), - CallOptions: client.CallOptions{ - Backoff: client.DefaultBackoff, - Retry: client.DefaultRetry, - Retries: client.DefaultRetries, - RequestTimeout: client.DefaultRequestTimeout, - DialTimeout: transport.DefaultDialTimeout, - }, - PoolSize: client.DefaultPoolSize, - PoolTTL: client.DefaultPoolTTL, - } + options := client.NewOptions() + // default content type for grpc + options.ContentType = "application/grpc+proto" for _, o := range opts { o(&options) } - if len(options.ContentType) == 0 { - options.ContentType = "application/grpc+proto" - } - - if options.Broker == nil { - options.Broker = broker.DefaultBroker - } - - if options.Registry == nil { - options.Registry = registry.DefaultRegistry - } - - if options.Selector == nil { - options.Selector = selector.NewSelector( - selector.Registry(options.Registry), - ) - } - rc := &grpcClient{ once: sync.Once{}, opts: options, } + rc.pool = newPool(options.PoolSize, options.PoolTTL, rc.poolMaxIdle(), rc.poolMaxStreams()) c := client.Client(rc) diff --git a/client/grpc/grpc_pool.go b/client/grpc/grpc_pool.go index ba076b2a..340aecce 100644 --- a/client/grpc/grpc_pool.go +++ b/client/grpc/grpc_pool.go @@ -10,11 +10,11 @@ import ( type pool struct { size int ttl int64 - + // max streams on a *poolConn maxStreams int // max idle conns - maxIdle int + maxIdle int sync.Mutex conns map[string]*streamsPool @@ -22,20 +22,20 @@ type pool struct { type streamsPool struct { // head of list - head *poolConn + head *poolConn // busy conns list - busy *poolConn + busy *poolConn // the siza of list - count int + count int // idle conn - idle int + idle int } type poolConn struct { // grpc conn *grpc.ClientConn - err error - addr string + err error + addr string // pool and streams pool pool *pool @@ -44,9 +44,9 @@ type poolConn struct { created int64 // list - pre *poolConn - next *poolConn - in bool + pre *poolConn + next *poolConn + in bool } func newPool(size int, ttl time.Duration, idle int, ms int) *pool { @@ -57,11 +57,11 @@ func newPool(size int, ttl time.Duration, idle int, ms int) *pool { idle = 0 } return &pool{ - size: size, - ttl: int64(ttl.Seconds()), + size: size, + ttl: int64(ttl.Seconds()), maxStreams: ms, - maxIdle: idle, - conns: make(map[string]*streamsPool), + maxIdle: idle, + conns: make(map[string]*streamsPool), } } @@ -70,7 +70,7 @@ func (p *pool) getConn(addr string, opts ...grpc.DialOption) (*poolConn, error) p.Lock() sp, ok := p.conns[addr] if !ok { - sp = &streamsPool{head:&poolConn{}, busy:&poolConn{}, count:0, idle:0} + sp = &streamsPool{head: &poolConn{}, busy: &poolConn{}, count: 0, idle: 0} p.conns[addr] = sp } // while we have conns check streams and then return one @@ -90,11 +90,11 @@ func (p *pool) getConn(addr string, opts ...grpc.DialOption) (*poolConn, error) } // a busy conn if conn.streams >= p.maxStreams { - next := conn.next - removeConn(conn) - addConnAfter(conn, sp.busy) - conn = next - continue + next := conn.next + removeConn(conn) + addConnAfter(conn, sp.busy) + conn = next + continue } // a idle conn if conn.streams == 0 { @@ -112,7 +112,7 @@ func (p *pool) getConn(addr string, opts ...grpc.DialOption) (*poolConn, error) if err != nil { return nil, err } - conn = &poolConn{cc,nil,addr,p,sp,1,time.Now().Unix(), nil, nil, false} + conn = &poolConn{cc, nil, addr, p, sp, 1, time.Now().Unix(), nil, nil, false} // add conn to streams pool p.Lock() @@ -148,7 +148,7 @@ func (p *pool) release(addr string, conn *poolConn, err error) { // 2. too many idle conn or // 3. conn is too old now := time.Now().Unix() - if err != nil || sp.idle >= p.maxIdle || now-created > p.ttl { + if err != nil || sp.idle >= p.maxIdle || now-created > p.ttl { removeConn(conn) p.Unlock() conn.ClientConn.Close() @@ -160,11 +160,11 @@ func (p *pool) release(addr string, conn *poolConn, err error) { return } -func (conn *poolConn)Close() { +func (conn *poolConn) Close() { conn.pool.release(conn.addr, conn, conn.err) } -func removeConn(conn *poolConn) { +func removeConn(conn *poolConn) { if conn.pre != nil { conn.pre.next = conn.next } @@ -178,7 +178,7 @@ func removeConn(conn *poolConn) { return } -func addConnAfter(conn *poolConn, after *poolConn) { +func addConnAfter(conn *poolConn, after *poolConn) { conn.next = after.next conn.pre = after if after.next != nil { diff --git a/client/grpc/options.go b/client/grpc/options.go index 8384c48a..146e42b0 100644 --- a/client/grpc/options.go +++ b/client/grpc/options.go @@ -28,8 +28,8 @@ var ( DefaultMaxSendMsgSize = 1024 * 1024 * 4 ) -type poolMaxStreams struct {} -type poolMaxIdle struct {} +type poolMaxStreams struct{} +type poolMaxIdle struct{} type codecsKey struct{} type tlsAuth struct{} type maxRecvMsgSizeKey struct{} @@ -129,4 +129,3 @@ func CallOptions(opts ...grpc.CallOption) client.CallOption { o.Context = context.WithValue(o.Context, grpcCallOptions{}, opts) } } - diff --git a/client/options.go b/client/options.go index 694a2fe9..50ec3951 100644 --- a/client/options.go +++ b/client/options.go @@ -85,9 +85,11 @@ type RequestOptions struct { Context context.Context } -func newOptions(options ...Option) Options { +func NewOptions(options ...Option) Options { opts := Options{ - Codecs: make(map[string]codec.NewCodec), + Context: context.Background(), + ContentType: DefaultContentType, + Codecs: make(map[string]codec.NewCodec), CallOptions: CallOptions{ Backoff: DefaultBackoff, Retry: DefaultRetry, @@ -95,40 +97,18 @@ func newOptions(options ...Option) Options { RequestTimeout: DefaultRequestTimeout, DialTimeout: transport.DefaultDialTimeout, }, - PoolSize: DefaultPoolSize, - PoolTTL: DefaultPoolTTL, + PoolSize: DefaultPoolSize, + PoolTTL: DefaultPoolTTL, + Broker: broker.DefaultBroker, + Selector: selector.DefaultSelector, + Registry: registry.DefaultRegistry, + Transport: transport.DefaultTransport, } for _, o := range options { o(&opts) } - if len(opts.ContentType) == 0 { - opts.ContentType = DefaultContentType - } - - if opts.Broker == nil { - opts.Broker = broker.DefaultBroker - } - - if opts.Registry == nil { - opts.Registry = registry.DefaultRegistry - } - - if opts.Selector == nil { - opts.Selector = selector.NewSelector( - selector.Registry(opts.Registry), - ) - } - - if opts.Transport == nil { - opts.Transport = transport.DefaultTransport - } - - if opts.Context == nil { - opts.Context = context.Background() - } - return opts } @@ -171,6 +151,8 @@ func PoolTTL(d time.Duration) Option { func Registry(r registry.Registry) Option { return func(o *Options) { o.Registry = r + // set in the selector + o.Selector.Init(selector.Registry(r)) } } diff --git a/client/options_test.go b/client/options_test.go index 9252994c..8d209e21 100644 --- a/client/options_test.go +++ b/client/options_test.go @@ -23,7 +23,7 @@ func TestCallOptions(t *testing.T) { var cl Client if d.set { - opts = newOptions( + opts = NewOptions( Retries(d.retries), RequestTimeout(d.rtimeout), DialTimeout(d.dtimeout), @@ -35,7 +35,7 @@ func TestCallOptions(t *testing.T) { DialTimeout(d.dtimeout), ) } else { - opts = newOptions() + opts = NewOptions() cl = NewClient() } diff --git a/client/rpc_client.go b/client/rpc_client.go index 4da6df45..34590f26 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -29,7 +29,7 @@ type rpcClient struct { } func newRpcClient(opt ...Option) Client { - opts := newOptions(opt...) + opts := NewOptions(opt...) p := pool.NewPool( pool.Size(opts.PoolSize), diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index ca02b6dd..47fb2776 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -202,7 +202,6 @@ var ( } DefaultClients = map[string]func(...client.Option) client.Client{ - "rpc": client.NewClient, "mucp": cmucp.NewClient, "grpc": cgrpc.NewClient, } @@ -224,7 +223,6 @@ var ( } DefaultServers = map[string]func(...server.Option) server.Server{ - "rpc": server.NewServer, "mucp": smucp.NewServer, "grpc": sgrpc.NewServer, } @@ -242,8 +240,8 @@ var ( } // used for default selection as the fall back - defaultClient = "rpc" - defaultServer = "rpc" + defaultClient = "grpc" + defaultServer = "grpc" defaultBroker = "http" defaultRegistry = "mdns" defaultSelector = "registry" diff --git a/options.go b/options.go index aa90c88f..673d1bfd 100644 --- a/options.go +++ b/options.go @@ -107,8 +107,6 @@ func Registry(r registry.Registry) Option { // Update Client and Server o.Client.Init(client.Registry(r)) o.Server.Init(server.Registry(r)) - // Update Selector - o.Client.Options().Selector.Init(selector.Registry(r)) // Update Broker o.Broker.Init(broker.Registry(r)) } diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 7d3d7426..11f48630 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -611,7 +611,7 @@ func (g *grpcServer) Register() error { g.Unlock() if !registered { - log.Logf("Registering node: %s", node.Id) + log.Logf("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) } // create registry options diff --git a/service/grpc/README.md b/service/grpc/README.md deleted file mode 100644 index ee333454..00000000 --- a/service/grpc/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# gRPC Service - -A simplified experience for building gRPC services. - -## Overview - -The **gRPC service** makes use of [go-micro](https://github.com/micro/go-micro) plugins to create a simpler framework for gRPC development. -It interoperates with standard gRPC services seamlessly, including the [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway). -The grpc service uses the go-micro broker, client and server plugins which make use of -[github.com/grpc/grpc-go](https://github.com/grpc/grpc-go) internally. -This means we ignore the go-micro codec and transport but provide a native grpc experience. - - - -## Features - -- **Service Discovery** - We make use of go-micro's registry and selector interfaces to provide pluggable discovery -and client side load balancing. There's no need to dial connections, we'll do everything beneath the covers for you. - -- **PubSub Messaging** - Where gRPC only provides you synchronous communication, the **gRPC service** uses the go-micro broker -to provide asynchronous messaging while using the gRPC protocol. - -- **Micro Ecosystem** - Make use of the existing micro ecosystem of tooling including our api gateway, web dashboard, -command line interface and much more. We're enhancing gRPC with a simplified experience using micro. - -## I18n - -### [中文](README_cn.md) diff --git a/service/grpc/README_cn.md b/service/grpc/README_cn.md deleted file mode 100644 index 99cdaf51..00000000 --- a/service/grpc/README_cn.md +++ /dev/null @@ -1,25 +0,0 @@ -# Micro gRPC [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![GoDoc](https://godoc.org/github.com/micro/go-micro/service/grpc?status.svg)](https://godoc.org/github.com/micro/go-micro/service/grpc) [![Travis CI](https://api.travis-ci.org/micro/go-micro/service/grpc.svg?branch=master)](https://travis-ci.org/micro/go-micro/service/grpc) [![Go Report Card](https://goreportcard.com/badge/micro/go-micro/service/grpc)](https://goreportcard.com/report/github.com/micro/go-micro/service/grpc) - -Micro gRPC是micro的gRPC框架插件,简化开发基于gRPC的服务。 - -## 概览 - -micro提供有基于Go的gRPC插件[go-micro](https://github.com/micro/go-micro),该插件可以在内部集成gPRC,并与之无缝交互,让开发gRPC更简单,并支持[grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway)。 - -micro有面向gRPC的[客户端](https://github.com/micro/go-plugins/tree/master/client)和[服务端](https://github.com/micro/go-plugins/tree/master/server)插件,go-grpc库调用客户端/服务端插件生成micro需要的gRPC代码,而客户端/服务端插件都是从[github.com/grpc/grpc-go](https://github.com/grpc/grpc-go)扩展而来,也即是说,我们不需要去知道go-micro是如何编解码或传输就可以使用原生的gRPC。 - -## 特性 - -- **服务发现** - go-micro的服务发现基于其[注册](https://github.com/micro/go-plugins/tree/master/registry)与[选择器](https://github.com/micro/go-micro/tree/master/selector)接口,实现了可插拔的服务发现与客户端侧的负载均衡,不需要拨号连接,micro已经把所有都封装好,大家只管用。 - -- **消息发布订阅** - 因为gRPC只提供同步通信机制,而**Go gRPC**使用go-micro的[broker代理](https://github.com/micro/go-micro/tree/master/broker)提供异步消息,broker也是基于gRPC协议。 - -- **Micro生态系统** - Micro生态系统包含工具链中,比如api网关、web管理控制台、CLI命令行接口等等。我们通过使用micro来增强gRPC框架的易用性。 - -## 示例 - -示例请查看[examples/greeter](https://github.com/micro/go-micro/service/grpc/tree/master/examples/greeter)。 - -## 开始使用 - -我们提供相关文档[docs](https://micro.mu/docs/go-grpc_cn.html),以便上手。 \ No newline at end of file diff --git a/service/grpc/grpc.go b/service/grpc/grpc.go index fac9024d..f6c0effa 100644 --- a/service/grpc/grpc.go +++ b/service/grpc/grpc.go @@ -1,58 +1,124 @@ package grpc import ( - "time" - - "github.com/micro/go-micro" - broker "github.com/micro/go-micro/broker" - client "github.com/micro/go-micro/client/grpc" - server "github.com/micro/go-micro/server/grpc" + "github.com/micro/go-micro/client" + gclient "github.com/micro/go-micro/client/grpc" + "github.com/micro/go-micro/server" + gserver "github.com/micro/go-micro/server/grpc" + "github.com/micro/go-micro/service" ) +type grpcService struct { + opts service.Options +} + +func newService(opts ...service.Option) service.Service { + options := service.NewOptions(opts...) + + return &grpcService{ + opts: options, + } +} + +func (s *grpcService) Name() string { + return s.opts.Server.Options().Name +} + +// Init initialises options. Additionally it calls cmd.Init +// which parses command line flags. cmd.Init is only called +// on first Init. +func (s *grpcService) Init(opts ...service.Option) { + // process options + for _, o := range opts { + o(&s.opts) + } +} + +func (s *grpcService) Options() service.Options { + return s.opts +} + +func (s *grpcService) Client() client.Client { + return s.opts.Client +} + +func (s *grpcService) Server() server.Server { + return s.opts.Server +} + +func (s *grpcService) String() string { + return "grpc" +} + +func (s *grpcService) Start() error { + for _, fn := range s.opts.BeforeStart { + if err := fn(); err != nil { + return err + } + } + + if err := s.opts.Server.Start(); err != nil { + return err + } + + for _, fn := range s.opts.AfterStart { + if err := fn(); err != nil { + return err + } + } + + return nil +} + +func (s *grpcService) Stop() error { + var gerr error + + for _, fn := range s.opts.BeforeStop { + if err := fn(); err != nil { + gerr = err + } + } + + if err := s.opts.Server.Stop(); err != nil { + return err + } + + for _, fn := range s.opts.AfterStop { + if err := fn(); err != nil { + gerr = err + } + } + + return gerr +} + +func (s *grpcService) Run() error { + if err := s.Start(); err != nil { + return err + } + + // wait on context cancel + <-s.opts.Context.Done() + + return s.Stop() +} + // NewService returns a grpc service compatible with go-micro.Service -func NewService(opts ...micro.Option) micro.Service { +func NewService(opts ...service.Option) service.Service { // our grpc client - c := client.NewClient() + c := gclient.NewClient() // our grpc server - s := server.NewServer() - // our grpc broker - b := broker.NewBroker() + s := gserver.NewServer() // create options with priority for our opts - options := []micro.Option{ - micro.Client(c), - micro.Server(s), - micro.Broker(b), + options := []service.Option{ + service.Client(c), + service.Server(s), } // append passed in opts options = append(options, opts...) // generate and return a service - return micro.NewService(options...) -} - -// NewFunction returns a grpc service compatible with go-micro.Function -func NewFunction(opts ...micro.Option) micro.Function { - // our grpc client - c := client.NewClient() - // our grpc server - s := server.NewServer() - // our grpc broker - b := broker.NewBroker() - - // create options with priority for our opts - options := []micro.Option{ - micro.Client(c), - micro.Server(s), - micro.Broker(b), - micro.RegisterTTL(time.Minute), - micro.RegisterInterval(time.Second * 30), - } - - // append passed in opts - options = append(options, opts...) - - // generate and return a function - return micro.NewFunction(options...) + return newService(options...) } diff --git a/service/grpc/grpc_test.go b/service/grpc/grpc_test.go index 5978c4fb..4ea738dd 100644 --- a/service/grpc/grpc_test.go +++ b/service/grpc/grpc_test.go @@ -7,8 +7,8 @@ import ( "testing" "time" - "github.com/micro/go-micro" "github.com/micro/go-micro/registry/memory" + "github.com/micro/go-micro/service" hello "github.com/micro/go-micro/service/grpc/proto" mls "github.com/micro/go-micro/util/tls" ) @@ -32,13 +32,13 @@ func TestGRPCService(t *testing.T) { // create GRPC service service := NewService( - micro.Name("test.service"), - micro.Registry(r), - micro.AfterStart(func() error { + service.Name("test.service"), + service.Registry(r), + service.AfterStart(func() error { wg.Done() return nil }), - micro.Context(ctx), + service.Context(ctx), ) // register test handler @@ -81,50 +81,6 @@ func TestGRPCService(t *testing.T) { } } -func TestGRPCFunction(t *testing.T) { - var wg sync.WaitGroup - wg.Add(1) - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - // create service - fn := NewFunction( - micro.Name("test.function"), - micro.Registry(memory.NewRegistry()), - micro.AfterStart(func() error { - wg.Done() - return nil - }), - micro.Context(ctx), - ) - - // register test handler - hello.RegisterTestHandler(fn.Server(), &testHandler{}) - - // run service - go fn.Run() - - // wait for start - wg.Wait() - - // create client - test := hello.NewTestService("test.function", fn.Client()) - - // call service - rsp, err := test.Call(context.Background(), &hello.Request{ - Name: "John", - }) - if err != nil { - t.Fatal(err) - } - - // check message - if rsp.Msg != "Hello John" { - t.Fatalf("unexpected response %s", rsp.Msg) - } -} - func TestGRPCTLSService(t *testing.T) { var wg sync.WaitGroup wg.Add(1) @@ -147,13 +103,13 @@ func TestGRPCTLSService(t *testing.T) { // create GRPC service service := NewService( - micro.Name("test.service"), - micro.Registry(r), - micro.AfterStart(func() error { + service.Name("test.service"), + service.Registry(r), + service.AfterStart(func() error { wg.Done() return nil }), - micro.Context(ctx), + service.Context(ctx), // set TLS config WithTLS(config), ) diff --git a/service/grpc/options.go b/service/grpc/options.go index cbbec81f..82dbb19f 100644 --- a/service/grpc/options.go +++ b/service/grpc/options.go @@ -3,14 +3,14 @@ package grpc import ( "crypto/tls" - "github.com/micro/go-micro" gc "github.com/micro/go-micro/client/grpc" gs "github.com/micro/go-micro/server/grpc" + "github.com/micro/go-micro/service" ) // WithTLS sets the TLS config for the service -func WithTLS(t *tls.Config) micro.Option { - return func(o *micro.Options) { +func WithTLS(t *tls.Config) service.Option { + return func(o *service.Options) { o.Client.Init( gc.AuthTLS(t), ) diff --git a/service/mucp/mucp.go b/service/mucp/mucp.go index 2ee454c4..9d9326d9 100644 --- a/service/mucp/mucp.go +++ b/service/mucp/mucp.go @@ -2,20 +2,116 @@ package mucp import ( - // TODO: change to go-micro/service - "github.com/micro/go-micro" + "github.com/micro/go-micro/client" + "github.com/micro/go-micro/server" cmucp "github.com/micro/go-micro/client/mucp" smucp "github.com/micro/go-micro/server/mucp" + "github.com/micro/go-micro/service" ) +type mucpService struct { + opts service.Options +} + +func newService(opts ...service.Option) service.Service { + options := service.NewOptions(opts...) + + return &mucpService{ + opts: options, + } +} + +func (s *mucpService) Name() string { + return s.opts.Server.Options().Name +} + +// Init initialises options. Additionally it calls cmd.Init +// which parses command line flags. cmd.Init is only called +// on first Init. +func (s *mucpService) Init(opts ...service.Option) { + // process options + for _, o := range opts { + o(&s.opts) + } +} + +func (s *mucpService) Options() service.Options { + return s.opts +} + +func (s *mucpService) Client() client.Client { + return s.opts.Client +} + +func (s *mucpService) Server() server.Server { + return s.opts.Server +} + +func (s *mucpService) String() string { + return "mucp" +} + +func (s *mucpService) Start() error { + for _, fn := range s.opts.BeforeStart { + if err := fn(); err != nil { + return err + } + } + + if err := s.opts.Server.Start(); err != nil { + return err + } + + for _, fn := range s.opts.AfterStart { + if err := fn(); err != nil { + return err + } + } + + return nil +} + +func (s *mucpService) Stop() error { + var gerr error + + for _, fn := range s.opts.BeforeStop { + if err := fn(); err != nil { + gerr = err + } + } + + if err := s.opts.Server.Stop(); err != nil { + return err + } + + for _, fn := range s.opts.AfterStop { + if err := fn(); err != nil { + gerr = err + } + } + + return gerr +} + +func (s *mucpService) Run() error { + if err := s.Start(); err != nil { + return err + } + + // wait on context cancel + <-s.opts.Context.Done() + + return s.Stop() +} + // NewService returns a new mucp service -func NewService(opts ...micro.Option) micro.Service { - options := []micro.Option{ - micro.Client(cmucp.NewClient()), - micro.Server(smucp.NewServer()), +func NewService(opts ...service.Option) service.Service { + options := []service.Option{ + service.Client(cmucp.NewClient()), + service.Server(smucp.NewServer()), } options = append(options, opts...) - return micro.NewService(options...) + return newService(options...) } diff --git a/service/options.go b/service/options.go index 9a077629..b3268786 100644 --- a/service/options.go +++ b/service/options.go @@ -31,7 +31,7 @@ type Options struct { type Option func(*Options) -func newOptions(opts ...Option) Options { +func NewOptions(opts ...Option) Options { opt := Options{ Broker: broker.DefaultBroker, Client: client.DefaultClient, From e0078bbcd51e5e15248f68a54ab7bed8522a925e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 30 Dec 2019 17:29:20 +0000 Subject: [PATCH 074/788] Remove use of config/cmd in api --- api/handler/http/http_test.go | 2 -- api/router/options.go | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/api/handler/http/http_test.go b/api/handler/http/http_test.go index 9812535c..7e737e06 100644 --- a/api/handler/http/http_test.go +++ b/api/handler/http/http_test.go @@ -9,14 +9,12 @@ import ( "github.com/micro/go-micro/api/handler" "github.com/micro/go-micro/api/router" regRouter "github.com/micro/go-micro/api/router/registry" - "github.com/micro/go-micro/config/cmd" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry/memory" ) func testHttp(t *testing.T, path, service, ns string) { r := memory.NewRegistry() - cmd.DefaultCmd = cmd.NewCmd(cmd.Registry(&r)) l, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { diff --git a/api/router/options.go b/api/router/options.go index 7285c74d..a48f3e39 100644 --- a/api/router/options.go +++ b/api/router/options.go @@ -3,7 +3,6 @@ package router import ( "github.com/micro/go-micro/api/resolver" "github.com/micro/go-micro/api/resolver/micro" - "github.com/micro/go-micro/config/cmd" "github.com/micro/go-micro/registry" ) @@ -19,7 +18,7 @@ type Option func(o *Options) func NewOptions(opts ...Option) Options { options := Options{ Handler: "meta", - Registry: *cmd.DefaultOptions().Registry, + Registry: registry.DefaultRegistry, } for _, o := range opts { From f40d4578d5bc0dc0a63bb4f255e3efd9e8671741 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 30 Dec 2019 17:29:45 +0000 Subject: [PATCH 075/788] go fmt --- config/cmd/cmd.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 47fb2776..381bde0c 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -28,8 +28,8 @@ import ( // registries "github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry/etcd" - "github.com/micro/go-micro/registry/mdns" kreg "github.com/micro/go-micro/registry/kubernetes" + "github.com/micro/go-micro/registry/mdns" rmem "github.com/micro/go-micro/registry/memory" regSrv "github.com/micro/go-micro/registry/service" @@ -207,10 +207,10 @@ var ( } DefaultRegistries = map[string]func(...registry.Option) registry.Registry{ - "service": regSrv.NewRegistry, - "etcd": etcd.NewRegistry, - "mdns": mdns.NewRegistry, - "memory": rmem.NewRegistry, + "service": regSrv.NewRegistry, + "etcd": etcd.NewRegistry, + "mdns": mdns.NewRegistry, + "memory": rmem.NewRegistry, "kubernetes": kreg.NewRegistry, } From d8fe030a4be710eee4f8491487624eb8fd4ad1d5 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 30 Dec 2019 17:29:57 +0000 Subject: [PATCH 076/788] go fmt --- service/mucp/mucp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/mucp/mucp.go b/service/mucp/mucp.go index 9d9326d9..64f70d51 100644 --- a/service/mucp/mucp.go +++ b/service/mucp/mucp.go @@ -3,8 +3,8 @@ package mucp import ( "github.com/micro/go-micro/client" - "github.com/micro/go-micro/server" cmucp "github.com/micro/go-micro/client/mucp" + "github.com/micro/go-micro/server" smucp "github.com/micro/go-micro/server/mucp" "github.com/micro/go-micro/service" ) From 04dfe4e867cc33a2c7c65fb8db67a9fbcba59d79 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 30 Dec 2019 17:39:02 +0000 Subject: [PATCH 077/788] fix breaking test --- api/handler/http/http_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/handler/http/http_test.go b/api/handler/http/http_test.go index 7e737e06..608b521f 100644 --- a/api/handler/http/http_test.go +++ b/api/handler/http/http_test.go @@ -55,6 +55,7 @@ func testHttp(t *testing.T, path, service, ns string) { rt := regRouter.NewRouter( router.WithHandler("http"), router.WithNamespace(ns), + router.WithRegistry(r), ) p := NewHandler(handler.WithRouter(rt)) From b6915f0898ab5f7f9ddb8edde4fef99d3a2bc6b5 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 30 Dec 2019 18:33:21 +0000 Subject: [PATCH 078/788] set grpc by default (#1070) --- defaults.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 defaults.go diff --git a/defaults.go b/defaults.go new file mode 100644 index 00000000..f1a81e7c --- /dev/null +++ b/defaults.go @@ -0,0 +1,17 @@ +package micro + +import ( + "github.com/micro/go-micro/client" + "github.com/micro/go-micro/server" + + // set defaults + gcli "github.com/micro/go-micro/client/grpc" + gsrv "github.com/micro/go-micro/server/grpc" +) + +func init() { + // default client + client.DefaultClient = gcli.NewClient() + // default server + server.DefaultServer = gsrv.NewServer() +} From 488dc317436795469998a3ad11c2e8d5d731b7dd Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 31 Dec 2019 12:07:52 +0000 Subject: [PATCH 079/788] log when starting the service --- service.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/service.go b/service.go index 69376e68..f6844e33 100644 --- a/service.go +++ b/service.go @@ -182,6 +182,8 @@ func (s *service) Run() error { defer profiler.Stop() } + log.Logf("Starting [service] %s", s.Name()) + if err := s.Start(); err != nil { return err } From 60ea537bbc28de24004c8d316d173343b6882b14 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 31 Dec 2019 13:37:29 +0000 Subject: [PATCH 080/788] upper case the metadata --- metadata/metadata.go | 22 ++++++++++++++++++++-- metadata/metadata_test.go | 20 ++++++++++---------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/metadata/metadata.go b/metadata/metadata.go index 74b0aa3c..3d6357ec 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -3,6 +3,7 @@ package metadata import ( "context" + "strings" ) type metaKey struct{} @@ -27,14 +28,32 @@ func Get(ctx context.Context, key string) (string, bool) { if !ok { return "", ok } + // attempt to get as is val, ok := md[key] + if ok { + return val, ok + } + + // attempt to get lower case + val, ok = md[strings.Title(key)] + return val, ok } // FromContext returns metadata from the given context func FromContext(ctx context.Context) (Metadata, bool) { md, ok := ctx.Value(metaKey{}).(Metadata) - return md, ok + if !ok { + return nil, ok + } + + // capitalise all values + newMD := make(map[string]string) + for k, v := range md { + newMD[strings.Title(k)] = v + } + + return newMD, ok } // NewContext creates a new context with the given metadata @@ -57,5 +76,4 @@ func MergeContext(ctx context.Context, patchMd Metadata, overwrite bool) context } } return context.WithValue(ctx, metaKey{}, cmd) - } diff --git a/metadata/metadata_test.go b/metadata/metadata_test.go index 3706d14c..764cc680 100644 --- a/metadata/metadata_test.go +++ b/metadata/metadata_test.go @@ -8,7 +8,7 @@ import ( func TestMetadataCopy(t *testing.T) { md := Metadata{ - "foo": "bar", + "Foo": "bar", "bar": "baz", } @@ -23,7 +23,7 @@ func TestMetadataCopy(t *testing.T) { func TestMetadataContext(t *testing.T) { md := Metadata{ - "foo": "bar", + "Foo": "bar", } ctx := NewContext(context.TODO(), md) @@ -33,8 +33,8 @@ func TestMetadataContext(t *testing.T) { t.Errorf("Unexpected error retrieving metadata, got %t", ok) } - if emd["foo"] != md["foo"] { - t.Errorf("Expected key: %s val: %s, got key: %s val: %s", "foo", md["foo"], "foo", emd["foo"]) + if emd["Foo"] != md["Foo"] { + t.Errorf("Expected key: %s val: %s, got key: %s val: %s", "Foo", md["Foo"], "Foo", emd["Foo"]) } if i := len(emd); i != 1 { @@ -56,20 +56,20 @@ func TestMergeContext(t *testing.T) { { name: "matching key, overwrite false", args: args{ - existing: Metadata{"foo": "bar", "sumo": "demo"}, - append: Metadata{"sumo": "demo2"}, + existing: Metadata{"Foo": "bar", "Sumo": "demo"}, + append: Metadata{"Sumo": "demo2"}, overwrite: false, }, - want: Metadata{"foo": "bar", "sumo": "demo"}, + want: Metadata{"Foo": "bar", "Sumo": "demo"}, }, { name: "matching key, overwrite true", args: args{ - existing: Metadata{"foo": "bar", "sumo": "demo"}, - append: Metadata{"sumo": "demo2"}, + existing: Metadata{"Foo": "bar", "Sumo": "demo"}, + append: Metadata{"Sumo": "demo2"}, overwrite: true, }, - want: Metadata{"foo": "bar", "sumo": "demo2"}, + want: Metadata{"Foo": "bar", "Sumo": "demo2"}, }, } for _, tt := range tests { From fe1e018e8ece47d98f8c96771ca6e26a4b6fade3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 31 Dec 2019 13:45:49 +0000 Subject: [PATCH 081/788] update wrapper test --- util/wrapper/wrapper_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/wrapper/wrapper_test.go b/util/wrapper/wrapper_test.go index de777cee..915eb668 100644 --- a/util/wrapper/wrapper_test.go +++ b/util/wrapper/wrapper_test.go @@ -16,16 +16,16 @@ func TestWrapper(t *testing.T) { { existing: metadata.Metadata{}, headers: metadata.Metadata{ - "foo": "bar", + "Foo": "bar", }, overwrite: true, }, { existing: metadata.Metadata{ - "foo": "bar", + "Foo": "bar", }, headers: metadata.Metadata{ - "foo": "baz", + "Foo": "baz", }, overwrite: false, }, From fa01ff66041ebdea711ba9881cf0e50e21a7df07 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 31 Dec 2019 13:53:48 +0000 Subject: [PATCH 082/788] update ctx test --- util/ctx/ctx_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/ctx/ctx_test.go b/util/ctx/ctx_test.go index 440baea1..3df4acc7 100644 --- a/util/ctx/ctx_test.go +++ b/util/ctx/ctx_test.go @@ -15,13 +15,13 @@ func TestRequestToContext(t *testing.T) { { &http.Request{ Header: http.Header{ - "foo1": []string{"bar"}, - "foo2": []string{"bar", "baz"}, + "Foo1": []string{"bar"}, + "Foo2": []string{"bar", "baz"}, }, }, metadata.Metadata{ - "foo1": "bar", - "foo2": "bar,baz", + "Foo1": "bar", + "Foo2": "bar,baz", }, }, } From 45c986c5f13bc71d9d9f94654c61f8fedac82b64 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 31 Dec 2019 21:36:22 +0000 Subject: [PATCH 083/788] don't marshal frame values --- client/rpc_codec.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/client/rpc_codec.go b/client/rpc_codec.go index a71f6a11..c3729be2 100644 --- a/client/rpc_codec.go +++ b/client/rpc_codec.go @@ -186,32 +186,30 @@ func (c *rpcCodec) Write(m *codec.Message, body interface{}) error { // if body is bytes Frame don't encode if body != nil { - b, ok := body.(*raw.Frame) - if ok { + if b, ok := body.(*raw.Frame); ok { // set body m.Body = b.Data - body = nil + } else { + // write to codec + if err := c.codec.Write(m, body); err != nil { + return errors.InternalServerError("go.micro.client.codec", err.Error()) + } + // set body + m.Body = c.buf.wbuf.Bytes() } } - if len(m.Body) == 0 { - // write to codec - if err := c.codec.Write(m, body); err != nil { - return errors.InternalServerError("go.micro.client.codec", err.Error()) - } - // set body - m.Body = c.buf.wbuf.Bytes() - } - // create new transport message msg := transport.Message{ Header: m.Header, Body: m.Body, } + // send the request if err := c.client.Send(&msg); err != nil { return errors.InternalServerError("go.micro.client.transport", err.Error()) } + return nil } From 6358b9277d9ada7bb2f819636b43855842dc5439 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 31 Dec 2019 22:58:14 +0000 Subject: [PATCH 084/788] don't write anything if theres no data --- codec/grpc/grpc.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/codec/grpc/grpc.go b/codec/grpc/grpc.go index 86630772..f044b55f 100644 --- a/codec/grpc/grpc.go +++ b/codec/grpc/grpc.go @@ -126,6 +126,10 @@ func (c *Codec) Write(m *codec.Message, b interface{}) error { return err } + if len(buf) == 0 { + return nil + } + return encode(0, buf, c.Conn) } From e697912ee5663c893764bfa0a8783d301dfb64b3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 1 Jan 2020 21:56:29 +0000 Subject: [PATCH 085/788] don't panic on nil --- server/grpc/codec.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/grpc/codec.go b/server/grpc/codec.go index 356f8e81..a1d4a659 100644 --- a/server/grpc/codec.go +++ b/server/grpc/codec.go @@ -64,6 +64,9 @@ func (w wrapCodec) Unmarshal(data []byte, v interface{}) error { b.Data = data return nil } + if v == nil { + return nil + } return w.Codec.Unmarshal(data, v) } From 225b17559b2995c60db082348c228038e802fb08 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 2 Jan 2020 18:23:43 +0000 Subject: [PATCH 086/788] fix log streaming --- server/grpc/codec.go | 2 +- server/grpc/grpc.go | 3 +++ server/rpc_router.go | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/server/grpc/codec.go b/server/grpc/codec.go index a1d4a659..8de1b8bf 100644 --- a/server/grpc/codec.go +++ b/server/grpc/codec.go @@ -180,5 +180,5 @@ func (g *grpcCodec) Close() error { } func (g *grpcCodec) String() string { - return g.c.Name() + return "grpc" } diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 11f48630..1113f842 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -248,6 +248,7 @@ func (g *grpcServer) handler(srv interface{}, stream grpc.ServerStream) error { contentType: ct, method: fmt.Sprintf("%s.%s", serviceName, methodName), codec: codec, + stream: true, } response := &rpcResponse{ @@ -385,9 +386,11 @@ func (g *grpcServer) processRequest(stream grpc.ServerStream, service *service, } return status.New(statusCode, statusDesc).Err() } + if err := stream.SendMsg(replyv.Interface()); err != nil { return err } + return status.New(statusCode, statusDesc).Err() } } diff --git a/server/rpc_router.go b/server/rpc_router.go index d607f5f8..b67417bf 100644 --- a/server/rpc_router.go +++ b/server/rpc_router.go @@ -346,7 +346,9 @@ func (router *router) readRequest(r Request) (service *service, mtype *methodTyp } // is it a streaming request? then we don't read the body if mtype.stream { - cc.ReadBody(nil) + if cc.(codec.Codec).String() != "grpc" { + cc.ReadBody(nil) + } return } From fe9c68238fae8000f1fcfaa448eed40b9893a9f6 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Thu, 2 Jan 2020 12:42:46 -0800 Subject: [PATCH 087/788] runtime/kubernetes: remove unused name variable (#1078) --- runtime/kubernetes/kubernetes.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 33cebb1d..d7dd472f 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -261,9 +261,6 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er name = name + "-" + s.Version } - // format as we'll format in the deployment - name = client.Format(name) - // create new kubernetes micro service service := newService(s, options) From 9cecf2e0979723a8d8e0bc2fa5eb4569e9500021 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 2 Jan 2020 21:11:25 +0000 Subject: [PATCH 088/788] make grpc proxy streaming work --- proxy/mucp/mucp.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index 0b059da3..388aba91 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -398,7 +398,7 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server // set address if available via routes or specific endpoint if len(routes) > 0 { - addresses := toNodes(routes) + addresses = toNodes(routes) opts = append(opts, client.WithAddress(addresses...)) } @@ -489,6 +489,25 @@ func (p *Proxy) serveRequest(ctx context.Context, link client.Client, service, e } defer stream.Close() + // if we receive a grpc stream we have to refire the initial request + if c, ok := req.Codec().(codec.Codec); ok && c.String() == "grpc" { + // get the header from client + hdr := req.Header() + msg := &codec.Message{ + Type: codec.Request, + Header: hdr, + Body: body, + } + + // write the raw request + err = stream.Request().Codec().Write(msg, nil) + if err == io.EOF { + return nil + } else if err != nil { + return err + } + } + // create client request read loop if streaming go readLoop(req, stream) From 31362bc3318dcf893a944d010f48858b6607e02a Mon Sep 17 00:00:00 2001 From: Shu xian Date: Fri, 3 Jan 2020 21:31:47 +0800 Subject: [PATCH 089/788] prevent resource leak (#1080) --- sync/task/broker/broker.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sync/task/broker/broker.go b/sync/task/broker/broker.go index f643fb2d..45c20b3e 100644 --- a/sync/task/broker/broker.go +++ b/sync/task/broker/broker.go @@ -99,14 +99,22 @@ func (t *Task) Run(c task.Command) error { // subscribe for the pool size for i := 0; i < t.Options.Pool; i++ { - // subscribe to work - subWork, err := t.Broker.Subscribe(topic, workFn, broker.Queue(fmt.Sprintf("work.%d", i))) + err := func() error { + // subscribe to work + subWork, err := t.Broker.Subscribe(topic, workFn, broker.Queue(fmt.Sprintf("work.%d", i))) + if err != nil { + return err + } + + // unsubscribe on completion + defer subWork.Unsubscribe() + + return nil + }() + if err != nil { return err } - - // unsubscribe on completion - defer subWork.Unsubscribe() } // subscribe to all status messages From 7098e59b5c74f1f138dcaae137f3f45a8c9c292a Mon Sep 17 00:00:00 2001 From: Eagle Wu Date: Sat, 4 Jan 2020 01:24:20 +0800 Subject: [PATCH 090/788] remove ignore error in method publish (#1075) --- broker/http_broker.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/broker/http_broker.go b/broker/http_broker.go index 53dd48f1..41d80f5d 100644 --- a/broker/http_broker.go +++ b/broker/http_broker.go @@ -533,8 +533,7 @@ func (h *httpBroker) Publish(topic string, msg *Message, opts ...PublishOption) s, err := h.r.GetService(serviceName) if err != nil { h.RUnlock() - // ignore error - return nil + return err } h.RUnlock() From 1af82df8b1b13da4eca9ea77ee873646815de4de Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 3 Jan 2020 19:46:14 +0000 Subject: [PATCH 091/788] Check link is grpc --- proxy/mucp/mucp.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index 388aba91..f8baaf91 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -490,7 +490,8 @@ func (p *Proxy) serveRequest(ctx context.Context, link client.Client, service, e defer stream.Close() // if we receive a grpc stream we have to refire the initial request - if c, ok := req.Codec().(codec.Codec); ok && c.String() == "grpc" { + c, ok := req.Codec().(codec.Codec) + if ok && c.String() == "grpc" && link.String() == "grpc" { // get the header from client hdr := req.Header() msg := &codec.Message{ From df9055f69cbd8a08e3388d03150d92205a085c23 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 3 Jan 2020 20:43:53 +0000 Subject: [PATCH 092/788] continue to process messages even after the connection is closed --- tunnel/session.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tunnel/session.go b/tunnel/session.go index 84153541..ebf01ded 100644 --- a/tunnel/session.go +++ b/tunnel/session.go @@ -173,6 +173,25 @@ func (s *session) waitFor(msgType string, timeout time.Duration) (*message, erro case <-after(timeout): return nil, ErrReadTimeout case <-s.closed: + // check pending message queue + select { + case msg := <-s.recv: + // there may be no message type + if len(msgType) == 0 { + return msg, nil + } + + // ignore what we don't want + if msg.typ != msgType { + log.Debugf("Tunnel received non %s message in waiting for %s", msg.typ, msgType) + continue + } + + // got the message + return msg, nil + default: + // non blocking + } return nil, io.EOF } } From be6e8a7c7827bd99cbf376228343df5ed4bf7a01 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 6 Jan 2020 17:44:32 +0000 Subject: [PATCH 093/788] add store to defaults (#1086) --- config/cmd/cmd.go | 28 ++++++++++++++++++++++++++++ config/cmd/options.go | 3 +++ store/cockroach/cockroach.go | 2 +- store/cockroach/cockroach_test.go | 2 +- store/store.go | 20 ++++++++++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 381bde0c..96973c2f 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -49,6 +49,14 @@ import ( // runtimes "github.com/micro/go-micro/runtime" "github.com/micro/go-micro/runtime/kubernetes" + + // stores + "github.com/micro/go-micro/store" + cfStore "github.com/micro/go-micro/store/cloudflare" + ckStore "github.com/micro/go-micro/store/cockroach" + etcdStore "github.com/micro/go-micro/store/etcd" + memStore "github.com/micro/go-micro/store/memory" + svcStore "github.com/micro/go-micro/store/service" ) type Cmd interface { @@ -239,6 +247,14 @@ var ( "kubernetes": kubernetes.NewRuntime, } + DefaultStores = map[string]func(...store.Option) store.Store{ + "memory": memStore.NewStore, + "cockroach": ckStore.NewStore, + "etcd": etcdStore.NewStore, + "cloudflare": cfStore.NewStore, + "service": svcStore.NewStore, + } + // used for default selection as the fall back defaultClient = "grpc" defaultServer = "grpc" @@ -267,6 +283,7 @@ func newCmd(opts ...Option) Cmd { Selector: &selector.DefaultSelector, Transport: &transport.DefaultTransport, Runtime: &runtime.DefaultRuntime, + Store: &store.DefaultStore, Brokers: DefaultBrokers, Clients: DefaultClients, @@ -275,6 +292,7 @@ func newCmd(opts ...Option) Cmd { Servers: DefaultServers, Transports: DefaultTransports, Runtimes: DefaultRuntimes, + Stores: DefaultStores, } for _, o := range opts { @@ -315,6 +333,16 @@ func (c *cmd) Before(ctx *cli.Context) error { var serverOpts []server.Option var clientOpts []client.Option + // Set the runtime + if name := ctx.String("store"); len(name) > 0 { + s, ok := c.opts.Stores[name] + if !ok { + return fmt.Errorf("Unsupported store: %s", name) + } + + *c.opts.Store = s() + } + // Set the runtime if name := ctx.String("runtime"); len(name) > 0 { r, ok := c.opts.Runtimes[name] diff --git a/config/cmd/options.go b/config/cmd/options.go index be831fe1..b6bf0ede 100644 --- a/config/cmd/options.go +++ b/config/cmd/options.go @@ -9,6 +9,7 @@ import ( "github.com/micro/go-micro/registry" "github.com/micro/go-micro/runtime" "github.com/micro/go-micro/server" + "github.com/micro/go-micro/store" "github.com/micro/go-micro/transport" ) @@ -26,6 +27,7 @@ type Options struct { Client *client.Client Server *server.Server Runtime *runtime.Runtime + Store *store.Store Brokers map[string]func(...broker.Option) broker.Broker Clients map[string]func(...client.Option) client.Client @@ -34,6 +36,7 @@ type Options struct { Servers map[string]func(...server.Option) server.Server Transports map[string]func(...transport.Option) transport.Transport Runtimes map[string]func(...runtime.Option) runtime.Runtime + Stores map[string]func(...store.Option) store.Store // Other options for implementations of the interface // can be stored in a context diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 31ec7d0c..7979d501 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -173,7 +173,7 @@ func (s *sqlStore) initDB() { } // New returns a new micro Store backed by sql -func New(opts ...store.Option) store.Store { +func NewStore(opts ...store.Option) store.Store { var options store.Options for _, o := range opts { o(&options) diff --git a/store/cockroach/cockroach_test.go b/store/cockroach/cockroach_test.go index 45948634..08f20135 100644 --- a/store/cockroach/cockroach_test.go +++ b/store/cockroach/cockroach_test.go @@ -27,7 +27,7 @@ func TestSQL(t *testing.T) { } db.Close() - sqlStore := New( + sqlStore := NewStore( store.Namespace("testsql"), store.Nodes(connection), ) diff --git a/store/store.go b/store/store.go index 9d265500..9fb97328 100644 --- a/store/store.go +++ b/store/store.go @@ -9,6 +9,8 @@ import ( var ( // ErrNotFound is returned when a Read key doesn't exist ErrNotFound = errors.New("not found") + // Default store + DefaultStore Store = new(noop) ) // Store is a data storage interface @@ -29,3 +31,21 @@ type Record struct { Value []byte Expiry time.Duration } + +type noop struct{} + +func (n *noop) List() ([]*Record, error) { + return nil, nil +} + +func (n *noop) Read(key ...string) ([]*Record, error) { + return nil, nil +} + +func (n *noop) Write(rec ...*Record) error { + return nil +} + +func (n *noop) Delete(key ...string) error { + return nil +} From 1892bd05a55db9f9d229c48adb1a0688b70e298f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 6 Jan 2020 22:22:36 +0000 Subject: [PATCH 094/788] only add api endpoint metadata if it exists (#1087) --- api/api.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/api/api.go b/api/api.go index 75ffe001..160c2dfd 100644 --- a/api/api.go +++ b/api/api.go @@ -57,14 +57,25 @@ func Encode(e *Endpoint) map[string]string { return nil } - return map[string]string{ - "endpoint": e.Name, - "description": e.Description, - "method": strings.Join(e.Method, ","), - "path": strings.Join(e.Path, ","), - "host": strings.Join(e.Host, ","), - "handler": e.Handler, + // endpoint map + ep := make(map[string]string) + + // set vals only if they exist + set := func(k, v string) { + if len(v) == 0 { + return + } + ep[k] = v } + + set("endpoint", e.Name) + set("description", e.Description) + set("handler", e.Handler) + set("method", strings.Join(e.Method, ",")) + set("path", strings.Join(e.Path, ",")) + set("host", strings.Join(e.Host, ",")) + + return ep } // Decode decodes endpoint metadata into an endpoint From 0b8ff3a8bb94c418afa18edf03ac999db097c583 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 7 Jan 2020 18:37:34 +0000 Subject: [PATCH 095/788] fix grpc json streaming by setting content sub type (#1089) --- client/grpc/codec.go | 4 +++- client/grpc/grpc.go | 2 +- server/grpc/codec.go | 4 +++- server/grpc/grpc.go | 4 ++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/client/grpc/codec.go b/client/grpc/codec.go index 44f16d54..70ef0b99 100644 --- a/client/grpc/codec.go +++ b/client/grpc/codec.go @@ -116,10 +116,12 @@ func (jsonCodec) Marshal(v interface{}) ([]byte, error) { } func (jsonCodec) Unmarshal(data []byte, v interface{}) error { + if len(data) == 0 { + return nil + } if pb, ok := v.(proto.Message); ok { return jsonpb.Unmarshal(b.NewReader(data), pb) } - return json.Unmarshal(data, v) } diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index e8e23a36..3d158ea0 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -207,7 +207,7 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client ServerStreams: true, } - grpcCallOptions := []grpc.CallOption{} + grpcCallOptions := []grpc.CallOption{grpc.CallContentSubtype(cf.Name())} if opts := g.getGrpcCallOptions(); opts != nil { grpcCallOptions = append(grpcCallOptions, opts...) } diff --git a/server/grpc/codec.go b/server/grpc/codec.go index 8de1b8bf..dff9f600 100644 --- a/server/grpc/codec.go +++ b/server/grpc/codec.go @@ -93,10 +93,12 @@ func (jsonCodec) Marshal(v interface{}) ([]byte, error) { } func (jsonCodec) Unmarshal(data []byte, v interface{}) error { + if len(data) == 0 { + return nil + } if pb, ok := v.(proto.Message); ok { return jsonpb.Unmarshal(b.NewReader(data), pb) } - return json.Unmarshal(data, v) } diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 1113f842..874f7273 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -203,9 +203,13 @@ func (g *grpcServer) handler(srv interface{}, stream grpc.ServerStream) error { // get content type ct := defaultContentType + if ctype, ok := md["x-content-type"]; ok { ct = ctype } + if ctype, ok := md["content-type"]; ok { + ct = ctype + } delete(md, "x-content-type") delete(md, "timeout") From 048065fe96b7af3b8230a2e7ca859ce390c9f9da Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Jan 2020 12:11:31 +0000 Subject: [PATCH 096/788] support ability to set store, address and namespace via flags and env vars (#1092) --- config/cmd/cmd.go | 27 ++++++++ store/cloudflare/cloudflare.go | 12 +++- store/cloudflare/options.go | 9 +-- store/cockroach/cockroach.go | 110 +++++++++++++++++++++------------ store/etcd/etcd.go | 7 +++ store/memory/memory.go | 7 +++ store/mock/store.go | 4 ++ store/service/service.go | 11 ++++ store/store.go | 6 ++ 9 files changed, 143 insertions(+), 50 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 96973c2f..c2dbd9a5 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -190,6 +190,21 @@ var ( EnvVar: "MICRO_SELECTOR", Usage: "Selector used to pick nodes for querying", }, + cli.StringFlag{ + Name: "store", + EnvVar: "MICRO_STORE", + Usage: "Store used for key-value storage", + }, + cli.StringFlag{ + Name: "store_address", + EnvVar: "MICRO_STORE_ADDRESS", + Usage: "Comma-separated list of store addresses", + }, + cli.StringFlag{ + Name: "store_namespace", + EnvVar: "MICRO_STORE_NAMESPACE", + Usage: "Namespace for store data", + }, cli.StringFlag{ Name: "transport", EnvVar: "MICRO_TRANSPORT", @@ -462,6 +477,18 @@ func (c *cmd) Before(ctx *cli.Context) error { } } + if len(ctx.String("store_address")) > 0 { + if err := (*c.opts.Store).Init(store.Nodes(strings.Split(ctx.String("store_address"), ",")...)); err != nil { + log.Fatalf("Error configuring store: %v", err) + } + } + + if len(ctx.String("store_namespace")) > 0 { + if err := (*c.opts.Store).Init(store.Namespace(ctx.String("store_address"))); err != nil { + log.Fatalf("Error configuring store: %v", err) + } + } + if len(ctx.String("server_name")) > 0 { serverOpts = append(serverOpts, server.Name(ctx.String("server_name"))) } diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index 20ce2bac..03e32298 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -96,6 +96,16 @@ func validateOptions(account, token, namespace string) { } } +func (w *workersKV) Init(opts ...store.Option) error { + for _, o := range opts { + o(&w.options) + } + if len(w.options.Namespace) > 0 { + w.namespace = w.options.Namespace + } + return nil +} + // In the cloudflare workers KV implemention, List() doesn't guarantee // anything as the workers API is eventually consistent. func (w *workersKV) List() ([]*store.Record, error) { @@ -308,7 +318,7 @@ func NewStore(opts ...store.Option) store.Store { } if len(namespace) == 0 { - namespace = getNamespace(options.Context) + namespace = options.Namespace } // validate options are not blank or log.Fatal diff --git a/store/cloudflare/options.go b/store/cloudflare/options.go index d9670ff4..be6bf6f6 100644 --- a/store/cloudflare/options.go +++ b/store/cloudflare/options.go @@ -25,10 +25,6 @@ func getAccount(ctx context.Context) string { return getOption(ctx, "CF_ACCOUNT_ID") } -func getNamespace(ctx context.Context) string { - return getOption(ctx, "KV_NAMESPACE_ID") -} - // Token sets the cloudflare api token func Token(t string) store.Option { return func(o *store.Options) { @@ -52,9 +48,6 @@ func Account(id string) store.Option { // Namespace sets the KV namespace func Namespace(ns string) store.Option { return func(o *store.Options) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, "KV_NAMESPACE_ID", ns) + o.Namespace = ns } } diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 7979d501..d321dc06 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -30,6 +30,14 @@ type sqlStore struct { options store.Options } +func (s *sqlStore) Init(opts ...store.Option) error { + for _, o := range opts { + o(&s.options) + } + // reconfigure + return s.configure() +} + // List all the known records func (s *sqlStore) List() ([]*store.Record, error) { rows, err := s.db.Query(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s;", s.database, s.table)) @@ -147,16 +155,16 @@ func (s *sqlStore) Delete(keys ...string) error { return nil } -func (s *sqlStore) initDB() { +func (s *sqlStore) initDB() error { // Create the namespace's database _, err := s.db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s ;", s.database)) if err != nil { - log.Fatal(err) + return err } _, err = s.db.Exec(fmt.Sprintf("SET DATABASE = %s ;", s.database)) if err != nil { - log.Fatal(errors.Wrap(err, "Couldn't set database")) + return errors.Wrap(err, "Couldn't set database") } // Create a table for the namespace's prefix @@ -168,8 +176,60 @@ func (s *sqlStore) initDB() { CONSTRAINT %s_pkey PRIMARY KEY (key) );`, s.table, s.table)) if err != nil { - log.Fatal(errors.Wrap(err, "Couldn't create table")) + return errors.Wrap(err, "Couldn't create table") } + + return nil +} + +func (s *sqlStore) configure() error { + nodes := s.options.Nodes + if len(nodes) == 0 { + nodes = []string{"localhost:26257"} + } + + namespace := s.options.Namespace + if len(namespace) == 0 { + namespace = DefaultNamespace + } + + prefix := s.options.Prefix + if len(prefix) == 0 { + prefix = DefaultPrefix + } + + for _, r := range namespace { + if !unicode.IsLetter(r) { + return errors.New("store.namespace must only contain letters") + } + } + + source := nodes[0] + if !strings.Contains(source, " ") { + source = fmt.Sprintf("host=%s", source) + } + + // create source from first node + db, err := sql.Open("postgres", source) + if err != nil { + return err + } + + if err := db.Ping(); err != nil { + return err + } + + if s.db != nil { + s.db.Close() + } + + // save the values + s.db = db + s.database = namespace + s.table = prefix + + // initialise the database + return s.initDB() } // New returns a new micro Store backed by sql @@ -179,46 +239,14 @@ func NewStore(opts ...store.Option) store.Store { o(&options) } - nodes := options.Nodes - if len(nodes) == 0 { - nodes = []string{"localhost:26257"} - } + // new store + s := new(sqlStore) - namespace := options.Namespace - if len(namespace) == 0 { - namespace = DefaultNamespace - } - - prefix := options.Prefix - if len(prefix) == 0 { - prefix = DefaultPrefix - } - - for _, r := range namespace { - if !unicode.IsLetter(r) { - log.Fatal("store.namespace must only contain letters") - } - } - - source := nodes[0] - if !strings.Contains(source, " ") { - source = fmt.Sprintf("host=%s", source) - } - // create source from first node - db, err := sql.Open("postgres", source) - if err != nil { + // configure the store + if err := s.configure(); err != nil { log.Fatal(err) } - if err := db.Ping(); err != nil { - log.Fatal(err) - } - - s := &sqlStore{ - db: db, - database: namespace, - table: prefix, - } - s.initDB() + // return store return s } diff --git a/store/etcd/etcd.go b/store/etcd/etcd.go index c9bc4047..5eac1e50 100644 --- a/store/etcd/etcd.go +++ b/store/etcd/etcd.go @@ -15,6 +15,13 @@ type ekv struct { kv client.KV } +func (e *ekv) Init(opts ...store.Option) error { + for _, o := range opts { + o(&e.options) + } + return nil +} + func (e *ekv) Read(keys ...string) ([]*store.Record, error) { //nolint:prealloc var values []*mvccpb.KeyValue diff --git a/store/memory/memory.go b/store/memory/memory.go index 78e85e82..5715f41e 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -20,6 +20,13 @@ type memoryRecord struct { c time.Time } +func (m *memoryStore) Init(opts ...store.Option) error { + for _, o := range opts { + o(&m.options) + } + return nil +} + func (m *memoryStore) List() ([]*store.Record, error) { m.RLock() defer m.RUnlock() diff --git a/store/mock/store.go b/store/mock/store.go index fe296b02..c9908400 100644 --- a/store/mock/store.go +++ b/store/mock/store.go @@ -10,6 +10,10 @@ type Store struct { mock.Mock } +func (_m *Store) Init(...store.Option) error { + return nil +} + // Delete provides a mock function with given fields: key func (_m *Store) Delete(key ...string) error { _va := make([]interface{}, len(key)) diff --git a/store/service/service.go b/store/service/service.go index 37a7a030..e364f794 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -28,6 +28,17 @@ type serviceStore struct { Client pb.StoreService } +func (s *serviceStore) Init(opts ...store.Option) error { + for _, o := range opts { + o(&s.options) + } + s.Namespace = s.options.Namespace + s.Prefix = s.options.Prefix + s.Nodes = s.options.Nodes + + return nil +} + func (s *serviceStore) Context() context.Context { ctx := context.Background() diff --git a/store/store.go b/store/store.go index 9fb97328..d8c44c62 100644 --- a/store/store.go +++ b/store/store.go @@ -15,6 +15,8 @@ var ( // Store is a data storage interface type Store interface { + // Initialise store options + Init(...Option) error // List all the known records List() ([]*Record, error) // Read records with keys @@ -34,6 +36,10 @@ type Record struct { type noop struct{} +func (n *noop) Init(...Option) error { + return nil +} + func (n *noop) List() ([]*Record, error) { return nil, nil } From 59fccb82ec27df6d3a34f808e9fabaacd65cf6a7 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Wed, 8 Jan 2020 13:18:11 +0000 Subject: [PATCH 097/788] Updated comments. Tiny cleanup changes. (#1093) --- network/default.go | 67 +++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/network/default.go b/network/default.go index e8489f34..7e78b992 100644 --- a/network/default.go +++ b/network/default.go @@ -6,7 +6,6 @@ import ( "hash/fnv" "io" "math" - "math/rand" "sort" "sync" "time" @@ -54,16 +53,16 @@ type network struct { options Options // rtr is network router router router.Router - // prx is network proxy + // proxy is network proxy proxy proxy.Proxy - // tun is network tunnel + // tunnel is network tunnel tunnel tunnel.Tunnel // server is network server server server.Server // client is network client client client.Client - // tunClient is a map of tunnel clients keyed over tunnel channel names + // tunClient is a map of tunnel channel clients tunClient map[string]transport.Client // peerLinks is a map of links for each peer peerLinks map[string]tunnel.Link @@ -89,9 +88,9 @@ type message struct { // newNetwork returns a new network node func newNetwork(opts ...Option) Network { - rand.Seed(time.Now().UnixNano()) + // create default options options := DefaultOptions() - + // initialize network options for _, o := range opts { o(&options) } @@ -180,11 +179,12 @@ func newNetwork(opts ...Option) Network { func (n *network) Init(opts ...Option) error { n.Lock() + defer n.Unlock() + // TODO: maybe only allow reinit of certain opts for _, o := range opts { o(&n.options) } - n.Unlock() return nil } @@ -192,14 +192,21 @@ func (n *network) Init(opts ...Option) error { // Options returns network options func (n *network) Options() Options { n.RLock() + defer n.RUnlock() + options := n.options - n.RUnlock() + return options } // Name returns network name func (n *network) Name() string { - return n.options.Name + n.RLock() + defer n.RUnlock() + + name := n.options.Name + + return name } // acceptNetConn accepts connections from NetworkChannel @@ -341,8 +348,11 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { } } +// initNodes initializes tunnel with a list of resolved nodes func (n *network) initNodes(startup bool) { nodes, err := n.resolveNodes() + // NOTE: this condition never fires + // as resolveNodes() never returns error if err != nil && !startup { log.Debugf("Network failed to resolve nodes: %v", err) return @@ -394,7 +404,7 @@ func (n *network) resolveNodes() ([]string, error) { } } - // use the dns resolver to expand peers + // use the DNS resolver to expand peers dns := &dns.Resolver{} // append seed nodes if we have them @@ -964,7 +974,7 @@ func (n *network) prunePeerRoutes(peer *node) error { // manage the process of announcing to peers and prune any peer nodes that have not been // seen for a period of time. Also removes all the routes either originated by or routable -//by the stale nodes. it also resolves nodes periodically and adds them to the tunnel +// by the stale nodes. it also resolves nodes periodically and adds them to the tunnel func (n *network) manage() { announce := time.NewTicker(AnnounceTime) defer announce.Stop() @@ -1046,7 +1056,6 @@ func (n *network) manage() { // we're only going to send to max 3 peers at any given tick for _, peer := range peers { - // advertise yourself to the network if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { log.Debugf("Network failed to advertise peer %s: %v", peer.id, err) @@ -1060,7 +1069,7 @@ func (n *network) manage() { // now look at links we may not have sent to. this may occur // where a connect message was lost for link, lastSent := range links { - if !lastSent.IsZero() { + if !lastSent.IsZero() || time.Since(lastSent) < KeepAliveTime { continue } @@ -1111,11 +1120,11 @@ func (n *network) manage() { // mark as processed routers[route.Router] = true - // if the router is NOT in our peer graph, delete all routes originated by it + // if the router is in our peer graph do NOT delete routes originated by it if peer := n.node.GetPeerNode(route.Router); peer != nil { continue } - + // otherwise delete all the routes originated by it if err := n.pruneRoutes(router.QueryRouter(route.Router)); err != nil { log.Debugf("Network failed deleting routes by %s: %v", route.Router, err) } @@ -1233,31 +1242,33 @@ func (n *network) updatePeerLinks(peer *node) error { // if the peerLink is found in the returned links update peerLinks log.Tracef("Network updating peer links for peer %s", peer.address) - // add peerLink to the peerLinks map + // lookup a link and update it if better link is available if link, ok := n.peerLinks[peer.address]; ok { // if the existing has better Length then the new, replace it if link.Length() < peerLink.Length() { n.peerLinks[peer.address] = peerLink } - } else { - n.peerLinks[peer.address] = peerLink + return nil } + // add peerLink to the peerLinks map + n.peerLinks[peer.address] = peerLink + return nil } // isLoopback checks if a link is a loopback to ourselves func (n *network) isLoopback(link tunnel.Link) bool { - // our advertise address - loopback := n.server.Options().Advertise - // actual address - address := n.tunnel.Address() - // skip loopback if link.Loopback() { return true } + // our advertise address + loopback := n.server.Options().Advertise + // actual address + address := n.tunnel.Address() + // if remote is ourselves switch link.Remote() { case loopback, address: @@ -1382,7 +1393,10 @@ func (n *network) Connect() error { } // dial into ControlChannel to send route adverts - ctrlClient, err := n.tunnel.Dial(ControlChannel, tunnel.DialMode(tunnel.Multicast)) + ctrlClient, err := n.tunnel.Dial( + ControlChannel, + tunnel.DialMode(tunnel.Multicast), + ) if err != nil { return err } @@ -1390,7 +1404,10 @@ func (n *network) Connect() error { n.tunClient[ControlChannel] = ctrlClient // dial into NetworkChannel to send network messages - netClient, err := n.tunnel.Dial(NetworkChannel, tunnel.DialMode(tunnel.Multicast)) + netClient, err := n.tunnel.Dial( + NetworkChannel, + tunnel.DialMode(tunnel.Multicast), + ) if err != nil { return err } From 78aed5beed0e8758a17b589a7fd0c96f50e4a6dd Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Wed, 8 Jan 2020 14:48:38 +0000 Subject: [PATCH 098/788] Fixed tunnel race conditions. (#1094) --- tunnel/default.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tunnel/default.go b/tunnel/default.go index 89de3dfb..cc8e78be 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -201,15 +201,15 @@ func (t *tun) announce(channel, session string, link *link) { } // manage monitors outbound links and attempts to reconnect to the failed ones -func (t *tun) manage() { - reconnect := time.NewTicker(ReconnectTime) - defer reconnect.Stop() +func (t *tun) manage(reconnect time.Duration) { + r := time.NewTicker(reconnect) + defer r.Stop() for { select { case <-t.closed: return - case <-reconnect.C: + case <-r.C: t.manageLinks() } } @@ -862,8 +862,11 @@ func (t *tun) setupLink(node string) (*link, error) { // create a new link link := newLink(c) + // set link id to remote side + link.Lock() link.id = c.Remote() + link.Unlock() // send the first connect message if err := t.sendMsg("connect", link); err != nil { @@ -984,7 +987,7 @@ func (t *tun) Connect() error { t.setupLinks() // manage the links - go t.manage() + go t.manage(ReconnectTime) return nil } From a90a74c9e28d5aabd0933a9e975837e219a5b945 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Jan 2020 22:23:14 +0000 Subject: [PATCH 099/788] Change the store interface to remove variadic args (#1095) --- store/cloudflare/cloudflare.go | 130 +++++++++++++++--------- store/cloudflare/cloudflare_test.go | 23 ++--- store/cockroach/cockroach.go | 89 +++++++++-------- store/cockroach/cockroach_test.go | 10 ++ store/etcd/etcd.go | 66 ++++++------- store/memory/memory.go | 47 ++++++--- store/mock/store.go | 107 -------------------- store/options.go | 7 ++ store/service/proto/store.pb.go | 147 ++++++++++++++++++---------- store/service/proto/store.proto | 16 +-- store/service/service.go | 33 ++++--- store/store.go | 19 ++-- sync/map_test.go | 40 -------- 13 files changed, 356 insertions(+), 378 deletions(-) delete mode 100644 store/mock/store.go delete mode 100644 sync/map_test.go diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index 03e32298..9bc4b69f 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -106,15 +106,19 @@ func (w *workersKV) Init(opts ...store.Option) error { return nil } -// In the cloudflare workers KV implemention, List() doesn't guarantee -// anything as the workers API is eventually consistent. -func (w *workersKV) List() ([]*store.Record, error) { +func (w *workersKV) list(prefix string) ([]string, error) { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() path := fmt.Sprintf("accounts/%s/storage/kv/namespaces/%s/keys", w.account, w.namespace) - response, _, _, err := w.request(ctx, http.MethodGet, path, nil, make(http.Header)) + body := make(map[string]string) + + if len(prefix) > 0 { + body["prefix"] = prefix + } + + response, _, _, err := w.request(ctx, http.MethodGet, path, body, make(http.Header)) if err != nil { return nil, err } @@ -138,13 +142,51 @@ func (w *workersKV) List() ([]*store.Record, error) { keys = append(keys, r.Name) } - return w.Read(keys...) + return keys, nil } -func (w *workersKV) Read(keys ...string) ([]*store.Record, error) { +// In the cloudflare workers KV implemention, List() doesn't guarantee +// anything as the workers API is eventually consistent. +func (w *workersKV) List() ([]*store.Record, error) { + keys, err := w.list("") + if err != nil { + return nil, err + } + + var gerr error + var records []*store.Record + + for _, key := range keys { + r, err := w.Read(key) + if err != nil { + gerr = err + continue + } + records = append(records, r...) + } + + return records, gerr +} + +func (w *workersKV) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() + var options store.ReadOptions + for _, o := range opts { + o(&options) + } + + keys := []string{key} + + if options.Prefix { + k, err := w.list(key) + if err != nil { + return nil, err + } + keys = k + } + //nolint:prealloc var records []*store.Record @@ -174,65 +216,61 @@ func (w *workersKV) Read(keys ...string) ([]*store.Record, error) { return records, nil } -func (w *workersKV) Write(records ...*store.Record) error { +func (w *workersKV) Write(r *store.Record) error { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() - for _, r := range records { - path := fmt.Sprintf("accounts/%s/storage/kv/namespaces/%s/values/%s", w.account, w.namespace, url.PathEscape(r.Key)) - if r.Expiry != 0 { - // Minimum cloudflare TTL is 60 Seconds - exp := int(math.Max(60, math.Round(r.Expiry.Seconds()))) - path = path + "?expiration_ttl=" + strconv.Itoa(exp) - } + path := fmt.Sprintf("accounts/%s/storage/kv/namespaces/%s/values/%s", w.account, w.namespace, url.PathEscape(r.Key)) + if r.Expiry != 0 { + // Minimum cloudflare TTL is 60 Seconds + exp := int(math.Max(60, math.Round(r.Expiry.Seconds()))) + path = path + "?expiration_ttl=" + strconv.Itoa(exp) + } - headers := make(http.Header) + headers := make(http.Header) - resp, _, _, err := w.request(ctx, http.MethodPut, path, r.Value, headers) - if err != nil { - return err - } + resp, _, _, err := w.request(ctx, http.MethodPut, path, r.Value, headers) + if err != nil { + return err + } - a := &apiResponse{} - if err := json.Unmarshal(resp, a); err != nil { - return err - } + a := &apiResponse{} + if err := json.Unmarshal(resp, a); err != nil { + return err + } - if !a.Success { - messages := "" - for _, m := range a.Errors { - messages += strconv.Itoa(m.Code) + " " + m.Message + "\n" - } - return errors.New(messages) + if !a.Success { + messages := "" + for _, m := range a.Errors { + messages += strconv.Itoa(m.Code) + " " + m.Message + "\n" } + return errors.New(messages) } return nil } -func (w *workersKV) Delete(keys ...string) error { +func (w *workersKV) Delete(key string) error { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() - for _, k := range keys { - path := fmt.Sprintf("accounts/%s/storage/kv/namespaces/%s/values/%s", w.account, w.namespace, url.PathEscape(k)) - resp, _, _, err := w.request(ctx, http.MethodDelete, path, nil, make(http.Header)) - if err != nil { - return err - } + path := fmt.Sprintf("accounts/%s/storage/kv/namespaces/%s/values/%s", w.account, w.namespace, url.PathEscape(key)) + resp, _, _, err := w.request(ctx, http.MethodDelete, path, nil, make(http.Header)) + if err != nil { + return err + } - a := &apiResponse{} - if err := json.Unmarshal(resp, a); err != nil { - return err - } + a := &apiResponse{} + if err := json.Unmarshal(resp, a); err != nil { + return err + } - if !a.Success { - messages := "" - for _, m := range a.Errors { - messages += strconv.Itoa(m.Code) + " " + m.Message + "\n" - } - return errors.New(messages) + if !a.Success { + messages := "" + for _, m := range a.Errors { + messages += strconv.Itoa(m.Code) + " " + m.Message + "\n" } + return errors.New(messages) } return nil diff --git a/store/cloudflare/cloudflare_test.go b/store/cloudflare/cloudflare_test.go index 525eeecd..b1586a36 100644 --- a/store/cloudflare/cloudflare_test.go +++ b/store/cloudflare/cloudflare_test.go @@ -33,17 +33,18 @@ func TestCloudflare(t *testing.T) { t.Log("Listed " + strconv.Itoa(len(records)) + " records") } - err = wkv.Write( - &store.Record{ - Key: randomK, - Value: []byte(randomV), - }, - &store.Record{ - Key: "expirationtest", - Value: []byte("This message will self destruct"), - Expiry: 75 * time.Second, - }, - ) + err = wkv.Write(&store.Record{ + Key: randomK, + Value: []byte(randomV), + }) + if err != nil { + t.Errorf("Write: %s", err.Error()) + } + err = wkv.Write(&store.Record{ + Key: "expirationtest", + Value: []byte("This message will self destruct"), + Expiry: 75 * time.Second, + }) if err != nil { t.Errorf("Write: %s", err.Error()) } diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index d321dc06..95fe34f4 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -80,39 +80,47 @@ func (s *sqlStore) List() ([]*store.Record, error) { } // Read all records with keys -func (s *sqlStore) Read(keys ...string) ([]*store.Record, error) { +func (s *sqlStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { + var options store.ReadOptions + for _, o := range opts { + o(&options) + } + + // TODO: make use of options.Prefix using WHERE key LIKE = ? + q, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key = $1;", s.database, s.table)) if err != nil { return nil, err } + var records []*store.Record var timehelper pq.NullTime - for _, key := range keys { - row := q.QueryRow(key) - record := &store.Record{} - if err := row.Scan(&record.Key, &record.Value, &timehelper); err != nil { - if err == sql.ErrNoRows { - return records, store.ErrNotFound - } - return records, err - } - if timehelper.Valid { - if timehelper.Time.Before(time.Now()) { - // record has expired - go s.Delete(key) - return records, store.ErrNotFound - } - record.Expiry = time.Until(timehelper.Time) - records = append(records, record) - } else { - records = append(records, record) + + row := q.QueryRow(key) + record := &store.Record{} + if err := row.Scan(&record.Key, &record.Value, &timehelper); err != nil { + if err == sql.ErrNoRows { + return records, store.ErrNotFound } + return records, err } + if timehelper.Valid { + if timehelper.Time.Before(time.Now()) { + // record has expired + go s.Delete(key) + return records, store.ErrNotFound + } + record.Expiry = time.Until(timehelper.Time) + records = append(records, record) + } else { + records = append(records, record) + } + return records, nil } // Write records -func (s *sqlStore) Write(rec ...*store.Record) error { +func (s *sqlStore) Write(r *store.Record) error { q, err := s.db.Prepare(fmt.Sprintf(`INSERT INTO %s.%s(key, value, expiry) VALUES ($1, $2::bytea, $3) ON CONFLICT (key) @@ -121,37 +129,36 @@ func (s *sqlStore) Write(rec ...*store.Record) error { if err != nil { return err } - for _, r := range rec { - var err error - if r.Expiry != 0 { - _, err = q.Exec(r.Key, r.Value, time.Now().Add(r.Expiry)) - } else { - _, err = q.Exec(r.Key, r.Value, nil) - } - if err != nil { - return errors.Wrap(err, "Couldn't insert record "+r.Key) - } + + if r.Expiry != 0 { + _, err = q.Exec(r.Key, r.Value, time.Now().Add(r.Expiry)) + } else { + _, err = q.Exec(r.Key, r.Value, nil) + } + + if err != nil { + return errors.Wrap(err, "Couldn't insert record "+r.Key) } return nil } // Delete records with keys -func (s *sqlStore) Delete(keys ...string) error { +func (s *sqlStore) Delete(key string) error { q, err := s.db.Prepare(fmt.Sprintf("DELETE FROM %s.%s WHERE key = $1;", s.database, s.table)) if err != nil { return err } - for _, key := range keys { - result, err := q.Exec(key) - if err != nil { - return err - } - _, err = result.RowsAffected() - if err != nil { - return err - } + + result, err := q.Exec(key) + if err != nil { + return err } + _, err = result.RowsAffected() + if err != nil { + return err + } + return nil } diff --git a/store/cockroach/cockroach_test.go b/store/cockroach/cockroach_test.go index 08f20135..cb0b53a8 100644 --- a/store/cockroach/cockroach_test.go +++ b/store/cockroach/cockroach_test.go @@ -44,10 +44,20 @@ func TestSQL(t *testing.T) { Key: "test", Value: []byte("foo"), }, + ) + if err != nil { + t.Error(err) + } + err = sqlStore.Write( &store.Record{ Key: "bar", Value: []byte("baz"), }, + ) + if err != nil { + t.Error(err) + } + err = sqlStore.Write( &store.Record{ Key: "qux", Value: []byte("aasad"), diff --git a/store/etcd/etcd.go b/store/etcd/etcd.go index 5eac1e50..c1d8850e 100644 --- a/store/etcd/etcd.go +++ b/store/etcd/etcd.go @@ -6,7 +6,6 @@ import ( "log" client "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/mvcc/mvccpb" "github.com/micro/go-micro/store" ) @@ -22,26 +21,31 @@ func (e *ekv) Init(opts ...store.Option) error { return nil } -func (e *ekv) Read(keys ...string) ([]*store.Record, error) { - //nolint:prealloc - var values []*mvccpb.KeyValue - - for _, key := range keys { - keyval, err := e.kv.Get(context.Background(), key) - if err != nil { - return nil, err - } - - if keyval == nil || len(keyval.Kvs) == 0 { - return nil, store.ErrNotFound - } - - values = append(values, keyval.Kvs...) +func (e *ekv) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { + var options store.ReadOptions + for _, o := range opts { + o(&options) } - records := make([]*store.Record, 0, len(values)) + var etcdOpts []client.OpOption - for _, kv := range values { + // set options prefix + if options.Prefix { + etcdOpts = append(etcdOpts, client.WithPrefix()) + } + + keyval, err := e.kv.Get(context.Background(), key, etcdOpts...) + if err != nil { + return nil, err + } + + if keyval == nil || len(keyval.Kvs) == 0 { + return nil, store.ErrNotFound + } + + records := make([]*store.Record, 0, len(keyval.Kvs)) + + for _, kv := range keyval.Kvs { records = append(records, &store.Record{ Key: string(kv.Key), Value: kv.Value, @@ -52,27 +56,15 @@ func (e *ekv) Read(keys ...string) ([]*store.Record, error) { return records, nil } -func (e *ekv) Delete(keys ...string) error { - var gerr error - for _, key := range keys { - _, err := e.kv.Delete(context.Background(), key) - if err != nil { - gerr = err - } - } - return gerr +func (e *ekv) Delete(key string) error { + _, err := e.kv.Delete(context.Background(), key) + return err } -func (e *ekv) Write(records ...*store.Record) error { - var gerr error - for _, record := range records { - // TODO create lease to expire keys - _, err := e.kv.Put(context.Background(), record.Key, string(record.Value)) - if err != nil { - gerr = err - } - } - return gerr +func (e *ekv) Write(record *store.Record) error { + // TODO create lease to expire keys + _, err := e.kv.Put(context.Background(), record.Key, string(record.Value)) + return err } func (e *ekv) List() ([]*store.Record, error) { diff --git a/store/memory/memory.go b/store/memory/memory.go index 5715f41e..814a7459 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -2,6 +2,7 @@ package memory import ( + "strings" "sync" "time" @@ -55,19 +56,37 @@ func (m *memoryStore) List() ([]*store.Record, error) { return values, nil } -func (m *memoryStore) Read(keys ...string) ([]*store.Record, error) { +func (m *memoryStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { m.RLock() defer m.RUnlock() - //nolint:prealloc - var records []*store.Record + var options store.ReadOptions - for _, key := range keys { + for _, o := range opts { + o(&options) + } + + var vals []*memoryRecord + + if !options.Prefix { v, ok := m.values[key] if !ok { return nil, store.ErrNotFound } + vals = []*memoryRecord{v} + } else { + for _, v := range m.values { + if !strings.HasPrefix(v.r.Key, key) { + continue + } + vals = append(vals, v) + } + } + //nolint:prealloc + var records []*store.Record + + for _, v := range vals { // get expiry d := v.r.Expiry t := time.Since(v.c) @@ -88,29 +107,25 @@ func (m *memoryStore) Read(keys ...string) ([]*store.Record, error) { return records, nil } -func (m *memoryStore) Write(records ...*store.Record) error { +func (m *memoryStore) Write(r *store.Record) error { m.Lock() defer m.Unlock() - for _, r := range records { - // set the record - m.values[r.Key] = &memoryRecord{ - r: r, - c: time.Now(), - } + // set the record + m.values[r.Key] = &memoryRecord{ + r: r, + c: time.Now(), } return nil } -func (m *memoryStore) Delete(keys ...string) error { +func (m *memoryStore) Delete(key string) error { m.Lock() defer m.Unlock() - for _, key := range keys { - // delete the value - delete(m.values, key) - } + // delete the value + delete(m.values, key) return nil } diff --git a/store/mock/store.go b/store/mock/store.go deleted file mode 100644 index c9908400..00000000 --- a/store/mock/store.go +++ /dev/null @@ -1,107 +0,0 @@ -// Code generated by mockery v1.0.0. DO NOT EDIT. - -package mock - -import mock "github.com/stretchr/testify/mock" -import store "github.com/micro/go-micro/store" - -// Store is an autogenerated mock type for the Store type -type Store struct { - mock.Mock -} - -func (_m *Store) Init(...store.Option) error { - return nil -} - -// Delete provides a mock function with given fields: key -func (_m *Store) Delete(key ...string) error { - _va := make([]interface{}, len(key)) - for _i := range key { - _va[_i] = key[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 error - if rf, ok := ret.Get(0).(func(...string) error); ok { - r0 = rf(key...) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// List provides a mock function with given fields: -func (_m *Store) List() ([]*store.Record, error) { - ret := _m.Called() - - var r0 []*store.Record - if rf, ok := ret.Get(0).(func() []*store.Record); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*store.Record) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// Read provides a mock function with given fields: key -func (_m *Store) Read(key ...string) ([]*store.Record, error) { - _va := make([]interface{}, len(key)) - for _i := range key { - _va[_i] = key[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 []*store.Record - if rf, ok := ret.Get(0).(func(...string) []*store.Record); ok { - r0 = rf(key...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*store.Record) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(...string) error); ok { - r1 = rf(key...) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// Write provides a mock function with given fields: rec -func (_m *Store) Write(rec ...*store.Record) error { - _va := make([]interface{}, len(rec)) - for _i := range rec { - _va[_i] = rec[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - var r0 error - if rf, ok := ret.Get(0).(func(...*store.Record) error); ok { - r0 = rf(rec...) - } else { - r0 = ret.Error(0) - } - - return r0 -} diff --git a/store/options.go b/store/options.go index 0161ed20..a319cf58 100644 --- a/store/options.go +++ b/store/options.go @@ -38,3 +38,10 @@ func Namespace(ns string) Option { o.Namespace = ns } } + +// ReadPrefix uses the key as a prefix +func ReadPrefix() ReadOption { + return func(o *ReadOptions) { + o.Prefix = true + } +} diff --git a/store/service/proto/store.pb.go b/store/service/proto/store.pb.go index 8aaa8a3f..6a05463a 100644 --- a/store/service/proto/store.pb.go +++ b/store/service/proto/store.pb.go @@ -78,18 +78,58 @@ func (m *Record) GetExpiry() int64 { return 0 } -type ReadRequest struct { - Keys []string `protobuf:"bytes,1,rep,name=keys,proto3" json:"keys,omitempty"` +type ReadOptions struct { + Prefix bool `protobuf:"varint,1,opt,name=prefix,proto3" json:"prefix,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } +func (m *ReadOptions) Reset() { *m = ReadOptions{} } +func (m *ReadOptions) String() string { return proto.CompactTextString(m) } +func (*ReadOptions) ProtoMessage() {} +func (*ReadOptions) Descriptor() ([]byte, []int) { + return fileDescriptor_f84ccc98e143ed3e, []int{1} +} + +func (m *ReadOptions) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ReadOptions.Unmarshal(m, b) +} +func (m *ReadOptions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ReadOptions.Marshal(b, m, deterministic) +} +func (m *ReadOptions) XXX_Merge(src proto.Message) { + xxx_messageInfo_ReadOptions.Merge(m, src) +} +func (m *ReadOptions) XXX_Size() int { + return xxx_messageInfo_ReadOptions.Size(m) +} +func (m *ReadOptions) XXX_DiscardUnknown() { + xxx_messageInfo_ReadOptions.DiscardUnknown(m) +} + +var xxx_messageInfo_ReadOptions proto.InternalMessageInfo + +func (m *ReadOptions) GetPrefix() bool { + if m != nil { + return m.Prefix + } + return false +} + +type ReadRequest struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Options *ReadOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{1} + return fileDescriptor_f84ccc98e143ed3e, []int{2} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -110,9 +150,16 @@ func (m *ReadRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ReadRequest proto.InternalMessageInfo -func (m *ReadRequest) GetKeys() []string { +func (m *ReadRequest) GetKey() string { if m != nil { - return m.Keys + return m.Key + } + return "" +} + +func (m *ReadRequest) GetOptions() *ReadOptions { + if m != nil { + return m.Options } return nil } @@ -128,7 +175,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{2} + return fileDescriptor_f84ccc98e143ed3e, []int{3} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -157,17 +204,17 @@ func (m *ReadResponse) GetRecords() []*Record { } type WriteRequest struct { - Records []*Record `protobuf:"bytes,2,rep,name=records,proto3" json:"records,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Record *Record `protobuf:"bytes,1,opt,name=record,proto3" json:"record,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *WriteRequest) Reset() { *m = WriteRequest{} } func (m *WriteRequest) String() string { return proto.CompactTextString(m) } func (*WriteRequest) ProtoMessage() {} func (*WriteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{3} + return fileDescriptor_f84ccc98e143ed3e, []int{4} } func (m *WriteRequest) XXX_Unmarshal(b []byte) error { @@ -188,9 +235,9 @@ func (m *WriteRequest) XXX_DiscardUnknown() { var xxx_messageInfo_WriteRequest proto.InternalMessageInfo -func (m *WriteRequest) GetRecords() []*Record { +func (m *WriteRequest) GetRecord() *Record { if m != nil { - return m.Records + return m.Record } return nil } @@ -205,7 +252,7 @@ func (m *WriteResponse) Reset() { *m = WriteResponse{} } func (m *WriteResponse) String() string { return proto.CompactTextString(m) } func (*WriteResponse) ProtoMessage() {} func (*WriteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{4} + return fileDescriptor_f84ccc98e143ed3e, []int{5} } func (m *WriteResponse) XXX_Unmarshal(b []byte) error { @@ -227,7 +274,7 @@ func (m *WriteResponse) XXX_DiscardUnknown() { var xxx_messageInfo_WriteResponse proto.InternalMessageInfo type DeleteRequest struct { - Keys []string `protobuf:"bytes,1,rep,name=keys,proto3" json:"keys,omitempty"` + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -237,7 +284,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{5} + return fileDescriptor_f84ccc98e143ed3e, []int{6} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -258,11 +305,11 @@ func (m *DeleteRequest) XXX_DiscardUnknown() { var xxx_messageInfo_DeleteRequest proto.InternalMessageInfo -func (m *DeleteRequest) GetKeys() []string { +func (m *DeleteRequest) GetKey() string { if m != nil { - return m.Keys + return m.Key } - return nil + return "" } type DeleteResponse struct { @@ -275,7 +322,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{6} + return fileDescriptor_f84ccc98e143ed3e, []int{7} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -297,8 +344,6 @@ func (m *DeleteResponse) XXX_DiscardUnknown() { var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo type ListRequest struct { - // optional key - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -308,7 +353,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{7} + return fileDescriptor_f84ccc98e143ed3e, []int{8} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -329,13 +374,6 @@ func (m *ListRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ListRequest proto.InternalMessageInfo -func (m *ListRequest) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - type ListResponse struct { Records []*Record `protobuf:"bytes,1,rep,name=records,proto3" json:"records,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -347,7 +385,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{8} + return fileDescriptor_f84ccc98e143ed3e, []int{9} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -377,6 +415,7 @@ func (m *ListResponse) GetRecords() []*Record { func init() { proto.RegisterType((*Record)(nil), "go.micro.store.Record") + proto.RegisterType((*ReadOptions)(nil), "go.micro.store.ReadOptions") proto.RegisterType((*ReadRequest)(nil), "go.micro.store.ReadRequest") proto.RegisterType((*ReadResponse)(nil), "go.micro.store.ReadResponse") proto.RegisterType((*WriteRequest)(nil), "go.micro.store.WriteRequest") @@ -392,26 +431,28 @@ func init() { } var fileDescriptor_f84ccc98e143ed3e = []byte{ - // 333 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0x4d, 0x4f, 0xc2, 0x40, - 0x10, 0x86, 0x59, 0x0a, 0x35, 0x0c, 0x1f, 0x92, 0x89, 0x21, 0x0d, 0x7e, 0xd5, 0x7a, 0xe9, 0xc5, - 0x42, 0xf0, 0x0f, 0x98, 0xf8, 0x11, 0x4d, 0x3c, 0xad, 0x07, 0xcf, 0x08, 0x13, 0xd2, 0x80, 0x2e, - 0xee, 0x16, 0x62, 0xff, 0x90, 0xbf, 0xd3, 0xec, 0x6e, 0xab, 0xc5, 0x42, 0x62, 0xbc, 0xcd, 0xee, - 0xbc, 0xf3, 0xec, 0xdb, 0x79, 0x0b, 0xd1, 0x6b, 0x3c, 0x91, 0x62, 0x30, 0x13, 0x17, 0xb6, 0x50, - 0x89, 0x90, 0x34, 0x50, 0x24, 0xd7, 0xf1, 0x84, 0x06, 0x4b, 0x29, 0x92, 0xec, 0x2e, 0x32, 0x35, - 0x76, 0x66, 0xc2, 0x8e, 0x44, 0xe6, 0x36, 0xb8, 0x07, 0x97, 0xd3, 0x44, 0xc8, 0x29, 0x76, 0xc1, - 0x99, 0x53, 0xea, 0x31, 0x9f, 0x85, 0x0d, 0xae, 0x4b, 0x3c, 0x80, 0xfa, 0x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 0xc8, 0xa3, 0x7f, 0xb2, 0xab, 0x9d, 0xa3, 0x5e, 0x5c, 0xf3, 0x6f, 0x5f, 0x7e, - 0x05, 0x00, 0x00, 0xff, 0xff, 0x30, 0x48, 0x25, 0x2d, 0x0d, 0x03, 0x00, 0x00, + // 364 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x4d, 0x4b, 0xc3, 0x40, + 0x10, 0x6d, 0x9a, 0x36, 0xd5, 0x49, 0x5b, 0xcb, 0x22, 0x25, 0xd4, 0x0f, 0xe2, 0x82, 0x90, 0x8b, + 0x69, 0xa9, 0x78, 0x15, 0xc1, 0x0f, 0x14, 0x04, 0x61, 0x05, 0x3d, 0xd7, 0x76, 0x2c, 0xc1, 0xda, + 0x8d, 0xbb, 0x69, 0x69, 0xff, 0x90, 0xbf, 0x53, 0xb2, 0xbb, 0xd1, 0x94, 0x34, 0x17, 0x6f, 0x33, + 0xfb, 0xde, 0xbc, 0x99, 0x79, 0xc3, 0x42, 0xf8, 0x19, 0x8d, 0x05, 0xef, 0x4f, 0xf9, 0x99, 0x0e, + 0x64, 0xc2, 0x05, 0xf6, 0x25, 0x8a, 0x65, 0x34, 0xc6, 0x7e, 0x2c, 0x78, 0x62, 0xde, 0x42, 0x15, + 0x93, 0xf6, 0x94, 0xeb, 0x92, 0x50, 0xbd, 0xd2, 0x7b, 0x70, 0x18, 0x8e, 0xb9, 0x98, 0x90, 0x0e, + 0xd8, 0x1f, 0xb8, 0xf6, 0x2c, 0xdf, 0x0a, 0x76, 0x59, 0x1a, 0x92, 0x7d, 0xa8, 0x2f, 0x47, 0xb3, + 0x05, 0x7a, 0x55, 0xdf, 0x0a, 0x9a, 0x4c, 0x27, 0xa4, 0x0b, 0x0e, 0xae, 0xe2, 0x48, 0xac, 0x3d, + 0xdb, 0xb7, 0x02, 0x9b, 0x99, 0x8c, 0x9e, 0x82, 0xcb, 0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x48, + 0x0a, 0xd4, 0x0d, 0xef, 0x7b, 0xc7, 0x65, 0x70, 0x26, 0xf5, 0xe6, 0xa8, 0x1f, 0x72, 0xfe, 0x13, + 0x00, 0x00, 0xff, 0xff, 0xf9, 0x20, 0x54, 0x71, 0x53, 0x03, 0x00, 0x00, } diff --git a/store/service/proto/store.proto b/store/service/proto/store.proto index 5f9ea233..39bd8afc 100644 --- a/store/service/proto/store.proto +++ b/store/service/proto/store.proto @@ -18,8 +18,13 @@ message Record { int64 expiry = 3; } +message ReadOptions { + bool prefix = 1; +} + message ReadRequest { - repeated string keys = 1; + string key = 1; + ReadOptions options = 2; } message ReadResponse { @@ -27,21 +32,18 @@ message ReadResponse { } message WriteRequest { - repeated Record records = 2; + Record record = 1; } message WriteResponse {} message DeleteRequest { - repeated string keys = 1; + string key = 1; } message DeleteResponse {} -message ListRequest { - // optional key - string key = 1; -} +message ListRequest {} message ListResponse { repeated Record records = 1; diff --git a/store/service/service.go b/store/service/service.go index e364f794..8610541b 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -73,6 +73,7 @@ func (s *serviceStore) List() ([]*store.Record, error) { if err != nil { return records, err } + for _, record := range rsp.Records { records = append(records, &store.Record{ Key: record.Key, @@ -86,15 +87,24 @@ func (s *serviceStore) List() ([]*store.Record, error) { } // Read a record with key -func (s *serviceStore) Read(keys ...string) ([]*store.Record, error) { +func (s *serviceStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { + var options store.ReadOptions + for _, o := range opts { + o(&options) + } + rsp, err := s.Client.Read(s.Context(), &pb.ReadRequest{ - Keys: keys, + Key: key, + Options: &pb.ReadOptions{ + Prefix: options.Prefix, + }, }, client.WithAddress(s.Nodes...)) if err != nil { return nil, err } records := make([]*store.Record, 0, len(rsp.Records)) + for _, val := range rsp.Records { records = append(records, &store.Record{ Key: val.Key, @@ -102,32 +112,27 @@ func (s *serviceStore) Read(keys ...string) ([]*store.Record, error) { Expiry: time.Duration(val.Expiry) * time.Second, }) } + return records, nil } // Write a record -func (s *serviceStore) Write(recs ...*store.Record) error { - records := make([]*pb.Record, 0, len(recs)) - - for _, record := range recs { - records = append(records, &pb.Record{ +func (s *serviceStore) Write(record *store.Record) error { + _, err := s.Client.Write(s.Context(), &pb.WriteRequest{ + Record: &pb.Record{ Key: record.Key, Value: record.Value, Expiry: int64(record.Expiry.Seconds()), - }) - } - - _, err := s.Client.Write(s.Context(), &pb.WriteRequest{ - Records: records, + }, }, client.WithAddress(s.Nodes...)) return err } // Delete a record with key -func (s *serviceStore) Delete(keys ...string) error { +func (s *serviceStore) Delete(key string) error { _, err := s.Client.Delete(s.Context(), &pb.DeleteRequest{ - Keys: keys, + Key: key, }, client.WithAddress(s.Nodes...)) return err } diff --git a/store/store.go b/store/store.go index d8c44c62..c84e76cb 100644 --- a/store/store.go +++ b/store/store.go @@ -20,11 +20,11 @@ type Store interface { // List all the known records List() ([]*Record, error) // Read records with keys - Read(key ...string) ([]*Record, error) + Read(key string, opts ...ReadOption) ([]*Record, error) // Write records - Write(rec ...*Record) error + Write(*Record) error // Delete records with keys - Delete(key ...string) error + Delete(key string) error } // Record represents a data record @@ -34,6 +34,13 @@ type Record struct { Expiry time.Duration } +type ReadOptions struct { + // Read key as a prefix + Prefix bool +} + +type ReadOption func(o *ReadOptions) + type noop struct{} func (n *noop) Init(...Option) error { @@ -44,14 +51,14 @@ func (n *noop) List() ([]*Record, error) { return nil, nil } -func (n *noop) Read(key ...string) ([]*Record, error) { +func (n *noop) Read(key string, opts ...ReadOption) ([]*Record, error) { return nil, nil } -func (n *noop) Write(rec ...*Record) error { +func (n *noop) Write(rec *Record) error { return nil } -func (n *noop) Delete(key ...string) error { +func (n *noop) Delete(key string) error { return nil } diff --git a/sync/map_test.go b/sync/map_test.go deleted file mode 100644 index fa54cd2c..00000000 --- a/sync/map_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package sync - -import ( - "testing" - "time" - - "github.com/micro/go-micro/store" - store_mock "github.com/micro/go-micro/store/mock" - mem_lock "github.com/micro/go-micro/sync/lock/memory" - "github.com/stretchr/testify/mock" -) - -func TestIterate(t *testing.T) { - recA := &store.Record{ - Key: "A", - Value: nil, - } - recB := &store.Record{ - Key: "B", - Value: nil, - } - s1 := &store_mock.Store{} - s2 := &store_mock.Store{} - s1.On("List").Return([]*store.Record{recA, recB}, nil) - s2.On("List").Return([]*store.Record{recB, recA}, nil) - s1.On("Write", mock.Anything).Return(nil) - s2.On("Write", mock.Anything).Return(nil) - - f := func(key, val interface{}) error { - time.Sleep(1 * time.Millisecond) - return nil - } - l := mem_lock.NewLock() - m1 := NewMap(WithStore(s1), WithLock(l)) - m2 := NewMap(WithStore(s2), WithLock(l)) - go func() { - m2.Iterate(f) - }() - m1.Iterate(f) -} From 37d1139a57c8c6fdcc507564c2c598565561675c Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 9 Jan 2020 17:00:14 +0000 Subject: [PATCH 100/788] ensure we close the grpc stream (#1098) * ensure we close the grpc stream * use g.Close * use closed bool flag for checking connection close --- client/grpc/grpc.go | 1 + client/grpc/stream.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 3d158ea0..f00a12b0 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -211,6 +211,7 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client if opts := g.getGrpcCallOptions(); opts != nil { grpcCallOptions = append(grpcCallOptions, opts...) } + st, err := cc.NewStream(ctx, desc, methodToGRPC(req.Service(), req.Endpoint()), grpcCallOptions...) if err != nil { return nil, errors.InternalServerError("go.micro.client", fmt.Sprintf("Error creating stream: %v", err)) diff --git a/client/grpc/stream.go b/client/grpc/stream.go index c6b38c15..ea9da43f 100644 --- a/client/grpc/stream.go +++ b/client/grpc/stream.go @@ -12,6 +12,7 @@ import ( // Implements the streamer interface type grpcStream struct { sync.RWMutex + closed bool err error conn *grpc.ClientConn stream grpc.ClientStream @@ -46,7 +47,7 @@ func (g *grpcStream) Recv(msg interface{}) (err error) { // #202 - inconsistent gRPC stream behavior // the only way to tell if the stream is done is when we get a EOF on the Recv // here we should close the underlying gRPC ClientConn - closeErr := g.conn.Close() + closeErr := g.Close() if err == io.EOF && closeErr != nil { err = closeErr } @@ -72,5 +73,14 @@ func (g *grpcStream) setError(e error) { // stream should still be able to receive after this function call // TODO: should the conn be closed in another way? func (g *grpcStream) Close() error { - return g.stream.CloseSend() + g.Lock() + defer g.Unlock() + + if g.closed { + return nil + } + + g.closed = true + g.stream.CloseSend() + return g.conn.Close() } From 32a2005f6d146581775ef08e7863421db5ee38ab Mon Sep 17 00:00:00 2001 From: shikbupt Date: Fri, 10 Jan 2020 22:25:28 +0800 Subject: [PATCH 101/788] add option for web service signal handler (#1091) --- web/options.go | 12 ++++++++++++ web/service.go | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/web/options.go b/web/options.go index 03e23484..0570f7ba 100644 --- a/web/options.go +++ b/web/options.go @@ -46,6 +46,8 @@ type Options struct { // Static directory StaticDir string + + Signal bool } func newOptions(opts ...Option) Options { @@ -59,6 +61,7 @@ func newOptions(opts ...Option) Options { StaticDir: DefaultStaticDir, Service: micro.NewService(), Context: context.TODO(), + Signal: true, } for _, o := range opts { @@ -242,3 +245,12 @@ func RegisterCheck(fn func(context.Context) error) Option { o.RegisterCheck = fn } } + +// HandleSignal toggles automatic installation of the signal handler that +// traps TERM, INT, and QUIT. Users of this feature to disable the signal +// handler, should control liveness of the service through the context. +func HandleSignal(b bool) Option { + return func(o *Options) { + o.Signal = b + } +} diff --git a/web/service.go b/web/service.go index e9d6801b..b76b13b9 100644 --- a/web/service.go +++ b/web/service.go @@ -383,7 +383,9 @@ func (s *service) Run() error { go s.run(ex) ch := make(chan os.Signal, 1) - signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT) + if s.opts.Signal { + signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT) + } select { // wait on kill signal From f4fb923fb2705b31a860fcb56f63ae30a450a50d Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 10 Jan 2020 18:04:15 +0300 Subject: [PATCH 102/788] pass additional context for broker subscribe (#1105) Signed-off-by: Vasiliy Tolstov --- server/grpc/grpc.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 874f7273..d2655a95 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -645,6 +645,10 @@ func (g *grpcServer) Register() error { opts = append(opts, broker.Queue(queue)) } + if cx := sb.Options().Context; cx != nil { + opts = append(opts, broker.SubscribeContext(cx)) + } + if !sb.Options().AutoAck { opts = append(opts, broker.DisableAutoAck()) } From 6ca298c61df424de9afc84ac6f5ce636eb644322 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Jan 2020 19:13:55 +0000 Subject: [PATCH 103/788] set default store, fix store options bug, add String method --- config/cmd/cmd.go | 1 + defaults.go | 4 ++++ store/cloudflare/cloudflare.go | 4 ++++ store/cockroach/cockroach.go | 6 ++++++ store/memory/memory.go | 4 ++++ store/service/service.go | 4 ++++ store/store.go | 6 ++++++ 7 files changed, 29 insertions(+) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index c2dbd9a5..d2811dc6 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -278,6 +278,7 @@ var ( defaultSelector = "registry" defaultTransport = "http" defaultRuntime = "local" + defaultStore = "memory" ) func init() { diff --git a/defaults.go b/defaults.go index f1a81e7c..0159f19c 100644 --- a/defaults.go +++ b/defaults.go @@ -3,10 +3,12 @@ package micro import ( "github.com/micro/go-micro/client" "github.com/micro/go-micro/server" + "github.com/micro/go-micro/store" // set defaults gcli "github.com/micro/go-micro/client/grpc" gsrv "github.com/micro/go-micro/server/grpc" + memStore "github.com/micro/go-micro/store/memory" ) func init() { @@ -14,4 +16,6 @@ func init() { client.DefaultClient = gcli.NewClient() // default server server.DefaultServer = gsrv.NewServer() + // default store + store.DefaultStore = memStore.NewStore() } diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index 9bc4b69f..ff1a6d8e 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -332,6 +332,10 @@ func (w *workersKV) request(ctx context.Context, method, path string, body inter return respBody, resp.Header, resp.StatusCode, nil } +func (w *workersKV) String() string { + return "cloudflare" +} + // New returns a cloudflare Store implementation. // Account ID, Token and Namespace must either be passed as options or // environment variables. If set as env vars we expect the following; diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 95fe34f4..bbfadf07 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -239,6 +239,10 @@ func (s *sqlStore) configure() error { return s.initDB() } +func (s *sqlStore) String() string { + return "cockroach" +} + // New returns a new micro Store backed by sql func NewStore(opts ...store.Option) store.Store { var options store.Options @@ -248,6 +252,8 @@ func NewStore(opts ...store.Option) store.Store { // new store s := new(sqlStore) + // set the options + s.options = options // configure the store if err := s.configure(); err != nil { diff --git a/store/memory/memory.go b/store/memory/memory.go index 814a7459..224c0f97 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -130,6 +130,10 @@ func (m *memoryStore) Delete(key string) error { return nil } +func (m *memoryStore) String() string { + return "memory" +} + // NewStore returns a new store.Store func NewStore(opts ...store.Option) store.Store { var options store.Options diff --git a/store/service/service.go b/store/service/service.go index 8610541b..6a34bdfe 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -137,6 +137,10 @@ func (s *serviceStore) Delete(key string) error { return err } +func (s *serviceStore) String() string { + return "service" +} + // NewStore returns a new store service implementation func NewStore(opts ...store.Option) store.Store { var options store.Options diff --git a/store/store.go b/store/store.go index c84e76cb..2e7d73ca 100644 --- a/store/store.go +++ b/store/store.go @@ -25,6 +25,8 @@ type Store interface { Write(*Record) error // Delete records with keys Delete(key string) error + // Name of the store + String() string } // Record represents a data record @@ -62,3 +64,7 @@ func (n *noop) Write(rec *Record) error { func (n *noop) Delete(key string) error { return nil } + +func (n *noop) String() string { + return "noop" +} From e1e6199743358bfca59bde02bee84b736d446c0e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Jan 2020 21:54:28 +0000 Subject: [PATCH 104/788] normalise runtime service status --- runtime/kubernetes/kubernetes.go | 13 ++++++++++++- runtime/kubernetes/service.go | 18 ++++++++++++++++++ runtime/service.go | 22 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index d7dd472f..2b3b479f 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -114,7 +114,18 @@ func (k *kubernetes) getService(labels map[string]string) ([]*runtime.Service, e // parse out deployment status and inject into service metadata if len(kdep.Status.Conditions) > 0 { - status := kdep.Status.Conditions[0].Type + var status string + switch kdep.Status.Conditions[0].Type { + case "Available": + status = "running" + delete(svc.Metadata, "error") + case "Progressing": + status = "starting" + delete(svc.Metadata, "error") + default: + status = "error" + svc.Metadata["error"] = kdep.Status.Conditions[0].Message + } // pick the last known condition type and mark the service status with it log.Debugf("Runtime setting %s service deployment status: %v", name, status) svc.Metadata["status"] = status diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index b74eb7f2..f939b924 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -89,14 +89,18 @@ func (s *service) Start(k client.Client) error { // create deployment first; if we fail, we dont create service if err := k.Create(deploymentResource(s.kdeploy)); err != nil { log.Debugf("Runtime failed to create deployment: %v", err) + s.Status("error", err) return err } // create service now that the deployment has been created if err := k.Create(serviceResource(s.kservice)); err != nil { log.Debugf("Runtime failed to create service: %v", err) + s.Status("error", err) return err } + s.Status("started", nil) + return nil } @@ -104,20 +108,25 @@ func (s *service) Stop(k client.Client) error { // first attempt to delete service if err := k.Delete(serviceResource(s.kservice)); err != nil { log.Debugf("Runtime failed to delete service: %v", err) + s.Status("error", err) return err } // delete deployment once the service has been deleted if err := k.Delete(deploymentResource(s.kdeploy)); err != nil { log.Debugf("Runtime failed to delete deployment: %v", err) + s.Status("error", err) return err } + s.Status("stopped", nil) + return nil } func (s *service) Update(k client.Client) error { if err := k.Update(deploymentResource(s.kdeploy)); err != nil { log.Debugf("Runtime failed to update deployment: %v", err) + s.Status("error", err) return err } if err := k.Update(serviceResource(s.kservice)); err != nil { @@ -127,3 +136,12 @@ func (s *service) Update(k client.Client) error { return nil } + +func (s *service) Status(status string, err error) { + if err == nil { + s.Metadata["status"] = status + return + } + s.Metadata["status"] = "error" + s.Metadata["error"] = err.Error() +} diff --git a/runtime/service.go b/runtime/service.go index 75e96fbf..c2b89394 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -86,10 +86,20 @@ func (s *service) Start() error { s.err = nil s.closed = make(chan bool) + if s.Metadata == nil { + s.Metadata = make(map[string]string) + } + + s.Metadata["status"] = "starting" + // delete any existing error + delete(s.Metadata, "error") + // TODO: pull source & build binary log.Debugf("Runtime service %s forking new process", s.Service.Name) p, err := s.Process.Fork(s.Exec) if err != nil { + s.Metadata["status"] = "error" + s.Metadata["error"] = err.Error() return err } @@ -97,6 +107,8 @@ func (s *service) Start() error { s.PID = p // set to running s.running = true + // set status + s.Metadata["status"] = "running" if s.output != nil { s.streamOutput() @@ -122,10 +134,18 @@ func (s *service) Stop() error { if s.PID == nil { return nil } + + // set status + s.Metadata["status"] = "stopping" + // kill the process err := s.Process.Kill(s.PID) // wait for it to exit s.Process.Wait(s.PID) + + // set status + s.Metadata["status"] = "stopped" + // return the kill error return err } @@ -148,6 +168,8 @@ func (s *service) Wait() { // save the error if err != nil { + s.Metadata["status"] = "error" + s.Metadata["error"] = err.Error() s.err = err } From f50a50eeb36a63c7d75e80865cc0695ebdfc036b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Jan 2020 21:54:36 +0000 Subject: [PATCH 105/788] go fmt --- config/cmd/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index d2811dc6..83dfcc46 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -278,7 +278,7 @@ var ( defaultSelector = "registry" defaultTransport = "http" defaultRuntime = "local" - defaultStore = "memory" + defaultStore = "memory" ) func init() { From fa5b3ee9d9fd371e7c68efc6033b2c8c9e585346 Mon Sep 17 00:00:00 2001 From: Shu xian Date: Sun, 12 Jan 2020 04:50:09 +0800 Subject: [PATCH 106/788] config/reader.Values add Set for specific path merge (#1099) * add Set for specific path merge * add Set * add Del --- config/default.go | 22 ++++++++++++++++++++++ config/reader/reader.go | 2 ++ 2 files changed, 24 insertions(+) diff --git a/config/default.go b/config/default.go index aa9bf365..c01da98c 100644 --- a/config/default.go +++ b/config/default.go @@ -172,6 +172,28 @@ func (c *config) Get(path ...string) reader.Value { return newValue() } +func (c *config) Set(val interface{}, path ...string) { + c.Lock() + defer c.Unlock() + + if c.vals != nil { + c.vals.Set(val, path...) + } + + return +} + +func (c *config) Del(path ...string) { + c.Lock() + defer c.Unlock() + + if c.vals != nil { + c.vals.Del(path...) + } + + return +} + func (c *config) Bytes() []byte { c.RLock() defer c.RUnlock() diff --git a/config/reader/reader.go b/config/reader/reader.go index eee333e3..9d6fbb1a 100644 --- a/config/reader/reader.go +++ b/config/reader/reader.go @@ -18,6 +18,8 @@ type Reader interface { type Values interface { Bytes() []byte Get(path ...string) Value + Set(val interface{}, path ...string) + Del(path ...string) Map() map[string]interface{} Scan(v interface{}) error } From 50b20413d35622d943604e7438aa836d97096d02 Mon Sep 17 00:00:00 2001 From: Maarten Bezemer Date: Sun, 12 Jan 2020 10:13:14 +0100 Subject: [PATCH 107/788] RPC stream client/server mutex fix (#884) * Unlock RPC client while actually receiving a message As receiving a message might block for a long time, unblocking the client allows to let it send messages in the meanwhile without using 'tricks' * Unlock RPC server while actually receiving a message As receiving a message might block for a long time, unblocking the client allows to let it send messages in the meanwhile without using 'tricks' * Protect Close() against race conditions * Concurrency and Sequence tests --- client/rpc_stream.go | 19 +++++- server/rpc_stream.go | 15 +++-- server/rpc_stream_test.go | 133 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 8 deletions(-) create mode 100644 server/rpc_stream_test.go diff --git a/client/rpc_stream.go b/client/rpc_stream.go index f904d2dd..abc4f5f1 100644 --- a/client/rpc_stream.go +++ b/client/rpc_stream.go @@ -83,7 +83,10 @@ func (r *rpcStream) Recv(msg interface{}) error { var resp codec.Message - if err := r.codec.ReadHeader(&resp, codec.Response); err != nil { + r.Unlock() + err := r.codec.ReadHeader(&resp, codec.Response) + r.Lock() + if err != nil { if err == io.EOF && !r.isClosed() { r.err = io.ErrUnexpectedEOF return io.ErrUnexpectedEOF @@ -102,11 +105,17 @@ func (r *rpcStream) Recv(msg interface{}) error { } else { r.err = io.EOF } - if err := r.codec.ReadBody(nil); err != nil { + r.Unlock() + err = r.codec.ReadBody(nil) + r.Lock() + if err != nil { r.err = err } default: - if err := r.codec.ReadBody(msg); err != nil { + r.Unlock() + err = r.codec.ReadBody(msg) + r.Lock() + if err != nil { r.err = err } } @@ -121,11 +130,15 @@ func (r *rpcStream) Error() error { } func (r *rpcStream) Close() error { + r.RLock() + select { case <-r.closed: + r.RUnlock() return nil default: close(r.closed) + r.RUnlock() // send the end of stream message if r.sendEOS { diff --git a/server/rpc_stream.go b/server/rpc_stream.go index a4e64af8..7421fd45 100644 --- a/server/rpc_stream.go +++ b/server/rpc_stream.go @@ -48,13 +48,13 @@ func (r *rpcStream) Send(msg interface{}) error { } func (r *rpcStream) Recv(msg interface{}) error { - r.Lock() - defer r.Unlock() - req := new(codec.Message) req.Type = codec.Request - if err := r.codec.ReadHeader(req, req.Type); err != nil { + err := r.codec.ReadHeader(req, req.Type) + r.Lock() + defer r.Unlock() + if err != nil { // discard body r.codec.ReadBody(nil) r.err = err @@ -67,7 +67,9 @@ func (r *rpcStream) Recv(msg interface{}) error { switch req.Error { case lastStreamResponseError.Error(): // discard body + r.Unlock() r.codec.ReadBody(nil) + r.Lock() r.err = io.EOF return io.EOF default: @@ -77,7 +79,10 @@ func (r *rpcStream) Recv(msg interface{}) error { // we need to stay up to date with sequence numbers r.id = req.Id - if err := r.codec.ReadBody(msg); err != nil { + r.Unlock() + err = r.codec.ReadBody(msg) + r.Lock() + if err != nil { r.err = err return err } diff --git a/server/rpc_stream_test.go b/server/rpc_stream_test.go new file mode 100644 index 00000000..18a0f0a3 --- /dev/null +++ b/server/rpc_stream_test.go @@ -0,0 +1,133 @@ +package server + +import ( + "bytes" + "fmt" + "io" + "math/rand" + "sync" + "testing" + "time" + + "github.com/golang/protobuf/proto" + "github.com/micro/go-micro/codec/json" + protoCodec "github.com/micro/go-micro/codec/proto" +) + +// protoStruct implements proto.Message +type protoStruct struct { + Payload string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` +} + +func (m *protoStruct) Reset() { *m = protoStruct{} } +func (m *protoStruct) String() string { return proto.CompactTextString(m) } +func (*protoStruct) ProtoMessage() {} + +// safeBuffer throws away everything and wont Read data back +type safeBuffer struct { + sync.RWMutex + buf []byte + off int +} + +func (b *safeBuffer) Write(p []byte) (n int, err error) { + if len(p) == 0 { + return 0, nil + } + // Cannot retain p, so we must copy it: + p2 := make([]byte, len(p)) + copy(p2, p) + b.Lock() + b.buf = append(b.buf, p2...) + b.Unlock() + return len(p2), nil +} + +func (b *safeBuffer) Read(p []byte) (n int, err error) { + if len(p) == 0 { + return 0, nil + } + b.RLock() + n = copy(p, b.buf[b.off:]) + b.RUnlock() + if n == 0 { + return 0, io.EOF + } + b.off += n + return n, nil +} + +func (b *safeBuffer) Close() error { + return nil +} + +func TestRPCStream_Sequence(t *testing.T) { + buffer := new(bytes.Buffer) + rwc := readWriteCloser{ + rbuf: buffer, + wbuf: buffer, + } + codec := json.NewCodec(&rwc) + streamServer := rpcStream{ + codec: codec, + request: &rpcRequest{ + codec: codec, + }, + } + + // Check if sequence is correct + for i := 0; i < 1000; i++ { + if err := streamServer.Send(fmt.Sprintf(`{"test":"value %d"}`, i)); err != nil { + t.Errorf("Unexpected Send error: %s", err) + } + } + + for i := 0; i < 1000; i++ { + var msg string + if err := streamServer.Recv(&msg); err != nil { + t.Errorf("Unexpected Recv error: %s", err) + } + if msg != fmt.Sprintf(`{"test":"value %d"}`, i) { + t.Errorf("Unexpected msg: %s", msg) + } + } +} + +func TestRPCStream_Concurrency(t *testing.T) { + buffer := new(safeBuffer) + codec := protoCodec.NewCodec(buffer) + streamServer := rpcStream{ + codec: codec, + request: &rpcRequest{ + codec: codec, + }, + } + + var wg sync.WaitGroup + // Check if race conditions happen + for i := 0; i < 10; i++ { + wg.Add(2) + + go func() { + for i := 0; i < 50; i++ { + msg := protoStruct{Payload: "test"} + <-time.After(time.Duration(rand.Intn(50)) * time.Millisecond) + if err := streamServer.Send(msg); err != nil { + t.Errorf("Unexpected Send error: %s", err) + } + } + wg.Done() + }() + + go func() { + for i := 0; i < 50; i++ { + <-time.After(time.Duration(rand.Intn(50)) * time.Millisecond) + if err := streamServer.Recv(&protoStruct{}); err != nil { + t.Errorf("Unexpected Recv error: %s", err) + } + } + wg.Done() + }() + } + wg.Wait() +} From 75b1a62af38f9f7d8dfc3b02355ba87d43bb2e44 Mon Sep 17 00:00:00 2001 From: Matthew Costa Date: Sun, 12 Jan 2020 14:37:12 +0000 Subject: [PATCH 108/788] Replace service prefix with FQDN style prefix (#1107) * Replace service prefix with FQDN style prefix According to the k8s documentation, the label and annotation prefixes should be in the format of a FQDN, with dot separated labels of no more than 63 characters. The current label and annotation paramteres are rejected by the k8s api, most likely because they have two forward slashes in them. * Use go.micro as service and annotation prefix --- registry/kubernetes/kubernetes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/registry/kubernetes/kubernetes.go b/registry/kubernetes/kubernetes.go index ccc22f1b..47fa7090 100644 --- a/registry/kubernetes/kubernetes.go +++ b/registry/kubernetes/kubernetes.go @@ -23,7 +23,7 @@ type kregistry struct { var ( // used on pods as labels & services to select // eg: svcSelectorPrefix+"svc.name" - servicePrefix = "micro/service/" + servicePrefix = "go.micro/" serviceValue = "service" labelTypeKey = "micro" @@ -31,7 +31,7 @@ var ( // used on k8s services to scope a serialised // micro service by pod name - annotationPrefix = "micro/service/" + annotationPrefix = "go.micro/" // Pod status podRunning = "Running" From 802cc8239aff7bda3686a312020c044a6372af3b Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Thu, 9 Jan 2020 17:48:28 +0000 Subject: [PATCH 109/788] Send solicit message properly. Updated comments. --- network/default.go | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/network/default.go b/network/default.go index 7e78b992..afe2fdeb 100644 --- a/network/default.go +++ b/network/default.go @@ -774,10 +774,10 @@ func (n *network) processNetChan(listener tunnel.Listener) { // and wants to know what's on the network. The faster we // respond the faster we start to converge - // get node peers down to MaxDepth encoded in protobuf - msg := PeersToProto(n.node, MaxDepth) - go func() { + // get node peers down to MaxDepth encoded in protobuf + msg := PeersToProto(n.node, MaxDepth) + // advertise yourself to the new node if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { log.Debugf("Network failed to advertise peers: %v", err) @@ -785,8 +785,13 @@ func (n *network) processNetChan(listener tunnel.Listener) { <-time.After(time.Millisecond * 100) + // send a solicit message when discovering new peer + solicit := &pbRtr.Solicit{ + Id: n.options.Id, + } + // ask for the new nodes routes - if err := n.sendTo("solicit", ControlChannel, peer, msg); err != nil { + if err := n.sendTo("solicit", ControlChannel, peer, solicit); err != nil { log.Debugf("Network failed to send solicit message: %s", err) } @@ -798,6 +803,8 @@ func (n *network) processNetChan(listener tunnel.Listener) { } // advertise all the routes when a new node has connected + // NOTE: this might unnecessarily flood network with advertisements + // every time a node's connection is flakey and it keeps reconnecting if err := n.router.Solicit(); err != nil { log.Debugf("Network failed to solicit routes: %s", err) } @@ -834,22 +841,23 @@ func (n *network) processNetChan(listener tunnel.Listener) { } if err := n.node.AddPeer(peer); err == nil { - // send a solicit message when discovering new peer - msg := &pbRtr.Solicit{ - Id: n.options.Id, - } - go func() { + msg := PeersToProto(n.node, MaxDepth) + // advertise yourself to the peer if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { log.Debugf("Network failed to advertise peers: %v", err) } - // wait for a second <-time.After(time.Millisecond * 100) + // send a solicit message when discovering new peer + solicit := &pbRtr.Solicit{ + Id: n.options.Id, + } + // then solicit this peer - if err := n.sendTo("solicit", ControlChannel, peer, msg); err != nil { + if err := n.sendTo("solicit", ControlChannel, peer, solicit); err != nil { log.Debugf("Network failed to send solicit message: %s", err) } @@ -1318,6 +1326,9 @@ func (n *network) connect() { if !discovered { // recreate the clients because all the tunnel links are gone // so we haven't send discovery beneath + // NOTE: when starting the tunnel for the first time we might be recreating potentially + // well functioning tunnel clients as "discovered" will be false until the + // n.discovered channel is read at some point later on. if err := n.createClients(); err != nil { log.Debugf("Failed to recreate network/control clients: %v", err) continue From 63edfaa852b93d99e705024c5fe18d043d4d30f6 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Thu, 9 Jan 2020 17:49:06 +0000 Subject: [PATCH 110/788] Added Sync message Sync message will be sent between peers when a new node connects/joins the network --- network/service/proto/network.pb.go | 174 +++++++++++++++------- network/service/proto/network.pb.micro.go | 2 +- network/service/proto/network.proto | 12 +- 3 files changed, 129 insertions(+), 59 deletions(-) diff --git a/network/service/proto/network.pb.go b/network/service/proto/network.pb.go index d94687f5..ae036d62 100644 --- a/network/service/proto/network.pb.go +++ b/network/service/proto/network.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/network/proto/network.proto +// source: network.proto package go_micro_network @@ -37,7 +37,7 @@ func (m *Query) Reset() { *m = Query{} } func (m *Query) String() string { return proto.CompactTextString(m) } func (*Query) ProtoMessage() {} func (*Query) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{0} + return fileDescriptor_8571034d60397816, []int{0} } func (m *Query) XXX_Unmarshal(b []byte) error { @@ -104,7 +104,7 @@ func (m *ConnectRequest) Reset() { *m = ConnectRequest{} } func (m *ConnectRequest) String() string { return proto.CompactTextString(m) } func (*ConnectRequest) ProtoMessage() {} func (*ConnectRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{1} + return fileDescriptor_8571034d60397816, []int{1} } func (m *ConnectRequest) XXX_Unmarshal(b []byte) error { @@ -142,7 +142,7 @@ func (m *ConnectResponse) Reset() { *m = ConnectResponse{} } func (m *ConnectResponse) String() string { return proto.CompactTextString(m) } func (*ConnectResponse) ProtoMessage() {} func (*ConnectResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{2} + return fileDescriptor_8571034d60397816, []int{2} } func (m *ConnectResponse) XXX_Unmarshal(b []byte) error { @@ -176,7 +176,7 @@ func (m *NodesRequest) Reset() { *m = NodesRequest{} } func (m *NodesRequest) String() string { return proto.CompactTextString(m) } func (*NodesRequest) ProtoMessage() {} func (*NodesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{3} + return fileDescriptor_8571034d60397816, []int{3} } func (m *NodesRequest) XXX_Unmarshal(b []byte) error { @@ -217,7 +217,7 @@ func (m *NodesResponse) Reset() { *m = NodesResponse{} } func (m *NodesResponse) String() string { return proto.CompactTextString(m) } func (*NodesResponse) ProtoMessage() {} func (*NodesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{4} + return fileDescriptor_8571034d60397816, []int{4} } func (m *NodesResponse) XXX_Unmarshal(b []byte) error { @@ -257,7 +257,7 @@ func (m *GraphRequest) Reset() { *m = GraphRequest{} } func (m *GraphRequest) String() string { return proto.CompactTextString(m) } func (*GraphRequest) ProtoMessage() {} func (*GraphRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{5} + return fileDescriptor_8571034d60397816, []int{5} } func (m *GraphRequest) XXX_Unmarshal(b []byte) error { @@ -296,7 +296,7 @@ func (m *GraphResponse) Reset() { *m = GraphResponse{} } func (m *GraphResponse) String() string { return proto.CompactTextString(m) } func (*GraphResponse) ProtoMessage() {} func (*GraphResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{6} + return fileDescriptor_8571034d60397816, []int{6} } func (m *GraphResponse) XXX_Unmarshal(b []byte) error { @@ -336,7 +336,7 @@ func (m *RoutesRequest) Reset() { *m = RoutesRequest{} } func (m *RoutesRequest) String() string { return proto.CompactTextString(m) } func (*RoutesRequest) ProtoMessage() {} func (*RoutesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{7} + return fileDescriptor_8571034d60397816, []int{7} } func (m *RoutesRequest) XXX_Unmarshal(b []byte) error { @@ -375,7 +375,7 @@ func (m *RoutesResponse) Reset() { *m = RoutesResponse{} } func (m *RoutesResponse) String() string { return proto.CompactTextString(m) } func (*RoutesResponse) ProtoMessage() {} func (*RoutesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{8} + return fileDescriptor_8571034d60397816, []int{8} } func (m *RoutesResponse) XXX_Unmarshal(b []byte) error { @@ -413,7 +413,7 @@ func (m *ServicesRequest) Reset() { *m = ServicesRequest{} } func (m *ServicesRequest) String() string { return proto.CompactTextString(m) } func (*ServicesRequest) ProtoMessage() {} func (*ServicesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{9} + return fileDescriptor_8571034d60397816, []int{9} } func (m *ServicesRequest) XXX_Unmarshal(b []byte) error { @@ -445,7 +445,7 @@ func (m *ServicesResponse) Reset() { *m = ServicesResponse{} } func (m *ServicesResponse) String() string { return proto.CompactTextString(m) } func (*ServicesResponse) ProtoMessage() {} func (*ServicesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{10} + return fileDescriptor_8571034d60397816, []int{10} } func (m *ServicesResponse) XXX_Unmarshal(b []byte) error { @@ -492,7 +492,7 @@ func (m *Node) Reset() { *m = Node{} } func (m *Node) String() string { return proto.CompactTextString(m) } func (*Node) ProtoMessage() {} func (*Node) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{11} + return fileDescriptor_8571034d60397816, []int{11} } func (m *Node) XXX_Unmarshal(b []byte) error { @@ -554,7 +554,7 @@ func (m *Connect) Reset() { *m = Connect{} } func (m *Connect) String() string { return proto.CompactTextString(m) } func (*Connect) ProtoMessage() {} func (*Connect) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{12} + return fileDescriptor_8571034d60397816, []int{12} } func (m *Connect) XXX_Unmarshal(b []byte) error { @@ -595,7 +595,7 @@ func (m *Close) Reset() { *m = Close{} } func (m *Close) String() string { return proto.CompactTextString(m) } func (*Close) ProtoMessage() {} func (*Close) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{13} + return fileDescriptor_8571034d60397816, []int{13} } func (m *Close) XXX_Unmarshal(b []byte) error { @@ -638,7 +638,7 @@ func (m *Peer) Reset() { *m = Peer{} } func (m *Peer) String() string { return proto.CompactTextString(m) } func (*Peer) ProtoMessage() {} func (*Peer) Descriptor() ([]byte, []int) { - return fileDescriptor_0b7953b26a7c4730, []int{14} + return fileDescriptor_8571034d60397816, []int{14} } func (m *Peer) XXX_Unmarshal(b []byte) error { @@ -673,6 +673,65 @@ func (m *Peer) GetPeers() []*Peer { return nil } +// Sync is network sync message +type Sync struct { + // node address + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // node peers + Peers []*Peer `protobuf:"bytes,2,rep,name=peers,proto3" json:"peers,omitempty"` + // node routes + Routes []*proto1.Route `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Sync) Reset() { *m = Sync{} } +func (m *Sync) String() string { return proto.CompactTextString(m) } +func (*Sync) ProtoMessage() {} +func (*Sync) Descriptor() ([]byte, []int) { + return fileDescriptor_8571034d60397816, []int{15} +} + +func (m *Sync) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Sync.Unmarshal(m, b) +} +func (m *Sync) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Sync.Marshal(b, m, deterministic) +} +func (m *Sync) XXX_Merge(src proto.Message) { + xxx_messageInfo_Sync.Merge(m, src) +} +func (m *Sync) XXX_Size() int { + return xxx_messageInfo_Sync.Size(m) +} +func (m *Sync) XXX_DiscardUnknown() { + xxx_messageInfo_Sync.DiscardUnknown(m) +} + +var xxx_messageInfo_Sync proto.InternalMessageInfo + +func (m *Sync) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *Sync) GetPeers() []*Peer { + if m != nil { + return m.Peers + } + return nil +} + +func (m *Sync) GetRoutes() []*proto1.Route { + if m != nil { + return m.Routes + } + return nil +} + func init() { proto.RegisterType((*Query)(nil), "go.micro.network.Query") proto.RegisterType((*ConnectRequest)(nil), "go.micro.network.ConnectRequest") @@ -690,48 +749,49 @@ func init() { proto.RegisterType((*Connect)(nil), "go.micro.network.Connect") proto.RegisterType((*Close)(nil), "go.micro.network.Close") proto.RegisterType((*Peer)(nil), "go.micro.network.Peer") + proto.RegisterType((*Sync)(nil), "go.micro.network.Sync") } -func init() { - proto.RegisterFile("github.com/micro/go-micro/network/proto/network.proto", fileDescriptor_0b7953b26a7c4730) -} +func init() { proto.RegisterFile("network.proto", fileDescriptor_8571034d60397816) } -var fileDescriptor_0b7953b26a7c4730 = []byte{ - // 576 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x61, 0x6a, 0xdb, 0x4c, - 0x10, 0x8d, 0x2c, 0xcb, 0x76, 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, 0xff, 0xa7, 0x5b, 0x0a, 0x25, 0x2c, 0x06, 0x00, 0x00, +var fileDescriptor_8571034d60397816 = []byte{ + // 594 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0xc1, 0x6a, 0xdb, 0x40, + 0x10, 0x8d, 0x2c, 0x29, 0x76, 0xa6, 0x91, 0xeb, 0x2e, 0x25, 0x15, 0x3a, 0xb4, 0xee, 0xe2, 0x43, + 0x28, 0x8d, 0x0c, 0x09, 0x85, 0x52, 0xd3, 0x10, 0x08, 0xa5, 0x50, 0x48, 0x48, 0xe5, 0x1f, 0xa8, + 0x62, 0x2d, 0xb6, 0x49, 0xac, 0x75, 0x56, 0xeb, 0x04, 0x5f, 0x7a, 0xed, 0x27, 0xf4, 0x9b, 0xfa, + 0x57, 0x65, 0x77, 0x47, 0x8e, 0x14, 0xcb, 0x22, 0xbe, 0x79, 0x34, 0x6f, 0xde, 0xec, 0xce, 0x7b, + 0xb3, 0x06, 0x2f, 0x65, 0xf2, 0x81, 0x8b, 0x9b, 0x70, 0x2e, 0xb8, 0xe4, 0xa4, 0x33, 0xe6, 0xe1, + 0x6c, 0x3a, 0x12, 0x3c, 0xc4, 0xef, 0xc1, 0x60, 0x3c, 0x95, 0x93, 0xc5, 0x75, 0x38, 0xe2, 0xb3, + 0xbe, 0xce, 0xf4, 0xc7, 0xfc, 0xc8, 0xfc, 0x10, 0x7c, 0x21, 0x99, 0xe8, 0x67, 0x4c, 0xdc, 0x4f, + 0x47, 0xac, 0xaf, 0x19, 0xf0, 0xa3, 0xa1, 0xa3, 0x7f, 0x2c, 0x70, 0x7f, 0x2e, 0x98, 0x58, 0x12, + 0x1f, 0x9a, 0x88, 0xf3, 0xad, 0xae, 0x75, 0xb8, 0x17, 0xe5, 0xa1, 0xca, 0xc4, 0x49, 0x22, 0x58, + 0x96, 0xf9, 0x0d, 0x93, 0xc1, 0x50, 0x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0xe9, 0xa7, 0xa2, 0x8a, 0xab, 0xf8, 0xd2, 0x54, 0x71, 0x95, 0xde, 0x18, 0xba, 0x43, + 0x2e, 0x60, 0xd7, 0x2c, 0x25, 0xa9, 0x00, 0x97, 0xd6, 0x3d, 0xe8, 0x6e, 0x06, 0xac, 0xe8, 0x86, + 0xd0, 0xca, 0xd7, 0x91, 0x54, 0xcc, 0xe5, 0xc9, 0xf6, 0x06, 0xb4, 0x0e, 0x92, 0x93, 0x5e, 0xef, + 0xea, 0x3f, 0x89, 0x93, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x78, 0x0e, 0x14, 0x60, 0x84, 0x06, + 0x00, 0x00, } diff --git a/network/service/proto/network.pb.micro.go b/network/service/proto/network.pb.micro.go index 488d0c97..cc01d095 100644 --- a/network/service/proto/network.pb.micro.go +++ b/network/service/proto/network.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/network/proto/network.proto +// source: network.proto package go_micro_network diff --git a/network/service/proto/network.proto b/network/service/proto/network.proto index b4dece64..b498e1bb 100644 --- a/network/service/proto/network.proto +++ b/network/service/proto/network.proto @@ -54,7 +54,7 @@ message GraphResponse { Peer root = 1; } -message RoutesRequest { +message RoutesRequest { // filter based on Query query = 1; } @@ -100,3 +100,13 @@ message Peer { // node peers repeated Peer peers = 2; } + +// Sync is network sync message +message Sync { + // node address + string address = 1; + // node peers + repeated Peer peers = 2; + // node routes + repeated go.micro.router.Route routes = 3; +} From 0a4bd02503d6088396da62c1cb723840d0ebefec Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Fri, 10 Jan 2020 10:43:07 +0000 Subject: [PATCH 111/788] Add RefreshSync method for Sync bookkeeping --- network/node.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/network/node.go b/network/node.go index 0d79ffc5..ec9b9962 100644 --- a/network/node.go +++ b/network/node.go @@ -36,6 +36,8 @@ type node struct { network Network // lastSeen keeps track of node lifetime and updates lastSeen time.Time + // lastSync keeps track of node last sync request + lastSync time.Time } // Id is node ide @@ -127,7 +129,7 @@ func (n *node) UpdatePeer(peer *node) error { return ErrPeerNotFound } -// RefreshPeer updates node timestamp +// RefreshPeer updates node last seen timestamp // It returns false if the peer has not been found. func (n *node) RefreshPeer(id, link string, now time.Time) error { n.Lock() @@ -146,6 +148,16 @@ func (n *node) RefreshPeer(id, link string, now time.Time) error { return nil } +// RefreshSync refreshes nodes sync time +func (n *node) RefreshSync(now time.Time) error { + n.Lock() + defer n.Unlock() + + n.lastSync = now + + return nil +} + // Nodes returns a slice of all nodes in the whole node topology func (n *node) Nodes() []Node { // we need to freeze the network graph here From bf42c028fbebad7c186fa240d998dfb4c7d5f4e5 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Fri, 10 Jan 2020 11:57:34 +0000 Subject: [PATCH 112/788] Added sync message. Refactored connect flow. Adverts are gossipped. This commit adds a Sync message which is sent as a reply to Connect message. This should in theory speed up convergence of a (re)connecting node. We respond to Sync message by sending a peer message back to the peer origin of the Sync message. We consequently update our routing table and peer graph with the data sent in via Sync message. We now gossip advertse to up to 3 randomly selected peers instead of sending a multicast message to the network. Equally, Solicitation i.e. full table adverts are gossipped to a randomly selected peer. If that fails we send a multicast message to the network. --- network/default.go | 168 +++++++++++++++++++++++----- network/service/proto/network.pb.go | 97 ++++++++-------- network/service/proto/network.proto | 8 +- util/proto/proto.go | 33 ++++++ 4 files changed, 222 insertions(+), 84 deletions(-) create mode 100644 util/proto/proto.go diff --git a/network/default.go b/network/default.go index afe2fdeb..ce5f7703 100644 --- a/network/default.go +++ b/network/default.go @@ -6,6 +6,7 @@ import ( "hash/fnv" "io" "math" + "math/rand" "sort" "sync" "time" @@ -25,6 +26,7 @@ import ( tun "github.com/micro/go-micro/tunnel/transport" "github.com/micro/go-micro/util/backoff" "github.com/micro/go-micro/util/log" + pbUtil "github.com/micro/go-micro/util/proto" ) var ( @@ -270,9 +272,9 @@ func (n *network) acceptCtrlConn(l tunnel.Listener, recv chan *message) { } } -// handleCtrlConn handles ControlChannel connections // advertise advertises routes to the network func (n *network) advertise(advertChan <-chan *router.Advert) { + rnd := rand.New(rand.NewSource(time.Now().UnixNano())) hasher := fnv.New64() for { select { @@ -322,11 +324,22 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { Events: events, } - // send the advert to all on the control channel - // since its not a solicitation + // send the advert to a select number of random peers if advert.Type != router.Solicitation { - if err := n.sendMsg("advert", ControlChannel, msg); err != nil { - log.Debugf("Network failed to advertise routes: %v", err) + // get a list of node peers + peers := n.Peers() + + // advertise to max 3 peers + max := len(peers) + if max > 3 { + max = 3 + } + for i := 0; i < max; i++ { + if peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()); peer != nil { + if err := n.sendTo("advert", ControlChannel, peer, msg); err != nil { + log.Debugf("Network failed to advertise routes: %v", err) + } + } } continue } @@ -338,8 +351,16 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { // someone requested the route n.sendTo("advert", ControlChannel, peer, msg) default: - if err := n.sendMsg("advert", ControlChannel, msg); err != nil { - log.Debugf("Network failed to advertise routes: %v", err) + // get a list of node peers + peers := n.Peers() + // pick a random peer from the list of peers + peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()) + if err := n.sendTo("advert", ControlChannel, peer, msg); err != nil { + log.Debugf("Network failed to advertise routes to %s: %v, sending multicast", err, peer.Id()) + // send a multicast message if we fail to send Unicast message + if err := n.sendMsg("advert", ControlChannel, msg); err != nil { + log.Debugf("Network failed to advertise routes: %v", err) + } } } case <-n.closed: @@ -460,6 +481,7 @@ func (n *network) handleNetConn(s tunnel.Session, msg chan *message) { } } +// handleCtrlConn handles ControlChannel connections func (n *network) handleCtrlConn(s tunnel.Session, msg chan *message) { for { m := new(transport.Message) @@ -733,8 +755,8 @@ func (n *network) processNetChan(listener tunnel.Listener) { case "connect": // mark the time the message has been received now := time.Now() - pbNetConnect := &pbNet.Connect{} + pbNetConnect := &pbNet.Connect{} if err := proto.Unmarshal(m.msg.Body, pbNetConnect); err != nil { log.Debugf("Network tunnel [%s] connect unmarshal error: %v", NetworkChannel, err) continue @@ -757,35 +779,61 @@ func (n *network) processNetChan(listener tunnel.Listener) { // update peer links + // TODO: should we do this only if we manage to add a peer + // What should we do if the peer links failed to be updated? if err := n.updatePeerLinks(peer); err != nil { log.Debugf("Network failed updating peer links: %s", err) } // add peer to the list of node peers - if err := n.node.AddPeer(peer); err == ErrPeerExists { + if err := n.AddPeer(peer); err == ErrPeerExists { log.Tracef("Network peer exists, refreshing: %s", peer.id) - // update lastSeen time for the existing node + // update lastSeen time for the peer if err := n.RefreshPeer(peer.id, peer.link, now); err != nil { log.Debugf("Network failed refreshing peer %s: %v", peer.id, err) } } - // we send the peer message because someone has sent connect - // and wants to know what's on the network. The faster we - // respond the faster we start to converge + // we send the sync message because someone has sent connect + // and wants to either connect or reconnect to the network + // The faster it gets the network config (routes and peer graph) + // the faster the network converges to a stable state go func() { - // get node peers down to MaxDepth encoded in protobuf - msg := PeersToProto(n.node, MaxDepth) + // get node peer graph to send back to the connecting node + node := PeersToProto(n.node, MaxDepth) - // advertise yourself to the new node - if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { - log.Debugf("Network failed to advertise peers: %v", err) + msg := &pbNet.Sync{ + Peer: node, } + // get a list of all of our routes + routes, err := n.options.Router.Table().List() + switch err { + case nil: + // encode the routes to protobuf + pbRoutes := make([]*pbRtr.Route, 0, len(routes)) + for _, route := range routes { + pbRoute := pbUtil.RouteToProto(route) + pbRoutes = append(pbRoutes, pbRoute) + } + // pack the routes into the sync message + msg.Routes = pbRoutes + default: + // we can't list the routes + log.Debugf("Network node %s failed listing routes: %v", n.id, err) + } + + // send sync message to the newly connected peer + if err := n.sendTo("sync", NetworkChannel, peer, msg); err != nil { + log.Debugf("Network failed to send sync message: %v", err) + } + // wait for a short period of time before sending a solicit message <-time.After(time.Millisecond * 100) // send a solicit message when discovering new peer + // this triggers the node to flush its routing table to the network + // and leads to faster convergence of the network solicit := &pbRtr.Solicit{ Id: n.options.Id, } @@ -801,13 +849,6 @@ func (n *network) processNetChan(listener tunnel.Listener) { default: // don't block } - - // advertise all the routes when a new node has connected - // NOTE: this might unnecessarily flood network with advertisements - // every time a node's connection is flakey and it keeps reconnecting - if err := n.router.Solicit(); err != nil { - log.Debugf("Network failed to solicit routes: %s", err) - } }() case "peer": // mark the time the message has been received @@ -836,10 +877,13 @@ func (n *network) processNetChan(listener tunnel.Listener) { // update peer links + // TODO: should we do this only if we manage to add a peer + // What should we do if the peer links failed to be updated? if err := n.updatePeerLinks(peer); err != nil { log.Debugf("Network failed updating peer links: %s", err) } + // if it's a new peer i.e. we do not have it in our graph, we solicit its routes if err := n.node.AddPeer(peer); err == nil { go func() { msg := PeersToProto(n.node, MaxDepth) @@ -875,7 +919,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { }() continue - // we're expecting any error to be ErrPeerExists + // if we already have the peer in our graph, skip further steps } else if err != ErrPeerExists { log.Debugf("Network got error adding peer %v", err) continue @@ -905,6 +949,75 @@ func (n *network) processNetChan(listener tunnel.Listener) { default: // don't block here } + case "sync": + // record the timestamp of the message receipt + now := time.Now() + + pbNetSync := &pbNet.Sync{} + if err := proto.Unmarshal(m.msg.Body, pbNetSync); err != nil { + log.Debugf("Network tunnel [%s] sync unmarshal error: %v", NetworkChannel, err) + continue + } + + // don't process your own messages + if pbNetSync.Peer.Node.Id == n.options.Id { + continue + } + + log.Debugf("Network received sync message from: %s", pbNetSync.Peer.Node.Id) + + peer := &node{ + id: pbNetSync.Peer.Node.Id, + address: pbNetSync.Peer.Node.Address, + link: m.msg.Header["Micro-Link"], + peers: make(map[string]*node), + lastSeen: now, + } + + // update peer links + + // TODO: should we do this only if we manage to add a peer + // What should we do if the peer links failed to be updated? + if err := n.updatePeerLinks(peer); err != nil { + log.Debugf("Network failed updating peer links: %s", err) + } + + // add peer to the list of node peers + if err := n.node.AddPeer(peer); err == ErrPeerExists { + log.Tracef("Network peer exists, refreshing: %s", peer.id) + // update lastSeen time for the existing node + if err := n.RefreshPeer(peer.id, peer.link, now); err != nil { + log.Debugf("Network failed refreshing peer %s: %v", peer.id, err) + } + } + + // when we receive a sync message we update our routing table + // and send a peer message back to the network to announce our presence + // we consequently flush our table to the network too to make the convergence faster + + go func() { + // add all the routes we have received in the sync message + for _, pbRoute := range pbNetSync.Routes { + route := pbUtil.ProtoToRoute(pbRoute) + if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { + log.Debugf("Network node %s failed to add route: %v", n.id, err) + } + } + + // update your sync timestamp + // NOTE: this might go away as we will be doing full table advert to random peer + if err := n.RefreshSync(now); err != nil { + log.Debugf("Network failed refreshing sync time: %v", err) + } + + // get node peer graph to send back to the syncing node + msg := PeersToProto(n.node, MaxDepth) + + // advertise yourself to the new node + if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { + log.Debugf("Network failed to advertise peers: %v", err) + } + }() case "close": pbNetClose := &pbNet.Close{} if err := proto.Unmarshal(m.msg.Body, pbNetClose); err != nil { @@ -932,6 +1045,9 @@ func (n *network) processNetChan(listener tunnel.Listener) { log.Debugf("Network failed pruning peer %s routes: %v", peer.id, err) } + // NOTE: we should maybe advertise this to the network so we converge faster on closed nodes + // as opposed to our waiting until the node eventually gets pruned; something to think about + // delete peer from the peerLinks n.Lock() delete(n.peerLinks, pbNetClose.Node.Address) diff --git a/network/service/proto/network.pb.go b/network/service/proto/network.pb.go index ae036d62..aa98ff3e 100644 --- a/network/service/proto/network.pb.go +++ b/network/service/proto/network.pb.go @@ -675,12 +675,10 @@ func (m *Peer) GetPeers() []*Peer { // Sync is network sync message type Sync struct { - // node address - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - // node peers - Peers []*Peer `protobuf:"bytes,2,rep,name=peers,proto3" json:"peers,omitempty"` + // peer origin + Peer *Peer `protobuf:"bytes,1,opt,name=peer,proto3" json:"peer,omitempty"` // node routes - Routes []*proto1.Route `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` + Routes []*proto1.Route `protobuf:"bytes,2,rep,name=routes,proto3" json:"routes,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -711,16 +709,9 @@ func (m *Sync) XXX_DiscardUnknown() { var xxx_messageInfo_Sync proto.InternalMessageInfo -func (m *Sync) GetAddress() string { +func (m *Sync) GetPeer() *Peer { if m != nil { - return m.Address - } - return "" -} - -func (m *Sync) GetPeers() []*Peer { - if m != nil { - return m.Peers + return m.Peer } return nil } @@ -755,43 +746,43 @@ func init() { func init() { proto.RegisterFile("network.proto", fileDescriptor_8571034d60397816) } var fileDescriptor_8571034d60397816 = []byte{ - // 594 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0xc1, 0x6a, 0xdb, 0x40, - 0x10, 0x8d, 0x2c, 0x29, 0x76, 0xa6, 0x91, 0xeb, 0x2e, 0x25, 0x15, 0x3a, 0xb4, 0xee, 0xe2, 0x43, - 0x28, 0x8d, 0x0c, 0x09, 0x85, 0x52, 0xd3, 0x10, 0x08, 0xa5, 0x50, 0x48, 0x48, 0xe5, 0x1f, 0xa8, - 0x62, 0x2d, 0xb6, 0x49, 0xac, 0x75, 0x56, 0xeb, 0x04, 0x5f, 0x7a, 0xed, 0x27, 0xf4, 0x9b, 0xfa, - 0x57, 0x65, 0x77, 0x47, 0x8e, 0x14, 0xcb, 0x22, 0xbe, 0x79, 0x34, 0x6f, 0xde, 0xec, 0xce, 0x7b, - 0xb3, 0x06, 0x2f, 0x65, 0xf2, 0x81, 0x8b, 0x9b, 0x70, 0x2e, 0xb8, 0xe4, 0xa4, 0x33, 0xe6, 0xe1, - 0x6c, 0x3a, 0x12, 0x3c, 0xc4, 0xef, 0xc1, 0x60, 0x3c, 0x95, 0x93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 0xf4, 0x37, 0x38, 0xc3, 0x65, 0x3a, 0x2a, 0x0a, 0x61, - 0x95, 0x85, 0xd8, 0x8a, 0xaf, 0x60, 0x2e, 0xfb, 0x39, 0xe6, 0x3a, 0xfe, 0x6b, 0x43, 0xf3, 0x12, - 0x85, 0xbd, 0x7a, 0x9c, 0x6c, 0x77, 0xbd, 0x4b, 0xf9, 0x81, 0x08, 0xde, 0xd7, 0x20, 0xf0, 0x09, - 0xd8, 0x21, 0x3f, 0xc0, 0xd5, 0x9b, 0x47, 0xde, 0xae, 0xa3, 0x8b, 0x8b, 0x1b, 0xbc, 0xdb, 0x98, - 0x2f, 0x72, 0xe9, 0xa7, 0xa2, 0x8a, 0xab, 0xf8, 0xd2, 0x54, 0x71, 0x95, 0xde, 0x18, 0xba, 0x43, - 0x2e, 0x60, 0xd7, 0x2c, 0x25, 0xa9, 0x00, 0x97, 0xd6, 0x3d, 0xe8, 0x6e, 0x06, 0xac, 0xe8, 0x86, - 0xd0, 0xca, 0xd7, 0x91, 0x54, 0xcc, 0xe5, 0xc9, 0xf6, 0x06, 0xb4, 0x0e, 0x92, 0x93, 0x5e, 0xef, - 0xea, 0x3f, 0x89, 0x93, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x78, 0x0e, 0x14, 0x60, 0x84, 0x06, - 0x00, 0x00, + // 593 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0x5d, 0x6a, 0xdb, 0x40, + 0x10, 0x8e, 0x2c, 0x29, 0x3f, 0xd3, 0xc8, 0x75, 0x97, 0x92, 0x0a, 0x3d, 0xb4, 0xee, 0xe2, 0x87, + 0x50, 0x1a, 0x19, 0x12, 0x0a, 0xa5, 0xa6, 0x21, 0x10, 0x4a, 0xa1, 0x90, 0x90, 0xca, 0x17, 0xa8, + 0x6c, 0x0d, 0xb6, 0x49, 0xac, 0x75, 0x56, 0xeb, 0x04, 0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 0xec, + 0x6b, 0x44, 0x51, 0x06, 0x7c, 0x0d, 0x7e, 0x86, 0x13, 0x35, 0x34, 0x05, 0x06, 0x89, 0x35, 0xf8, + 0x57, 0x08, 0x08, 0x65, 0x69, 0xcf, 0xcc, 0xdb, 0x82, 0xfd, 0xef, 0x32, 0x9d, 0x0c, 0x37, 0x27, + 0xe9, 0x40, 0x40, 0x28, 0x4a, 0xf2, 0x01, 0x3c, 0x29, 0x84, 0x32, 0xa8, 0xca, 0x1c, 0x57, 0x88, + 0x32, 0x31, 0x18, 0x7e, 0x0a, 0x41, 0xa2, 0xdb, 0x37, 0x2f, 0xe4, 0x08, 0xfc, 0x5b, 0x3d, 0x34, + 0x62, 0xbf, 0x59, 0x65, 0x9b, 0x99, 0x26, 0x16, 0xc5, 0xcf, 0xa0, 0x5e, 0xf2, 0x29, 0x7b, 0x4c, + 0xe3, 0xa9, 0xa8, 0x91, 0xe4, 0x61, 0x08, 0x34, 0x36, 0xd3, 0xdc, 0xae, 0x55, 0x43, 0x79, 0x07, + 0x1e, 0x43, 0xe3, 0xe1, 0x88, 0xc2, 0x46, 0xb0, 0x4b, 0xa2, 0xb1, 0x81, 0xf7, 0x92, 0xb9, 0xcd, + 0xff, 0x3a, 0xe0, 0xe9, 0xbe, 0xb1, 0x3a, 0xd4, 0x46, 0x19, 0x69, 0xac, 0x36, 0xca, 0x36, 0xcb, + 0xab, 0x14, 0x8b, 0xbb, 0x24, 0x16, 0x76, 0x06, 0xbb, 0x63, 0x54, 0x69, 0x96, 0xaa, 0x34, 0xf4, + 0x4c, 0x05, 0xad, 0xea, 0x29, 0xc5, 0x17, 0x04, 0xfb, 0x96, 0x2b, 0x39, 0x4b, 0xe6, 0xac, 0xa8, + 0x03, 0xc1, 0x92, 0x8b, 0x35, 0xc0, 0xbd, 0xc6, 0x19, 0xdd, 0x4b, 0x7f, 0xea, 0x49, 0xde, 0xa5, + 0x37, 0x53, 0xa4, 0x6b, 0x59, 0xe3, 0x4b, 0xed, 0xb3, 0xc3, 0x3f, 0xc1, 0x0e, 0x69, 0x4d, 0xcf, + 0x51, 0xeb, 0x60, 0xfd, 0x1c, 0x8d, 0x56, 0x0c, 0x86, 0x9f, 0x80, 0x7f, 0x7e, 0x23, 0xec, 0xf0, + 0x9f, 0x4c, 0xfa, 0x05, 0x9e, 0x96, 0xc2, 0x73, 0x38, 0x5a, 0xc1, 0x13, 0x44, 0xa9, 0x1b, 0xea, + 0x6e, 0x50, 0x97, 0x05, 0xf1, 0x1e, 0x78, 0xdd, 0x59, 0xde, 0xd7, 0x19, 0xf4, 0xc1, 0xff, 0x24, + 0xa9, 0x31, 0x0b, 0x02, 0xaa, 0x3d, 0x45, 0x40, 0xc7, 0x7f, 0x5c, 0xd8, 0xb9, 0xa4, 0xe1, 0x5d, + 0x3d, 0x74, 0xaf, 0xb9, 0x9a, 0x64, 0xf9, 0x11, 0x88, 0xde, 0x6f, 0x40, 0xd0, 0x9a, 0x6f, 0xb1, + 0x1f, 0xe0, 0x9b, 0xed, 0x62, 0x6f, 0x57, 0xd1, 0x8b, 0xcb, 0x19, 0xbd, 0x5b, 0xeb, 0x5f, 0x8c, + 0x65, 0x9e, 0x83, 0xaa, 0x58, 0x8b, 0xaf, 0x49, 0x55, 0xac, 0xa5, 0x77, 0x84, 0x6f, 0xb1, 0x0b, + 0xd8, 0xb6, 0x8b, 0xc7, 0x2a, 0xc0, 0x4b, 0x2b, 0x1d, 0x35, 0xd7, 0x03, 0xe6, 0xe1, 0xba, 0xb0, + 0x5b, 0xae, 0x1c, 0xab, 0xe8, 0xcb, 0xa3, 0x0d, 0x8d, 0xf8, 0x26, 0x48, 0x19, 0xb4, 0xb7, 0x6d, + 0x7e, 0x04, 0x27, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x66, 0x66, 0x42, 0x5f, 0x68, 0x06, 0x00, + 0x00, } diff --git a/network/service/proto/network.proto b/network/service/proto/network.proto index b498e1bb..ee02cf8f 100644 --- a/network/service/proto/network.proto +++ b/network/service/proto/network.proto @@ -103,10 +103,8 @@ message Peer { // Sync is network sync message message Sync { - // node address - string address = 1; - // node peers - repeated Peer peers = 2; + // peer origin + Peer peer = 1; // node routes - repeated go.micro.router.Route routes = 3; + repeated go.micro.router.Route routes = 2; } diff --git a/util/proto/proto.go b/util/proto/proto.go new file mode 100644 index 00000000..1e41c61c --- /dev/null +++ b/util/proto/proto.go @@ -0,0 +1,33 @@ +// Package proto contains utility functions for working with protobufs +package proto + +import ( + "github.com/micro/go-micro/router" + pbRtr "github.com/micro/go-micro/router/service/proto" +) + +// RouteToProto encodes route into protobuf and returns it +func RouteToProto(route router.Route) *pbRtr.Route { + return &pbRtr.Route{ + Service: route.Service, + Address: route.Address, + Gateway: route.Gateway, + Network: route.Network, + Router: route.Router, + Link: route.Link, + Metric: int64(route.Metric), + } +} + +// ProtoToRoute decodes protobuf route into router route and returns it +func ProtoToRoute(route *pbRtr.Route) router.Route { + return router.Route{ + Service: route.Service, + Address: route.Address, + Gateway: route.Gateway, + Network: route.Network, + Router: route.Router, + Link: route.Link, + Metric: route.Metric, + } +} From 1e009e52dd228501f91738ecbe465dc116526083 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Fri, 10 Jan 2020 12:27:49 +0000 Subject: [PATCH 113/788] Avoid having the same log statements in initNodes and resolveNodes --- network/default.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/default.go b/network/default.go index ce5f7703..e0697f18 100644 --- a/network/default.go +++ b/network/default.go @@ -375,7 +375,7 @@ func (n *network) initNodes(startup bool) { // NOTE: this condition never fires // as resolveNodes() never returns error if err != nil && !startup { - log.Debugf("Network failed to resolve nodes: %v", err) + log.Debugf("Network failed to init nodes: %v", err) return } From 11904e11372853cd8dbebc6d5adc9689c99a5cb1 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Fri, 10 Jan 2020 19:02:42 +0000 Subject: [PATCH 114/788] Regular sync with network every 5 minutes. Apply routes before peering. --- network/default.go | 81 ++++++++++++++++++++++++++++++++++------------ network/network.go | 2 ++ 2 files changed, 62 insertions(+), 21 deletions(-) diff --git a/network/default.go b/network/default.go index e0697f18..15530c47 100644 --- a/network/default.go +++ b/network/default.go @@ -354,12 +354,13 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { // get a list of node peers peers := n.Peers() // pick a random peer from the list of peers - peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()) - if err := n.sendTo("advert", ControlChannel, peer, msg); err != nil { - log.Debugf("Network failed to advertise routes to %s: %v, sending multicast", err, peer.Id()) - // send a multicast message if we fail to send Unicast message - if err := n.sendMsg("advert", ControlChannel, msg); err != nil { - log.Debugf("Network failed to advertise routes: %v", err) + if peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()); peer != nil { + if err := n.sendTo("advert", ControlChannel, peer, msg); err != nil { + log.Debugf("Network failed to advertise routes to %s: %v, sending multicast", peer.Id(), err) + // send a multicast message if we fail to send Unicast message + if err := n.sendMsg("advert", ControlChannel, msg); err != nil { + log.Debugf("Network failed to advertise routes: %v", err) + } } } } @@ -993,23 +994,22 @@ func (n *network) processNetChan(listener tunnel.Listener) { // when we receive a sync message we update our routing table // and send a peer message back to the network to announce our presence - // we consequently flush our table to the network too to make the convergence faster + + // add all the routes we have received in the sync message + for _, pbRoute := range pbNetSync.Routes { + route := pbUtil.ProtoToRoute(pbRoute) + if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { + log.Debugf("Network node %s failed to add route: %v", n.id, err) + } + } + + // update your sync timestamp + // NOTE: this might go away as we will be doing full table advert to random peer + if err := n.RefreshSync(now); err != nil { + log.Debugf("Network failed refreshing sync time: %v", err) + } go func() { - // add all the routes we have received in the sync message - for _, pbRoute := range pbNetSync.Routes { - route := pbUtil.ProtoToRoute(pbRoute) - if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { - log.Debugf("Network node %s failed to add route: %v", n.id, err) - } - } - - // update your sync timestamp - // NOTE: this might go away as we will be doing full table advert to random peer - if err := n.RefreshSync(now); err != nil { - log.Debugf("Network failed refreshing sync time: %v", err) - } - // get node peer graph to send back to the syncing node msg := PeersToProto(n.node, MaxDepth) @@ -1100,12 +1100,15 @@ func (n *network) prunePeerRoutes(peer *node) error { // seen for a period of time. Also removes all the routes either originated by or routable // by the stale nodes. it also resolves nodes periodically and adds them to the tunnel func (n *network) manage() { + rnd := rand.New(rand.NewSource(time.Now().UnixNano())) announce := time.NewTicker(AnnounceTime) defer announce.Stop() prune := time.NewTicker(PruneTime) defer prune.Stop() resolve := time.NewTicker(ResolveTime) defer resolve.Stop() + netsync := time.NewTicker(SyncTime) + defer netsync.Stop() // list of links we've sent to links := make(map[string]time.Time) @@ -1253,6 +1256,42 @@ func (n *network) manage() { log.Debugf("Network failed deleting routes by %s: %v", route.Router, err) } } + case <-netsync.C: + // get a list of node peers + peers := n.Peers() + // pick a random peer from the list of peers and request full sync + if peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()); peer != nil { + go func() { + // get node peer graph to send back to the connecting node + node := PeersToProto(n.node, MaxDepth) + + msg := &pbNet.Sync{ + Peer: node, + } + + // get a list of all of our routes + routes, err := n.options.Router.Table().List() + switch err { + case nil: + // encode the routes to protobuf + pbRoutes := make([]*pbRtr.Route, 0, len(routes)) + for _, route := range routes { + pbRoute := pbUtil.RouteToProto(route) + pbRoutes = append(pbRoutes, pbRoute) + } + // pack the routes into the sync message + msg.Routes = pbRoutes + default: + // we can't list the routes + log.Debugf("Network node %s failed listing routes: %v", n.id, err) + } + + // send sync message to the newly connected peer + if err := n.sendTo("sync", NetworkChannel, peer, msg); err != nil { + log.Debugf("Network failed to send sync message: %v", err) + } + }() + } case <-resolve.C: n.initNodes(false) } diff --git a/network/network.go b/network/network.go index 571deee1..5d959e1d 100644 --- a/network/network.go +++ b/network/network.go @@ -19,6 +19,8 @@ var ( AnnounceTime = 1 * time.Second // KeepAliveTime is the time in which we want to have sent a message to a peer KeepAliveTime = 30 * time.Second + // SyncTime is the time a network node requests full sync from the network + SyncTime = 5 * time.Minute // PruneTime defines time interval to periodically check nodes that need to be pruned // due to their not announcing their presence within this time interval PruneTime = 90 * time.Second From 770c7686babec754a82a2ee1bab0f067f0b3e8de Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Mon, 13 Jan 2020 20:02:56 +0000 Subject: [PATCH 115/788] Fix nasty bug when graph action may not have been executed in some branches --- network/node.go | 50 ++++++++++++++++++++++++++++++++++++++++++-- network/node_test.go | 19 +++++++++++++++-- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/network/node.go b/network/node.go index ec9b9962..159f15f9 100644 --- a/network/node.go +++ b/network/node.go @@ -38,6 +38,8 @@ type node struct { lastSeen time.Time // lastSync keeps track of node last sync request lastSync time.Time + // errCount tracks error count when communicating with peer + errCount int } // Id is node ide @@ -71,15 +73,17 @@ func (n *node) walk(until func(peer *node) bool, action func(parent, peer *node) for queue.Len() > 0 { // pop the node from the front of the queue qnode := queue.Front() + //fmt.Printf("qnodeValue: %v\n", qnode.Value.(*node)) if until(qnode.Value.(*node)) { return visited } // iterate through all of the node peers // mark the visited nodes; enqueue the non-visted for id, peer := range qnode.Value.(*node).peers { + action(qnode.Value.(*node), peer) if _, ok := visited[id]; !ok { visited[id] = peer - action(qnode.Value.(*node), peer) + //action(qnode.Value.(*node), peer) queue.PushBack(peer) } } @@ -229,7 +233,25 @@ func (n *node) DeletePeerNode(id string) error { return nil } -// PruneStalePeerNodes prune the peers that have not been seen for longer than given time +// PrunePeer prunes the peers with the given id +func (n *node) PrunePeer(id string) { + n.Lock() + defer n.Unlock() + + untilNoMorePeers := func(node *node) bool { + return node == nil + } + + prunePeer := func(parent, node *node) { + if node.id != n.id && node.id == id { + delete(parent.peers, node.id) + } + } + + n.walk(untilNoMorePeers, prunePeer) +} + +// PruneStalePeerNodes prunes the peers that have not been seen for longer than pruneTime // It returns a map of the the nodes that got pruned func (n *node) PruneStalePeers(pruneTime time.Duration) map[string]*node { n.Lock() @@ -252,6 +274,30 @@ func (n *node) PruneStalePeers(pruneTime time.Duration) map[string]*node { return pruned } +// IncErrCount increments node error count +func (n *node) IncErrCount() { + n.Lock() + defer n.Unlock() + + n.errCount++ +} + +// ResetErrCount reset node error count +func (n *node) ResetErrCount() { + n.Lock() + defer n.Unlock() + + n.errCount = 0 +} + +// ErrCount returns node error count +func (n *node) ErrCount() int { + n.RLock() + defer n.RUnlock() + + return n.errCount +} + // getTopology traverses node graph and builds node topology // NOTE: this function is not thread safe func (n *node) getTopology(depth uint) *node { diff --git a/network/node_test.go b/network/node_test.go index 51c4988f..7f2efe3b 100644 --- a/network/node_test.go +++ b/network/node_test.go @@ -215,7 +215,22 @@ func TestDeletePeerNode(t *testing.T) { } } -func TestPruneStalePeerNodes(t *testing.T) { +func TestPrunePeer(t *testing.T) { + // complicated node graph + node := testSetup() + + before := node.Nodes() + + node.PrunePeer("peer3") + + now := node.Nodes() + + if len(now) != len(before)-1 { + t.Errorf("Expected pruned node count: %d, got: %d", len(before)-1, len(now)) + } +} + +func TestPruneStalePeers(t *testing.T) { // complicated node graph node := testSetup() @@ -224,7 +239,7 @@ func TestPruneStalePeerNodes(t *testing.T) { pruneTime := 10 * time.Millisecond time.Sleep(pruneTime) - // should delete all nodes besides node + // should delete all nodes besides (root) node pruned := node.PruneStalePeers(pruneTime) if len(pruned) != len(nodes)-1 { From efcac3d009430964047d916bddfa7fff9a1fa904 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Mon, 13 Jan 2020 20:06:02 +0000 Subject: [PATCH 116/788] Define tunnel errors --- tunnel/default.go | 8 ++++---- tunnel/tunnel.go | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tunnel/default.go b/tunnel/default.go index cc8e78be..798bc886 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -384,7 +384,7 @@ func (t *tun) process() { // if the link is not connected skip it if !connected { log.Debugf("Link for node %s not connected", id) - err = errors.New("link not connected") + err = ErrLinkDisconnected continue } @@ -392,14 +392,14 @@ func (t *tun) process() { // and the message is being sent outbound via // a dialled connection don't use this link if loopback && msg.outbound { - err = errors.New("link is loopback") + err = ErrLinkLoopback continue } // if the message was being returned by the loopback listener // send it back up the loopback link only if msg.loopback && !loopback { - err = errors.New("link is not loopback") + err = ErrLinkRemote continue } @@ -414,7 +414,7 @@ func (t *tun) process() { // this is where we explicitly set the link // in a message received via the listen method if len(msg.link) > 0 && id != msg.link { - err = errors.New("link not found") + err = ErrLinkNotFound continue } } diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index b59eb31d..516ce6c0 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -26,6 +26,12 @@ var ( ErrDiscoverChan = errors.New("failed to discover channel") // ErrLinkNotFound is returned when a link is specified at dial time and does not exist ErrLinkNotFound = errors.New("link not found") + // ErrLinkDisconnected is returned when a link we attempt to send to is disconnected + ErrLinkDisconnected = errors.New("link not connected") + // ErrLinkLoppback is returned when attempting to send an outbound message over loopback link + ErrLinkLoopback = errors.New("link is loopback") + // ErrLinkRemote is returned when attempting to send a loopback message over remote link + ErrLinkRemote = errors.New("link is remote") // ErrReadTimeout is a timeout on session.Recv ErrReadTimeout = errors.New("read timeout") // ErrDecryptingData is for when theres a nonce error From b4261e8cf9f8815375e1d549d5743725041d3d1e Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Mon, 13 Jan 2020 20:07:10 +0000 Subject: [PATCH 117/788] Updated log and comments --- network/default.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/network/default.go b/network/default.go index 15530c47..831118a5 100644 --- a/network/default.go +++ b/network/default.go @@ -337,7 +337,7 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { for i := 0; i < max; i++ { if peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()); peer != nil { if err := n.sendTo("advert", ControlChannel, peer, msg); err != nil { - log.Debugf("Network failed to advertise routes: %v", err) + log.Debugf("Network failed to advertise routes to %s: %v", peer.Id(), err) } } } @@ -359,7 +359,7 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { log.Debugf("Network failed to advertise routes to %s: %v, sending multicast", peer.Id(), err) // send a multicast message if we fail to send Unicast message if err := n.sendMsg("advert", ControlChannel, msg); err != nil { - log.Debugf("Network failed to advertise routes: %v", err) + log.Debugf("Network failed to advertise routes to %s: %v", peer.Id(), err) } } } @@ -516,10 +516,11 @@ func (n *network) handleCtrlConn(s tunnel.Session, msg chan *message) { } // getHopCount queries network graph and returns hop count for given router +// NOTE: this should be called getHopeMetric // - Routes for local services have hop count 1 -// - Routes with ID of adjacent nodes have hop count 2 -// - Routes by peers of the advertiser have hop count 3 -// - Routes beyond node neighbourhood have hop count 4 +// - Routes with ID of adjacent nodes have hop count 10 +// - Routes by peers of the advertiser have hop count 100 +// - Routes beyond node neighbourhood have hop count 1000 func (n *network) getHopCount(rtr string) int { // make sure node.peers are not modified n.node.RLock() @@ -1207,7 +1208,7 @@ func (n *network) manage() { // unknown link and peer so lets do the connect flow if err := n.sendTo("connect", NetworkChannel, peer, msg); err != nil { - log.Debugf("Network failed to advertise peer %s: %v", peer.id, err) + log.Debugf("Network failed to connect %s: %v", peer.id, err) continue } From a91dad04eeabc4bbddb7a5e3178ddb4299cef7b7 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Mon, 13 Jan 2020 22:22:12 +0000 Subject: [PATCH 118/788] Increment node error count and prune when Max limit is hit --- network/default.go | 20 +++++++++++++++- network/node.go | 57 +++++++++++++++++++++++++--------------------- 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/network/default.go b/network/default.go index 831118a5..e80f5d8d 100644 --- a/network/default.go +++ b/network/default.go @@ -38,6 +38,8 @@ var ( DefaultLink = "network" // MaxConnections is the max number of network client connections MaxConnections = 3 + // MaxPeerErrors is the max number of peer errors before we remove it from network graph + MaxPeerErrors = 3 ) var ( @@ -45,6 +47,8 @@ var ( ErrClientNotFound = errors.New("client not found") // ErrPeerLinkNotFound is returned when peer link could not be found in tunnel Links ErrPeerLinkNotFound = errors.New("peer link not found") + // ErrPeerMaxExceeded is returned when peer has reached its max error count limit + ErrPeerMaxExceeded = errors.New("peer max errors exceeded") ) // network implements Network interface @@ -1327,6 +1331,11 @@ func (n *network) sendTo(method, channel string, peer *node, msg proto.Message) // Create a unicast connection to the peer but don't do the open/accept flow c, err := n.tunnel.Dial(channel, tunnel.DialWait(false), tunnel.DialLink(peer.link)) if err != nil { + // increment the peer error count; prune peer if we exceed MaxPeerErrors + peer.err.Increment() + if count := peer.err.GetCount(); count == MaxPeerErrors { + n.PrunePeer(peer.id) + } return err } defer c.Close() @@ -1351,7 +1360,16 @@ func (n *network) sendTo(method, channel string, peer *node, msg proto.Message) tmsg.Header["Micro-Peer"] = peer.id } - return c.Send(tmsg) + if err := c.Send(tmsg); err != nil { + // increment the peer error count; prune peer if we exceed MaxPeerErrors + peer.err.Increment() + if count := peer.err.GetCount(); count == MaxPeerErrors { + n.PrunePeer(peer.id) + } + return err + } + + return nil } // sendMsg sends a message to the tunnel channel diff --git a/network/node.go b/network/node.go index 159f15f9..a5d3ad91 100644 --- a/network/node.go +++ b/network/node.go @@ -21,6 +21,35 @@ var ( ErrPeerNotFound = errors.New("peer not found") ) +type nodeError struct { + sync.RWMutex + count int +} + +// Increment increments node error count +func (n *nodeError) Increment() { + n.Lock() + defer n.Unlock() + + n.count++ +} + +// Reset reset node error count +func (n *nodeError) Reset() { + n.Lock() + defer n.Unlock() + + n.count = 0 +} + +// GetCount returns node error count +func (n *nodeError) GetCount() int { + n.RLock() + defer n.RUnlock() + + return n.count +} + // node is network node type node struct { sync.RWMutex @@ -38,8 +67,8 @@ type node struct { lastSeen time.Time // lastSync keeps track of node last sync request lastSync time.Time - // errCount tracks error count when communicating with peer - errCount int + // err tracks node errors + err nodeError } // Id is node ide @@ -274,30 +303,6 @@ func (n *node) PruneStalePeers(pruneTime time.Duration) map[string]*node { return pruned } -// IncErrCount increments node error count -func (n *node) IncErrCount() { - n.Lock() - defer n.Unlock() - - n.errCount++ -} - -// ResetErrCount reset node error count -func (n *node) ResetErrCount() { - n.Lock() - defer n.Unlock() - - n.errCount = 0 -} - -// ErrCount returns node error count -func (n *node) ErrCount() int { - n.RLock() - defer n.RUnlock() - - return n.errCount -} - // getTopology traverses node graph and builds node topology // NOTE: this function is not thread safe func (n *node) getTopology(depth uint) *node { From 994d371ff1bd67a976c99c644f1e321672411c6d Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 14 Jan 2020 10:49:34 +0000 Subject: [PATCH 119/788] Removed redundant comments. Add proper PruneStalePeers test. --- network/node.go | 2 -- network/node_test.go | 21 +++++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/network/node.go b/network/node.go index a5d3ad91..caacc7fd 100644 --- a/network/node.go +++ b/network/node.go @@ -102,7 +102,6 @@ func (n *node) walk(until func(peer *node) bool, action func(parent, peer *node) for queue.Len() > 0 { // pop the node from the front of the queue qnode := queue.Front() - //fmt.Printf("qnodeValue: %v\n", qnode.Value.(*node)) if until(qnode.Value.(*node)) { return visited } @@ -112,7 +111,6 @@ func (n *node) walk(until func(peer *node) bool, action func(parent, peer *node) action(qnode.Value.(*node), peer) if _, ok := visited[id]; !ok { visited[id] = peer - //action(qnode.Value.(*node), peer) queue.PushBack(peer) } } diff --git a/network/node_test.go b/network/node_test.go index 7f2efe3b..fc3088df 100644 --- a/network/node_test.go +++ b/network/node_test.go @@ -233,9 +233,8 @@ func TestPrunePeer(t *testing.T) { func TestPruneStalePeers(t *testing.T) { // complicated node graph node := testSetup() - nodes := node.Nodes() - + // this will delete all nodes besides the root node pruneTime := 10 * time.Millisecond time.Sleep(pruneTime) @@ -245,6 +244,24 @@ func TestPruneStalePeers(t *testing.T) { if len(pruned) != len(nodes)-1 { t.Errorf("Expected pruned node count: %d, got: %d", len(nodes)-1, len(pruned)) } + + // complicated node graph + node = testSetup() + nodes = node.Nodes() + + // set prune time to 100ms and wait for half of it + pruneTime = 100 * time.Millisecond + time.Sleep(pruneTime) + + // update the time of peer1 + node.peers["peer1"].lastSeen = time.Now() + + // should prune all but the root nodes and peer1 + pruned = node.PruneStalePeers(pruneTime) + + if len(pruned) != len(nodes)-2 { + t.Errorf("Expected pruned node count: %d, got: %d", len(nodes)-2, len(pruned)) + } } func TestUnpackPeerTopology(t *testing.T) { From b699d969e474727080cbf78c97f48da7dadd306d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 14 Jan 2020 11:20:13 +0000 Subject: [PATCH 120/788] if the address is produced by a default route don't hash it (#1108) --- network/default.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/default.go b/network/default.go index 7e78b992..f8f9ef9b 100644 --- a/network/default.go +++ b/network/default.go @@ -286,7 +286,7 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { address := event.Route.Address // only hash the address if we're advertising our own local routes - if event.Route.Router == advert.Id { + if event.Route.Router == advert.Id && event.Route.Address != "*" { // hash the service before advertising it hasher.Reset() // routes for multiple instances of a service will be collapsed here. From 1d311ab457ef208de696652178a4f4d34805d16b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 14 Jan 2020 13:23:16 +0000 Subject: [PATCH 121/788] Embedded NATS Broker (#1110) * if the address is produced by a default route don't hash it * embedded nats * fix url parsing * don't override help * add ready flag --- broker/http_broker.go | 13 +-- broker/nats/nats.go | 254 +++++++++++++++++++++++++++++++++++++---- broker/nats/options.go | 6 + broker/options.go | 4 +- config/cmd/cmd.go | 9 +- defaults.go | 7 ++ go.mod | 3 + go.sum | 10 ++ util/addr/addr.go | 23 ++++ util/addr/addr_test.go | 20 ++++ 10 files changed, 308 insertions(+), 41 deletions(-) diff --git a/broker/http_broker.go b/broker/http_broker.go index 41d80f5d..98430dae 100644 --- a/broker/http_broker.go +++ b/broker/http_broker.go @@ -106,8 +106,9 @@ func newTransport(config *tls.Config) *http.Transport { func newHttpBroker(opts ...Option) Broker { options := Options{ - Codec: json.Marshaler{}, - Context: context.TODO(), + Codec: json.Marshaler{}, + Context: context.TODO(), + Registry: registry.DefaultRegistry, } for _, o := range opts { @@ -120,17 +121,11 @@ func newHttpBroker(opts ...Option) Broker { addr = options.Addrs[0] } - // get registry - reg, ok := options.Context.Value(registryKey).(registry.Registry) - if !ok { - reg = registry.DefaultRegistry - } - h := &httpBroker{ id: uuid.New().String(), address: addr, opts: options, - r: reg, + r: options.Registry, c: &http.Client{Transport: newTransport(options.TLSConfig)}, subscribers: make(map[string][]*httpSubscriber), exit: make(chan chan error), diff --git a/broker/nats/nats.go b/broker/nats/nats.go index a72f7682..775c92f0 100644 --- a/broker/nats/nats.go +++ b/broker/nats/nats.go @@ -4,23 +4,44 @@ package nats import ( "context" "errors" + "net" + "net/url" + "strconv" "strings" "sync" + "time" "github.com/micro/go-micro/broker" "github.com/micro/go-micro/codec/json" + "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/util/addr" + "github.com/micro/go-micro/util/log" + "github.com/nats-io/nats-server/v2/server" nats "github.com/nats-io/nats.go" ) type natsBroker struct { sync.Once sync.RWMutex - addrs []string - conn *nats.Conn - opts broker.Options - nopts nats.Options + + // indicate if we're connected + connected bool + + addrs []string + conn *nats.Conn + opts broker.Options + nopts nats.Options + + // should we drain the connection drain bool closeCh chan (error) + + // embedded server + server *server.Server + // configure to use local server + local bool + // server exit channel + exit chan bool } type subscriber struct { @@ -62,6 +83,7 @@ func (n *natsBroker) Address() string { if n.conn != nil && n.conn.IsConnected() { return n.conn.ConnectedUrl() } + if len(n.addrs) > 0 { return n.addrs[0] } @@ -69,7 +91,7 @@ func (n *natsBroker) Address() string { return "" } -func setAddrs(addrs []string) []string { +func (n *natsBroker) setAddrs(addrs []string) []string { //nolint:prealloc var cAddrs []string for _, addr := range addrs { @@ -81,16 +103,178 @@ func setAddrs(addrs []string) []string { } cAddrs = append(cAddrs, addr) } - if len(cAddrs) == 0 { + // if there's no address and we weren't told to + // embed a local server then use the default url + if len(cAddrs) == 0 && !n.local { cAddrs = []string{nats.DefaultURL} } return cAddrs } +// serve stats a local nats server if needed +func (n *natsBroker) serve(exit chan bool) error { + var host string + var port int + var local bool + + // with no address we just default it + // this is a local client address + if len(n.addrs) == 0 || n.local { + host = "127.0.0.1" + port = -1 + local = true + // with a local address we parse it + } else { + address := n.addrs[0] + if strings.HasPrefix(address, "nats://") { + address = strings.TrimPrefix(address, "nats://") + } + + if addr.IsLocal(address) { + h, p, err := net.SplitHostPort(address) + if err == nil { + host = h + port, _ = strconv.Atoi(p) + local = true + } + } + } + + // we only setup a server for local things + if !local { + return nil + } + + // 1. create new server + // 2. register the server + // 3. connect to other servers + var cOpts server.ClusterOpts + var routes []*url.URL + + // get existing nats servers to connect to + services, err := n.opts.Registry.GetService("go.micro.nats.broker") + if err == nil { + for _, service := range services { + for _, node := range service.Nodes { + u, err := url.Parse("nats://" + node.Address) + if err != nil { + log.Log(err) + continue + } + // append to the cluster routes + routes = append(routes, u) + } + } + } + + // try get existing server + s := n.server + + // get a host address + caddr, err := addr.Extract("") + if err != nil { + caddr = "0.0.0.0" + } + + // set cluster opts + cOpts = server.ClusterOpts{ + Host: caddr, + Port: -1, + } + + if s == nil { + var err error + s, err = server.NewServer(&server.Options{ + // Specify the host + Host: host, + // Use a random port + Port: port, + // Set the cluster ops + Cluster: cOpts, + // Set the routes + Routes: routes, + NoLog: true, + NoSigs: true, + MaxControlLine: 2048, + TLSConfig: n.opts.TLSConfig, + }) + if err != nil { + return err + } + + // save the server + n.server = s + } + + // start the server + go s.Start() + + var ready bool + + // wait till its ready for connections + for i := 0; i < 3; i++ { + if s.ReadyForConnections(time.Second) { + ready = true + break + } + } + + if !ready { + return errors.New("server not ready") + } + + // set the client address + n.addrs = []string{s.ClientURL()} + + go func() { + // register the cluster address + for { + select { + case <-exit: + // deregister on exit + n.opts.Registry.Deregister(®istry.Service{ + Name: "go.micro.nats.broker", + Version: "v2", + Nodes: []*registry.Node{ + {Id: s.ID(), Address: s.ClusterAddr().String()}, + }, + }) + s.Shutdown() + return + default: + // register the broker + n.opts.Registry.Register(®istry.Service{ + Name: "go.micro.nats.broker", + Version: "v2", + Nodes: []*registry.Node{ + {Id: s.ID(), Address: s.ClusterAddr().String()}, + }, + }, registry.RegisterTTL(time.Minute)) + time.Sleep(time.Minute) + } + } + }() + + return nil +} + func (n *natsBroker) Connect() error { n.Lock() defer n.Unlock() + if !n.connected { + // create exit chan + n.exit = make(chan bool) + + // start the server if needed + if err := n.serve(n.exit); err != nil { + return err + } + + // set to connected + n.connected = true + } + status := nats.CLOSED if n.conn != nil { status = n.conn.Status() @@ -122,11 +306,29 @@ func (n *natsBroker) Connect() error { func (n *natsBroker) Disconnect() error { n.RLock() defer n.RUnlock() + + // drain the connection if specified if n.drain { n.conn.Drain() return <-n.closeCh } + + // close the client connection n.conn.Close() + + // shutdown the local server + // and deregister + if n.server != nil { + select { + case <-n.exit: + default: + close(n.exit) + } + } + + // set not connected + n.connected = false + return nil } @@ -191,21 +393,6 @@ func (n *natsBroker) String() string { return "nats" } -func NewBroker(opts ...broker.Option) broker.Broker { - options := broker.Options{ - // Default codec - Codec: json.Marshaler{}, - Context: context.Background(), - } - - n := &natsBroker{ - opts: options, - } - n.setOption(opts...) - - return n -} - func (n *natsBroker) setOption(opts ...broker.Option) { for _, o := range opts { o(&n.opts) @@ -219,10 +406,15 @@ func (n *natsBroker) setOption(opts ...broker.Option) { n.nopts = nopts } + local, ok := n.opts.Context.Value(localServerKey{}).(bool) + if ok { + n.local = local + } + // broker.Options have higher priority than nats.Options // only if Addrs, Secure or TLSConfig were not set through a broker.Option // we read them from nats.Option - if len(n.opts.Addrs) == 0 { + if len(n.opts.Addrs) == 0 && !n.local { n.opts.Addrs = n.nopts.Servers } @@ -233,7 +425,7 @@ func (n *natsBroker) setOption(opts ...broker.Option) { if n.opts.TLSConfig == nil { n.opts.TLSConfig = n.nopts.TLSConfig } - n.addrs = setAddrs(n.opts.Addrs) + n.addrs = n.setAddrs(n.opts.Addrs) if n.opts.Context.Value(drainConnectionKey{}) != nil { n.drain = true @@ -254,3 +446,19 @@ func (n *natsBroker) onAsyncError(conn *nats.Conn, sub *nats.Subscription, err e n.closeCh <- err } } + +func NewBroker(opts ...broker.Option) broker.Broker { + options := broker.Options{ + // Default codec + Codec: json.Marshaler{}, + Context: context.Background(), + Registry: registry.DefaultRegistry, + } + + n := &natsBroker{ + opts: options, + } + n.setOption(opts...) + + return n +} diff --git a/broker/nats/options.go b/broker/nats/options.go index b5b106c0..ae8ca80d 100644 --- a/broker/nats/options.go +++ b/broker/nats/options.go @@ -7,12 +7,18 @@ import ( type optionsKey struct{} type drainConnectionKey struct{} +type localServerKey struct{} // Options accepts nats.Options func Options(opts nats.Options) broker.Option { return setBrokerOption(optionsKey{}, opts) } +// LocalServer embeds a local server rather than connecting to one +func LocalServer() broker.Option { + return setBrokerOption(localServerKey{}, true) +} + // DrainConnection will drain subscription on close func DrainConnection() broker.Option { return setBrokerOption(drainConnectionKey{}, struct{}{}) diff --git a/broker/options.go b/broker/options.go index 9a60e150..f0877a27 100644 --- a/broker/options.go +++ b/broker/options.go @@ -13,6 +13,8 @@ type Options struct { Secure bool Codec codec.Marshaler TLSConfig *tls.Config + // Registry used for clustering + Registry registry.Registry // Other options for implementations of the interface // can be stored in a context Context context.Context @@ -92,7 +94,7 @@ func Queue(name string) SubscribeOption { func Registry(r registry.Registry) Option { return func(o *Options) { - o.Context = context.WithValue(o.Context, registryKey, r) + o.Registry = r } } diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 83dfcc46..f553f44b 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -3,9 +3,7 @@ package cmd import ( "fmt" - "io" "math/rand" - "os" "strings" "time" @@ -273,7 +271,7 @@ var ( // used for default selection as the fall back defaultClient = "grpc" defaultServer = "grpc" - defaultBroker = "http" + defaultBroker = "nats" defaultRegistry = "mdns" defaultSelector = "registry" defaultTransport = "http" @@ -283,11 +281,6 @@ var ( func init() { rand.Seed(time.Now().Unix()) - help := cli.HelpPrinter - cli.HelpPrinter = func(writer io.Writer, templ string, data interface{}) { - help(writer, templ, data) - os.Exit(0) - } } func newCmd(opts ...Option) Cmd { diff --git a/defaults.go b/defaults.go index 0159f19c..65844c23 100644 --- a/defaults.go +++ b/defaults.go @@ -1,17 +1,24 @@ package micro import ( + "github.com/micro/go-micro/broker" "github.com/micro/go-micro/client" "github.com/micro/go-micro/server" "github.com/micro/go-micro/store" // set defaults + "github.com/micro/go-micro/broker/nats" gcli "github.com/micro/go-micro/client/grpc" gsrv "github.com/micro/go-micro/server/grpc" memStore "github.com/micro/go-micro/store/memory" ) func init() { + // default broker + broker.DefaultBroker = nats.NewBroker( + // embedded nats server + nats.LocalServer(), + ) // default client client.DefaultClient = gcli.NewClient() // default server diff --git a/go.mod b/go.mod index 58b17fb5..8308c9d4 100644 --- a/go.mod +++ b/go.mod @@ -32,6 +32,9 @@ require ( github.com/micro/mdns v0.3.0 github.com/miekg/dns v1.1.26 github.com/mitchellh/hashstructure v1.0.0 + github.com/nats-io/gnatsd v1.4.1 // indirect + github.com/nats-io/nats-server v1.4.1 + github.com/nats-io/nats-server/v2 v2.1.2 github.com/nats-io/nats.go v1.9.1 github.com/nlopes/slack v0.6.0 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c diff --git a/go.sum b/go.sum index 71f5b50f..23a96d27 100644 --- a/go.sum +++ b/go.sum @@ -253,12 +253,22 @@ github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8d github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= +github.com/nats-io/gnatsd v1.4.1 h1:RconcfDeWpKCD6QIIwiVFcvForlXpWeJP7i5/lDLy44= +github.com/nats-io/gnatsd v1.4.1/go.mod h1:nqco77VO78hLCJpIcVfygDP2rPGfsEHkGTUk94uh5DQ= github.com/nats-io/jwt v0.3.0 h1:xdnzwFETV++jNc4W1mw//qFyJGb2ABOombmZJQS4+Qo= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= +github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= +github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= +github.com/nats-io/nats-server v1.4.1 h1:Ul1oSOGNV/L8kjr4v6l2f9Yet6WY+LevH1/7cRZ/qyA= +github.com/nats-io/nats-server v1.4.1/go.mod h1:c8f/fHd2B6Hgms3LtCaI7y6pC4WD1f4SUxcCud5vhBc= +github.com/nats-io/nats-server/v2 v2.1.2 h1:i2Ly0B+1+rzNZHHWtD4ZwKi+OU5l+uQo1iDHZ2PmiIc= +github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= github.com/nats-io/nkeys v0.1.0 h1:qMd4+pRHgdr1nAClu+2h/2a5F2TmKcCzjCDazVgRoX4= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= +github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= +github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= diff --git a/util/addr/addr.go b/util/addr/addr.go index eb0a5972..fafe8b56 100644 --- a/util/addr/addr.go +++ b/util/addr/addr.go @@ -27,6 +27,29 @@ func isPrivateIP(ipAddr string) bool { return false } +// IsLocal tells us whether an ip is local +func IsLocal(addr string) bool { + // extract the host + host, _, err := net.SplitHostPort(addr) + if err == nil { + addr = host + } + + // check if its localhost + if addr == "localhost" { + return true + } + + // check against all local ips + for _, ip := range IPs() { + if addr == ip { + return true + } + } + + return false +} + // Extract returns a real ip func Extract(addr string) (string, error) { // if addr specified then its returned diff --git a/util/addr/addr_test.go b/util/addr/addr_test.go index ad23b128..06aae9a6 100644 --- a/util/addr/addr_test.go +++ b/util/addr/addr_test.go @@ -5,6 +5,26 @@ import ( "testing" ) +func TestIsLocal(t *testing.T) { + testData := []struct { + addr string + expect bool + }{ + {"localhost", true}, + {"localhost:8080", true}, + {"127.0.0.1", true}, + {"127.0.0.1:1001", true}, + {"80.1.1.1", false}, + } + + for _, d := range testData { + res := IsLocal(d.addr) + if res != d.expect { + t.Fatalf("expected %t got %t", d.expect, res) + } + } +} + func TestExtractor(t *testing.T) { testData := []struct { addr string From 821fda41ae54eb59548fff40c0447b7ec55669ba Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 14 Jan 2020 18:12:36 +0000 Subject: [PATCH 122/788] Added Status method to network.Node fixed random segfaults. --- network/default.go | 58 +++-- network/network.go | 16 ++ network/node.go | 122 ++++++++-- network/node_test.go | 8 + network/service/proto/network.pb.go | 272 ++++++++++++++++++---- network/service/proto/network.pb.micro.go | 19 ++ network/service/proto/network.proto | 21 ++ 7 files changed, 432 insertions(+), 84 deletions(-) diff --git a/network/default.go b/network/default.go index e80f5d8d..39e29b4b 100644 --- a/network/default.go +++ b/network/default.go @@ -165,6 +165,7 @@ func newNetwork(opts ...Option) Network { id: options.Id, address: peerAddress, peers: make(map[string]*node), + status: newStatus(), }, options: options, router: options.Router, @@ -780,6 +781,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { address: pbNetConnect.Node.Address, link: m.msg.Header["Micro-Link"], peers: make(map[string]*node), + status: newStatus(), lastSeen: now, } @@ -874,10 +876,16 @@ func (n *network) processNetChan(listener tunnel.Listener) { log.Debugf("Network received peer message from: %s %s", pbNetPeer.Node.Id, pbNetPeer.Node.Address) peer := &node{ - id: pbNetPeer.Node.Id, - address: pbNetPeer.Node.Address, - link: m.msg.Header["Micro-Link"], - peers: make(map[string]*node), + id: pbNetPeer.Node.Id, + address: pbNetPeer.Node.Address, + link: m.msg.Header["Micro-Link"], + peers: make(map[string]*node), + status: &status{ + err: &nerr{ + count: int(pbNetPeer.Node.Status.Error.Count), + msg: errors.New(pbNetPeer.Node.Status.Error.Msg), + }, + }, lastSeen: now, } @@ -973,10 +981,16 @@ func (n *network) processNetChan(listener tunnel.Listener) { log.Debugf("Network received sync message from: %s", pbNetSync.Peer.Node.Id) peer := &node{ - id: pbNetSync.Peer.Node.Id, - address: pbNetSync.Peer.Node.Address, - link: m.msg.Header["Micro-Link"], - peers: make(map[string]*node), + id: pbNetSync.Peer.Node.Id, + address: pbNetSync.Peer.Node.Address, + link: m.msg.Header["Micro-Link"], + peers: make(map[string]*node), + status: &status{ + err: &nerr{ + count: int(pbNetSync.Peer.Node.Status.Error.Count), + msg: errors.New(pbNetSync.Peer.Node.Status.Error.Msg), + }, + }, lastSeen: now, } @@ -1328,13 +1342,19 @@ func (n *network) sendTo(method, channel string, peer *node, msg proto.Message) if err != nil { return err } + // Create a unicast connection to the peer but don't do the open/accept flow c, err := n.tunnel.Dial(channel, tunnel.DialWait(false), tunnel.DialLink(peer.link)) if err != nil { - // increment the peer error count; prune peer if we exceed MaxPeerErrors - peer.err.Increment() - if count := peer.err.GetCount(); count == MaxPeerErrors { - n.PrunePeer(peer.id) + if peerNode := n.GetPeerNode(peer.id); peerNode != nil { + log.Debugf("Network found peer %s: %v", peer.id, peerNode) + // update node status when error happens + peerNode.status.err.Update(err) + log.Debugf("Network increment node peer %p %v count to: %d", peerNode, peerNode, peerNode.status.Error().Count()) + if count := peerNode.status.Error().Count(); count == MaxPeerErrors { + log.Debugf("Network node peer %v count exceeded %d: %d", peerNode, MaxPeerErrors, peerNode.status.Error().Count()) + n.PrunePeer(peerNode.id) + } } return err } @@ -1361,10 +1381,16 @@ func (n *network) sendTo(method, channel string, peer *node, msg proto.Message) } if err := c.Send(tmsg); err != nil { - // increment the peer error count; prune peer if we exceed MaxPeerErrors - peer.err.Increment() - if count := peer.err.GetCount(); count == MaxPeerErrors { - n.PrunePeer(peer.id) + // TODO: Lookup peer in our graph + if peerNode := n.GetPeerNode(peer.id); peerNode != nil { + log.Debugf("Network found peer %s: %v", peer.id, peerNode) + // update node status when error happens + peerNode.status.err.Update(err) + log.Debugf("Network increment node peer %p %v count to: %d", peerNode, peerNode, peerNode.status.Error().Count()) + if count := peerNode.status.Error().Count(); count == MaxPeerErrors { + log.Debugf("Network node peer %v count exceeded %d: %d", peerNode, MaxPeerErrors, peerNode.status.Error().Count()) + n.PrunePeer(peerNode.id) + } } return err } diff --git a/network/network.go b/network/network.go index 5d959e1d..e06cd2c6 100644 --- a/network/network.go +++ b/network/network.go @@ -26,6 +26,20 @@ var ( PruneTime = 90 * time.Second ) +// Error is network node errors +type Error interface { + // Count is current count of errors + Count() int + // Msg is last error message + Msg() string +} + +// Status is node status +type Status interface { + // Error reports error status + Error() Error +} + // Node is network node type Node interface { // Id is node id @@ -36,6 +50,8 @@ type Node interface { Peers() []Node // Network is the network node is in Network() Network + // Status returns node status + Status() Status } // Network is micro network diff --git a/network/node.go b/network/node.go index caacc7fd..a7f3c51a 100644 --- a/network/node.go +++ b/network/node.go @@ -21,33 +21,62 @@ var ( ErrPeerNotFound = errors.New("peer not found") ) -type nodeError struct { +// nerr tracks node errors +type nerr struct { sync.RWMutex count int + msg error } // Increment increments node error count -func (n *nodeError) Increment() { - n.Lock() - defer n.Unlock() +func (e *nerr) Update(err error) { + e.Lock() + defer e.Unlock() - n.count++ + e.count++ + e.msg = err } -// Reset reset node error count -func (n *nodeError) Reset() { - n.Lock() - defer n.Unlock() +// Count returns node error count +func (e *nerr) Count() int { + e.RLock() + defer e.RUnlock() - n.count = 0 + return e.count } -// GetCount returns node error count -func (n *nodeError) GetCount() int { - n.RLock() - defer n.RUnlock() +func (e *nerr) Msg() string { + e.RLock() + defer e.RUnlock() - return n.count + if e.msg != nil { + return e.msg.Error() + } + + return "" +} + +// status returns node status +type status struct { + sync.RWMutex + err *nerr +} + +// newStatus creates +func newStatus() *status { + return &status{ + err: new(nerr), + } +} + +func (s *status) Error() Error { + s.RLock() + defer s.RUnlock() + + return &nerr{ + count: s.err.count, + msg: s.err.msg, + } } // node is network node @@ -67,8 +96,8 @@ type node struct { lastSeen time.Time // lastSync keeps track of node last sync request lastSync time.Time - // err tracks node errors - err nodeError + // err tracks node status + status *status } // Id is node ide @@ -86,6 +115,19 @@ func (n *node) Network() Network { return n.network } +// Status returns node status +func (n *node) Status() Status { + n.RLock() + defer n.RUnlock() + + return &status{ + err: &nerr{ + count: n.status.err.count, + msg: n.status.err.msg, + }, + } +} + // walk walks the node graph until some condition is met func (n *node) walk(until func(peer *node) bool, action func(parent, peer *node)) map[string]*node { // track the visited nodes @@ -127,7 +169,28 @@ func (n *node) AddPeer(peer *node) error { n.Lock() defer n.Unlock() + // get node topology: we need to check if the peer + // we are trying to add is already in our graph + top := n.getTopology(MaxDepth) + + untilFoundPeer := func(n *node) bool { + return n.id == peer.id + } + + justWalk := func(paent, node *node) {} + + visited := top.walk(untilFoundPeer, justWalk) + + peerNode, inTop := visited[peer.id] + if _, ok := n.peers[peer.id]; !ok { + if inTop { + // just create a new edge to the existing peer + // but make sure you update the peer link + peerNode.link = peer.link + n.peers[peer.id] = peerNode + return nil + } n.peers[peer.id] = peer return nil } @@ -310,6 +373,7 @@ func (n *node) getTopology(depth uint) *node { address: n.address, peers: make(map[string]*node), network: n.network, + status: n.status, lastSeen: n.lastSeen, } @@ -358,9 +422,15 @@ func (n *node) Peers() []Node { // UnpackPeerTopology unpacks pb.Peer into node topology of given depth func UnpackPeerTopology(pbPeer *pb.Peer, lastSeen time.Time, depth uint) *node { peerNode := &node{ - id: pbPeer.Node.Id, - address: pbPeer.Node.Address, - peers: make(map[string]*node), + id: pbPeer.Node.Id, + address: pbPeer.Node.Address, + peers: make(map[string]*node), + status: &status{ + err: &nerr{ + count: int(pbPeer.Node.Status.Error.Count), + msg: errors.New(pbPeer.Node.Status.Error.Msg), + }, + }, lastSeen: lastSeen, } @@ -387,6 +457,12 @@ func peerProtoTopology(peer Node, depth uint) *pb.Peer { node := &pb.Node{ Id: peer.Id(), Address: peer.Address(), + Status: &pb.Status{ + Error: &pb.Error{ + Count: uint32(peer.Status().Error().Count()), + Msg: peer.Status().Error().Msg(), + }, + }, } // set the network name if network is not nil @@ -422,6 +498,12 @@ func PeersToProto(node Node, depth uint) *pb.Peer { pbNode := &pb.Node{ Id: node.Id(), Address: node.Address(), + Status: &pb.Status{ + Error: &pb.Error{ + Count: uint32(node.Status().Error().Count()), + Msg: node.Status().Error().Msg(), + }, + }, } // set the network name if network is not nil diff --git a/network/node_test.go b/network/node_test.go index fc3088df..d4849a1c 100644 --- a/network/node_test.go +++ b/network/node_test.go @@ -21,6 +21,7 @@ func testSetup() *node { address: testNodeAddress, peers: make(map[string]*node), network: newNetwork(Name(testNodeNetName)), + err: new(nodeError), } // add some peers to the node @@ -30,6 +31,7 @@ func testSetup() *node { address: testNode.address + "-" + id, peers: make(map[string]*node), network: testNode.network, + err: new(nodeError), } } @@ -41,6 +43,7 @@ func testSetup() *node { address: testNode.address + "-" + id, peers: make(map[string]*node), network: testNode.network, + err: new(nodeError), } } @@ -269,6 +272,7 @@ func TestUnpackPeerTopology(t *testing.T) { Node: &pb.Node{ Id: "newPeer", Address: "newPeerAddress", + Err: &pb.NodeError{}, }, Peers: make([]*pb.Peer, 0), } @@ -284,12 +288,14 @@ func TestUnpackPeerTopology(t *testing.T) { pbPeer1Node := &pb.Node{ Id: peer1.id, Address: peer1.address, + Err: &pb.NodeError{}, } pbPeer111 := &pb.Peer{ Node: &pb.Node{ Id: "peer111", Address: "peer111Address", + Err: &pb.NodeError{}, }, Peers: make([]*pb.Peer, 0), } @@ -298,6 +304,7 @@ func TestUnpackPeerTopology(t *testing.T) { Node: &pb.Node{ Id: "peer121", Address: "peer121Address", + Err: &pb.NodeError{}, }, Peers: make([]*pb.Peer, 0), } @@ -324,6 +331,7 @@ func TestPeersToProto(t *testing.T) { address: testNodeAddress, peers: make(map[string]*node), network: newNetwork(Name(testNodeNetName)), + err: &nodeError{}, } topCount := 0 diff --git a/network/service/proto/network.pb.go b/network/service/proto/network.pb.go index aa98ff3e..54902c65 100644 --- a/network/service/proto/network.pb.go +++ b/network/service/proto/network.pb.go @@ -473,6 +473,164 @@ func (m *ServicesResponse) GetServices() []string { return nil } +type StatusRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *StatusRequest) Reset() { *m = StatusRequest{} } +func (m *StatusRequest) String() string { return proto.CompactTextString(m) } +func (*StatusRequest) ProtoMessage() {} +func (*StatusRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8571034d60397816, []int{11} +} + +func (m *StatusRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_StatusRequest.Unmarshal(m, b) +} +func (m *StatusRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_StatusRequest.Marshal(b, m, deterministic) +} +func (m *StatusRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_StatusRequest.Merge(m, src) +} +func (m *StatusRequest) XXX_Size() int { + return xxx_messageInfo_StatusRequest.Size(m) +} +func (m *StatusRequest) XXX_DiscardUnknown() { + xxx_messageInfo_StatusRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_StatusRequest proto.InternalMessageInfo + +type StatusResponse struct { + Status *Status `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *StatusResponse) Reset() { *m = StatusResponse{} } +func (m *StatusResponse) String() string { return proto.CompactTextString(m) } +func (*StatusResponse) ProtoMessage() {} +func (*StatusResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8571034d60397816, []int{12} +} + +func (m *StatusResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_StatusResponse.Unmarshal(m, b) +} +func (m *StatusResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_StatusResponse.Marshal(b, m, deterministic) +} +func (m *StatusResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_StatusResponse.Merge(m, src) +} +func (m *StatusResponse) XXX_Size() int { + return xxx_messageInfo_StatusResponse.Size(m) +} +func (m *StatusResponse) XXX_DiscardUnknown() { + xxx_messageInfo_StatusResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_StatusResponse proto.InternalMessageInfo + +func (m *StatusResponse) GetStatus() *Status { + if m != nil { + return m.Status + } + return nil +} + +// Error tracks network errors +type Error struct { + Count uint32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` + Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Error) Reset() { *m = Error{} } +func (m *Error) String() string { return proto.CompactTextString(m) } +func (*Error) ProtoMessage() {} +func (*Error) Descriptor() ([]byte, []int) { + return fileDescriptor_8571034d60397816, []int{13} +} + +func (m *Error) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Error.Unmarshal(m, b) +} +func (m *Error) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Error.Marshal(b, m, deterministic) +} +func (m *Error) XXX_Merge(src proto.Message) { + xxx_messageInfo_Error.Merge(m, src) +} +func (m *Error) XXX_Size() int { + return xxx_messageInfo_Error.Size(m) +} +func (m *Error) XXX_DiscardUnknown() { + xxx_messageInfo_Error.DiscardUnknown(m) +} + +var xxx_messageInfo_Error proto.InternalMessageInfo + +func (m *Error) GetCount() uint32 { + if m != nil { + return m.Count + } + return 0 +} + +func (m *Error) GetMsg() string { + if m != nil { + return m.Msg + } + return "" +} + +// Status is node status +type Status struct { + Error *Error `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Status) Reset() { *m = Status{} } +func (m *Status) String() string { return proto.CompactTextString(m) } +func (*Status) ProtoMessage() {} +func (*Status) Descriptor() ([]byte, []int) { + return fileDescriptor_8571034d60397816, []int{14} +} + +func (m *Status) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Status.Unmarshal(m, b) +} +func (m *Status) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Status.Marshal(b, m, deterministic) +} +func (m *Status) XXX_Merge(src proto.Message) { + xxx_messageInfo_Status.Merge(m, src) +} +func (m *Status) XXX_Size() int { + return xxx_messageInfo_Status.Size(m) +} +func (m *Status) XXX_DiscardUnknown() { + xxx_messageInfo_Status.DiscardUnknown(m) +} + +var xxx_messageInfo_Status proto.InternalMessageInfo + +func (m *Status) GetError() *Error { + if m != nil { + return m.Error + } + return nil +} + // Node is network node type Node struct { // node id @@ -482,17 +640,19 @@ type Node struct { // the network Network string `protobuf:"bytes,3,opt,name=network,proto3" json:"network,omitempty"` // associated metadata - Metadata map[string]string `protobuf:"bytes,4,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Metadata map[string]string `protobuf:"bytes,4,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + // node status + Status *Status `protobuf:"bytes,5,opt,name=status,proto3" json:"status,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Node) Reset() { *m = Node{} } func (m *Node) String() string { return proto.CompactTextString(m) } func (*Node) ProtoMessage() {} func (*Node) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{11} + return fileDescriptor_8571034d60397816, []int{15} } func (m *Node) XXX_Unmarshal(b []byte) error { @@ -541,6 +701,13 @@ func (m *Node) GetMetadata() map[string]string { return nil } +func (m *Node) GetStatus() *Status { + if m != nil { + return m.Status + } + return nil +} + // Connect is sent when the node connects to the network type Connect struct { // network mode @@ -554,7 +721,7 @@ func (m *Connect) Reset() { *m = Connect{} } func (m *Connect) String() string { return proto.CompactTextString(m) } func (*Connect) ProtoMessage() {} func (*Connect) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{12} + return fileDescriptor_8571034d60397816, []int{16} } func (m *Connect) XXX_Unmarshal(b []byte) error { @@ -595,7 +762,7 @@ func (m *Close) Reset() { *m = Close{} } func (m *Close) String() string { return proto.CompactTextString(m) } func (*Close) ProtoMessage() {} func (*Close) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{13} + return fileDescriptor_8571034d60397816, []int{17} } func (m *Close) XXX_Unmarshal(b []byte) error { @@ -638,7 +805,7 @@ func (m *Peer) Reset() { *m = Peer{} } func (m *Peer) String() string { return proto.CompactTextString(m) } func (*Peer) ProtoMessage() {} func (*Peer) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{14} + return fileDescriptor_8571034d60397816, []int{18} } func (m *Peer) XXX_Unmarshal(b []byte) error { @@ -688,7 +855,7 @@ func (m *Sync) Reset() { *m = Sync{} } func (m *Sync) String() string { return proto.CompactTextString(m) } func (*Sync) ProtoMessage() {} func (*Sync) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{15} + return fileDescriptor_8571034d60397816, []int{19} } func (m *Sync) XXX_Unmarshal(b []byte) error { @@ -735,6 +902,10 @@ func init() { proto.RegisterType((*RoutesResponse)(nil), "go.micro.network.RoutesResponse") proto.RegisterType((*ServicesRequest)(nil), "go.micro.network.ServicesRequest") proto.RegisterType((*ServicesResponse)(nil), "go.micro.network.ServicesResponse") + proto.RegisterType((*StatusRequest)(nil), "go.micro.network.StatusRequest") + proto.RegisterType((*StatusResponse)(nil), "go.micro.network.StatusResponse") + proto.RegisterType((*Error)(nil), "go.micro.network.Error") + proto.RegisterType((*Status)(nil), "go.micro.network.Status") proto.RegisterType((*Node)(nil), "go.micro.network.Node") proto.RegisterMapType((map[string]string)(nil), "go.micro.network.Node.MetadataEntry") proto.RegisterType((*Connect)(nil), "go.micro.network.Connect") @@ -746,43 +917,48 @@ func init() { func init() { proto.RegisterFile("network.proto", fileDescriptor_8571034d60397816) } var fileDescriptor_8571034d60397816 = []byte{ - // 593 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0x5d, 0x6a, 0xdb, 0x40, - 0x10, 0x8e, 0x2c, 0x29, 0x3f, 0xd3, 0xc8, 0x75, 0x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0xe0, - 0xe7, 0x22, 0xc3, 0x22, 0x74, 0x9a, 0xee, 0xe1, 0x8b, 0xe3, 0x83, 0xf8, 0x71, 0xe9, 0xf1, 0xa5, - 0xc8, 0x30, 0xb1, 0x20, 0xfe, 0x0a, 0x5e, 0xce, 0xf9, 0xc5, 0x44, 0xe4, 0x05, 0xf2, 0x16, 0xec, - 0x6b, 0x44, 0x51, 0x06, 0x7c, 0x0d, 0x7e, 0x86, 0x13, 0x35, 0x34, 0x05, 0x06, 0x89, 0x35, 0xf8, - 0x57, 0x08, 0x08, 0x65, 0x69, 0xcf, 0xcc, 0xdb, 0x82, 0xfd, 0xef, 0x32, 0x9d, 0x0c, 0x37, 0x27, - 0xe9, 0x40, 0x40, 0x28, 0x4a, 0xf2, 0x01, 0x3c, 0x29, 0x84, 0x32, 0xa8, 0xca, 0x1c, 0x57, 0x88, - 0x32, 0x31, 0x18, 0x7e, 0x0a, 0x41, 0xa2, 0xdb, 0x37, 0x2f, 0xe4, 0x08, 0xfc, 0x5b, 0x3d, 0x34, - 0x62, 0xbf, 0x59, 0x65, 0x9b, 0x99, 0x26, 0x16, 0xc5, 0xcf, 0xa0, 0x5e, 0xf2, 0x29, 0x7b, 0x4c, - 0xe3, 0xa9, 0xa8, 0x91, 0xe4, 0x61, 0x08, 0x34, 0x36, 0xd3, 0xdc, 0xae, 0x55, 0x43, 0x79, 0x07, - 0x1e, 0x43, 0xe3, 0xe1, 0x88, 0xc2, 0x46, 0xb0, 0x4b, 0xa2, 0xb1, 0x81, 0xf7, 0x92, 0xb9, 0xcd, - 0xff, 0x3a, 0xe0, 0xe9, 0xbe, 0xb1, 0x3a, 0xd4, 0x46, 0x19, 0x69, 0xac, 0x36, 0xca, 0x36, 0xcb, - 0xab, 0x14, 0x8b, 0xbb, 0x24, 0x16, 0x76, 0x06, 0xbb, 0x63, 0x54, 0x69, 0x96, 0xaa, 0x34, 0xf4, - 0x4c, 0x05, 0xad, 0xea, 0x29, 0xc5, 0x17, 0x04, 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0x19, 0xb4, 0xb7, 0x6d, - 0x7e, 0x04, 0x27, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x66, 0x66, 0x42, 0x5f, 0x68, 0x06, 0x00, - 0x00, + // 678 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0xdd, 0x4e, 0xdb, 0x30, + 0x14, 0xa6, 0x6d, 0x52, 0xe0, 0x8c, 0x14, 0x66, 0x4d, 0x2c, 0xca, 0xc5, 0xe8, 0x2c, 0x2e, 0xd0, + 0x34, 0xd2, 0x09, 0x34, 0x6d, 0x1a, 0x1a, 0x42, 0x43, 0x68, 0xd2, 0x24, 0x10, 0x4b, 0x5f, 0x60, + 0x21, 0xb1, 0x4a, 0x05, 0x8d, 0x8b, 0xe3, 0x80, 0xfa, 0x04, 0x7b, 0xd3, 0xbd, 0xc4, 0x6e, 0x26, + 0xdb, 0x27, 0x21, 0xa1, 0x49, 0x57, 0xee, 0x72, 0xec, 0xef, 0x3b, 0xc7, 0xe7, 0xef, 0x0b, 0x38, + 0x09, 0x93, 0x0f, 0x5c, 0xdc, 0xf8, 0x53, 0xc1, 0x25, 0x27, 0x5b, 0x23, 0xee, 0x4f, 0xc6, 0x91, + 0xe0, 0x3e, 0x9e, 0x7b, 0x47, 0xa3, 0xb1, 0xbc, 0xce, 0xae, 0xfc, 0x88, 0x4f, 0x06, 0xfa, 0x66, + 0x30, 0xe2, 0xfb, 0xe6, 0x43, 0xf0, 0x4c, 0x32, 0x31, 0x48, 0x99, 0xb8, 0x1f, 0x47, 0x6c, 0xa0, + 0x3d, 0xe0, 0xa1, 0x71, 0x47, 0x7f, 0xb7, 0xc0, 0xfe, 0x99, 0x31, 0x31, 0x23, 0x2e, 0xac, 0x22, + 0xce, 0x6d, 0xf5, 0x5b, 0x7b, 0xeb, 0x41, 0x6e, 0xaa, 0x9b, 0x30, 0x8e, 0x05, 0x4b, 0x53,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 0x4d, 0xfa, 0x05, 0x96, 0x9a, + 0xfd, 0xe7, 0x70, 0xd4, 0xca, 0x4e, 0x19, 0x13, 0xaa, 0x05, 0x9d, 0x05, 0xeb, 0x64, 0x40, 0xf4, + 0x0a, 0xac, 0xe1, 0x2c, 0x89, 0x54, 0x04, 0x75, 0xf0, 0xbf, 0x1d, 0x54, 0x98, 0xd2, 0xc6, 0xb4, + 0x97, 0xd9, 0x98, 0x83, 0x3f, 0x1d, 0x58, 0xbd, 0xc0, 0x76, 0x5f, 0x3e, 0x56, 0xaf, 0x3f, 0x1f, + 0xa4, 0xaa, 0x7a, 0xde, 0xdb, 0x05, 0x08, 0xd4, 0xb5, 0x15, 0xf2, 0x03, 0x6c, 0x2d, 0x27, 0xe4, + 0xcd, 0x3c, 0xba, 0xac, 0x46, 0xde, 0x4e, 0xe3, 0x7d, 0xd9, 0x97, 0xd6, 0xbf, 0x3a, 0x5f, 0x65, + 0xf9, 0xac, 0xf3, 0x55, 0x11, 0x4e, 0xba, 0x42, 0xce, 0xa1, 0x6b, 0x94, 0x86, 0xd4, 0x80, 0x2b, + 0x1a, 0xe6, 0xf5, 0x9b, 0x01, 0x85, 0xbb, 0x21, 0xac, 0xe5, 0x1a, 0x43, 0x6a, 0xea, 0xf2, 0x44, + 0x92, 0x3c, 0xba, 0x08, 0x52, 0x7e, 0x23, 0x4a, 0xc0, 0x4e, 0xe3, 0xd2, 0x34, 0xbf, 0xb1, 0x2a, + 0x59, 0x74, 0xe5, 0xaa, 0xab, 0x7f, 0xa4, 0x87, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x11, 0x45, + 0xe6, 0xf4, 0xa8, 0x07, 0x00, 0x00, } diff --git a/network/service/proto/network.pb.micro.go b/network/service/proto/network.pb.micro.go index cc01d095..a6df00c6 100644 --- a/network/service/proto/network.pb.micro.go +++ b/network/service/proto/network.pb.micro.go @@ -45,6 +45,8 @@ type NetworkService interface { Routes(ctx context.Context, in *RoutesRequest, opts ...client.CallOption) (*RoutesResponse, error) // Returns a list of known services based on routes Services(ctx context.Context, in *ServicesRequest, opts ...client.CallOption) (*ServicesResponse, error) + // Status returns network status + Status(ctx context.Context, in *StatusRequest, opts ...client.CallOption) (*StatusResponse, error) } type networkService struct { @@ -115,6 +117,16 @@ func (c *networkService) Services(ctx context.Context, in *ServicesRequest, opts return out, nil } +func (c *networkService) Status(ctx context.Context, in *StatusRequest, opts ...client.CallOption) (*StatusResponse, error) { + req := c.c.NewRequest(c.name, "Network.Status", in) + out := new(StatusResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for Network service type NetworkHandler interface { @@ -128,6 +140,8 @@ type NetworkHandler interface { Routes(context.Context, *RoutesRequest, *RoutesResponse) error // Returns a list of known services based on routes Services(context.Context, *ServicesRequest, *ServicesResponse) error + // Status returns network status + Status(context.Context, *StatusRequest, *StatusResponse) error } func RegisterNetworkHandler(s server.Server, hdlr NetworkHandler, opts ...server.HandlerOption) error { @@ -137,6 +151,7 @@ func RegisterNetworkHandler(s server.Server, hdlr NetworkHandler, opts ...server Nodes(ctx context.Context, in *NodesRequest, out *NodesResponse) error Routes(ctx context.Context, in *RoutesRequest, out *RoutesResponse) error Services(ctx context.Context, in *ServicesRequest, out *ServicesResponse) error + Status(ctx context.Context, in *StatusRequest, out *StatusResponse) error } type Network struct { network @@ -168,3 +183,7 @@ func (h *networkHandler) Routes(ctx context.Context, in *RoutesRequest, out *Rou func (h *networkHandler) Services(ctx context.Context, in *ServicesRequest, out *ServicesResponse) error { return h.NetworkHandler.Services(ctx, in, out) } + +func (h *networkHandler) Status(ctx context.Context, in *StatusRequest, out *StatusResponse) error { + return h.NetworkHandler.Status(ctx, in, out) +} diff --git a/network/service/proto/network.proto b/network/service/proto/network.proto index ee02cf8f..da08293a 100644 --- a/network/service/proto/network.proto +++ b/network/service/proto/network.proto @@ -16,6 +16,8 @@ service Network { rpc Routes(RoutesRequest) returns (RoutesResponse) {}; // Returns a list of known services based on routes rpc Services(ServicesRequest) returns (ServicesResponse) {}; + // Status returns network status + rpc Status(StatusRequest) returns (StatusResponse) {}; } // Query is passed in a LookupRequest @@ -69,6 +71,23 @@ message ServicesResponse { repeated string services = 1; } +message StatusRequest {} + +message StatusResponse { + Status status = 1; +} + +// Error tracks network errors +message Error { + uint32 count = 1; + string msg = 2; +} + +// Status is node status +message Status { + Error error = 1; +} + // Node is network node message Node { // node id @@ -79,6 +98,8 @@ message Node { string network = 3; // associated metadata map metadata = 4; + // node status + Status status = 5; } // Connect is sent when the node connects to the network From 0ea56a5ffef7eb79e850c1573336aaa32548aa56 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 14 Jan 2020 18:22:58 +0000 Subject: [PATCH 123/788] Fixed tests --- network/node_test.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/network/node_test.go b/network/node_test.go index d4849a1c..99975415 100644 --- a/network/node_test.go +++ b/network/node_test.go @@ -21,7 +21,7 @@ func testSetup() *node { address: testNodeAddress, peers: make(map[string]*node), network: newNetwork(Name(testNodeNetName)), - err: new(nodeError), + status: newStatus(), } // add some peers to the node @@ -31,7 +31,7 @@ func testSetup() *node { address: testNode.address + "-" + id, peers: make(map[string]*node), network: testNode.network, - err: new(nodeError), + status: newStatus(), } } @@ -43,7 +43,7 @@ func testSetup() *node { address: testNode.address + "-" + id, peers: make(map[string]*node), network: testNode.network, - err: new(nodeError), + status: newStatus(), } } @@ -272,7 +272,9 @@ func TestUnpackPeerTopology(t *testing.T) { Node: &pb.Node{ Id: "newPeer", Address: "newPeerAddress", - Err: &pb.NodeError{}, + Status: &pb.Status{ + Error: &pb.Error{}, + }, }, Peers: make([]*pb.Peer, 0), } @@ -288,14 +290,18 @@ func TestUnpackPeerTopology(t *testing.T) { pbPeer1Node := &pb.Node{ Id: peer1.id, Address: peer1.address, - Err: &pb.NodeError{}, + Status: &pb.Status{ + Error: &pb.Error{}, + }, } pbPeer111 := &pb.Peer{ Node: &pb.Node{ Id: "peer111", Address: "peer111Address", - Err: &pb.NodeError{}, + Status: &pb.Status{ + Error: &pb.Error{}, + }, }, Peers: make([]*pb.Peer, 0), } @@ -304,7 +310,9 @@ func TestUnpackPeerTopology(t *testing.T) { Node: &pb.Node{ Id: "peer121", Address: "peer121Address", - Err: &pb.NodeError{}, + Status: &pb.Status{ + Error: &pb.Error{}, + }, }, Peers: make([]*pb.Peer, 0), } @@ -331,7 +339,7 @@ func TestPeersToProto(t *testing.T) { address: testNodeAddress, peers: make(map[string]*node), network: newNetwork(Name(testNodeNetName)), - err: &nodeError{}, + status: newStatus(), } topCount := 0 From dcd925f1e53a9512d9b7b995df9aaf90261bb51c Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 14 Jan 2020 18:48:42 +0000 Subject: [PATCH 124/788] Code cleanup; Indentation. --- network/default.go | 95 +++++++++++++---------------- network/network.go | 2 +- network/node.go | 9 +++ network/service/proto/network.proto | 16 ++--- 4 files changed, 62 insertions(+), 60 deletions(-) diff --git a/network/default.go b/network/default.go index 39e29b4b..06137041 100644 --- a/network/default.go +++ b/network/default.go @@ -876,16 +876,11 @@ func (n *network) processNetChan(listener tunnel.Listener) { log.Debugf("Network received peer message from: %s %s", pbNetPeer.Node.Id, pbNetPeer.Node.Address) peer := &node{ - id: pbNetPeer.Node.Id, - address: pbNetPeer.Node.Address, - link: m.msg.Header["Micro-Link"], - peers: make(map[string]*node), - status: &status{ - err: &nerr{ - count: int(pbNetPeer.Node.Status.Error.Count), - msg: errors.New(pbNetPeer.Node.Status.Error.Msg), - }, - }, + id: pbNetPeer.Node.Id, + address: pbNetPeer.Node.Address, + link: m.msg.Header["Micro-Link"], + peers: make(map[string]*node), + status: newPeerStatus(pbNetPeer), lastSeen: now, } @@ -981,16 +976,11 @@ func (n *network) processNetChan(listener tunnel.Listener) { log.Debugf("Network received sync message from: %s", pbNetSync.Peer.Node.Id) peer := &node{ - id: pbNetSync.Peer.Node.Id, - address: pbNetSync.Peer.Node.Address, - link: m.msg.Header["Micro-Link"], - peers: make(map[string]*node), - status: &status{ - err: &nerr{ - count: int(pbNetSync.Peer.Node.Status.Error.Count), - msg: errors.New(pbNetSync.Peer.Node.Status.Error.Msg), - }, - }, + id: pbNetSync.Peer.Node.Id, + address: pbNetSync.Peer.Node.Address, + link: m.msg.Header["Micro-Link"], + peers: make(map[string]*node), + status: newPeerStatus(pbNetSync.Peer), lastSeen: now, } @@ -1279,38 +1269,41 @@ func (n *network) manage() { // get a list of node peers peers := n.Peers() // pick a random peer from the list of peers and request full sync - if peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()); peer != nil { - go func() { - // get node peer graph to send back to the connecting node - node := PeersToProto(n.node, MaxDepth) - - msg := &pbNet.Sync{ - Peer: node, - } - - // get a list of all of our routes - routes, err := n.options.Router.Table().List() - switch err { - case nil: - // encode the routes to protobuf - pbRoutes := make([]*pbRtr.Route, 0, len(routes)) - for _, route := range routes { - pbRoute := pbUtil.RouteToProto(route) - pbRoutes = append(pbRoutes, pbRoute) - } - // pack the routes into the sync message - msg.Routes = pbRoutes - default: - // we can't list the routes - log.Debugf("Network node %s failed listing routes: %v", n.id, err) - } - - // send sync message to the newly connected peer - if err := n.sendTo("sync", NetworkChannel, peer, msg); err != nil { - log.Debugf("Network failed to send sync message: %v", err) - } - }() + peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()) + if peer != nil { + continue } + + go func() { + // get node peer graph to send back to the connecting node + node := PeersToProto(n.node, MaxDepth) + + msg := &pbNet.Sync{ + Peer: node, + } + + // get a list of all of our routes + routes, err := n.options.Router.Table().List() + switch err { + case nil: + // encode the routes to protobuf + pbRoutes := make([]*pbRtr.Route, 0, len(routes)) + for _, route := range routes { + pbRoute := pbUtil.RouteToProto(route) + pbRoutes = append(pbRoutes, pbRoute) + } + // pack the routes into the sync message + msg.Routes = pbRoutes + default: + // we can't list the routes + log.Debugf("Network node %s failed listing routes: %v", n.id, err) + } + + // send sync message to the newly connected peer + if err := n.sendTo("sync", NetworkChannel, peer, msg); err != nil { + log.Debugf("Network failed to send sync message: %v", err) + } + }() case <-resolve.C: n.initNodes(false) } diff --git a/network/network.go b/network/network.go index e06cd2c6..535870f0 100644 --- a/network/network.go +++ b/network/network.go @@ -20,7 +20,7 @@ var ( // KeepAliveTime is the time in which we want to have sent a message to a peer KeepAliveTime = 30 * time.Second // SyncTime is the time a network node requests full sync from the network - SyncTime = 5 * time.Minute + SyncTime = 1 * time.Minute // PruneTime defines time interval to periodically check nodes that need to be pruned // due to their not announcing their presence within this time interval PruneTime = 90 * time.Second diff --git a/network/node.go b/network/node.go index a7f3c51a..d632e299 100644 --- a/network/node.go +++ b/network/node.go @@ -69,6 +69,15 @@ func newStatus() *status { } } +func newPeerStatus(peer *pb.Peer) *status { + return &status{ + err: &nerr{ + count: int(peer.Node.Status.Error.Count), + msg: errors.New(peer.Node.Status.Error.Msg), + }, + } +} + func (s *status) Error() Error { s.RLock() defer s.RUnlock() diff --git a/network/service/proto/network.proto b/network/service/proto/network.proto index da08293a..f2bbdb9e 100644 --- a/network/service/proto/network.proto +++ b/network/service/proto/network.proto @@ -6,16 +6,16 @@ import "github.com/micro/go-micro/router/service/proto/router.proto"; // Network service is usesd to gain visibility into networks service Network { - // Connect to the network - rpc Connect(ConnectRequest) returns (ConnectResponse) {}; - // Returns the entire network graph - rpc Graph(GraphRequest) returns (GraphResponse) {}; - // Returns a list of known nodes in the network + // Connect to the network + rpc Connect(ConnectRequest) returns (ConnectResponse) {}; + // Returns the entire network graph + rpc Graph(GraphRequest) returns (GraphResponse) {}; + // Returns a list of known nodes in the network rpc Nodes(NodesRequest) returns (NodesResponse) {}; - // Returns a list of known routes in the network + // Returns a list of known routes in the network rpc Routes(RoutesRequest) returns (RoutesResponse) {}; - // Returns a list of known services based on routes - rpc Services(ServicesRequest) returns (ServicesResponse) {}; + // Returns a list of known services based on routes + rpc Services(ServicesRequest) returns (ServicesResponse) {}; // Status returns network status rpc Status(StatusRequest) returns (StatusResponse) {}; } From c67ef7e01705335658ef86a20d3261ff530de372 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Tue, 14 Jan 2020 19:37:50 +0000 Subject: [PATCH 125/788] Bug fix: skip sending sync message if the peer is not in our graph --- network/default.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/network/default.go b/network/default.go index 06137041..2b49331f 100644 --- a/network/default.go +++ b/network/default.go @@ -1270,7 +1270,8 @@ func (n *network) manage() { peers := n.Peers() // pick a random peer from the list of peers and request full sync peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()) - if peer != nil { + // skip if we can't find randmly selected peer + if peer == nil { continue } From 36928b716c52f1354dd8e46115bf15b62c0774a2 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Wed, 15 Jan 2020 19:45:43 +0000 Subject: [PATCH 126/788] Fixed bug:m network.proto backwards compatibility unmarshal --- network/node.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/network/node.go b/network/node.go index d632e299..e740ad73 100644 --- a/network/node.go +++ b/network/node.go @@ -70,12 +70,22 @@ func newStatus() *status { } func newPeerStatus(peer *pb.Peer) *status { - return &status{ - err: &nerr{ - count: int(peer.Node.Status.Error.Count), - msg: errors.New(peer.Node.Status.Error.Msg), - }, + status := &status{ + err: new(nerr), } + + // if Node.Status is nil, return empty status + if peer.Node.Status == nil { + return status + } + + // if peer.Node.Status.Error is NOT nil, update status fields + if err := peer.Node.Status.GetError(); err != nil { + status.err.count = int(peer.Node.Status.Error.Count) + status.err.msg = errors.New(peer.Node.Status.Error.Msg) + } + + return status } func (s *status) Error() Error { From f20e4daa6002272f630188238ee3117d6ec6c8d2 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 15 Jan 2020 21:02:53 +0000 Subject: [PATCH 127/788] fix rand panic --- network/default.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/network/default.go b/network/default.go index 68f73d9b..3f632210 100644 --- a/network/default.go +++ b/network/default.go @@ -334,11 +334,17 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { // get a list of node peers peers := n.Peers() + // there is no one to send to + if len(peers) == 0 { + continue + } + // advertise to max 3 peers max := len(peers) if max > 3 { max = 3 } + for i := 0; i < max; i++ { if peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()); peer != nil { if err := n.sendTo("advert", ControlChannel, peer, msg); err != nil { @@ -346,6 +352,7 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { } } } + continue } @@ -1268,6 +1275,12 @@ func (n *network) manage() { case <-netsync.C: // get a list of node peers peers := n.Peers() + + // skip when there are no peers + if len(peers) == 0 { + continue + } + // pick a random peer from the list of peers and request full sync peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()) // skip if we can't find randmly selected peer From b32ebddf85e845dc7d312979704e91731c1f5a8e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 15 Jan 2020 21:22:07 +0000 Subject: [PATCH 128/788] update nlopes/slack dep --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 8308c9d4..31f419f1 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/nats-io/nats-server v1.4.1 github.com/nats-io/nats-server/v2 v2.1.2 github.com/nats-io/nats.go v1.9.1 - github.com/nlopes/slack v0.6.0 + github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/pkg/errors v0.8.1 github.com/stretchr/testify v1.4.0 diff --git a/go.sum b/go.sum index 23a96d27..568f4d11 100644 --- a/go.sum +++ b/go.sum @@ -274,6 +274,8 @@ github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OS github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA= github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= +github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= +github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2SwKQ= github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw= From 6562154573a050c79cb6b8cef1c9f15c4387a2b6 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 15 Jan 2020 21:38:37 +0000 Subject: [PATCH 129/788] Fix the next panic --- network/node.go | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/network/node.go b/network/node.go index e740ad73..4ff181f6 100644 --- a/network/node.go +++ b/network/node.go @@ -21,15 +21,15 @@ var ( ErrPeerNotFound = errors.New("peer not found") ) -// nerr tracks node errors -type nerr struct { +// nodeError tracks node errors +type nodeError struct { sync.RWMutex count int msg error } // Increment increments node error count -func (e *nerr) Update(err error) { +func (e *nodeError) Update(err error) { e.Lock() defer e.Unlock() @@ -38,14 +38,14 @@ func (e *nerr) Update(err error) { } // Count returns node error count -func (e *nerr) Count() int { +func (e *nodeError) Count() int { e.RLock() defer e.RUnlock() return e.count } -func (e *nerr) Msg() string { +func (e *nodeError) Msg() string { e.RLock() defer e.RUnlock() @@ -59,19 +59,19 @@ func (e *nerr) Msg() string { // status returns node status type status struct { sync.RWMutex - err *nerr + err *nodeError } // newStatus creates func newStatus() *status { return &status{ - err: new(nerr), + err: new(nodeError), } } func newPeerStatus(peer *pb.Peer) *status { status := &status{ - err: new(nerr), + err: new(nodeError), } // if Node.Status is nil, return empty status @@ -92,7 +92,7 @@ func (s *status) Error() Error { s.RLock() defer s.RUnlock() - return &nerr{ + return &nodeError{ count: s.err.count, msg: s.err.msg, } @@ -140,7 +140,7 @@ func (n *node) Status() Status { defer n.RUnlock() return &status{ - err: &nerr{ + err: &nodeError{ count: n.status.err.count, msg: n.status.err.msg, }, @@ -441,15 +441,10 @@ func (n *node) Peers() []Node { // UnpackPeerTopology unpacks pb.Peer into node topology of given depth func UnpackPeerTopology(pbPeer *pb.Peer, lastSeen time.Time, depth uint) *node { peerNode := &node{ - id: pbPeer.Node.Id, - address: pbPeer.Node.Address, - peers: make(map[string]*node), - status: &status{ - err: &nerr{ - count: int(pbPeer.Node.Status.Error.Count), - msg: errors.New(pbPeer.Node.Status.Error.Msg), - }, - }, + id: pbPeer.Node.Id, + address: pbPeer.Node.Address, + peers: make(map[string]*node), + status: newPeerStatus(pbPeer), lastSeen: lastSeen, } From 33a9b3bc17d96e35aeed621633edbd10b5b7e288 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 15 Jan 2020 23:06:58 +0000 Subject: [PATCH 130/788] mask the route before sending --- network/default.go | 88 +++++++++++++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 28 deletions(-) diff --git a/network/default.go b/network/default.go index 3f632210..aea8ae8e 100644 --- a/network/default.go +++ b/network/default.go @@ -277,10 +277,37 @@ func (n *network) acceptCtrlConn(l tunnel.Listener, recv chan *message) { } } +// maskRoute will mask the route so that we apply the right values +func (n *network) maskRoute(r *pbRtr.Route) { + hasher := fnv.New64() + // the routes service address + address := r.Address + + // only hash the address if we're advertising our own local routes + // avoid hashing * based routes + if r.Router == n.Id() && r.Address != "*" { + // hash the service before advertising it + hasher.Reset() + // routes for multiple instances of a service will be collapsed here. + // TODO: once we store labels in the table this may need to change + // to include the labels in case they differ but highly unlikely + hasher.Write([]byte(r.Service + n.Address())) + address = fmt.Sprintf("%d", hasher.Sum64()) + } + + // calculate route metric to advertise + metric := n.getRouteMetric(r.Router, r.Gateway, r.Link) + + // NOTE: we override Gateway, Link and Address here + r.Address = address + r.Gateway = n.Address() + r.Link = DefaultLink + r.Metric = metric +} + // advertise advertises routes to the network func (n *network) advertise(advertChan <-chan *router.Advert) { rnd := rand.New(rand.NewSource(time.Now().UnixNano())) - hasher := fnv.New64() for { select { // process local adverts and randomly fire them at other nodes @@ -289,36 +316,26 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { var events []*pbRtr.Event for _, event := range advert.Events { - // the routes service address - address := event.Route.Address - - // only hash the address if we're advertising our own local routes - if event.Route.Router == advert.Id && event.Route.Address != "*" { - // hash the service before advertising it - hasher.Reset() - // routes for multiple instances of a service will be collapsed here. - // TODO: once we store labels in the table this may need to change - // to include the labels in case they differ but highly unlikely - hasher.Write([]byte(event.Route.Service + n.node.Address())) - address = fmt.Sprintf("%d", hasher.Sum64()) - } - // calculate route metric to advertise - metric := n.getRouteMetric(event.Route.Router, event.Route.Gateway, event.Route.Link) - // NOTE: we override Gateway, Link and Address here + // make a copy of the route route := &pbRtr.Route{ Service: event.Route.Service, - Address: address, - Gateway: n.node.Address(), + Address: event.Route.Address, + Gateway: event.Route.Gateway, Network: event.Route.Network, Router: event.Route.Router, - Link: DefaultLink, - Metric: metric, + Link: event.Route.Link, + Metric: event.Route.Metric, } + + // override the various values + n.maskRoute(route) + e := &pbRtr.Event{ Type: pbRtr.EventType(event.Type), Timestamp: event.Timestamp.UnixNano(), Route: route, } + events = append(events, e) } @@ -365,14 +382,25 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { default: // get a list of node peers peers := n.Peers() + + // only proceed if we have a peer + if len(peers) == 0 { + continue + } + // pick a random peer from the list of peers - if peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()); peer != nil { - if err := n.sendTo("advert", ControlChannel, peer, msg); err != nil { - log.Debugf("Network failed to advertise routes to %s: %v, sending multicast", peer.Id(), err) - // send a multicast message if we fail to send Unicast message - if err := n.sendMsg("advert", ControlChannel, msg); err != nil { - log.Debugf("Network failed to advertise routes to %s: %v", peer.Id(), err) - } + peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()) + // only proceed with a peer + if peer == nil { + continue + } + + // attempt to send the advert to the peer + if err := n.sendTo("advert", ControlChannel, peer, msg); err != nil { + log.Debugf("Network failed to advertise routes to %s: %v, sending multicast", peer.Id(), err) + // send a multicast message if we fail to send Unicast message + if err := n.sendMsg("advert", ControlChannel, msg); err != nil { + log.Debugf("Network failed to advertise routes to %s: %v", peer.Id(), err) } } } @@ -829,7 +857,11 @@ func (n *network) processNetChan(listener tunnel.Listener) { // encode the routes to protobuf pbRoutes := make([]*pbRtr.Route, 0, len(routes)) for _, route := range routes { + // generate new route proto pbRoute := pbUtil.RouteToProto(route) + // mask the route before outbounding + n.maskRoute(pbRoute) + // add to list of routes pbRoutes = append(pbRoutes, pbRoute) } // pack the routes into the sync message From 19dbd77402bc6fec4a576682237053ed816d1efa Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 16 Jan 2020 00:12:38 +0000 Subject: [PATCH 131/788] fix net masking in listed routes --- network/default.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/network/default.go b/network/default.go index aea8ae8e..4bad341a 100644 --- a/network/default.go +++ b/network/default.go @@ -1335,7 +1335,11 @@ func (n *network) manage() { // encode the routes to protobuf pbRoutes := make([]*pbRtr.Route, 0, len(routes)) for _, route := range routes { + // generate new route proto pbRoute := pbUtil.RouteToProto(route) + // mask the route before outbounding + n.maskRoute(pbRoute) + // add to list of routes pbRoutes = append(pbRoutes, pbRoute) } // pack the routes into the sync message From 689ae7cfc7d867f31901c914b64d773168766425 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 16 Jan 2020 00:28:58 +0000 Subject: [PATCH 132/788] Storing tunnel.Session rather than transport.Client --- network/default.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network/default.go b/network/default.go index 4bad341a..04e971ad 100644 --- a/network/default.go +++ b/network/default.go @@ -69,7 +69,7 @@ type network struct { client client.Client // tunClient is a map of tunnel channel clients - tunClient map[string]transport.Client + tunClient map[string]tunnel.Session // peerLinks is a map of links for each peer peerLinks map[string]tunnel.Link @@ -173,7 +173,7 @@ func newNetwork(opts ...Option) Network { tunnel: options.Tunnel, server: server, client: client, - tunClient: make(map[string]transport.Client), + tunClient: make(map[string]tunnel.Session), peerLinks: make(map[string]tunnel.Link), discovered: make(chan bool, 1), solicited: make(chan *node, 32), From 5e85194a13e6ebd6a9eb858b7560c8f8d958d149 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Thu, 16 Jan 2020 12:48:36 +0000 Subject: [PATCH 133/788] QueryStrategy to allow querying routes based on Advertising Strategy --- router/query.go | 20 ++++++++--- router/router.go | 1 + router/table.go | 64 ++++++++++++++++++++++++++++++----- router/table_test.go | 79 +++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 146 insertions(+), 18 deletions(-) diff --git a/router/query.go b/router/query.go index 557d44e0..ec079887 100644 --- a/router/query.go +++ b/router/query.go @@ -15,6 +15,8 @@ type QueryOptions struct { Network string // Router is router id Router string + // Strategy is routing strategy + Strategy Strategy } // QueryService sets service to query @@ -52,15 +54,23 @@ func QueryRouter(r string) QueryOption { } } +// QueryStrategy sets strategy to query +func QueryStrategy(s Strategy) QueryOption { + return func(o *QueryOptions) { + o.Strategy = s + } +} + // NewQuery creates new query and returns it func NewQuery(opts ...QueryOption) QueryOptions { // default options qopts := QueryOptions{ - Service: "*", - Address: "*", - Gateway: "*", - Network: "*", - Router: "*", + Service: "*", + Address: "*", + Gateway: "*", + Network: "*", + Router: "*", + Strategy: AdvertiseAll, } for _, o := range opts { diff --git a/router/router.go b/router/router.go index fc6f18c2..cf6294ef 100644 --- a/router/router.go +++ b/router/router.go @@ -146,6 +146,7 @@ type Advert struct { // Strategy is route advertisement strategy type Strategy int +// TODO: remove the "Advertise" prefix from these const ( // AdvertiseAll advertises all routes to the network AdvertiseAll Strategy = iota diff --git a/router/table.go b/router/table.go index 2b05ada0..821d782c 100644 --- a/router/table.go +++ b/router/table.go @@ -135,7 +135,7 @@ func (t *table) List() ([]Route, error) { } // isMatch checks if the route matches given query options -func isMatch(route Route, address, gateway, network, router string) bool { +func isMatch(route Route, address, gateway, network, router string, strategy Strategy) bool { // matches the values provided match := func(a, b string) bool { if a == "*" || a == b { @@ -150,12 +150,20 @@ func isMatch(route Route, address, gateway, network, router string) bool { b string } + // by default assume we are querying all routes + link := "*" + // if AdvertiseLocal change the link query accordingly + if strategy == AdvertiseLocal { + link = "local" + } + // compare the following values values := []compare{ {gateway, route.Gateway}, {network, route.Network}, {router, route.Router}, {address, route.Address}, + {link, route.Link}, } for _, v := range values { @@ -169,13 +177,46 @@ func isMatch(route Route, address, gateway, network, router string) bool { } // findRoutes finds all the routes for given network and router and returns them -func findRoutes(routes map[uint64]Route, address, gateway, network, router string) []Route { - var results []Route +func findRoutes(routes map[uint64]Route, address, gateway, network, router string, strategy Strategy) []Route { + // routeMap stores the routes we're going to advertise + routeMap := make(map[string][]Route) + for _, route := range routes { - if isMatch(route, address, gateway, network, router) { - results = append(results, route) + if isMatch(route, address, gateway, network, router, strategy) { + // add matchihg route to the routeMap + routeKey := route.Service + "@" + route.Network + // append the first found route to routeMap + _, ok := routeMap[routeKey] + if !ok { + routeMap[routeKey] = append(routeMap[routeKey], route) + continue + } + + // if AdvertiseAll, keep appending + if strategy == AdvertiseAll || strategy == AdvertiseLocal { + routeMap[routeKey] = append(routeMap[routeKey], route) + continue + } + + // now we're going to find the best routes + if strategy == AdvertiseBest { + // if the current optimal route metric is higher than routing table route, replace it + if len(routeMap[routeKey]) > 0 { + // NOTE: we know that when AdvertiseBest is set, we only ever have one item in current + if routeMap[routeKey][0].Metric > route.Metric { + routeMap[routeKey][0] = route + continue + } + } + } } } + + var results []Route + for _, route := range routeMap { + results = append(results, route...) + } + return results } @@ -187,17 +228,24 @@ func (t *table) Query(q ...QueryOption) ([]Route, error) { // create new query options opts := NewQuery(q...) + // create a cwslicelist of query results + results := make([]Route, 0, len(t.routes)) + + // if No routes are queried, return early + if opts.Strategy == AdvertiseNone { + return results, nil + } + if opts.Service != "*" { if _, ok := t.routes[opts.Service]; !ok { return nil, ErrRouteNotFound } - return findRoutes(t.routes[opts.Service], opts.Address, opts.Gateway, opts.Network, opts.Router), nil + return findRoutes(t.routes[opts.Service], opts.Address, opts.Gateway, opts.Network, opts.Router, opts.Strategy), nil } - results := make([]Route, 0, len(t.routes)) // search through all destinations for _, routes := range t.routes { - results = append(results, findRoutes(routes, opts.Address, opts.Gateway, opts.Network, opts.Router)...) + results = append(results, findRoutes(routes, opts.Address, opts.Gateway, opts.Network, opts.Router, opts.Strategy)...) } return results, nil diff --git a/router/table_test.go b/router/table_test.go index a05cb956..21c72510 100644 --- a/router/table_test.go +++ b/router/table_test.go @@ -1,6 +1,9 @@ package router -import "testing" +import ( + "fmt" + "testing" +) func testSetup() (*table, Route) { table := newTable() @@ -108,10 +111,10 @@ func TestList(t *testing.T) { func TestQuery(t *testing.T) { table, route := testSetup() - svc := []string{"svc1", "svc2", "svc3"} - net := []string{"net1", "net2", "net1"} - gw := []string{"gw1", "gw2", "gw3"} - rtr := []string{"rtr1", "rt2", "rt3"} + svc := []string{"svc1", "svc2", "svc3", "svc1"} + net := []string{"net1", "net2", "net1", "net3"} + gw := []string{"gw1", "gw2", "gw3", "gw3"} + rtr := []string{"rtr1", "rt2", "rt3", "rtr3"} for i := 0; i < len(svc); i++ { route.Service = svc[i] @@ -218,4 +221,70 @@ func TestQuery(t *testing.T) { if len(routes) != 0 { t.Errorf("incorrect number of routes returned. Expected: %d, found: %d", 0, len(routes)) } + + // query NO routes + query = []QueryOption{ + QueryGateway(gateway), + QueryNetwork(network), + QueryStrategy(AdvertiseNone), + } + + routes, err = table.Query(query...) + if err != nil { + t.Errorf("error looking up routes: %s", err) + } + + if len(routes) > 0 { + t.Errorf("incorrect number of routes returned. Expected: %d, found: %d", 0, len(routes)) + } + + // insert local routes to query + for i := 0; i < 2; i++ { + route.Link = "local" + route.Address = fmt.Sprintf("local.route.address-%d", i) + if err := table.Create(route); err != nil { + t.Errorf("error adding route: %s", err) + } + } + + // query local routes + query = []QueryOption{ + QueryGateway("*"), + QueryNetwork("*"), + QueryStrategy(AdvertiseLocal), + } + + routes, err = table.Query(query...) + if err != nil { + t.Errorf("error looking up routes: %s", err) + } + + if len(routes) != 2 { + t.Errorf("incorrect number of routes returned. Expected: %d, found: %d", 2, len(routes)) + } + + // add two different routes for svcX with different metric + for i := 0; i < 2; i++ { + route.Service = "svcX" + route.Address = fmt.Sprintf("svcX.route.address-%d", i) + route.Metric = int64(100 + i) + if err := table.Create(route); err != nil { + t.Errorf("error adding route: %s", err) + } + } + + // query best routes for svcX + query = []QueryOption{ + QueryService("svcX"), + QueryStrategy(AdvertiseBest), + } + + routes, err = table.Query(query...) + if err != nil { + t.Errorf("error looking up routes: %s", err) + } + + if len(routes) != 1 { + t.Errorf("incorrect number of routes returned. Expected: %d, found: %d", 1, len(routes)) + } } From 491a42d352ce5906a9c645e144eae4751e439368 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 16 Jan 2020 13:34:04 +0000 Subject: [PATCH 134/788] Switch notifier to scheduler --- runtime/default.go | 10 +++++----- runtime/kubernetes/kubernetes.go | 10 +++++----- runtime/options.go | 10 +++++----- runtime/runtime.go | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index 1f40380e..740ceb7d 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -290,9 +290,9 @@ func (r *runtime) Start() error { r.closed = make(chan bool) var events <-chan Event - if r.options.Notifier != nil { + if r.options.Scheduler != nil { var err error - events, err = r.options.Notifier.Notify() + events, err = r.options.Scheduler.Notify() if err != nil { // TODO: should we bail here? log.Debugf("Runtime failed to start update notifier") @@ -327,9 +327,9 @@ func (r *runtime) Stop() error { log.Debugf("Runtime stopping %s", service.Name) service.Stop() } - // stop the notifier too - if r.options.Notifier != nil { - return r.options.Notifier.Close() + // stop the scheduler + if r.options.Scheduler != nil { + return r.options.Scheduler.Close() } } diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 2b3b479f..29993b6c 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -365,9 +365,9 @@ func (k *kubernetes) Start() error { k.closed = make(chan bool) var events <-chan runtime.Event - if k.options.Notifier != nil { + if k.options.Scheduler != nil { var err error - events, err = k.options.Notifier.Notify() + events, err = k.options.Scheduler.Notify() if err != nil { // TODO: should we bail here? log.Debugf("Runtime failed to start update notifier") @@ -395,9 +395,9 @@ func (k *kubernetes) Stop() error { close(k.closed) // set not running k.running = false - // stop the notifier too - if k.options.Notifier != nil { - return k.options.Notifier.Close() + // stop the scheduler + if k.options.Scheduler != nil { + return k.options.Scheduler.Close() } } diff --git a/runtime/options.go b/runtime/options.go index e469346b..02bc99e8 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -8,16 +8,16 @@ type Option func(o *Options) // Options configure runtime type Options struct { - // Notifier for updates - Notifier Notifier + // Scheduler for updates + Scheduler Scheduler // Service type to manage Type string } -// WithNotifier specifies a notifier for updates -func WithNotifier(n Notifier) Option { +// WithScheduler specifies a scheduler for updates +func WithScheduler(n Scheduler) Option { return func(o *Options) { - o.Notifier = n + o.Scheduler = n } } diff --git a/runtime/runtime.go b/runtime/runtime.go index ef584960..801ac57c 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -30,15 +30,15 @@ type Runtime interface { Stop() error } -// Notifier is an update notifier -type Notifier interface { - // Notify publishes notification events +// Scheduler is a runtime service scheduler +type Scheduler interface { + // Notify publishes schedule events Notify() (<-chan Event, error) - // Close stops the notifier + // Close stops the scheduler Close() error } -// EventType defines notification event +// EventType defines schedule event type EventType int const ( From eda8b00f84860aa723e59826a8aa3e3fe39dc214 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Thu, 16 Jan 2020 16:08:49 +0000 Subject: [PATCH 135/788] Send only best routes via Sync. Only apply best routes. --- network/default.go | 56 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/network/default.go b/network/default.go index 04e971ad..dea02e65 100644 --- a/network/default.go +++ b/network/default.go @@ -850,8 +850,9 @@ func (n *network) processNetChan(listener tunnel.Listener) { Peer: node, } - // get a list of all of our routes - routes, err := n.options.Router.Table().List() + // get a list of the best routes for each service in our routing table + q := []router.QueryOption{router.QueryStrategy(router.AdvertiseBest)} + routes, err := n.options.Router.Table().Query(q...) switch err { case nil: // encode the routes to protobuf @@ -1045,9 +1046,51 @@ func (n *network) processNetChan(listener tunnel.Listener) { // add all the routes we have received in the sync message for _, pbRoute := range pbNetSync.Routes { + // unmarshal the routes received from remote peer route := pbUtil.ProtoToRoute(pbRoute) - if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { - log.Debugf("Network node %s failed to add route: %v", n.id, err) + // lookup the best route for the given service in our routing table + q := []router.QueryOption{ + router.QueryService(route.Service), + router.QueryStrategy(router.AdvertiseBest), + } + // NOTE: bestRoutes is either an empty slice or one element slice + bestRoutes, err := n.options.Router.Table().Query(q...) + if err != nil { + log.Debugf("Network node %s failed listing best routes for %s: %v", n.id, route.Service, err) + continue + } + // we found no route for given service + // create the route we have just received + if len(bestRoutes) == 0 { + // add routes to the routing table + if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { + log.Debugf("Network node %s failed to add route: %v", n.id, err) + continue + } + } + + // Take the best route to given service and: + // * prefer our own routes if metric is the same + // * only add new routes if the metric is better than the metric of our best route + bestRoute := bestRoutes[0] + if bestRoute.Metric == route.Metric { + if route.Router == n.options.Router.Options().Id { + log.Debugf("Network node %s skipping route addition: already has local route", n.id) + continue + } + // NOTE: we might want to skip here, too as we already have equally good route + // add routes to the routing table + if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { + log.Debugf("Network node %s failed to add route: %v", n.id, err) + continue + } + } + if bestRoute.Metric > route.Metric { + // TODO: should we delete our best route here? + // add route to the routing table + if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { + log.Debugf("Network node %s failed to add route: %v", n.id, err) + } } } @@ -1328,8 +1371,9 @@ func (n *network) manage() { Peer: node, } - // get a list of all of our routes - routes, err := n.options.Router.Table().List() + // get a list of the best routes for each service in our routing table + q := []router.QueryOption{router.QueryStrategy(router.AdvertiseBest)} + routes, err := n.options.Router.Table().Query(q...) switch err { case nil: // encode the routes to protobuf From 071ab7aededeeb13db5066d19cc4888ae65d30fd Mon Sep 17 00:00:00 2001 From: shu xian Date: Fri, 17 Jan 2020 00:10:15 +0800 Subject: [PATCH 136/788] add mucp for config/source --- config/source/mucp/mucp.go | 72 +++ config/source/mucp/options.go | 18 + config/source/mucp/proto/mucp.pb.go | 649 ++++++++++++++++++++++ config/source/mucp/proto/mucp.pb.micro.go | 241 ++++++++ config/source/mucp/proto/mucp.proto | 76 +++ config/source/mucp/util.go | 18 + config/source/mucp/watcher.go | 27 + 7 files changed, 1101 insertions(+) create mode 100644 config/source/mucp/mucp.go create mode 100644 config/source/mucp/options.go create mode 100644 config/source/mucp/proto/mucp.pb.go create mode 100644 config/source/mucp/proto/mucp.pb.micro.go create mode 100644 config/source/mucp/proto/mucp.proto create mode 100644 config/source/mucp/util.go create mode 100644 config/source/mucp/watcher.go diff --git a/config/source/mucp/mucp.go b/config/source/mucp/mucp.go new file mode 100644 index 00000000..eeb4bb84 --- /dev/null +++ b/config/source/mucp/mucp.go @@ -0,0 +1,72 @@ +package mucp + +import ( + "context" + + "github.com/micro/go-micro/config/cmd" + "github.com/micro/go-micro/config/source" + proto "github.com/micro/go-micro/config/source/mucp/proto" + "github.com/micro/go-micro/util/log" +) + +var ( + DefaultServiceName = "go.micro.config" +) + +type mucpSource struct { + serviceName string + key string + opts source.Options + client proto.SourceService +} + +func (m *mucpSource) Read() (set *source.ChangeSet, err error) { + req, err := m.client.Read(context.Background(), &proto.ReadRequest{Path: m.key}) + if err != nil { + return nil, err + } + + return toChangeSet(req.Change.ChangeSet), nil +} + +func (m *mucpSource) Watch() (w source.Watcher, err error) { + stream, err := m.client.Watch(context.Background(), &proto.WatchRequest{Key: m.key}) + if err != nil { + log.Error("watch err: ", err) + return + } + return newWatcher(stream) +} + +// Write is unsupported +func (m *mucpSource) Write(cs *source.ChangeSet) error { + return nil +} + +func (m *mucpSource) String() string { + return "mucp" +} + +func NewSource(opts ...source.Option) source.Source { + var options source.Options + for _, o := range opts { + o(&options) + } + + addr := DefaultServiceName + + if options.Context != nil { + a, ok := options.Context.Value(serviceNameKey{}).(string) + if ok { + addr = a + } + } + + s := &mucpSource{ + serviceName: addr, + opts: options, + client: proto.NewSourceService(addr, *cmd.DefaultOptions().Client), + } + + return s +} diff --git a/config/source/mucp/options.go b/config/source/mucp/options.go new file mode 100644 index 00000000..c8717cbd --- /dev/null +++ b/config/source/mucp/options.go @@ -0,0 +1,18 @@ +package mucp + +import ( + "context" + + "github.com/micro/go-micro/config/source" +) + +type serviceNameKey struct{} + +func ServiceName(a string) source.Option { + return func(o *source.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, serviceNameKey{}, a) + } +} diff --git a/config/source/mucp/proto/mucp.pb.go b/config/source/mucp/proto/mucp.pb.go new file mode 100644 index 00000000..b72b9070 --- /dev/null +++ b/config/source/mucp/proto/mucp.pb.go @@ -0,0 +1,649 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: proto/mucp.proto + +package mucp + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type ChangeSet struct { + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` + Checksum string `protobuf:"bytes,2,opt,name=checksum,proto3" json:"checksum,omitempty"` + Format string `protobuf:"bytes,3,opt,name=format,proto3" json:"format,omitempty"` + Source string `protobuf:"bytes,4,opt,name=source,proto3" json:"source,omitempty"` + Timestamp int64 `protobuf:"varint,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ChangeSet) Reset() { *m = ChangeSet{} } +func (m *ChangeSet) String() string { return proto.CompactTextString(m) } +func (*ChangeSet) ProtoMessage() {} +func (*ChangeSet) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{0} +} + +func (m *ChangeSet) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ChangeSet.Unmarshal(m, b) +} +func (m *ChangeSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ChangeSet.Marshal(b, m, deterministic) +} +func (m *ChangeSet) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChangeSet.Merge(m, src) +} +func (m *ChangeSet) XXX_Size() int { + return xxx_messageInfo_ChangeSet.Size(m) +} +func (m *ChangeSet) XXX_DiscardUnknown() { + xxx_messageInfo_ChangeSet.DiscardUnknown(m) +} + +var xxx_messageInfo_ChangeSet proto.InternalMessageInfo + +func (m *ChangeSet) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +func (m *ChangeSet) GetChecksum() string { + if m != nil { + return m.Checksum + } + return "" +} + +func (m *ChangeSet) GetFormat() string { + if m != nil { + return m.Format + } + return "" +} + +func (m *ChangeSet) GetSource() string { + if m != nil { + return m.Source + } + return "" +} + +func (m *ChangeSet) GetTimestamp() int64 { + if m != nil { + return m.Timestamp + } + return 0 +} + +type Change struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` + ChangeSet *ChangeSet `protobuf:"bytes,3,opt,name=changeSet,proto3" json:"changeSet,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Change) Reset() { *m = Change{} } +func (m *Change) String() string { return proto.CompactTextString(m) } +func (*Change) ProtoMessage() {} +func (*Change) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{1} +} + +func (m *Change) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Change.Unmarshal(m, b) +} +func (m *Change) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Change.Marshal(b, m, deterministic) +} +func (m *Change) XXX_Merge(src proto.Message) { + xxx_messageInfo_Change.Merge(m, src) +} +func (m *Change) XXX_Size() int { + return xxx_messageInfo_Change.Size(m) +} +func (m *Change) XXX_DiscardUnknown() { + xxx_messageInfo_Change.DiscardUnknown(m) +} + +var xxx_messageInfo_Change proto.InternalMessageInfo + +func (m *Change) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *Change) GetPath() string { + if m != nil { + return m.Path + } + return "" +} + +func (m *Change) GetChangeSet() *ChangeSet { + if m != nil { + return m.ChangeSet + } + return nil +} + +type CreateRequest struct { + Change *Change `protobuf:"bytes,1,opt,name=change,proto3" json:"change,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateRequest) Reset() { *m = CreateRequest{} } +func (m *CreateRequest) String() string { return proto.CompactTextString(m) } +func (*CreateRequest) ProtoMessage() {} +func (*CreateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{2} +} + +func (m *CreateRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateRequest.Unmarshal(m, b) +} +func (m *CreateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateRequest.Marshal(b, m, deterministic) +} +func (m *CreateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateRequest.Merge(m, src) +} +func (m *CreateRequest) XXX_Size() int { + return xxx_messageInfo_CreateRequest.Size(m) +} +func (m *CreateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CreateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateRequest proto.InternalMessageInfo + +func (m *CreateRequest) GetChange() *Change { + if m != nil { + return m.Change + } + return nil +} + +type CreateResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateResponse) Reset() { *m = CreateResponse{} } +func (m *CreateResponse) String() string { return proto.CompactTextString(m) } +func (*CreateResponse) ProtoMessage() {} +func (*CreateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{3} +} + +func (m *CreateResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateResponse.Unmarshal(m, b) +} +func (m *CreateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateResponse.Marshal(b, m, deterministic) +} +func (m *CreateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateResponse.Merge(m, src) +} +func (m *CreateResponse) XXX_Size() int { + return xxx_messageInfo_CreateResponse.Size(m) +} +func (m *CreateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CreateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateResponse proto.InternalMessageInfo + +type UpdateRequest struct { + Change *Change `protobuf:"bytes,1,opt,name=change,proto3" json:"change,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } +func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } +func (*UpdateRequest) ProtoMessage() {} +func (*UpdateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{4} +} + +func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateRequest.Unmarshal(m, b) +} +func (m *UpdateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateRequest.Marshal(b, m, deterministic) +} +func (m *UpdateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateRequest.Merge(m, src) +} +func (m *UpdateRequest) XXX_Size() int { + return xxx_messageInfo_UpdateRequest.Size(m) +} +func (m *UpdateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateRequest proto.InternalMessageInfo + +func (m *UpdateRequest) GetChange() *Change { + if m != nil { + return m.Change + } + return nil +} + +type UpdateResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } +func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } +func (*UpdateResponse) ProtoMessage() {} +func (*UpdateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{5} +} + +func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateResponse.Unmarshal(m, b) +} +func (m *UpdateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateResponse.Marshal(b, m, deterministic) +} +func (m *UpdateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateResponse.Merge(m, src) +} +func (m *UpdateResponse) XXX_Size() int { + return xxx_messageInfo_UpdateResponse.Size(m) +} +func (m *UpdateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateResponse proto.InternalMessageInfo + +type DeleteRequest struct { + Change *Change `protobuf:"bytes,1,opt,name=change,proto3" json:"change,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } +func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } +func (*DeleteRequest) ProtoMessage() {} +func (*DeleteRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{6} +} + +func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteRequest.Unmarshal(m, b) +} +func (m *DeleteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteRequest.Marshal(b, m, deterministic) +} +func (m *DeleteRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteRequest.Merge(m, src) +} +func (m *DeleteRequest) XXX_Size() int { + return xxx_messageInfo_DeleteRequest.Size(m) +} +func (m *DeleteRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteRequest proto.InternalMessageInfo + +func (m *DeleteRequest) GetChange() *Change { + if m != nil { + return m.Change + } + return nil +} + +type DeleteResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } +func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } +func (*DeleteResponse) ProtoMessage() {} +func (*DeleteResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{7} +} + +func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteResponse.Unmarshal(m, b) +} +func (m *DeleteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteResponse.Marshal(b, m, deterministic) +} +func (m *DeleteResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteResponse.Merge(m, src) +} +func (m *DeleteResponse) XXX_Size() int { + return xxx_messageInfo_DeleteResponse.Size(m) +} +func (m *DeleteResponse) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo + +type ListRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListRequest) Reset() { *m = ListRequest{} } +func (m *ListRequest) String() string { return proto.CompactTextString(m) } +func (*ListRequest) ProtoMessage() {} +func (*ListRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{8} +} + +func (m *ListRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListRequest.Unmarshal(m, b) +} +func (m *ListRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListRequest.Marshal(b, m, deterministic) +} +func (m *ListRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListRequest.Merge(m, src) +} +func (m *ListRequest) XXX_Size() int { + return xxx_messageInfo_ListRequest.Size(m) +} +func (m *ListRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ListRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ListRequest proto.InternalMessageInfo + +type ListResponse struct { + Configs []*Change `protobuf:"bytes,1,rep,name=configs,proto3" json:"configs,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListResponse) Reset() { *m = ListResponse{} } +func (m *ListResponse) String() string { return proto.CompactTextString(m) } +func (*ListResponse) ProtoMessage() {} +func (*ListResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{9} +} + +func (m *ListResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListResponse.Unmarshal(m, b) +} +func (m *ListResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListResponse.Marshal(b, m, deterministic) +} +func (m *ListResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListResponse.Merge(m, src) +} +func (m *ListResponse) XXX_Size() int { + return xxx_messageInfo_ListResponse.Size(m) +} +func (m *ListResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ListResponse proto.InternalMessageInfo + +func (m *ListResponse) GetConfigs() []*Change { + if m != nil { + return m.Configs + } + return nil +} + +type ReadRequest struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ReadRequest) Reset() { *m = ReadRequest{} } +func (m *ReadRequest) String() string { return proto.CompactTextString(m) } +func (*ReadRequest) ProtoMessage() {} +func (*ReadRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{10} +} + +func (m *ReadRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ReadRequest.Unmarshal(m, b) +} +func (m *ReadRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ReadRequest.Marshal(b, m, deterministic) +} +func (m *ReadRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ReadRequest.Merge(m, src) +} +func (m *ReadRequest) XXX_Size() int { + return xxx_messageInfo_ReadRequest.Size(m) +} +func (m *ReadRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ReadRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ReadRequest proto.InternalMessageInfo + +func (m *ReadRequest) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *ReadRequest) GetPath() string { + if m != nil { + return m.Path + } + return "" +} + +type ReadResponse struct { + Change *Change `protobuf:"bytes,1,opt,name=change,proto3" json:"change,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ReadResponse) Reset() { *m = ReadResponse{} } +func (m *ReadResponse) String() string { return proto.CompactTextString(m) } +func (*ReadResponse) ProtoMessage() {} +func (*ReadResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{11} +} + +func (m *ReadResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ReadResponse.Unmarshal(m, b) +} +func (m *ReadResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ReadResponse.Marshal(b, m, deterministic) +} +func (m *ReadResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ReadResponse.Merge(m, src) +} +func (m *ReadResponse) XXX_Size() int { + return xxx_messageInfo_ReadResponse.Size(m) +} +func (m *ReadResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ReadResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ReadResponse proto.InternalMessageInfo + +func (m *ReadResponse) GetChange() *Change { + if m != nil { + return m.Change + } + return nil +} + +type WatchRequest struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WatchRequest) Reset() { *m = WatchRequest{} } +func (m *WatchRequest) String() string { return proto.CompactTextString(m) } +func (*WatchRequest) ProtoMessage() {} +func (*WatchRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{12} +} + +func (m *WatchRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WatchRequest.Unmarshal(m, b) +} +func (m *WatchRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WatchRequest.Marshal(b, m, deterministic) +} +func (m *WatchRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_WatchRequest.Merge(m, src) +} +func (m *WatchRequest) XXX_Size() int { + return xxx_messageInfo_WatchRequest.Size(m) +} +func (m *WatchRequest) XXX_DiscardUnknown() { + xxx_messageInfo_WatchRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_WatchRequest proto.InternalMessageInfo + +func (m *WatchRequest) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +type WatchResponse struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + ChangeSet *ChangeSet `protobuf:"bytes,2,opt,name=changeSet,proto3" json:"changeSet,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *WatchResponse) Reset() { *m = WatchResponse{} } +func (m *WatchResponse) String() string { return proto.CompactTextString(m) } +func (*WatchResponse) ProtoMessage() {} +func (*WatchResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_942f149553cfb65d, []int{13} +} + +func (m *WatchResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WatchResponse.Unmarshal(m, b) +} +func (m *WatchResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WatchResponse.Marshal(b, m, deterministic) +} +func (m *WatchResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_WatchResponse.Merge(m, src) +} +func (m *WatchResponse) XXX_Size() int { + return xxx_messageInfo_WatchResponse.Size(m) +} +func (m *WatchResponse) XXX_DiscardUnknown() { + xxx_messageInfo_WatchResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_WatchResponse proto.InternalMessageInfo + +func (m *WatchResponse) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *WatchResponse) GetChangeSet() *ChangeSet { + if m != nil { + return m.ChangeSet + } + return nil +} + +func init() { + proto.RegisterType((*ChangeSet)(nil), "ChangeSet") + proto.RegisterType((*Change)(nil), "Change") + proto.RegisterType((*CreateRequest)(nil), "CreateRequest") + proto.RegisterType((*CreateResponse)(nil), "CreateResponse") + proto.RegisterType((*UpdateRequest)(nil), "UpdateRequest") + proto.RegisterType((*UpdateResponse)(nil), "UpdateResponse") + proto.RegisterType((*DeleteRequest)(nil), "DeleteRequest") + proto.RegisterType((*DeleteResponse)(nil), "DeleteResponse") + proto.RegisterType((*ListRequest)(nil), "ListRequest") + proto.RegisterType((*ListResponse)(nil), "ListResponse") + proto.RegisterType((*ReadRequest)(nil), "ReadRequest") + proto.RegisterType((*ReadResponse)(nil), "ReadResponse") + proto.RegisterType((*WatchRequest)(nil), "WatchRequest") + proto.RegisterType((*WatchResponse)(nil), "WatchResponse") +} + +func init() { proto.RegisterFile("proto/mucp.proto", fileDescriptor_942f149553cfb65d) } + +var fileDescriptor_942f149553cfb65d = []byte{ + // 425 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xdd, 0x6e, 0xd3, 0x30, + 0x14, 0xc7, 0x93, 0xa6, 0xcb, 0xc8, 0xc9, 0x47, 0xab, 0x73, 0x81, 0xa2, 0x08, 0x89, 0x60, 0x09, + 0x29, 0x02, 0xc9, 0x1b, 0xdd, 0x23, 0x8c, 0x3b, 0xb8, 0xf2, 0x84, 0xe0, 0xd6, 0xa4, 0xde, 0x52, + 0x8d, 0x34, 0x21, 0x76, 0x2e, 0x78, 0x84, 0xbd, 0x35, 0x8a, 0xed, 0xb4, 0x49, 0x11, 0xb0, 0xde, + 0x9d, 0xcf, 0xbf, 0xff, 0x3d, 0xbf, 0x06, 0xd6, 0x6d, 0xd7, 0xa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03, 0x44, 0x26, 0x35, 0x6d, 0x7c, 0x03, 0x97, 0x65, 0xb3, 0xbf, 0xdf, 0x3d, 0xc8, 0xd4, 0xcd, + 0xbd, 0xa9, 0xe4, 0x58, 0x27, 0x37, 0x10, 0x32, 0xc1, 0xb7, 0xa3, 0x87, 0x67, 0x1d, 0x9b, 0x5c, + 0x41, 0x64, 0x96, 0xec, 0x3b, 0xff, 0x75, 0x9e, 0x43, 0xf4, 0x95, 0xab, 0xb2, 0xfa, 0xeb, 0x33, + 0xe4, 0x13, 0xc4, 0x76, 0xc2, 0x6a, 0xfe, 0xe9, 0x64, 0x86, 0x78, 0xf1, 0x0f, 0xc4, 0x9b, 0xa7, + 0x05, 0xf8, 0x77, 0xe6, 0x5f, 0xf6, 0x1e, 0x7c, 0xc3, 0x0e, 0x13, 0x3a, 0xc3, 0x9e, 0xad, 0xe8, + 0x09, 0x54, 0x67, 0x18, 0x36, 0x90, 0x30, 0xa1, 0x33, 0xbe, 0xd9, 0x8a, 0x9e, 0xd0, 0xd3, 0xc3, + 0x86, 0x06, 0x26, 0x74, 0x06, 0x32, 0x5b, 0xd1, 0x13, 0x4c, 0x0e, 0xbe, 0x85, 0xe5, 0x40, 0x06, + 0x23, 0x3a, 0xe1, 0x95, 0xc5, 0x74, 0x8a, 0xcb, 0x8c, 0x0d, 0x87, 0xc5, 0x88, 0x4e, 0xa0, 0x64, + 0x31, 0x9d, 0x5e, 0x9b, 0x38, 0xf8, 0x0e, 0x2e, 0xf4, 0xb1, 0x30, 0xa6, 0xd3, 0xb3, 0x66, 0x09, + 0x9d, 0xdd, 0x90, 0x38, 0xd7, 0xee, 0x77, 0x5f, 0x7f, 0xdb, 0x37, 0xbf, 0x03, 0x00, 0x00, 0xff, + 0xff, 0x66, 0x66, 0xa8, 0x5d, 0xef, 0x03, 0x00, 0x00, +} diff --git a/config/source/mucp/proto/mucp.pb.micro.go b/config/source/mucp/proto/mucp.pb.micro.go new file mode 100644 index 00000000..088cd8ee --- /dev/null +++ b/config/source/mucp/proto/mucp.pb.micro.go @@ -0,0 +1,241 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: proto/mucp.proto + +package mucp + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +import ( + context "context" + client "github.com/micro/go-micro/client" + server "github.com/micro/go-micro/server" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ client.Option +var _ server.Option + +// Client API for Source service + +type SourceService interface { + Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) + Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) + List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) + Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) + Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Source_WatchService, error) +} + +type sourceService struct { + c client.Client + name string +} + +func NewSourceService(name string, c client.Client) SourceService { + if c == nil { + c = client.NewClient() + } + if len(name) == 0 { + name = "source" + } + return &sourceService{ + c: c, + name: name, + } +} + +func (c *sourceService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { + req := c.c.NewRequest(c.name, "Source.Create", in) + out := new(CreateResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sourceService) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) { + req := c.c.NewRequest(c.name, "Source.Update", in) + out := new(UpdateResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sourceService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { + req := c.c.NewRequest(c.name, "Source.Delete", in) + out := new(DeleteResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sourceService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { + req := c.c.NewRequest(c.name, "Source.List", in) + out := new(ListResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sourceService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) { + req := c.c.NewRequest(c.name, "Source.Read", in) + out := new(ReadResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sourceService) Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Source_WatchService, error) { + req := c.c.NewRequest(c.name, "Source.Watch", &WatchRequest{}) + stream, err := c.c.Stream(ctx, req, opts...) + if err != nil { + return nil, err + } + if err := stream.Send(in); err != nil { + return nil, err + } + return &sourceServiceWatch{stream}, nil +} + +type Source_WatchService interface { + SendMsg(interface{}) error + RecvMsg(interface{}) error + Close() error + Recv() (*WatchResponse, error) +} + +type sourceServiceWatch struct { + stream client.Stream +} + +func (x *sourceServiceWatch) Close() error { + return x.stream.Close() +} + +func (x *sourceServiceWatch) SendMsg(m interface{}) error { + return x.stream.Send(m) +} + +func (x *sourceServiceWatch) RecvMsg(m interface{}) error { + return x.stream.Recv(m) +} + +func (x *sourceServiceWatch) Recv() (*WatchResponse, error) { + m := new(WatchResponse) + err := x.stream.Recv(m) + if err != nil { + return nil, err + } + return m, nil +} + +// Server API for Source service + +type SourceHandler interface { + Create(context.Context, *CreateRequest, *CreateResponse) error + Update(context.Context, *UpdateRequest, *UpdateResponse) error + Delete(context.Context, *DeleteRequest, *DeleteResponse) error + List(context.Context, *ListRequest, *ListResponse) error + Read(context.Context, *ReadRequest, *ReadResponse) error + Watch(context.Context, *WatchRequest, Source_WatchStream) error +} + +func RegisterSourceHandler(s server.Server, hdlr SourceHandler, opts ...server.HandlerOption) error { + type source interface { + Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error + Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error + Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error + List(ctx context.Context, in *ListRequest, out *ListResponse) error + Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error + Watch(ctx context.Context, stream server.Stream) error + } + type Source struct { + source + } + h := &sourceHandler{hdlr} + return s.Handle(s.NewHandler(&Source{h}, opts...)) +} + +type sourceHandler struct { + SourceHandler +} + +func (h *sourceHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { + return h.SourceHandler.Create(ctx, in, out) +} + +func (h *sourceHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error { + return h.SourceHandler.Update(ctx, in, out) +} + +func (h *sourceHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { + return h.SourceHandler.Delete(ctx, in, out) +} + +func (h *sourceHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { + return h.SourceHandler.List(ctx, in, out) +} + +func (h *sourceHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error { + return h.SourceHandler.Read(ctx, in, out) +} + +func (h *sourceHandler) Watch(ctx context.Context, stream server.Stream) error { + m := new(WatchRequest) + if err := stream.Recv(m); err != nil { + return err + } + return h.SourceHandler.Watch(ctx, m, &sourceWatchStream{stream}) +} + +type Source_WatchStream interface { + SendMsg(interface{}) error + RecvMsg(interface{}) error + Close() error + Send(*WatchResponse) error +} + +type sourceWatchStream struct { + stream server.Stream +} + +func (x *sourceWatchStream) Close() error { + return x.stream.Close() +} + +func (x *sourceWatchStream) SendMsg(m interface{}) error { + return x.stream.Send(m) +} + +func (x *sourceWatchStream) RecvMsg(m interface{}) error { + return x.stream.Recv(m) +} + +func (x *sourceWatchStream) Send(m *WatchResponse) error { + return x.stream.Send(m) +} diff --git a/config/source/mucp/proto/mucp.proto b/config/source/mucp/proto/mucp.proto new file mode 100644 index 00000000..71bf99bc --- /dev/null +++ b/config/source/mucp/proto/mucp.proto @@ -0,0 +1,76 @@ +syntax = "proto3"; + +service Source { + rpc Create (CreateRequest) returns (CreateResponse) { + } + rpc Update (UpdateRequest) returns (UpdateResponse) { + } + rpc Delete (DeleteRequest) returns (DeleteResponse) { + } + rpc List (ListRequest) returns (ListResponse) { + } + rpc Read (ReadRequest) returns (ReadResponse) { + } + rpc Watch (WatchRequest) returns (stream WatchResponse) { + } +} + +message ChangeSet { + bytes data = 1; + string checksum = 2; + string format = 3; + string source = 4; + int64 timestamp = 5; +} + +message Change { + string key = 1; + string path = 2; + ChangeSet changeSet = 3; +} + +message CreateRequest { + Change change = 1; +} + +message CreateResponse { +} + +message UpdateRequest { + Change change = 1; +} + +message UpdateResponse { +} + +message DeleteRequest { + Change change = 1; +} + +message DeleteResponse { +} + +message ListRequest { +} + +message ListResponse { + repeated Change configs = 1; +} + +message ReadRequest { + string key = 1; + string path = 2; +} + +message ReadResponse { + Change change = 1; +} + +message WatchRequest { + string key = 1; +} + +message WatchResponse { + string key = 1; + ChangeSet changeSet = 2; +} \ No newline at end of file diff --git a/config/source/mucp/util.go b/config/source/mucp/util.go new file mode 100644 index 00000000..b1a8deec --- /dev/null +++ b/config/source/mucp/util.go @@ -0,0 +1,18 @@ +package mucp + +import ( + "time" + + "github.com/micro/go-micro/config/source" + proto "github.com/micro/go-micro/config/source/mucp/proto" +) + +func toChangeSet(c *proto.ChangeSet) *source.ChangeSet { + return &source.ChangeSet{ + Data: c.Data, + Checksum: c.Checksum, + Format: c.Format, + Timestamp: time.Unix(c.Timestamp, 0), + Source: c.Source, + } +} diff --git a/config/source/mucp/watcher.go b/config/source/mucp/watcher.go new file mode 100644 index 00000000..466703e9 --- /dev/null +++ b/config/source/mucp/watcher.go @@ -0,0 +1,27 @@ +package mucp + +import ( + "github.com/micro/go-micro/config/source" + proto "github.com/micro/go-micro/config/source/mucp/proto" +) + +type watcher struct { + stream proto.Source_WatchService +} + +func newWatcher(stream proto.Source_WatchService) (source.Watcher, error) { + return &watcher{stream: stream}, nil +} + +func (w *watcher) Next() (*source.ChangeSet, error) { + var rsp proto.WatchResponse + err := w.stream.RecvMsg(&rsp) + if err != nil { + return nil, err + } + return toChangeSet(rsp.ChangeSet), nil +} + +func (w *watcher) Stop() error { + return w.stream.Close() +} From 793e6013e5644a7cb8e820a6a42b6c234b17c974 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Thu, 16 Jan 2020 16:42:23 +0000 Subject: [PATCH 137/788] Advertise routes with configured strategy. Simplify Sync apply logic --- network/default.go | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/network/default.go b/network/default.go index dea02e65..d981e4ab 100644 --- a/network/default.go +++ b/network/default.go @@ -851,7 +851,9 @@ func (n *network) processNetChan(listener tunnel.Listener) { } // get a list of the best routes for each service in our routing table - q := []router.QueryOption{router.QueryStrategy(router.AdvertiseBest)} + q := []router.QueryOption{ + router.QueryStrategy(n.router.Options().Advertise), + } routes, err := n.options.Router.Table().Query(q...) switch err { case nil: @@ -1048,19 +1050,24 @@ func (n *network) processNetChan(listener tunnel.Listener) { for _, pbRoute := range pbNetSync.Routes { // unmarshal the routes received from remote peer route := pbUtil.ProtoToRoute(pbRoute) - // lookup the best route for the given service in our routing table + // continue if we are the originator of the route + if route.Router == n.options.Router.Options().Id { + log.Debugf("Network node %s skipping route addition: route already present", n.id) + continue + } + // lookup best routes for the services in the just received route q := []router.QueryOption{ router.QueryService(route.Service), router.QueryStrategy(router.AdvertiseBest), } - // NOTE: bestRoutes is either an empty slice or one element slice bestRoutes, err := n.options.Router.Table().Query(q...) if err != nil { log.Debugf("Network node %s failed listing best routes for %s: %v", n.id, route.Service, err) continue } - // we found no route for given service - // create the route we have just received + + // we found no route for the given service + // create new route we have just received if len(bestRoutes) == 0 { // add routes to the routing table if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { @@ -1073,24 +1080,14 @@ func (n *network) processNetChan(listener tunnel.Listener) { // * prefer our own routes if metric is the same // * only add new routes if the metric is better than the metric of our best route bestRoute := bestRoutes[0] - if bestRoute.Metric == route.Metric { - if route.Router == n.options.Router.Options().Id { - log.Debugf("Network node %s skipping route addition: already has local route", n.id) - continue - } - // NOTE: we might want to skip here, too as we already have equally good route - // add routes to the routing table - if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { - log.Debugf("Network node %s failed to add route: %v", n.id, err) - continue - } + + if bestRoute.Metric <= route.Metric { + continue } - if bestRoute.Metric > route.Metric { - // TODO: should we delete our best route here? - // add route to the routing table - if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { - log.Debugf("Network node %s failed to add route: %v", n.id, err) - } + + // add route to the routing table + if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { + log.Debugf("Network node %s failed to add route: %v", n.id, err) } } @@ -1372,7 +1369,9 @@ func (n *network) manage() { } // get a list of the best routes for each service in our routing table - q := []router.QueryOption{router.QueryStrategy(router.AdvertiseBest)} + q := []router.QueryOption{ + router.QueryStrategy(n.router.Options().Advertise), + } routes, err := n.options.Router.Table().Query(q...) switch err { case nil: From 60c05bd89922cd0c77e309aed8db7b946d19abab Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Thu, 16 Jan 2020 16:53:39 +0000 Subject: [PATCH 138/788] Find the best routes in the routes we would advertise based on Strategy --- network/default.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/network/default.go b/network/default.go index d981e4ab..612f2b5c 100644 --- a/network/default.go +++ b/network/default.go @@ -1058,17 +1058,18 @@ func (n *network) processNetChan(listener tunnel.Listener) { // lookup best routes for the services in the just received route q := []router.QueryOption{ router.QueryService(route.Service), - router.QueryStrategy(router.AdvertiseBest), + router.QueryStrategy(n.router.Options().Advertise), } - bestRoutes, err := n.options.Router.Table().Query(q...) + + routes, err := n.options.Router.Table().Query(q...) if err != nil { log.Debugf("Network node %s failed listing best routes for %s: %v", n.id, route.Service, err) continue } - // we found no route for the given service - // create new route we have just received - if len(bestRoutes) == 0 { + // we found no routes for the given service + // create the new route we have just received + if len(routes) == 0 { // add routes to the routing table if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { log.Debugf("Network node %s failed to add route: %v", n.id, err) @@ -1076,10 +1077,18 @@ func (n *network) processNetChan(listener tunnel.Listener) { } } + // find the best route for the given service + // from the routes that we would advertise + bestRoute := routes[0] + for _, r := range routes[0:] { + if bestRoute.Metric > r.Metric { + bestRoute = r + } + } + // Take the best route to given service and: - // * prefer our own routes if metric is the same - // * only add new routes if the metric is better than the metric of our best route - bestRoute := bestRoutes[0] + // only add new routes if the metric is better + // than the metric of our best route if bestRoute.Metric <= route.Metric { continue From 472186c1be06b2e37f64a7a8a1c0e7bc2a85159a Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Thu, 16 Jan 2020 17:04:04 +0000 Subject: [PATCH 139/788] Code consistency. Small bug fix. --- network/default.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/network/default.go b/network/default.go index 612f2b5c..160d3b21 100644 --- a/network/default.go +++ b/network/default.go @@ -854,7 +854,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { q := []router.QueryOption{ router.QueryStrategy(n.router.Options().Advertise), } - routes, err := n.options.Router.Table().Query(q...) + routes, err := n.router.Table().Query(q...) switch err { case nil: // encode the routes to protobuf @@ -1051,7 +1051,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { // unmarshal the routes received from remote peer route := pbUtil.ProtoToRoute(pbRoute) // continue if we are the originator of the route - if route.Router == n.options.Router.Options().Id { + if route.Router == n.router.Options().Id { log.Debugf("Network node %s skipping route addition: route already present", n.id) continue } @@ -1061,7 +1061,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { router.QueryStrategy(n.router.Options().Advertise), } - routes, err := n.options.Router.Table().Query(q...) + routes, err := n.router.Table().Query(q...) if err != nil { log.Debugf("Network node %s failed listing best routes for %s: %v", n.id, route.Service, err) continue @@ -1075,6 +1075,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { log.Debugf("Network node %s failed to add route: %v", n.id, err) continue } + continue } // find the best route for the given service @@ -1381,7 +1382,7 @@ func (n *network) manage() { q := []router.QueryOption{ router.QueryStrategy(n.router.Options().Advertise), } - routes, err := n.options.Router.Table().Query(q...) + routes, err := n.router.Table().Query(q...) switch err { case nil: // encode the routes to protobuf From 8fcfbc0d2097766688b3ebacb3d22b8a3915609a Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Thu, 16 Jan 2020 17:33:53 +0000 Subject: [PATCH 140/788] Strip unnecessary continue statement --- network/default.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/network/default.go b/network/default.go index 160d3b21..9123949e 100644 --- a/network/default.go +++ b/network/default.go @@ -1070,10 +1070,8 @@ func (n *network) processNetChan(listener tunnel.Listener) { // we found no routes for the given service // create the new route we have just received if len(routes) == 0 { - // add routes to the routing table if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { log.Debugf("Network node %s failed to add route: %v", n.id, err) - continue } continue } From 7f9b3b5556471d574490eccbbde33abbf20ae962 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Thu, 16 Jan 2020 19:43:10 +0000 Subject: [PATCH 141/788] Remove Solicitation from the network Instead, when a new peer is discovered it is sent a sync message i.e. we do the full sync when discovering peers --- network/default.go | 232 +++++++----------------- router/default.go | 22 --- router/router.go | 6 - router/service/proto/router.pb.go | 182 +++++++------------ router/service/proto/router.pb.micro.go | 19 +- router/service/proto/router.proto | 7 - router/service/service.go | 36 ---- 7 files changed, 130 insertions(+), 374 deletions(-) diff --git a/network/default.go b/network/default.go index 9123949e..fec4a9ce 100644 --- a/network/default.go +++ b/network/default.go @@ -80,8 +80,6 @@ type network struct { closed chan bool // whether we've discovered by the network discovered chan bool - // solicted checks whether routes were solicited by one node - solicited chan *node } // message is network message @@ -176,7 +174,6 @@ func newNetwork(opts ...Option) Network { tunClient: make(map[string]tunnel.Session), peerLinks: make(map[string]tunnel.Link), discovered: make(chan bool, 1), - solicited: make(chan *node, 32), } network.node.network = network @@ -346,60 +343,23 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { Events: events, } - // send the advert to a select number of random peers - if advert.Type != router.Solicitation { - // get a list of node peers - peers := n.Peers() - - // there is no one to send to - if len(peers) == 0 { - continue - } - - // advertise to max 3 peers - max := len(peers) - if max > 3 { - max = 3 - } - - for i := 0; i < max; i++ { - if peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()); peer != nil { - if err := n.sendTo("advert", ControlChannel, peer, msg); err != nil { - log.Debugf("Network failed to advertise routes to %s: %v", peer.Id(), err) - } - } - } + // get a list of node peers + peers := n.Peers() + // continue if there is no one to send to + if len(peers) == 0 { continue } - // it's a solication, someone asked for it - // so we're going to pick off the node and send it - select { - case peer := <-n.solicited: - // someone requested the route - n.sendTo("advert", ControlChannel, peer, msg) - default: - // get a list of node peers - peers := n.Peers() + // advertise to max 3 peers + max := len(peers) + if max > 3 { + max = 3 + } - // only proceed if we have a peer - if len(peers) == 0 { - continue - } - - // pick a random peer from the list of peers - peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()) - // only proceed with a peer - if peer == nil { - continue - } - - // attempt to send the advert to the peer - if err := n.sendTo("advert", ControlChannel, peer, msg); err != nil { - log.Debugf("Network failed to advertise routes to %s: %v, sending multicast", peer.Id(), err) - // send a multicast message if we fail to send Unicast message - if err := n.sendMsg("advert", ControlChannel, msg); err != nil { + for i := 0; i < max; i++ { + if peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()); peer != nil { + if err := n.sendTo("advert", ControlChannel, peer, msg); err != nil { log.Debugf("Network failed to advertise routes to %s: %v", peer.Id(), err) } } @@ -740,38 +700,6 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { if err := n.router.Process(advert); err != nil { log.Debugf("Network failed to process advert %s: %v", advert.Id, err) } - case "solicit": - pbRtrSolicit := new(pbRtr.Solicit) - if err := proto.Unmarshal(m.msg.Body, pbRtrSolicit); err != nil { - log.Debugf("Network fail to unmarshal solicit message: %v", err) - continue - } - - log.Debugf("Network received solicit message from: %s", pbRtrSolicit.Id) - - // ignore solicitation when requested by you - if pbRtrSolicit.Id == n.options.Id { - continue - } - - log.Tracef("Network router flushing routes for: %s", pbRtrSolicit.Id) - - peer := &node{ - id: pbRtrSolicit.Id, - link: m.msg.Header["Micro-Link"], - } - - // specify that someone solicited the route - select { - case n.solicited <- peer: - default: - // don't block - } - - // advertise all the routes when a new node has connected - if err := n.router.Solicit(); err != nil { - log.Debugf("Network failed to solicit routes: %s", err) - } } case <-n.closed: return @@ -851,54 +779,17 @@ func (n *network) processNetChan(listener tunnel.Listener) { } // get a list of the best routes for each service in our routing table - q := []router.QueryOption{ - router.QueryStrategy(n.router.Options().Advertise), - } - routes, err := n.router.Table().Query(q...) - switch err { - case nil: - // encode the routes to protobuf - pbRoutes := make([]*pbRtr.Route, 0, len(routes)) - for _, route := range routes { - // generate new route proto - pbRoute := pbUtil.RouteToProto(route) - // mask the route before outbounding - n.maskRoute(pbRoute) - // add to list of routes - pbRoutes = append(pbRoutes, pbRoute) - } - // pack the routes into the sync message - msg.Routes = pbRoutes - default: - // we can't list the routes + routes, err := n.getProtoRoutes() + if err != nil { log.Debugf("Network node %s failed listing routes: %v", n.id, err) } + // attached the routes to the message + msg.Routes = routes // send sync message to the newly connected peer if err := n.sendTo("sync", NetworkChannel, peer, msg); err != nil { log.Debugf("Network failed to send sync message: %v", err) } - // wait for a short period of time before sending a solicit message - <-time.After(time.Millisecond * 100) - - // send a solicit message when discovering new peer - // this triggers the node to flush its routing table to the network - // and leads to faster convergence of the network - solicit := &pbRtr.Solicit{ - Id: n.options.Id, - } - - // ask for the new nodes routes - if err := n.sendTo("solicit", ControlChannel, peer, solicit); err != nil { - log.Debugf("Network failed to send solicit message: %s", err) - } - - // now advertise our own routes - select { - case n.solicited <- peer: - default: - // don't block - } }() case "peer": // mark the time the message has been received @@ -934,38 +825,27 @@ func (n *network) processNetChan(listener tunnel.Listener) { log.Debugf("Network failed updating peer links: %s", err) } - // if it's a new peer i.e. we do not have it in our graph, we solicit its routes + // if it's a new peer i.e. we do not have it in our graph, we request full sync if err := n.node.AddPeer(peer); err == nil { go func() { - msg := PeersToProto(n.node, MaxDepth) + // marshal node graph into protobuf + node := PeersToProto(n.node, MaxDepth) - // advertise yourself to the peer - if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { - log.Debugf("Network failed to advertise peers: %v", err) + msg := &pbNet.Sync{ + Peer: node, } - <-time.After(time.Millisecond * 100) - - // send a solicit message when discovering new peer - solicit := &pbRtr.Solicit{ - Id: n.options.Id, + // get a list of the best routes for each service in our routing table + routes, err := n.getProtoRoutes() + if err != nil { + log.Debugf("Network node %s failed listing routes: %v", n.id, err) } + // attached the routes to the message + msg.Routes = routes - // then solicit this peer - if err := n.sendTo("solicit", ControlChannel, peer, solicit); err != nil { - log.Debugf("Network failed to send solicit message: %s", err) - } - - // now advertise our own routes - select { - case n.solicited <- peer: - default: - // don't block - } - - // advertise all the routes when a new node has connected - if err := n.router.Solicit(); err != nil { - log.Debugf("Network failed to solicit routes: %s", err) + // send sync message to the newly connected peer + if err := n.sendTo("sync", NetworkChannel, peer, msg); err != nil { + log.Debugf("Network failed to send sync message: %v", err) } }() @@ -1377,28 +1257,12 @@ func (n *network) manage() { } // get a list of the best routes for each service in our routing table - q := []router.QueryOption{ - router.QueryStrategy(n.router.Options().Advertise), - } - routes, err := n.router.Table().Query(q...) - switch err { - case nil: - // encode the routes to protobuf - pbRoutes := make([]*pbRtr.Route, 0, len(routes)) - for _, route := range routes { - // generate new route proto - pbRoute := pbUtil.RouteToProto(route) - // mask the route before outbounding - n.maskRoute(pbRoute) - // add to list of routes - pbRoutes = append(pbRoutes, pbRoute) - } - // pack the routes into the sync message - msg.Routes = pbRoutes - default: - // we can't list the routes + routes, err := n.getProtoRoutes() + if err != nil { log.Debugf("Network node %s failed listing routes: %v", n.id, err) } + // attached the routes to the message + msg.Routes = routes // send sync message to the newly connected peer if err := n.sendTo("sync", NetworkChannel, peer, msg); err != nil { @@ -1411,6 +1275,33 @@ func (n *network) manage() { } } +// getAdvertProtoRoutes returns a list of routes to advertise to remote peer +// based on the advertisement strategy encoded in protobuf +// It returns error if the routes failed to be retrieved from the routing table +func (n *network) getProtoRoutes() ([]*pbRtr.Route, error) { + // get a list of the best routes for each service in our routing table + q := []router.QueryOption{ + router.QueryStrategy(n.router.Options().Advertise), + } + + routes, err := n.router.Table().Query(q...) + if err != nil { + return nil, err + } + + // encode the routes to protobuf + pbRoutes := make([]*pbRtr.Route, 0, len(routes)) + for _, route := range routes { + // generate new route proto + pbRoute := pbUtil.RouteToProto(route) + // mask the route before outbounding + n.maskRoute(pbRoute) + // add to list of routes + pbRoutes = append(pbRoutes, pbRoute) + } + return pbRoutes, nil +} + func (n *network) sendConnect() { // send connect message to NetworkChannel // NOTE: in theory we could do this as soon as @@ -1822,7 +1713,6 @@ func (n *network) Close() error { n.Unlock() return nil default: - // TODO: send close message to the network channel close(n.closed) // set connected to false diff --git a/router/default.go b/router/default.go index 459488df..688d5337 100644 --- a/router/default.go +++ b/router/default.go @@ -115,9 +115,6 @@ func (r *router) manageRoute(route Route, action string) error { if err := r.table.Update(route); err != nil { return fmt.Errorf("failed updating route for service %s: %s", route.Service, err) } - case "solicit": - // nothing to do here - return nil default: return fmt.Errorf("failed to manage route for service %s: unknown action %s", route.Service, action) } @@ -816,25 +813,6 @@ func (r *router) flushRouteEvents(evType EventType) ([]*Event, error) { return events, nil } -// Solicit advertises all of its routes to the network -// It returns error if the router fails to list the routes -func (r *router) Solicit() error { - events, err := r.flushRouteEvents(Update) - if err != nil { - return fmt.Errorf("failed solicit routes: %s", err) - } - - // advertise the routes - r.advertWg.Add(1) - - go func() { - r.publishAdvert(Solicitation, events) - r.advertWg.Done() - }() - - return nil -} - // Lookup routes in the routing table func (r *router) Lookup(q ...QueryOption) ([]Route, error) { return r.table.Query(q...) diff --git a/router/router.go b/router/router.go index cf6294ef..b71cbcac 100644 --- a/router/router.go +++ b/router/router.go @@ -28,8 +28,6 @@ type Router interface { Advertise() (<-chan *Advert, error) // Process processes incoming adverts Process(*Advert) error - // Solicit advertises the whole routing table - Solicit() error // Lookup queries routes in the routing table Lookup(...QueryOption) ([]Route, error) // Watch returns a watcher which tracks updates to the routing table @@ -111,8 +109,6 @@ const ( Announce AdvertType = iota // RouteUpdate advertises route updates RouteUpdate - // Solicitation indicates routes were solicited - Solicitation ) // String returns human readable advertisement type @@ -122,8 +118,6 @@ func (t AdvertType) String() string { return "announce" case RouteUpdate: return "update" - case Solicitation: - return "solicitation" default: return "unknown" } diff --git a/router/service/proto/router.pb.go b/router/service/proto/router.pb.go index 4e2c4cc0..29904323 100644 --- a/router/service/proto/router.pb.go +++ b/router/service/proto/router.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/router/proto/router.proto +// source: router.proto package go_micro_router @@ -43,7 +43,7 @@ func (x AdvertType) String() string { } func (AdvertType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{0} + return fileDescriptor_367072455c71aedc, []int{0} } // EventType defines the type of event @@ -72,7 +72,7 @@ func (x EventType) String() string { } func (EventType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{1} + return fileDescriptor_367072455c71aedc, []int{1} } // Empty request @@ -86,7 +86,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{0} + return fileDescriptor_367072455c71aedc, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { @@ -118,7 +118,7 @@ func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{1} + return fileDescriptor_367072455c71aedc, []int{1} } func (m *Response) XXX_Unmarshal(b []byte) error { @@ -151,7 +151,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{2} + return fileDescriptor_367072455c71aedc, []int{2} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -191,7 +191,7 @@ func (m *LookupRequest) Reset() { *m = LookupRequest{} } func (m *LookupRequest) String() string { return proto.CompactTextString(m) } func (*LookupRequest) ProtoMessage() {} func (*LookupRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{3} + return fileDescriptor_367072455c71aedc, []int{3} } func (m *LookupRequest) XXX_Unmarshal(b []byte) error { @@ -231,7 +231,7 @@ func (m *LookupResponse) Reset() { *m = LookupResponse{} } func (m *LookupResponse) String() string { return proto.CompactTextString(m) } func (*LookupResponse) ProtoMessage() {} func (*LookupResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{4} + return fileDescriptor_367072455c71aedc, []int{4} } func (m *LookupResponse) XXX_Unmarshal(b []byte) error { @@ -271,7 +271,7 @@ func (m *QueryRequest) Reset() { *m = QueryRequest{} } func (m *QueryRequest) String() string { return proto.CompactTextString(m) } func (*QueryRequest) ProtoMessage() {} func (*QueryRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{5} + return fileDescriptor_367072455c71aedc, []int{5} } func (m *QueryRequest) XXX_Unmarshal(b []byte) error { @@ -311,7 +311,7 @@ func (m *QueryResponse) Reset() { *m = QueryResponse{} } func (m *QueryResponse) String() string { return proto.CompactTextString(m) } func (*QueryResponse) ProtoMessage() {} func (*QueryResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{6} + return fileDescriptor_367072455c71aedc, []int{6} } func (m *QueryResponse) XXX_Unmarshal(b []byte) error { @@ -350,7 +350,7 @@ func (m *WatchRequest) Reset() { *m = WatchRequest{} } func (m *WatchRequest) String() string { return proto.CompactTextString(m) } func (*WatchRequest) ProtoMessage() {} func (*WatchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{7} + return fileDescriptor_367072455c71aedc, []int{7} } func (m *WatchRequest) XXX_Unmarshal(b []byte) error { @@ -392,7 +392,7 @@ func (m *Advert) Reset() { *m = Advert{} } func (m *Advert) String() string { return proto.CompactTextString(m) } func (*Advert) ProtoMessage() {} func (*Advert) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{8} + return fileDescriptor_367072455c71aedc, []int{8} } func (m *Advert) XXX_Unmarshal(b []byte) error { @@ -448,47 +448,6 @@ func (m *Advert) GetEvents() []*Event { return nil } -// Solicit solicits routes -type Solicit struct { - // id of the soliciting router - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Solicit) Reset() { *m = Solicit{} } -func (m *Solicit) String() string { return proto.CompactTextString(m) } -func (*Solicit) ProtoMessage() {} -func (*Solicit) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{9} -} - -func (m *Solicit) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Solicit.Unmarshal(m, b) -} -func (m *Solicit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Solicit.Marshal(b, m, deterministic) -} -func (m *Solicit) XXX_Merge(src proto.Message) { - xxx_messageInfo_Solicit.Merge(m, src) -} -func (m *Solicit) XXX_Size() int { - return xxx_messageInfo_Solicit.Size(m) -} -func (m *Solicit) XXX_DiscardUnknown() { - xxx_messageInfo_Solicit.DiscardUnknown(m) -} - -var xxx_messageInfo_Solicit proto.InternalMessageInfo - -func (m *Solicit) GetId() string { - if m != nil { - return m.Id - } - return "" -} - // ProcessResponse is returned by Process type ProcessResponse struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -500,7 +459,7 @@ func (m *ProcessResponse) Reset() { *m = ProcessResponse{} } func (m *ProcessResponse) String() string { return proto.CompactTextString(m) } func (*ProcessResponse) ProtoMessage() {} func (*ProcessResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{10} + return fileDescriptor_367072455c71aedc, []int{9} } func (m *ProcessResponse) XXX_Unmarshal(b []byte) error { @@ -532,7 +491,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{11} + return fileDescriptor_367072455c71aedc, []int{10} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -564,7 +523,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{12} + return fileDescriptor_367072455c71aedc, []int{11} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -596,7 +555,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{13} + return fileDescriptor_367072455c71aedc, []int{12} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -634,7 +593,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{14} + return fileDescriptor_367072455c71aedc, []int{13} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -693,7 +652,7 @@ func (m *Query) Reset() { *m = Query{} } func (m *Query) String() string { return proto.CompactTextString(m) } func (*Query) ProtoMessage() {} func (*Query) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{15} + return fileDescriptor_367072455c71aedc, []int{14} } func (m *Query) XXX_Unmarshal(b []byte) error { @@ -760,7 +719,7 @@ func (m *Route) Reset() { *m = Route{} } func (m *Route) String() string { return proto.CompactTextString(m) } func (*Route) ProtoMessage() {} func (*Route) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{16} + return fileDescriptor_367072455c71aedc, []int{15} } func (m *Route) XXX_Unmarshal(b []byte) error { @@ -842,7 +801,7 @@ func (m *Status) Reset() { *m = Status{} } func (m *Status) String() string { return proto.CompactTextString(m) } func (*Status) ProtoMessage() {} func (*Status) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{17} + return fileDescriptor_367072455c71aedc, []int{16} } func (m *Status) XXX_Unmarshal(b []byte) error { @@ -888,7 +847,7 @@ func (m *StatusResponse) Reset() { *m = StatusResponse{} } func (m *StatusResponse) String() string { return proto.CompactTextString(m) } func (*StatusResponse) ProtoMessage() {} func (*StatusResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2dd64c6ec344e37e, []int{18} + return fileDescriptor_367072455c71aedc, []int{17} } func (m *StatusResponse) XXX_Unmarshal(b []byte) error { @@ -928,7 +887,6 @@ func init() { proto.RegisterType((*QueryResponse)(nil), "go.micro.router.QueryResponse") proto.RegisterType((*WatchRequest)(nil), "go.micro.router.WatchRequest") proto.RegisterType((*Advert)(nil), "go.micro.router.Advert") - proto.RegisterType((*Solicit)(nil), "go.micro.router.Solicit") proto.RegisterType((*ProcessResponse)(nil), "go.micro.router.ProcessResponse") proto.RegisterType((*CreateResponse)(nil), "go.micro.router.CreateResponse") proto.RegisterType((*DeleteResponse)(nil), "go.micro.router.DeleteResponse") @@ -940,56 +898,52 @@ func init() { proto.RegisterType((*StatusResponse)(nil), "go.micro.router.StatusResponse") } -func init() { - proto.RegisterFile("github.com/micro/go-micro/router/proto/router.proto", fileDescriptor_2dd64c6ec344e37e) -} +func init() { proto.RegisterFile("router.proto", fileDescriptor_367072455c71aedc) } -var fileDescriptor_2dd64c6ec344e37e = []byte{ - // 736 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0x4f, 0x4f, 0xdb, 0x4a, - 0x10, 0xb7, 0x93, 0xd8, 0x79, 0x99, 0x17, 0x42, 0xde, 0xe8, 0x09, 0x4c, 0xde, 0x03, 0x22, 0x9f, - 0x10, 0xa2, 0x4e, 0x15, 0xae, 0xfd, 0x43, 0xa0, 0x54, 0x95, 0xca, 0xa1, 0x35, 0xa0, 0x9e, 0x8d, - 0xb3, 0x0a, 0x16, 0x49, 0xd6, 0xec, 0xae, 0x41, 0x39, 0xf7, 0xd3, 0xf4, 0xd2, 0x4b, 0x3f, 0x52, - 0xbf, 0x48, 0xe5, 0xdd, 0x75, 0x08, 0x71, 0x16, 0x09, 0x4e, 0xd9, 0xf9, 0xf7, 0x9b, 0x99, 0xdd, - 0xdf, 0x8c, 0x03, 0x87, 0xa3, 0x44, 0x5c, 0x67, 0x57, 0x41, 0x4c, 0x27, 0xbd, 0x49, 0x12, 0x33, - 0xda, 0x1b, 0xd1, 0x57, 0xea, 0xc0, 0x68, 0x26, 0x08, 0xeb, 0xa5, 0x8c, 0x8a, 0x42, 0x08, 0xa4, - 0x80, 0xe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0x29, 0x9e, 0x17, 0x0d, 0xc3, 0xbc, 0x02, 0x6e, 0x69, 0x21, 0x59, 0x39, 0x88, - 0xe2, 0xc5, 0x33, 0x40, 0x96, 0x76, 0x98, 0x04, 0x51, 0x84, 0x7a, 0x06, 0xc8, 0xd2, 0xda, 0xb3, - 0x70, 0x00, 0xb5, 0xfc, 0xc3, 0xfa, 0xc4, 0xed, 0x94, 0xa9, 0xb4, 0xf8, 0x25, 0xf6, 0x2d, 0xfc, - 0x54, 0x6c, 0xad, 0x6d, 0xc3, 0x47, 0x4c, 0x03, 0xed, 0x98, 0xcc, 0x05, 0xd2, 0x95, 0x2b, 0xff, - 0x14, 0x1c, 0xfe, 0x09, 0x00, 0x00, 0xff, 0xff, 0x47, 0x98, 0xd8, 0x20, 0x4b, 0x08, 0x00, 0x00, +var fileDescriptor_367072455c71aedc = []byte{ + // 693 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0x4f, 0x4f, 0xdb, 0x4a, + 0x10, 0xb7, 0x93, 0xd8, 0x79, 0x99, 0x17, 0x8c, 0xdf, 0xe8, 0x09, 0xac, 0xb4, 0x40, 0xe4, 0x13, + 0x42, 0xc8, 0x54, 0xe9, 0xb5, 0xff, 0x02, 0xa5, 0xaa, 0x54, 0x0e, 0xad, 0x0b, 0xea, 0xd9, 0xd8, + 0x23, 0x6a, 0x91, 0xd8, 0x66, 0x77, 0x03, 0xca, 0xb9, 0x9f, 0xa6, 0xe7, 0x7e, 0xa4, 0x5e, 0xfb, + 0x21, 0x2a, 0xef, 0xae, 0x43, 0x88, 0x31, 0x12, 0x9c, 0xbc, 0xf3, 0xef, 0x37, 0xb3, 0x3b, 0xbf, + 0x19, 0x43, 0x9f, 0xe5, 0x33, 0x41, 0x2c, 0x28, 0x58, 0x2e, 0x72, 0x5c, 0xbf, 0xc8, 0x83, 0x69, + 0x1a, 0xb3, 0x3c, 0x50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xe5, 0xbf, 0xef, 0x81, 0xd7, 0xa9, 0x13, 0x61, + 0xf9, 0x67, 0xe9, 0x1b, 0xf8, 0xb1, 0xda, 0x39, 0x5b, 0x0d, 0xff, 0x19, 0x0d, 0xb4, 0xdd, 0x64, + 0xae, 0x90, 0xce, 0x6d, 0xf9, 0xdf, 0x7e, 0xf9, 0x37, 0x00, 0x00, 0xff, 0xff, 0x86, 0x75, 0x28, + 0x0b, 0xc7, 0x07, 0x00, 0x00, } diff --git a/router/service/proto/router.pb.micro.go b/router/service/proto/router.pb.micro.go index 024989b9..3c0059f8 100644 --- a/router/service/proto/router.pb.micro.go +++ b/router/service/proto/router.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/router/proto/router.proto +// source: router.proto package go_micro_router @@ -37,7 +37,6 @@ type RouterService interface { Lookup(ctx context.Context, in *LookupRequest, opts ...client.CallOption) (*LookupResponse, error) Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Router_WatchService, error) Advertise(ctx context.Context, in *Request, opts ...client.CallOption) (Router_AdvertiseService, error) - Solicit(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) Process(ctx context.Context, in *Advert, opts ...client.CallOption) (*ProcessResponse, error) Status(ctx context.Context, in *Request, opts ...client.CallOption) (*StatusResponse, error) } @@ -158,16 +157,6 @@ func (x *routerServiceAdvertise) Recv() (*Advert, error) { return m, nil } -func (c *routerService) Solicit(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) { - req := c.c.NewRequest(c.name, "Router.Solicit", in) - out := new(Response) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *routerService) Process(ctx context.Context, in *Advert, opts ...client.CallOption) (*ProcessResponse, error) { req := c.c.NewRequest(c.name, "Router.Process", in) out := new(ProcessResponse) @@ -194,7 +183,6 @@ type RouterHandler interface { Lookup(context.Context, *LookupRequest, *LookupResponse) error Watch(context.Context, *WatchRequest, Router_WatchStream) error Advertise(context.Context, *Request, Router_AdvertiseStream) error - Solicit(context.Context, *Request, *Response) error Process(context.Context, *Advert, *ProcessResponse) error Status(context.Context, *Request, *StatusResponse) error } @@ -204,7 +192,6 @@ func RegisterRouterHandler(s server.Server, hdlr RouterHandler, opts ...server.H Lookup(ctx context.Context, in *LookupRequest, out *LookupResponse) error Watch(ctx context.Context, stream server.Stream) error Advertise(ctx context.Context, stream server.Stream) error - Solicit(ctx context.Context, in *Request, out *Response) error Process(ctx context.Context, in *Advert, out *ProcessResponse) error Status(ctx context.Context, in *Request, out *StatusResponse) error } @@ -293,10 +280,6 @@ func (x *routerAdvertiseStream) Send(m *Advert) error { return x.stream.Send(m) } -func (h *routerHandler) Solicit(ctx context.Context, in *Request, out *Response) error { - return h.RouterHandler.Solicit(ctx, in, out) -} - func (h *routerHandler) Process(ctx context.Context, in *Advert, out *ProcessResponse) error { return h.RouterHandler.Process(ctx, in, out) } diff --git a/router/service/proto/router.proto b/router/service/proto/router.proto index 0ae180c9..44539332 100644 --- a/router/service/proto/router.proto +++ b/router/service/proto/router.proto @@ -7,7 +7,6 @@ service Router { rpc Lookup(LookupRequest) returns (LookupResponse) {}; rpc Watch(WatchRequest) returns (stream Event) {}; rpc Advertise(Request) returns (stream Advert) {}; - rpc Solicit(Request) returns (Response) {}; rpc Process(Advert) returns (ProcessResponse) {}; rpc Status(Request) returns (StatusResponse) {}; } @@ -74,12 +73,6 @@ message Advert { repeated Event events = 5; } -// Solicit solicits routes -message Solicit { - // id of the soliciting router - string id = 1; -} - // ProcessResponse is returned by Process message ProcessResponse {} diff --git a/router/service/service.go b/router/service/service.go index 1087da3d..b92a03fd 100644 --- a/router/service/service.go +++ b/router/service/service.go @@ -220,42 +220,6 @@ func (s *svc) Process(advert *router.Advert) error { return nil } -// Solicit advertise all routes -func (s *svc) Solicit() error { - // list all the routes - routes, err := s.table.List() - if err != nil { - return err - } - - // build events to advertise - events := make([]*router.Event, len(routes)) - for i := range events { - events[i] = &router.Event{ - Type: router.Update, - Timestamp: time.Now(), - Route: routes[i], - } - } - - advert := &router.Advert{ - Id: s.opts.Id, - Type: router.RouteUpdate, - Timestamp: time.Now(), - TTL: time.Duration(router.DefaultAdvertTTL), - Events: events, - } - - select { - case s.advertChan <- advert: - case <-s.exit: - close(s.advertChan) - return nil - } - - return nil -} - // Status returns router status func (s *svc) Status() router.Status { s.Lock() From 607a226e34ac200ced9d14974c19c641fd72b6f1 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Fri, 17 Jan 2020 12:14:56 +0000 Subject: [PATCH 142/788] Updated debug logs to make them less verbose --- network/default.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/network/default.go b/network/default.go index fec4a9ce..098920c1 100644 --- a/network/default.go +++ b/network/default.go @@ -1190,6 +1190,7 @@ func (n *network) manage() { links[peer.link] = time.Now() } case <-prune.C: + log.Debugf("Network node %s pruning stale peers", n.id) pruned := n.PruneStalePeers(PruneTime) for id, peer := range pruned { @@ -1332,12 +1333,11 @@ func (n *network) sendTo(method, channel string, peer *node, msg proto.Message) c, err := n.tunnel.Dial(channel, tunnel.DialWait(false), tunnel.DialLink(peer.link)) if err != nil { if peerNode := n.GetPeerNode(peer.id); peerNode != nil { - log.Debugf("Network found peer %s: %v", peer.id, peerNode) // update node status when error happens peerNode.status.err.Update(err) - log.Debugf("Network increment node peer %p %v count to: %d", peerNode, peerNode, peerNode.status.Error().Count()) + log.Debugf("Network increment peer %v error count to: %d", peerNode, peerNode, peerNode.status.Error().Count()) if count := peerNode.status.Error().Count(); count == MaxPeerErrors { - log.Debugf("Network node peer %v count exceeded %d: %d", peerNode, MaxPeerErrors, peerNode.status.Error().Count()) + log.Debugf("Network peer %v error count exceeded %d. Prunning.", peerNode, MaxPeerErrors) n.PrunePeer(peerNode.id) } } From 624f1c1980b4f7a165f66b875bf5fe9e998b76a1 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Fri, 17 Jan 2020 12:58:13 +0000 Subject: [PATCH 143/788] Continue processing Sync if no routes were returned from router Query --- network/default.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/network/default.go b/network/default.go index 098920c1..ad83c133 100644 --- a/network/default.go +++ b/network/default.go @@ -942,7 +942,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { } routes, err := n.router.Table().Query(q...) - if err != nil { + if err != nil && err != router.ErrRouteNotFound { log.Debugf("Network node %s failed listing best routes for %s: %v", n.id, route.Service, err) continue } @@ -1286,7 +1286,7 @@ func (n *network) getProtoRoutes() ([]*pbRtr.Route, error) { } routes, err := n.router.Table().Query(q...) - if err != nil { + if err != nil && err != router.ErrRouteNotFound { return nil, err } From a03791c5815e7a3c6cece48c4946bf2f54b60027 Mon Sep 17 00:00:00 2001 From: shu xian Date: Fri, 17 Jan 2020 21:32:00 +0800 Subject: [PATCH 144/788] set DefaultClient --- config/source/mucp/mucp.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/source/mucp/mucp.go b/config/source/mucp/mucp.go index eeb4bb84..119c74da 100644 --- a/config/source/mucp/mucp.go +++ b/config/source/mucp/mucp.go @@ -3,7 +3,7 @@ package mucp import ( "context" - "github.com/micro/go-micro/config/cmd" + "github.com/micro/go-micro/client" "github.com/micro/go-micro/config/source" proto "github.com/micro/go-micro/config/source/mucp/proto" "github.com/micro/go-micro/util/log" @@ -11,6 +11,7 @@ import ( var ( DefaultServiceName = "go.micro.config" + DefaultClient = client.DefaultClient ) type mucpSource struct { @@ -65,7 +66,7 @@ func NewSource(opts ...source.Option) source.Source { s := &mucpSource{ serviceName: addr, opts: options, - client: proto.NewSourceService(addr, *cmd.DefaultOptions().Client), + client: proto.NewSourceService(addr, DefaultClient), } return s From be788415adf35a57b870d8528c921a4ba5b855fb Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 17 Jan 2020 14:14:47 +0000 Subject: [PATCH 145/788] minor runtime fixes --- runtime/default.go | 2 +- runtime/options.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/runtime/default.go b/runtime/default.go index 740ceb7d..453510a3 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -155,7 +155,7 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error { defer r.Unlock() if _, ok := r.services[s.Name]; ok { - return errors.New("service already registered") + return errors.New("service already running") } var options CreateOptions diff --git a/runtime/options.go b/runtime/options.go index 02bc99e8..5c2ce688 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -54,6 +54,13 @@ type ReadOptions struct { Type string } +// CreateType sets the type of service to create +func CreateType(t string) CreateOption { + return func(o *CreateOptions) { + o.Type = t + } +} + // WithCommand specifies the command to execute func WithCommand(args ...string) CreateOption { return func(o *CreateOptions) { From d7b9b2713b9bf3265bcca23ded6fcdb399a2087b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 17 Jan 2020 15:23:10 +0000 Subject: [PATCH 146/788] don't block forever --- router/table.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/router/table.go b/router/table.go index 821d782c..1f3c96ef 100644 --- a/router/table.go +++ b/router/table.go @@ -42,6 +42,8 @@ func (t *table) sendEvent(e *Event) { select { case w.resChan <- e: case <-w.done: + // don't block forever + case <-time.After(time.Second): } } } From ad28b72dd3e56d8ceb57234cc5800245652f6edc Mon Sep 17 00:00:00 2001 From: shu xian Date: Fri, 17 Jan 2020 23:27:41 +0800 Subject: [PATCH 147/788] rename mucpSource to service --- config/source/mucp/mucp.go | 16 ++-- config/source/mucp/proto/mucp.pb.go | 56 +++++------ config/source/mucp/proto/mucp.pb.micro.go | 110 +++++++++++----------- config/source/mucp/proto/mucp.proto | 2 +- config/source/mucp/watcher.go | 4 +- 5 files changed, 94 insertions(+), 94 deletions(-) diff --git a/config/source/mucp/mucp.go b/config/source/mucp/mucp.go index 119c74da..72be5e9f 100644 --- a/config/source/mucp/mucp.go +++ b/config/source/mucp/mucp.go @@ -14,14 +14,14 @@ var ( DefaultClient = client.DefaultClient ) -type mucpSource struct { +type service struct { serviceName string key string opts source.Options - client proto.SourceService + client proto.Service } -func (m *mucpSource) Read() (set *source.ChangeSet, err error) { +func (m *service) Read() (set *source.ChangeSet, err error) { req, err := m.client.Read(context.Background(), &proto.ReadRequest{Path: m.key}) if err != nil { return nil, err @@ -30,7 +30,7 @@ func (m *mucpSource) Read() (set *source.ChangeSet, err error) { return toChangeSet(req.Change.ChangeSet), nil } -func (m *mucpSource) Watch() (w source.Watcher, err error) { +func (m *service) Watch() (w source.Watcher, err error) { stream, err := m.client.Watch(context.Background(), &proto.WatchRequest{Key: m.key}) if err != nil { log.Error("watch err: ", err) @@ -40,11 +40,11 @@ func (m *mucpSource) Watch() (w source.Watcher, err error) { } // Write is unsupported -func (m *mucpSource) Write(cs *source.ChangeSet) error { +func (m *service) Write(cs *source.ChangeSet) error { return nil } -func (m *mucpSource) String() string { +func (m *service) String() string { return "mucp" } @@ -63,10 +63,10 @@ func NewSource(opts ...source.Option) source.Source { } } - s := &mucpSource{ + s := &service{ serviceName: addr, opts: options, - client: proto.NewSourceService(addr, DefaultClient), + client: proto.NewService(addr, DefaultClient), } return s diff --git a/config/source/mucp/proto/mucp.pb.go b/config/source/mucp/proto/mucp.pb.go index b72b9070..08024585 100644 --- a/config/source/mucp/proto/mucp.pb.go +++ b/config/source/mucp/proto/mucp.pb.go @@ -618,32 +618,32 @@ func init() { func init() { proto.RegisterFile("proto/mucp.proto", fileDescriptor_942f149553cfb65d) } var fileDescriptor_942f149553cfb65d = []byte{ - // 425 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xdd, 0x6e, 0xd3, 0x30, - 0x14, 0xc7, 0x93, 0xa6, 0xcb, 0xc8, 0xc9, 0x47, 0xab, 0x73, 0x81, 0xa2, 0x08, 0x89, 0x60, 0x09, - 0x29, 0x02, 0xc9, 0x1b, 0xdd, 0x23, 0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, 0x90, 0x38, 0xd7, 0xee, 0x77, 0x5f, 0x7f, 0xdb, 0x37, 0xbf, 0x03, 0x00, 0x00, 0xff, - 0xff, 0x66, 0x66, 0xa8, 0x5d, 0xef, 0x03, 0x00, 0x00, + // 429 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xdd, 0x8a, 0xd3, 0x40, + 0x14, 0xc7, 0x9b, 0xb6, 0x9b, 0x9a, 0xd3, 0x24, 0x2d, 0xe7, 0x42, 0x42, 0x10, 0x8c, 0x03, 0x42, + 0x51, 0x98, 0x5d, 0xbb, 0x8f, 0xb0, 0xde, 0xe9, 0xd5, 0x2c, 0xa2, 0xb7, 0xe3, 0xf4, 0xec, 0xb6, + 0xac, 0x69, 0x62, 0x66, 0x2a, 0xf8, 0x08, 0xfa, 0xd4, 0x92, 0x99, 0xc9, 0x36, 0xa9, 0xf8, 0xd1, + 0xbb, 0xf3, 0xf9, 0x9f, 0x7f, 0xce, 0x8f, 0xc0, 0xb2, 0x6e, 0x2a, 0x53, 0x5d, 0x96, 0x07, 0x55, + 0x73, 0x1b, 0xb2, 0x1f, 0x01, 0x44, 0x37, 0x5b, 0xb9, 0xbf, 0xa7, 0x5b, 0x32, 0x88, 0x30, 0xdd, + 0x48, 0x23, 0xb3, 0xa0, 0x08, 0x56, 0xb1, 0xb0, 0x31, 0xe6, 0xf0, 0x44, 0x6d, 0x49, 0x3d, 0xe8, + 0x43, 0x99, 0x8d, 0x8b, 0x60, 0x15, 0x89, 0xc7, 0x1c, 0x9f, 0x42, 0x78, 0x57, 0x35, 0xa5, 0x34, + 0xd9, 0xc4, 0x76, 0x7c, 0xd6, 0xd6, 0x75, 0x75, 0x68, 0x14, 0x65, 0x53, 0x57, 0x77, 0x19, 0x3e, + 0x83, 0xc8, 0xec, 0x4a, 0xd2, 0x46, 0x96, 0x75, 0x76, 0x51, 0x04, 0xab, 0x89, 0x38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 0x27, 0x54, 0x47, 0xed, 0xb0, 0xa3, 0x84, 0x29, 0x1f, 0x00, 0xce, 0x17, 0xfc, + 0x04, 0x9f, 0x1d, 0x76, 0x38, 0x30, 0xe5, 0x03, 0x92, 0xf9, 0x82, 0x9f, 0x70, 0x1a, 0xe1, 0x4b, + 0x98, 0xb6, 0x68, 0x30, 0xe6, 0x3d, 0x60, 0x79, 0xc2, 0xfb, 0xbc, 0xdc, 0x58, 0x7b, 0x59, 0x8c, + 0x79, 0x8f, 0x4a, 0x9e, 0xf0, 0xfe, 0xb9, 0xd9, 0x08, 0x5f, 0xc1, 0x85, 0xbd, 0x16, 0x26, 0xbc, + 0x7f, 0xd7, 0x3c, 0xe5, 0x83, 0x23, 0xb2, 0xd1, 0x55, 0xf0, 0x39, 0xb4, 0x3f, 0xf7, 0xf5, 0xaf, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x75, 0xb2, 0x55, 0xf0, 0x03, 0x00, 0x00, } diff --git a/config/source/mucp/proto/mucp.pb.micro.go b/config/source/mucp/proto/mucp.pb.micro.go index 088cd8ee..430b7842 100644 --- a/config/source/mucp/proto/mucp.pb.micro.go +++ b/config/source/mucp/proto/mucp.pb.micro.go @@ -31,37 +31,37 @@ var _ context.Context var _ client.Option var _ server.Option -// Client API for Source service +// Client API for Service service -type SourceService interface { +type Service interface { Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) - Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Source_WatchService, error) + Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Service_WatchService, error) } -type sourceService struct { +type service struct { c client.Client name string } -func NewSourceService(name string, c client.Client) SourceService { +func NewService(name string, c client.Client) Service { if c == nil { c = client.NewClient() } if len(name) == 0 { - name = "source" + name = "service" } - return &sourceService{ + return &service{ c: c, name: name, } } -func (c *sourceService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { - req := c.c.NewRequest(c.name, "Source.Create", in) +func (c *service) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { + req := c.c.NewRequest(c.name, "Service.Create", in) out := new(CreateResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -70,8 +70,8 @@ func (c *sourceService) Create(ctx context.Context, in *CreateRequest, opts ...c return out, nil } -func (c *sourceService) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) { - req := c.c.NewRequest(c.name, "Source.Update", in) +func (c *service) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) { + req := c.c.NewRequest(c.name, "Service.Update", in) out := new(UpdateResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -80,8 +80,8 @@ func (c *sourceService) Update(ctx context.Context, in *UpdateRequest, opts ...c return out, nil } -func (c *sourceService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { - req := c.c.NewRequest(c.name, "Source.Delete", in) +func (c *service) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { + req := c.c.NewRequest(c.name, "Service.Delete", in) out := new(DeleteResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -90,8 +90,8 @@ func (c *sourceService) Delete(ctx context.Context, in *DeleteRequest, opts ...c return out, nil } -func (c *sourceService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { - req := c.c.NewRequest(c.name, "Source.List", in) +func (c *service) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { + req := c.c.NewRequest(c.name, "Service.List", in) out := new(ListResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -100,8 +100,8 @@ func (c *sourceService) List(ctx context.Context, in *ListRequest, opts ...clien return out, nil } -func (c *sourceService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) { - req := c.c.NewRequest(c.name, "Source.Read", in) +func (c *service) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) { + req := c.c.NewRequest(c.name, "Service.Read", in) out := new(ReadResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -110,8 +110,8 @@ func (c *sourceService) Read(ctx context.Context, in *ReadRequest, opts ...clien return out, nil } -func (c *sourceService) Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Source_WatchService, error) { - req := c.c.NewRequest(c.name, "Source.Watch", &WatchRequest{}) +func (c *service) Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Service_WatchService, error) { + req := c.c.NewRequest(c.name, "Service.Watch", &WatchRequest{}) stream, err := c.c.Stream(ctx, req, opts...) if err != nil { return nil, err @@ -119,33 +119,33 @@ func (c *sourceService) Watch(ctx context.Context, in *WatchRequest, opts ...cli if err := stream.Send(in); err != nil { return nil, err } - return &sourceServiceWatch{stream}, nil + return &serviceWatch{stream}, nil } -type Source_WatchService interface { +type Service_WatchService interface { SendMsg(interface{}) error RecvMsg(interface{}) error Close() error Recv() (*WatchResponse, error) } -type sourceServiceWatch struct { +type serviceWatch struct { stream client.Stream } -func (x *sourceServiceWatch) Close() error { +func (x *serviceWatch) Close() error { return x.stream.Close() } -func (x *sourceServiceWatch) SendMsg(m interface{}) error { +func (x *serviceWatch) SendMsg(m interface{}) error { return x.stream.Send(m) } -func (x *sourceServiceWatch) RecvMsg(m interface{}) error { +func (x *serviceWatch) RecvMsg(m interface{}) error { return x.stream.Recv(m) } -func (x *sourceServiceWatch) Recv() (*WatchResponse, error) { +func (x *serviceWatch) Recv() (*WatchResponse, error) { m := new(WatchResponse) err := x.stream.Recv(m) if err != nil { @@ -154,19 +154,19 @@ func (x *sourceServiceWatch) Recv() (*WatchResponse, error) { return m, nil } -// Server API for Source service +// Server API for Service service -type SourceHandler interface { +type ServiceHandler interface { Create(context.Context, *CreateRequest, *CreateResponse) error Update(context.Context, *UpdateRequest, *UpdateResponse) error Delete(context.Context, *DeleteRequest, *DeleteResponse) error List(context.Context, *ListRequest, *ListResponse) error Read(context.Context, *ReadRequest, *ReadResponse) error - Watch(context.Context, *WatchRequest, Source_WatchStream) error + Watch(context.Context, *WatchRequest, Service_WatchStream) error } -func RegisterSourceHandler(s server.Server, hdlr SourceHandler, opts ...server.HandlerOption) error { - type source interface { +func RegisterServiceHandler(s server.Server, hdlr ServiceHandler, opts ...server.HandlerOption) error { + type service interface { Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error @@ -174,68 +174,68 @@ func RegisterSourceHandler(s server.Server, hdlr SourceHandler, opts ...server.H Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error Watch(ctx context.Context, stream server.Stream) error } - type Source struct { - source + type Service struct { + service } - h := &sourceHandler{hdlr} - return s.Handle(s.NewHandler(&Source{h}, opts...)) + h := &serviceHandler{hdlr} + return s.Handle(s.NewHandler(&Service{h}, opts...)) } -type sourceHandler struct { - SourceHandler +type serviceHandler struct { + ServiceHandler } -func (h *sourceHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { - return h.SourceHandler.Create(ctx, in, out) +func (h *serviceHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { + return h.ServiceHandler.Create(ctx, in, out) } -func (h *sourceHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error { - return h.SourceHandler.Update(ctx, in, out) +func (h *serviceHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error { + return h.ServiceHandler.Update(ctx, in, out) } -func (h *sourceHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { - return h.SourceHandler.Delete(ctx, in, out) +func (h *serviceHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { + return h.ServiceHandler.Delete(ctx, in, out) } -func (h *sourceHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { - return h.SourceHandler.List(ctx, in, out) +func (h *serviceHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { + return h.ServiceHandler.List(ctx, in, out) } -func (h *sourceHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error { - return h.SourceHandler.Read(ctx, in, out) +func (h *serviceHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error { + return h.ServiceHandler.Read(ctx, in, out) } -func (h *sourceHandler) Watch(ctx context.Context, stream server.Stream) error { +func (h *serviceHandler) Watch(ctx context.Context, stream server.Stream) error { m := new(WatchRequest) if err := stream.Recv(m); err != nil { return err } - return h.SourceHandler.Watch(ctx, m, &sourceWatchStream{stream}) + return h.ServiceHandler.Watch(ctx, m, &serviceWatchStream{stream}) } -type Source_WatchStream interface { +type Service_WatchStream interface { SendMsg(interface{}) error RecvMsg(interface{}) error Close() error Send(*WatchResponse) error } -type sourceWatchStream struct { +type serviceWatchStream struct { stream server.Stream } -func (x *sourceWatchStream) Close() error { +func (x *serviceWatchStream) Close() error { return x.stream.Close() } -func (x *sourceWatchStream) SendMsg(m interface{}) error { +func (x *serviceWatchStream) SendMsg(m interface{}) error { return x.stream.Send(m) } -func (x *sourceWatchStream) RecvMsg(m interface{}) error { +func (x *serviceWatchStream) RecvMsg(m interface{}) error { return x.stream.Recv(m) } -func (x *sourceWatchStream) Send(m *WatchResponse) error { +func (x *serviceWatchStream) Send(m *WatchResponse) error { return x.stream.Send(m) } diff --git a/config/source/mucp/proto/mucp.proto b/config/source/mucp/proto/mucp.proto index 71bf99bc..2e88c7e5 100644 --- a/config/source/mucp/proto/mucp.proto +++ b/config/source/mucp/proto/mucp.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -service Source { +service Service { rpc Create (CreateRequest) returns (CreateResponse) { } rpc Update (UpdateRequest) returns (UpdateResponse) { diff --git a/config/source/mucp/watcher.go b/config/source/mucp/watcher.go index 466703e9..fd6fb6fe 100644 --- a/config/source/mucp/watcher.go +++ b/config/source/mucp/watcher.go @@ -6,10 +6,10 @@ import ( ) type watcher struct { - stream proto.Source_WatchService + stream proto.Service_WatchService } -func newWatcher(stream proto.Source_WatchService) (source.Watcher, error) { +func newWatcher(stream proto.Service_WatchService) (source.Watcher, error) { return &watcher{stream: stream}, nil } From bf9f319cdf6ba198befc969fc684d6d64c3b8b0f Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Fri, 17 Jan 2020 15:35:51 +0000 Subject: [PATCH 148/788] Update route metric before sending the Sync message --- network/default.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/network/default.go b/network/default.go index ad83c133..5b961537 100644 --- a/network/default.go +++ b/network/default.go @@ -1293,6 +1293,20 @@ func (n *network) getProtoRoutes() ([]*pbRtr.Route, error) { // encode the routes to protobuf pbRoutes := make([]*pbRtr.Route, 0, len(routes)) for _, route := range routes { + // calculate route metric and add to the advertised metric + // we need to make sure we do not overflow math.MaxInt64 + metric := n.getRouteMetric(route.Router, route.Gateway, route.Link) + log.Tracef("Network metric for router %s and gateway %s: %v", route.Router, route.Gateway, metric) + + // check we don't overflow max int 64 + if d := route.Metric + metric; d <= 0 { + // set to max int64 if we overflow + route.Metric = math.MaxInt64 + } else { + // set the combined value of metrics otherwise + route.Metric = d + } + // generate new route proto pbRoute := pbUtil.RouteToProto(route) // mask the route before outbounding From 9ea4919b9b64a41a3334789e8520d231be6c35df Mon Sep 17 00:00:00 2001 From: shu xian Date: Fri, 17 Jan 2020 23:53:33 +0800 Subject: [PATCH 149/788] rename mucp source directory to service --- config/source/{mucp => service}/mucp.go | 4 ++-- config/source/{mucp => service}/options.go | 2 +- config/source/{mucp => service}/proto/mucp.pb.go | 0 config/source/{mucp => service}/proto/mucp.pb.micro.go | 0 config/source/{mucp => service}/proto/mucp.proto | 0 config/source/{mucp => service}/util.go | 4 ++-- config/source/{mucp => service}/watcher.go | 4 ++-- 7 files changed, 7 insertions(+), 7 deletions(-) rename config/source/{mucp => service}/mucp.go (94%) rename config/source/{mucp => service}/options.go (95%) rename config/source/{mucp => service}/proto/mucp.pb.go (100%) rename config/source/{mucp => service}/proto/mucp.pb.micro.go (100%) rename config/source/{mucp => service}/proto/mucp.proto (100%) rename config/source/{mucp => service}/util.go (78%) rename config/source/{mucp => service}/watcher.go (86%) diff --git a/config/source/mucp/mucp.go b/config/source/service/mucp.go similarity index 94% rename from config/source/mucp/mucp.go rename to config/source/service/mucp.go index 72be5e9f..3f5ee0fe 100644 --- a/config/source/mucp/mucp.go +++ b/config/source/service/mucp.go @@ -1,11 +1,11 @@ -package mucp +package service import ( "context" "github.com/micro/go-micro/client" "github.com/micro/go-micro/config/source" - proto "github.com/micro/go-micro/config/source/mucp/proto" + proto "github.com/micro/go-micro/config/source/service/proto" "github.com/micro/go-micro/util/log" ) diff --git a/config/source/mucp/options.go b/config/source/service/options.go similarity index 95% rename from config/source/mucp/options.go rename to config/source/service/options.go index c8717cbd..ac4079e9 100644 --- a/config/source/mucp/options.go +++ b/config/source/service/options.go @@ -1,4 +1,4 @@ -package mucp +package service import ( "context" diff --git a/config/source/mucp/proto/mucp.pb.go b/config/source/service/proto/mucp.pb.go similarity index 100% rename from config/source/mucp/proto/mucp.pb.go rename to config/source/service/proto/mucp.pb.go diff --git a/config/source/mucp/proto/mucp.pb.micro.go b/config/source/service/proto/mucp.pb.micro.go similarity index 100% rename from config/source/mucp/proto/mucp.pb.micro.go rename to config/source/service/proto/mucp.pb.micro.go diff --git a/config/source/mucp/proto/mucp.proto b/config/source/service/proto/mucp.proto similarity index 100% rename from config/source/mucp/proto/mucp.proto rename to config/source/service/proto/mucp.proto diff --git a/config/source/mucp/util.go b/config/source/service/util.go similarity index 78% rename from config/source/mucp/util.go rename to config/source/service/util.go index b1a8deec..eb248356 100644 --- a/config/source/mucp/util.go +++ b/config/source/service/util.go @@ -1,10 +1,10 @@ -package mucp +package service import ( "time" "github.com/micro/go-micro/config/source" - proto "github.com/micro/go-micro/config/source/mucp/proto" + proto "github.com/micro/go-micro/config/source/service/proto" ) func toChangeSet(c *proto.ChangeSet) *source.ChangeSet { diff --git a/config/source/mucp/watcher.go b/config/source/service/watcher.go similarity index 86% rename from config/source/mucp/watcher.go rename to config/source/service/watcher.go index fd6fb6fe..d604dddf 100644 --- a/config/source/mucp/watcher.go +++ b/config/source/service/watcher.go @@ -1,8 +1,8 @@ -package mucp +package service import ( "github.com/micro/go-micro/config/source" - proto "github.com/micro/go-micro/config/source/mucp/proto" + proto "github.com/micro/go-micro/config/source/service/proto" ) type watcher struct { From 23d65145e648f658ed721b697ee205fa236ef33e Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Fri, 17 Jan 2020 16:25:18 +0000 Subject: [PATCH 150/788] Use the same logic for advertising routes in Router and Network router.Query() allows to query the routes with given router.Strategy. It uses the same logic as was implemented in flushRoutes but the code was never updated. This way we are consistent across both router and network packages. --- router/default.go | 75 ++++++++---------------------------------- router/default_test.go | 1 - 2 files changed, 13 insertions(+), 63 deletions(-) diff --git a/router/default.go b/router/default.go index 688d5337..07bddc0d 100644 --- a/router/default.go +++ b/router/default.go @@ -88,9 +88,10 @@ func (r *router) Init(opts ...Option) error { // Options returns router options func (r *router) Options() Options { - r.Lock() + r.RLock() + defer r.RUnlock() + options := r.options - r.Unlock() return options } @@ -733,74 +734,24 @@ func (r *router) Process(a *Advert) error { // flushRouteEvents returns a slice of events, one per each route in the routing table func (r *router) flushRouteEvents(evType EventType) ([]*Event, error) { - // Do not advertise anything - if r.options.Advertise == AdvertiseNone { - return []*Event{}, nil + // get a list of routes for each service in our routing table + // for the configured advertising strategy + q := []QueryOption{ + QueryStrategy(r.options.Advertise), } - // list all routes - routes, err := r.table.List() - if err != nil { - return nil, fmt.Errorf("failed listing routes: %s", err) + routes, err := r.Table().Query(q...) + if err != nil && err != ErrRouteNotFound { + return nil, err } - // Return all the routes - if r.options.Advertise == AdvertiseAll { - // build a list of events to advertise - events := make([]*Event, len(routes)) - for i, route := range routes { - event := &Event{ - Type: evType, - Timestamp: time.Now(), - Route: route, - } - events[i] = event - } - return events, nil - } - - // routeMap stores the routes we're going to advertise - bestRoutes := make(map[string]Route) - - // set whether we're advertising only local - advertiseLocal := r.options.Advertise == AdvertiseLocal - - // go through all routes found in the routing table and collapse them to optimal routes - for _, route := range routes { - // if we're only advertising local routes - if advertiseLocal && route.Link != "local" { - continue - } - - // now we're going to find the best routes - - routeKey := route.Service + "@" + route.Network - current, ok := bestRoutes[routeKey] - if !ok { - bestRoutes[routeKey] = route - continue - } - // if the current optimal route metric is higher than routing table route, replace it - if current.Metric > route.Metric { - bestRoutes[routeKey] = route - continue - } - // if the metrics are the same, prefer advertising your own route - if current.Metric == route.Metric { - if route.Router == r.options.Id { - bestRoutes[routeKey] = route - continue - } - } - } - - log.Debugf("Router advertising %d %s routes out of %d", len(bestRoutes), r.options.Advertise, len(routes)) + log.Debugf("Router advertising %d routes with strategy %s", len(routes), r.options.Advertise) // build a list of events to advertise - events := make([]*Event, len(bestRoutes)) + events := make([]*Event, len(routes)) var i int - for _, route := range bestRoutes { + for _, route := range routes { event := &Event{ Type: evType, Timestamp: time.Now(), diff --git a/router/default_test.go b/router/default_test.go index d3edf67d..9427ecbc 100644 --- a/router/default_test.go +++ b/router/default_test.go @@ -18,7 +18,6 @@ func routerTestSetup() Router { func TestRouterStartStop(t *testing.T) { r := routerTestSetup() - log.Debugf("TestRouterStartStop STARTING") if err := r.Start(); err != nil { t.Errorf("failed to start router: %v", err) } From 891af703be776b5666e8898616a4812d3f8ad318 Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Fri, 17 Jan 2020 18:24:36 +0000 Subject: [PATCH 151/788] Update route metric when receiving Sync routes --- network/default.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/network/default.go b/network/default.go index 5b961537..cee65e16 100644 --- a/network/default.go +++ b/network/default.go @@ -935,6 +935,20 @@ func (n *network) processNetChan(listener tunnel.Listener) { log.Debugf("Network node %s skipping route addition: route already present", n.id) continue } + + metric := n.getRouteMetric(route.Router, route.Gateway, route.Link) + // check we don't overflow max int 64 + if d := route.Metric + metric; d <= 0 { + // set to max int64 if we overflow + route.Metric = math.MaxInt64 + } else { + // set the combined value of metrics otherwise + route.Metric = d + } + + ///////////////////////////////////////////////////////////////////// + // maybe we should not be this clever ¯\_(ツ)_/¯ // + ///////////////////////////////////////////////////////////////////// // lookup best routes for the services in the just received route q := []router.QueryOption{ router.QueryService(route.Service), @@ -972,6 +986,8 @@ func (n *network) processNetChan(listener tunnel.Listener) { if bestRoute.Metric <= route.Metric { continue } + /////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////// // add route to the routing table if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { @@ -1293,20 +1309,6 @@ func (n *network) getProtoRoutes() ([]*pbRtr.Route, error) { // encode the routes to protobuf pbRoutes := make([]*pbRtr.Route, 0, len(routes)) for _, route := range routes { - // calculate route metric and add to the advertised metric - // we need to make sure we do not overflow math.MaxInt64 - metric := n.getRouteMetric(route.Router, route.Gateway, route.Link) - log.Tracef("Network metric for router %s and gateway %s: %v", route.Router, route.Gateway, metric) - - // check we don't overflow max int 64 - if d := route.Metric + metric; d <= 0 { - // set to max int64 if we overflow - route.Metric = math.MaxInt64 - } else { - // set the combined value of metrics otherwise - route.Metric = d - } - // generate new route proto pbRoute := pbUtil.RouteToProto(route) // mask the route before outbounding @@ -1314,6 +1316,7 @@ func (n *network) getProtoRoutes() ([]*pbRtr.Route, error) { // add to list of routes pbRoutes = append(pbRoutes, pbRoute) } + return pbRoutes, nil } From fd6eb233075af0393952e3d7f123497105e5a5de Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Jan 2020 00:58:27 +0000 Subject: [PATCH 152/788] do not wait to stop --- server/grpc/grpc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index d2655a95..1123a67e 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -810,7 +810,7 @@ func (g *grpcServer) Start() error { } // stop the grpc server - g.srv.GracefulStop() + g.srv.Stop() // close transport ch <- nil From 65df711b010a2d153e8768960d724dc26b995570 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Jan 2020 01:29:53 +0000 Subject: [PATCH 153/788] move nats local logic --- broker/nats/nats.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/broker/nats/nats.go b/broker/nats/nats.go index 775c92f0..44d66216 100644 --- a/broker/nats/nats.go +++ b/broker/nats/nats.go @@ -119,17 +119,17 @@ func (n *natsBroker) serve(exit chan bool) error { // with no address we just default it // this is a local client address - if len(n.addrs) == 0 || n.local { + if len(n.addrs) == 0 { host = "127.0.0.1" port = -1 local = true - // with a local address we parse it } else { address := n.addrs[0] if strings.HasPrefix(address, "nats://") { address = strings.TrimPrefix(address, "nats://") } + // check if its a local address and only then embed if addr.IsLocal(address) { h, p, err := net.SplitHostPort(address) if err == nil { @@ -266,9 +266,11 @@ func (n *natsBroker) Connect() error { // create exit chan n.exit = make(chan bool) - // start the server if needed - if err := n.serve(n.exit); err != nil { - return err + // start embedded server if asked to + if n.local { + if err := n.serve(n.exit); err != nil { + return err + } } // set to connected From 39d79384051d9c5ea6aff083cc61ac41005a4ef8 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Jan 2020 02:13:24 +0000 Subject: [PATCH 154/788] Extract k8s run error --- runtime/kubernetes/kubernetes.go | 5 +++++ runtime/kubernetes/service.go | 16 ++++++++++++++++ runtime/runtime.go | 7 ++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 29993b6c..fe9b5af8 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -266,6 +266,11 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er o(&options) } + // hackish + if len(options.Type) == 0 { + options.Type = k.options.Type + } + // quickly prevalidate the name and version name := s.Name if len(s.Version) > 0 { diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index f939b924..3b6963be 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -1,10 +1,12 @@ package kubernetes import ( + "encoding/json" "strings" "time" "github.com/micro/go-micro/runtime" + "github.com/micro/go-micro/util/kubernetes/api" "github.com/micro/go-micro/util/kubernetes/client" "github.com/micro/go-micro/util/log" ) @@ -18,6 +20,12 @@ type service struct { kdeploy *client.Deployment } +func parseError(err error) *api.Status { + status := new(api.Status) + json.Unmarshal([]byte(err.Error()), &status) + return status +} + func newService(s *runtime.Service, c runtime.CreateOptions) *service { // use pre-formatted name/version name := client.Format(s.Name) @@ -90,12 +98,20 @@ func (s *service) Start(k client.Client) error { if err := k.Create(deploymentResource(s.kdeploy)); err != nil { log.Debugf("Runtime failed to create deployment: %v", err) s.Status("error", err) + v := parseError(err) + if v.Reason == "AlreadyExists" { + return runtime.ErrAlreadyExists + } return err } // create service now that the deployment has been created if err := k.Create(serviceResource(s.kservice)); err != nil { log.Debugf("Runtime failed to create service: %v", err) s.Status("error", err) + v := parseError(err) + if v.Reason == "AlreadyExists" { + return runtime.ErrAlreadyExists + } return err } diff --git a/runtime/runtime.go b/runtime/runtime.go index 801ac57c..4dfe5d27 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -1,13 +1,18 @@ // Package runtime is a service runtime manager package runtime -import "time" +import ( + "errors" + "time" +) var ( // DefaultRuntime is default micro runtime DefaultRuntime Runtime = NewRuntime() // DefaultName is default runtime service name DefaultName = "go.micro.runtime" + + ErrAlreadyExists = errors.New("already exists") ) // Runtime is a service runtime manager From e666d0b807ed083987a9eab88148d1a8e9e2d241 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Jan 2020 02:28:44 +0000 Subject: [PATCH 155/788] add missing commit --- util/kubernetes/api/response.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/util/kubernetes/api/response.go b/util/kubernetes/api/response.go index 6185a880..1d835ae9 100644 --- a/util/kubernetes/api/response.go +++ b/util/kubernetes/api/response.go @@ -16,13 +16,13 @@ var ( // Status is an object that is returned when a request // failed or delete succeeded. -// type Status struct { -// Kind string `json:"kind"` -// Status string `json:"status"` -// Message string `json:"message"` -// Reason string `json:"reason"` -// Code int `json:"code"` -// } +type Status struct { + Kind string `json:"kind"` + Status string `json:"status"` + Message string `json:"message"` + Reason string `json:"reason"` + Code int `json:"code"` +} // Response ... type Response struct { From 13d1d2fa08696a49d0c6cf936e20613dd9e4aee1 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Jan 2020 10:18:23 +0000 Subject: [PATCH 156/788] hard stop if graceful stop fails after 1 second --- server/grpc/grpc.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 1123a67e..08c771e3 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -810,7 +810,18 @@ func (g *grpcServer) Start() error { } // stop the grpc server - g.srv.Stop() + exit := make(chan bool) + + go func() { + g.srv.GracefulStop() + close(exit) + }() + + select { + case <-exit: + case <-time.After(time.Second): + g.srv.Stop() + } // close transport ch <- nil From 058fd8adbf69fa88e2d2ac07075d9d222bafd209 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Jan 2020 10:20:46 +0000 Subject: [PATCH 157/788] trace 1 --- debug/trace/default.go | 71 ++++++++++++++++++++++++++++++++++++++++++ debug/trace/options.go | 12 +++++++ debug/trace/trace.go | 48 ++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 debug/trace/default.go create mode 100644 debug/trace/options.go create mode 100644 debug/trace/trace.go diff --git a/debug/trace/default.go b/debug/trace/default.go new file mode 100644 index 00000000..abbf1c15 --- /dev/null +++ b/debug/trace/default.go @@ -0,0 +1,71 @@ +package trace + +import ( + "context" + "time" + + "github.com/google/uuid" + "github.com/micro/go-micro/util/ring" +) + +type trace struct { + opts Options + + // ring buffer of traces + buffer *ring.Buffer +} + +func (t *trace) Read(opts ...ReadOption) ([]*Span, error) { + return []*Span{}, nil +} + +func (t *trace) Start(ctx context.Context, name string) *Span { + span := &Span{ + Name: name, + Trace: uuid.New().String(), + Id: uuid.New().String(), + Started: time.Now(), + Metadata: make(map[string]string), + } + + // return span if no context + if ctx == nil { + return span + } + + s, ok := FromContext(ctx) + if !ok { + return span + } + + // set trace id + span.Trace = s.Trace + // set parent + span.Parent = s.Id + + // return the sapn + return span +} + +func (t *trace) Finish(s *Span) error { + // set finished time + s.Finished = time.Now() + + // save the span + t.buffer.Put(s) + + return nil +} + +func NewTrace(opts ...Option) Trace { + var options Options + for _, o := range opts { + o(&options) + } + + return &trace{ + opts: options, + // the last 64 requests + buffer: ring.New(64), + } +} diff --git a/debug/trace/options.go b/debug/trace/options.go new file mode 100644 index 00000000..d92abad9 --- /dev/null +++ b/debug/trace/options.go @@ -0,0 +1,12 @@ +package trace + +type Options struct{} + +type Option func(o *Options) + +type ReadOptions struct { + // Trace id + Trace string +} + +type ReadOption func(o *ReadOptions) diff --git a/debug/trace/trace.go b/debug/trace/trace.go new file mode 100644 index 00000000..4a4471c3 --- /dev/null +++ b/debug/trace/trace.go @@ -0,0 +1,48 @@ +// Package trace provides an interface for distributed tracing +package trace + +import ( + "context" + "time" +) + +// Trace is an interface for distributed tracing +type Trace interface { + // Start a trace + Start(ctx context.Context, name string) *Span + // Finish the trace + Finish(*Span) error + // Read the traces + Read(...ReadOption) ([]*Span, error) +} + +// Span is used to record an entry +type Span struct { + // Id of the trace + Trace string + // name of the span + Name string + // id of the span + Id string + // parent span id + Parent string + // Start time + Started time.Time + // Finish time + Finished time.Time + // associated data + Metadata map[string]string +} + +type spanKey struct{} + +// FromContext returns a span from context +func FromContext(ctx context.Context) (*Span, bool) { + s, ok := ctx.Value(spanKey{}).(*Span) + return s, ok +} + +// NewContext creates a new context with the span +func NewContext(ctx context.Context, s *Span) context.Context { + return context.WithValue(ctx, spanKey{}, s) +} From 8d6f82707a2ad2afec3ef641ea8832ff03ee292d Mon Sep 17 00:00:00 2001 From: shu xian Date: Sat, 18 Jan 2020 23:16:23 +0800 Subject: [PATCH 158/788] update to standard name convention --- .../proto/{mucp.pb.go => service.pb.go} | 98 +++++++++---------- .../{mucp.pb.micro.go => service.pb.micro.go} | 4 +- .../proto/{mucp.proto => service.proto} | 32 +++--- config/source/service/{mucp.go => service.go} | 8 +- 4 files changed, 66 insertions(+), 76 deletions(-) rename config/source/service/proto/{mucp.pb.go => service.pb.go} (83%) rename config/source/service/proto/{mucp.pb.micro.go => service.pb.micro.go} (99%) rename config/source/service/proto/{mucp.proto => service.proto} (57%) rename config/source/service/{mucp.go => service.go} (91%) diff --git a/config/source/service/proto/mucp.pb.go b/config/source/service/proto/service.pb.go similarity index 83% rename from config/source/service/proto/mucp.pb.go rename to config/source/service/proto/service.pb.go index 08024585..85ba138f 100644 --- a/config/source/service/proto/mucp.pb.go +++ b/config/source/service/proto/service.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: proto/mucp.proto +// source: proto/service.proto -package mucp +package service import ( fmt "fmt" @@ -35,7 +35,7 @@ func (m *ChangeSet) Reset() { *m = ChangeSet{} } func (m *ChangeSet) String() string { return proto.CompactTextString(m) } func (*ChangeSet) ProtoMessage() {} func (*ChangeSet) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{0} + return fileDescriptor_c33392ef2c1961ba, []int{0} } func (m *ChangeSet) XXX_Unmarshal(b []byte) error { @@ -104,7 +104,7 @@ func (m *Change) Reset() { *m = Change{} } func (m *Change) String() string { return proto.CompactTextString(m) } func (*Change) ProtoMessage() {} func (*Change) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{1} + return fileDescriptor_c33392ef2c1961ba, []int{1} } func (m *Change) XXX_Unmarshal(b []byte) error { @@ -157,7 +157,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{2} + return fileDescriptor_c33392ef2c1961ba, []int{2} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -195,7 +195,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{3} + return fileDescriptor_c33392ef2c1961ba, []int{3} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -227,7 +227,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{4} + return fileDescriptor_c33392ef2c1961ba, []int{4} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -265,7 +265,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{5} + return fileDescriptor_c33392ef2c1961ba, []int{5} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -297,7 +297,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{6} + return fileDescriptor_c33392ef2c1961ba, []int{6} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -335,7 +335,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{7} + return fileDescriptor_c33392ef2c1961ba, []int{7} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -366,7 +366,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{8} + return fileDescriptor_c33392ef2c1961ba, []int{8} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -388,7 +388,7 @@ func (m *ListRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ListRequest proto.InternalMessageInfo type ListResponse struct { - Configs []*Change `protobuf:"bytes,1,rep,name=configs,proto3" json:"configs,omitempty"` + Values []*Change `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -398,7 +398,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{9} + return fileDescriptor_c33392ef2c1961ba, []int{9} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -419,9 +419,9 @@ func (m *ListResponse) XXX_DiscardUnknown() { var xxx_messageInfo_ListResponse proto.InternalMessageInfo -func (m *ListResponse) GetConfigs() []*Change { +func (m *ListResponse) GetValues() []*Change { if m != nil { - return m.Configs + return m.Values } return nil } @@ -438,7 +438,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{10} + return fileDescriptor_c33392ef2c1961ba, []int{10} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -484,7 +484,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{11} + return fileDescriptor_c33392ef2c1961ba, []int{11} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -523,7 +523,7 @@ func (m *WatchRequest) Reset() { *m = WatchRequest{} } func (m *WatchRequest) String() string { return proto.CompactTextString(m) } func (*WatchRequest) ProtoMessage() {} func (*WatchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{12} + return fileDescriptor_c33392ef2c1961ba, []int{12} } func (m *WatchRequest) XXX_Unmarshal(b []byte) error { @@ -563,7 +563,7 @@ func (m *WatchResponse) Reset() { *m = WatchResponse{} } func (m *WatchResponse) String() string { return proto.CompactTextString(m) } func (*WatchResponse) ProtoMessage() {} func (*WatchResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_942f149553cfb65d, []int{13} + return fileDescriptor_c33392ef2c1961ba, []int{13} } func (m *WatchResponse) XXX_Unmarshal(b []byte) error { @@ -615,35 +615,35 @@ func init() { proto.RegisterType((*WatchResponse)(nil), "WatchResponse") } -func init() { proto.RegisterFile("proto/mucp.proto", fileDescriptor_942f149553cfb65d) } +func init() { proto.RegisterFile("proto/service.proto", fileDescriptor_c33392ef2c1961ba) } -var fileDescriptor_942f149553cfb65d = []byte{ - // 429 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xdd, 0x8a, 0xd3, 0x40, - 0x14, 0xc7, 0x9b, 0xb6, 0x9b, 0x9a, 0xd3, 0x24, 0x2d, 0xe7, 0x42, 0x42, 0x10, 0x8c, 0x03, 0x42, - 0x51, 0x98, 0x5d, 0xbb, 0x8f, 0xb0, 0xde, 0xe9, 0xd5, 0x2c, 0xa2, 0xb7, 0xe3, 0xf4, 0xec, 0xb6, - 0xac, 0x69, 0x62, 0x66, 0x2a, 0xf8, 0x08, 0xfa, 0xd4, 0x92, 0x99, 0xc9, 0x36, 0xa9, 0xf8, 0xd1, - 0xbb, 0xf3, 0xf9, 0x9f, 0x7f, 0xce, 0x8f, 0xc0, 0xb2, 0x6e, 0x2a, 0x53, 0x5d, 0x96, 0x07, 0x55, - 0x73, 0x1b, 0xb2, 0x1f, 0x01, 0x44, 0x37, 0x5b, 0xb9, 0xbf, 0xa7, 0x5b, 0x32, 0x88, 0x30, 0xdd, - 0x48, 0x23, 0xb3, 0xa0, 0x08, 0x56, 0xb1, 0xb0, 0x31, 0xe6, 0xf0, 0x44, 0x6d, 0x49, 0x3d, 0xe8, - 0x43, 0x99, 0x8d, 0x8b, 0x60, 0x15, 0x89, 0xc7, 0x1c, 0x9f, 0x42, 0x78, 0x57, 0x35, 0xa5, 0x34, - 0xd9, 0xc4, 0x76, 0x7c, 0xd6, 0xd6, 0x75, 0x75, 0x68, 0x14, 0x65, 0x53, 0x57, 0x77, 0x19, 0x3e, - 0x83, 0xc8, 0xec, 0x4a, 0xd2, 0x46, 0x96, 0x75, 0x76, 0x51, 0x04, 0xab, 0x89, 0x38, 0x16, 0xd8, - 0x27, 0x08, 0x9d, 0x15, 0x5c, 0xc2, 0xe4, 0x81, 0xbe, 0x5b, 0x1b, 0x91, 0x68, 0xc3, 0xd6, 0x59, - 0x2d,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0x03, 0x92, 0xf9, 0x82, 0x9f, 0x70, 0x1a, 0xe1, 0x4b, - 0x98, 0xb6, 0x68, 0x30, 0xe6, 0x3d, 0x60, 0x79, 0xc2, 0xfb, 0xbc, 0xdc, 0x58, 0x7b, 0x59, 0x8c, - 0x79, 0x8f, 0x4a, 0x9e, 0xf0, 0xfe, 0xb9, 0xd9, 0x08, 0x5f, 0xc1, 0x85, 0xbd, 0x16, 0x26, 0xbc, - 0x7f, 0xd7, 0x3c, 0xe5, 0x83, 0x23, 0xb2, 0xd1, 0x55, 0xf0, 0x39, 0xb4, 0x3f, 0xf7, 0xf5, 0xaf, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x75, 0xb2, 0x55, 0xf0, 0x03, 0x00, 0x00, +var fileDescriptor_c33392ef2c1961ba = []byte{ + // 425 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xdb, 0x6a, 0xdb, 0x40, + 0x10, 0x86, 0x2d, 0xdb, 0x51, 0xaa, 0xb1, 0x24, 0x87, 0x29, 0x14, 0x21, 0x0a, 0x15, 0x0b, 0x05, + 0xd3, 0xc2, 0x26, 0x38, 0x8f, 0x90, 0xde, 0xb5, 0x57, 0x1b, 0x4a, 0x7b, 0xbb, 0x95, 0xa7, 0xb5, + 0x49, 0x14, 0xa9, 0xda, 0x55, 0xa0, 0x8f, 0xd0, 0x3e, 0x75, 0xd9, 0x83, 0x22, 0xc9, 0xa5, 0x21, + 0xb9, 0xdb, 0x39, 0xfd, 0xf3, 0x7b, 0x3e, 0x0b, 0x5e, 0x36, 0x6d, 0xad, 0xeb, 0x73, 0x45, 0xed, + 0xfd, 0xa1, 0x24, 0x6e, 0x23, 0xf6, 0x3b, 0x80, 0xe8, 0x6a, 0x2f, 0xef, 0x7e, 0xd0, 0x35, 0x69, + 0x44, 0x58, 0xee, 0xa4, 0x96, 0x59, 0x50, 0x04, 0x9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4e, 0x6d, + 0xb6, 0xb8, 0xa1, 0x61, 0xcb, 0xe3, 0xbe, 0x0b, 0x88, 0xbf, 0x48, 0x5d, 0xee, 0xff, 0xbb, 0x86, + 0x7d, 0x84, 0xc4, 0x77, 0x78, 0xcd, 0x7f, 0x9d, 0x4c, 0x00, 0xcf, 0x1f, 0x01, 0xbc, 0xfd, 0x33, + 0x87, 0xd3, 0x6b, 0xf7, 0xc7, 0xc6, 0xf7, 0x10, 0x3a, 0x74, 0x98, 0xf2, 0x09, 0xf5, 0x7c, 0xcd, + 0x8f, 0x98, 0xce, 0x4c, 0xb3, 0x63, 0x84, 0x29, 0x9f, 0xe0, 0xcd, 0xd7, 0xfc, 0x08, 0x9e, 0x6d, + 0x76, 0x30, 0x30, 0xe5, 0x13, 0x8e, 0xf9, 0x9a, 0x1f, 0x51, 0x9a, 0xe1, 0x5b, 0x58, 0x1a, 0x30, + 0x18, 0xf3, 0x11, 0xae, 0x3c, 0xe1, 0x63, 0x5a, 0xae, 0xcd, 0x5c, 0x16, 0x63, 0x3e, 0xa2, 0x92, + 0x27, 0x7c, 0x7c, 0x6e, 0x36, 0xc3, 0x77, 0x70, 0x62, 0xaf, 0x85, 0x09, 0x1f, 0xdf, 0x35, 0x4f, + 0xf9, 0xe4, 0x88, 0x6c, 0x76, 0x11, 0x7c, 0x0b, 0xed, 0xa7, 0x7d, 0xf9, 0x37, 0x00, 0x00, 0xff, + 0xff, 0x85, 0xa3, 0x8e, 0x20, 0xf1, 0x03, 0x00, 0x00, } diff --git a/config/source/service/proto/mucp.pb.micro.go b/config/source/service/proto/service.pb.micro.go similarity index 99% rename from config/source/service/proto/mucp.pb.micro.go rename to config/source/service/proto/service.pb.micro.go index 430b7842..e3847a25 100644 --- a/config/source/service/proto/mucp.pb.micro.go +++ b/config/source/service/proto/service.pb.micro.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: proto/mucp.proto +// source: proto/service.proto -package mucp +package service import ( fmt "fmt" diff --git a/config/source/service/proto/mucp.proto b/config/source/service/proto/service.proto similarity index 57% rename from config/source/service/proto/mucp.proto rename to config/source/service/proto/service.proto index 2e88c7e5..bce92dbe 100644 --- a/config/source/service/proto/mucp.proto +++ b/config/source/service/proto/service.proto @@ -1,18 +1,12 @@ syntax = "proto3"; service Service { - rpc Create (CreateRequest) returns (CreateResponse) { - } - rpc Update (UpdateRequest) returns (UpdateResponse) { - } - rpc Delete (DeleteRequest) returns (DeleteResponse) { - } - rpc List (ListRequest) returns (ListResponse) { - } - rpc Read (ReadRequest) returns (ReadResponse) { - } - rpc Watch (WatchRequest) returns (stream WatchResponse) { - } + rpc Create (CreateRequest) returns (CreateResponse) {} + rpc Update (UpdateRequest) returns (UpdateResponse) {} + rpc Delete (DeleteRequest) returns (DeleteResponse) {} + rpc List (ListRequest) returns (ListResponse) {} + rpc Read (ReadRequest) returns (ReadResponse) {} + rpc Watch (WatchRequest) returns (stream WatchResponse) {} } message ChangeSet { @@ -33,28 +27,24 @@ message CreateRequest { Change change = 1; } -message CreateResponse { -} +message CreateResponse {} message UpdateRequest { Change change = 1; } -message UpdateResponse { -} +message UpdateResponse {} message DeleteRequest { Change change = 1; } -message DeleteResponse { -} +message DeleteResponse {} -message ListRequest { -} +message ListRequest {} message ListResponse { - repeated Change configs = 1; + repeated Change values = 1; } message ReadRequest { diff --git a/config/source/service/mucp.go b/config/source/service/service.go similarity index 91% rename from config/source/service/mucp.go rename to config/source/service/service.go index 3f5ee0fe..9d053126 100644 --- a/config/source/service/mucp.go +++ b/config/source/service/service.go @@ -10,8 +10,8 @@ import ( ) var ( - DefaultServiceName = "go.micro.config" - DefaultClient = client.DefaultClient + DefaultName = "go.micro.config" + DefaultClient = client.DefaultClient ) type service struct { @@ -45,7 +45,7 @@ func (m *service) Write(cs *source.ChangeSet) error { } func (m *service) String() string { - return "mucp" + return "service" } func NewSource(opts ...source.Option) source.Source { @@ -54,7 +54,7 @@ func NewSource(opts ...source.Option) source.Source { o(&options) } - addr := DefaultServiceName + addr := DefaultName if options.Context != nil { a, ok := options.Context.Value(serviceNameKey{}).(string) From bdf1d20f4ec79cbc7be7b552121de0ee55456af3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Jan 2020 15:39:26 +0000 Subject: [PATCH 159/788] extract an ip that can be advertised in embedded nats --- broker/nats/nats.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/broker/nats/nats.go b/broker/nats/nats.go index 44d66216..67833092 100644 --- a/broker/nats/nats.go +++ b/broker/nats/nats.go @@ -120,7 +120,13 @@ func (n *natsBroker) serve(exit chan bool) error { // with no address we just default it // this is a local client address if len(n.addrs) == 0 { - host = "127.0.0.1" + // find an advertiseable ip + if h, err := addr.Extract(""); err != nil { + host = "127.0.0.1" + } else { + host = h + } + port = -1 local = true } else { From 31e195bac7a263e6133eff10efe5604c18b2204f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Jan 2020 18:37:38 +0000 Subject: [PATCH 160/788] strip image pull policy always --- util/kubernetes/client/templates.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index e3681539..7132c23c 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -5,6 +5,9 @@ var templates = map[string]string{ "service": serviceTmpl, } + +// stripped image pull policy always +// imagePullPolicy: Always var deploymentTmpl = ` apiVersion: apps/v1 kind: Deployment @@ -63,7 +66,6 @@ spec: - {{.}} {{- end }} image: {{ .Image }} - imagePullPolicy: Always ports: {{- with .Ports }} {{- range . }} From 0a377671271faabf75b092f985737d597633eebd Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Jan 2020 19:53:51 +0000 Subject: [PATCH 161/788] Fix service registration with registry service --- client/client.go | 8 +++----- defaults.go | 4 ++++ registry/service/service.go | 4 ++-- registry/service/util.go | 1 + server/server.go | 8 +++----- util/kubernetes/client/templates.go | 1 - 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/client/client.go b/client/client.go index 6d597342..b09ae3af 100644 --- a/client/client.go +++ b/client/client.go @@ -110,6 +110,9 @@ var ( DefaultPoolSize = 100 // DefaultPoolTTL sets the connection pool ttl DefaultPoolTTL = time.Minute + + // NewClient returns a new client + NewClient func(...Option) Client = newRpcClient ) // Makes a synchronous call to a service using the default client @@ -128,11 +131,6 @@ func NewMessage(topic string, payload interface{}, opts ...MessageOption) Messag return DefaultClient.NewMessage(topic, payload, opts...) } -// Creates a new client with the options passed in -func NewClient(opt ...Option) Client { - return newRpcClient(opt...) -} - // Creates a new request using the default client. Content Type will // be set to the default within options and use the appropriate codec func NewRequest(service, endpoint string, request interface{}, reqOpts ...RequestOption) Request { diff --git a/defaults.go b/defaults.go index 65844c23..1a83bcf0 100644 --- a/defaults.go +++ b/defaults.go @@ -19,6 +19,10 @@ func init() { // embedded nats server nats.LocalServer(), ) + // new client initialisation + client.NewClient = gcli.NewClient + // new server initialisation + server.NewServer = gsrv.NewServer // default client client.DefaultClient = gcli.NewClient() // default server diff --git a/registry/service/service.go b/registry/service/service.go index 86f1becc..5a70cee7 100644 --- a/registry/service/service.go +++ b/registry/service/service.go @@ -12,7 +12,7 @@ import ( var ( // The default service name - DefaultService = "go.micro.service" + DefaultService = "go.micro.registry" ) type serviceRegistry struct { @@ -128,7 +128,7 @@ func (s *serviceRegistry) Watch(opts ...registry.WatchOption) (registry.Watcher, } func (s *serviceRegistry) String() string { - return s.name + return "service" } // NewRegistry returns a new registry service client diff --git a/registry/service/util.go b/registry/service/util.go index ad74ce0c..76d8ea9d 100644 --- a/registry/service/util.go +++ b/registry/service/util.go @@ -82,6 +82,7 @@ func ToProto(s *registry.Service) *pb.Service { Metadata: s.Metadata, Endpoints: endpoints, Nodes: nodes, + Options: new(pb.Options), } } diff --git a/server/server.go b/server/server.go index 0fcc3436..8e2d8473 100644 --- a/server/server.go +++ b/server/server.go @@ -136,6 +136,9 @@ var ( DefaultRegisterCheck = func(context.Context) error { return nil } DefaultRegisterInterval = time.Second * 30 DefaultRegisterTTL = time.Minute + + // NewServer creates a new server + NewServer func(...Option) Server = newRpcServer ) // DefaultOptions returns config options for the default service @@ -151,11 +154,6 @@ func Init(opt ...Option) { DefaultServer.Init(opt...) } -// NewServer returns a new server with options passed in -func NewServer(opt ...Option) Server { - return newRpcServer(opt...) -} - // NewRouter returns a new router func NewRouter() *router { return newRpcRouter() diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index 7132c23c..12b5be7f 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -5,7 +5,6 @@ var templates = map[string]string{ "service": serviceTmpl, } - // stripped image pull policy always // imagePullPolicy: Always var deploymentTmpl = ` From 105596a0e54dffec0bdafe876a43e937365d6ae0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Jan 2020 20:48:08 +0000 Subject: [PATCH 162/788] use mucp server --- network/default.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/network/default.go b/network/default.go index cee65e16..f52ba563 100644 --- a/network/default.go +++ b/network/default.go @@ -13,6 +13,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/micro/go-micro/client" + cmucp "github.com/micro/go-micro/client/mucp" rtr "github.com/micro/go-micro/client/selector/router" "github.com/micro/go-micro/network/resolver/dns" pbNet "github.com/micro/go-micro/network/service/proto" @@ -20,6 +21,7 @@ import ( "github.com/micro/go-micro/router" pbRtr "github.com/micro/go-micro/router/service/proto" "github.com/micro/go-micro/server" + smucp "github.com/micro/go-micro/server/mucp" "github.com/micro/go-micro/transport" "github.com/micro/go-micro/tunnel" bun "github.com/micro/go-micro/tunnel/broker" @@ -138,7 +140,7 @@ func newNetwork(opts ...Option) Network { ) // server is network server - server := server.NewServer( + server := smucp.NewServer( server.Id(options.Id), server.Address(peerAddress), server.Advertise(advertise), @@ -148,7 +150,7 @@ func newNetwork(opts ...Option) Network { ) // client is network client - client := client.NewClient( + client := cmucp.NewClient( client.Broker(tunBroker), client.Transport(tunTransport), client.Selector( From 11b104677a5f22f1882a81f4fa51f6abeb737593 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 00:55:01 +0000 Subject: [PATCH 163/788] Shift embedded nats to the default --- broker/broker.go | 6 +- broker/common_test.go | 47 -- broker/default.go | 459 ++++++++++++ broker/http/http.go | 696 ++++++++++++++++- .../http_test.go} | 83 ++- broker/http_broker.go | 698 ------------------ broker/service/service.go | 4 +- config/cmd/cmd.go | 40 +- defaults.go | 11 - runtime/service/service.go | 39 +- service.go | 5 + 11 files changed, 1265 insertions(+), 823 deletions(-) delete mode 100644 broker/common_test.go create mode 100644 broker/default.go rename broker/{http_broker_test.go => http/http_test.go} (80%) delete mode 100644 broker/http_broker.go diff --git a/broker/broker.go b/broker/broker.go index 2871e818..97845f12 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -38,13 +38,9 @@ type Subscriber interface { } var ( - DefaultBroker Broker = newHttpBroker() + DefaultBroker Broker = NewBroker() ) -func NewBroker(opts ...Option) Broker { - return newHttpBroker(opts...) -} - func Init(opts ...Option) error { return DefaultBroker.Init(opts...) } diff --git a/broker/common_test.go b/broker/common_test.go deleted file mode 100644 index c01d42c7..00000000 --- a/broker/common_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package broker - -import ( - "github.com/micro/go-micro/registry" -) - -var ( - // mock data - testData = map[string][]*registry.Service{ - "foo": { - { - Name: "foo", - Version: "1.0.0", - Nodes: []*registry.Node{ - { - Id: "foo-1.0.0-123", - Address: "localhost:9999", - }, - { - Id: "foo-1.0.0-321", - Address: "localhost:9999", - }, - }, - }, - { - Name: "foo", - Version: "1.0.1", - Nodes: []*registry.Node{ - { - Id: "foo-1.0.1-321", - Address: "localhost:6666", - }, - }, - }, - { - Name: "foo", - Version: "1.0.3", - Nodes: []*registry.Node{ - { - Id: "foo-1.0.3-345", - Address: "localhost:8888", - }, - }, - }, - }, - } -) diff --git a/broker/default.go b/broker/default.go new file mode 100644 index 00000000..3f45c3ef --- /dev/null +++ b/broker/default.go @@ -0,0 +1,459 @@ +package broker + +import ( + "context" + "errors" + "net" + "net/url" + "strconv" + "strings" + "sync" + "time" + + "github.com/micro/go-micro/codec/json" + "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/util/addr" + "github.com/nats-io/nats-server/v2/server" + nats "github.com/nats-io/nats.go" +) + +type natsBroker struct { + sync.Once + sync.RWMutex + + // indicate if we're connected + connected bool + + // address to bind routes to + addrs []string + // servers for the client + servers []string + + // client connection and nats opts + conn *nats.Conn + opts Options + nopts nats.Options + + // should we drain the connection + drain bool + closeCh chan (error) + + // embedded server + server *server.Server + // configure to use local server + local bool + // server exit channel + exit chan bool +} + +type subscriber struct { + s *nats.Subscription + opts SubscribeOptions +} + +type publication struct { + t string + m *Message +} + +func (p *publication) Topic() string { + return p.t +} + +func (p *publication) Message() *Message { + return p.m +} + +func (p *publication) Ack() error { + // nats does not support acking + return nil +} + +func (s *subscriber) Options() SubscribeOptions { + return s.opts +} + +func (s *subscriber) Topic() string { + return s.s.Subject +} + +func (s *subscriber) Unsubscribe() error { + return s.s.Unsubscribe() +} + +func (n *natsBroker) Address() string { + n.RLock() + defer n.RUnlock() + + if n.server != nil { + return n.server.ClusterAddr().String() + } + + if n.conn != nil && n.conn.IsConnected() { + return n.conn.ConnectedUrl() + } + + if len(n.addrs) > 0 { + return n.addrs[0] + } + + return "127.0.0.1:-1" +} + +func (n *natsBroker) setAddrs(addrs []string) []string { + //nolint:prealloc + var cAddrs []string + for _, addr := range addrs { + if len(addr) == 0 { + continue + } + if !strings.HasPrefix(addr, "nats://") { + addr = "nats://" + addr + } + cAddrs = append(cAddrs, addr) + } + // if there's no address and we weren't told to + // embed a local server then use the default url + if len(cAddrs) == 0 && !n.local { + cAddrs = []string{nats.DefaultURL} + } + return cAddrs +} + +// serve stats a local nats server if needed +func (n *natsBroker) serve(exit chan bool) error { + // local server address + host := "127.0.0.1" + port := -1 + + // cluster address + caddr := "0.0.0.0" + cport := -1 + + // with no address we just default it + // this is a local client address + if len(n.addrs) > 0 { + address := n.addrs[0] + if strings.HasPrefix(address, "nats://") { + address = strings.TrimPrefix(address, "nats://") + } + + // parse out the address + h, p, err := net.SplitHostPort(address) + if err == nil { + caddr = h + cport, _ = strconv.Atoi(p) + } + } + + // 1. create new server + // 2. register the server + // 3. connect to other servers + + // set cluster opts + cOpts := server.ClusterOpts{ + Host: caddr, + Port: cport, + } + + // get the routes for other nodes + var routes []*url.URL + + // get existing nats servers to connect to + services, err := n.opts.Registry.GetService("go.micro.nats.broker") + if err == nil { + for _, service := range services { + for _, node := range service.Nodes { + u, err := url.Parse("nats://" + node.Address) + if err != nil { + log.Log(err) + continue + } + // append to the cluster routes + routes = append(routes, u) + } + } + } + + // try get existing server + s := n.server + + if s != nil { + // stop the existing server + s.Shutdown() + } + + s, err = server.NewServer(&server.Options{ + // Specify the host + Host: host, + // Use a random port + Port: port, + // Set the cluster ops + Cluster: cOpts, + // Set the routes + Routes: routes, + NoLog: true, + NoSigs: true, + MaxControlLine: 2048, + TLSConfig: n.opts.TLSConfig, + }) + if err != nil { + return err + } + + // save the server + n.server = s + + // start the server + go s.Start() + + var ready bool + + // wait till its ready for connections + for i := 0; i < 3; i++ { + if s.ReadyForConnections(time.Second) { + ready = true + break + } + } + + if !ready { + return errors.New("server not ready") + } + + // set the client address + n.servers = []string{s.ClientURL()} + + go func() { + var advertise string + + // parse out the address + _, port, err := net.SplitHostPort(s.ClusterAddr().String()) + if err == nil { + addr, _ := addr.Extract("") + advertise = net.JoinHostPort(addr, port) + } else { + s.ClusterAddr().String() + } + + // register the cluster address + for { + select { + case <-exit: + // deregister on exit + n.opts.Registry.Deregister(®istry.Service{ + Name: "go.micro.nats.broker", + Version: "v2", + Nodes: []*registry.Node{ + {Id: s.ID(), Address: advertise}, + }, + }) + s.Shutdown() + return + default: + // register the broker + n.opts.Registry.Register(®istry.Service{ + Name: "go.micro.nats.broker", + Version: "v2", + Nodes: []*registry.Node{ + {Id: s.ID(), Address: advertise}, + }, + }, registry.RegisterTTL(time.Minute)) + time.Sleep(time.Minute) + } + } + }() + + return nil +} + +func (n *natsBroker) Connect() error { + n.Lock() + defer n.Unlock() + + if !n.connected { + // create exit chan + n.exit = make(chan bool) + + // start the local server + if err := n.serve(n.exit); err != nil { + return err + } + + // set to connected + n.connected = true + } + + status := nats.CLOSED + if n.conn != nil { + status = n.conn.Status() + } + + switch status { + case nats.CONNECTED, nats.RECONNECTING, nats.CONNECTING: + return nil + default: // DISCONNECTED or CLOSED or DRAINING + opts := n.nopts + opts.Servers = n.servers + opts.Secure = n.opts.Secure + opts.TLSConfig = n.opts.TLSConfig + + // secure might not be set + if n.opts.TLSConfig != nil { + opts.Secure = true + } + + c, err := opts.Connect() + if err != nil { + return err + } + n.conn = c + return nil + } +} + +func (n *natsBroker) Disconnect() error { + n.RLock() + defer n.RUnlock() + + if !n.connected { + return nil + } + + // drain the connection if specified + if n.drain { + n.conn.Drain() + return <-n.closeCh + } + + // close the client connection + n.conn.Close() + + // shutdown the local server + // and deregister + select { + case <-n.exit: + default: + close(n.exit) + } + + // set not connected + n.connected = false + + return nil +} + +func (n *natsBroker) Init(opts ...Option) error { + n.setOption(opts...) + return nil +} + +func (n *natsBroker) Options() Options { + return n.opts +} + +func (n *natsBroker) Publish(topic string, msg *Message, opts ...PublishOption) error { + b, err := n.opts.Codec.Marshal(msg) + if err != nil { + return err + } + n.RLock() + defer n.RUnlock() + return n.conn.Publish(topic, b) +} + +func (n *natsBroker) Subscribe(topic string, handler Handler, opts ...SubscribeOption) (Subscriber, error) { + if n.conn == nil { + return nil, errors.New("not connected") + } + + opt := SubscribeOptions{ + AutoAck: true, + Context: context.Background(), + } + + for _, o := range opts { + o(&opt) + } + + fn := func(msg *nats.Msg) { + var m Message + if err := n.opts.Codec.Unmarshal(msg.Data, &m); err != nil { + return + } + handler(&publication{m: &m, t: msg.Subject}) + } + + var sub *nats.Subscription + var err error + + n.RLock() + if len(opt.Queue) > 0 { + sub, err = n.conn.QueueSubscribe(topic, opt.Queue, fn) + } else { + sub, err = n.conn.Subscribe(topic, fn) + } + n.RUnlock() + if err != nil { + return nil, err + } + return &subscriber{s: sub, opts: opt}, nil +} + +func (n *natsBroker) String() string { + return "nats" +} + +func (n *natsBroker) setOption(opts ...Option) { + for _, o := range opts { + o(&n.opts) + } + + n.Once.Do(func() { + n.nopts = nats.GetDefaultOptions() + }) + + // local embedded server + n.local = true + // set to drain + n.drain = true + + if !n.opts.Secure { + n.opts.Secure = n.nopts.Secure + } + + if n.opts.TLSConfig == nil { + n.opts.TLSConfig = n.nopts.TLSConfig + } + + n.addrs = n.setAddrs(n.opts.Addrs) +} + +func (n *natsBroker) onClose(conn *nats.Conn) { + n.closeCh <- nil +} + +func (n *natsBroker) onAsyncError(conn *nats.Conn, sub *nats.Subscription, err error) { + // There are kinds of different async error nats might callback, but we are interested + // in ErrDrainTimeout only here. + if err == nats.ErrDrainTimeout { + n.closeCh <- err + } +} + +func NewBroker(opts ...Option) Broker { + options := Options{ + // Default codec + Codec: json.Marshaler{}, + Context: context.Background(), + Registry: registry.DefaultRegistry, + } + + n := &natsBroker{ + opts: options, + } + n.setOption(opts...) + + return n +} diff --git a/broker/http/http.go b/broker/http/http.go index 7d09986a..7ae7ed7f 100644 --- a/broker/http/http.go +++ b/broker/http/http.go @@ -2,10 +2,704 @@ package http import ( + "bytes" + "context" + "crypto/tls" + "errors" + "fmt" + "io" + "io/ioutil" + "math/rand" + "net" + "net/http" + "net/url" + "runtime" + "sync" + "time" + + "github.com/google/uuid" "github.com/micro/go-micro/broker" + "github.com/micro/go-micro/codec/json" + merr "github.com/micro/go-micro/errors" + "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/registry/cache" + maddr "github.com/micro/go-micro/util/addr" + mnet "github.com/micro/go-micro/util/net" + mls "github.com/micro/go-micro/util/tls" + "golang.org/x/net/http2" ) +// HTTP Broker is a point to point async broker +type httpBroker struct { + id string + address string + opts broker.Options + + mux *http.ServeMux + + c *http.Client + r registry.Registry + + sync.RWMutex + subscribers map[string][]*httpSubscriber + running bool + exit chan chan error + + // offline message inbox + mtx sync.RWMutex + inbox map[string][][]byte +} + +type httpSubscriber struct { + opts broker.SubscribeOptions + id string + topic string + fn broker.Handler + svc *registry.Service + hb *httpBroker +} + +type httpEvent struct { + m *broker.Message + t string +} + +var ( + DefaultSubPath = "/_sub" + serviceName = "go.micro.http.broker" + broadcastVersion = "ff.http.broadcast" + registerTTL = time.Minute + registerInterval = time.Second * 30 +) + +func init() { + rand.Seed(time.Now().Unix()) +} + +func newTransport(config *tls.Config) *http.Transport { + if config == nil { + config = &tls.Config{ + InsecureSkipVerify: true, + } + } + + dialTLS := func(network string, addr string) (net.Conn, error) { + return tls.Dial(network, addr, config) + } + + t := &http.Transport{ + Proxy: http.ProxyFromEnvironment, + Dial: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + }).Dial, + TLSHandshakeTimeout: 10 * time.Second, + DialTLS: dialTLS, + } + runtime.SetFinalizer(&t, func(tr **http.Transport) { + (*tr).CloseIdleConnections() + }) + + // setup http2 + http2.ConfigureTransport(t) + + return t +} + +func newHttpBroker(opts ...broker.Option) broker.Broker { + options := broker.Options{ + Codec: json.Marshaler{}, + Context: context.TODO(), + Registry: registry.DefaultRegistry, + } + + for _, o := range opts { + o(&options) + } + + // set address + addr := ":0" + if len(options.Addrs) > 0 && len(options.Addrs[0]) > 0 { + addr = options.Addrs[0] + } + + h := &httpBroker{ + id: uuid.New().String(), + address: addr, + opts: options, + r: options.Registry, + c: &http.Client{Transport: newTransport(options.TLSConfig)}, + subscribers: make(map[string][]*httpSubscriber), + exit: make(chan chan error), + mux: http.NewServeMux(), + inbox: make(map[string][][]byte), + } + + // specify the message handler + h.mux.Handle(DefaultSubPath, h) + + // get optional handlers + if h.opts.Context != nil { + handlers, ok := h.opts.Context.Value("http_handlers").(map[string]http.Handler) + if ok { + for pattern, handler := range handlers { + h.mux.Handle(pattern, handler) + } + } + } + + return h +} + +func (h *httpEvent) Ack() error { + return nil +} + +func (h *httpEvent) Message() *broker.Message { + return h.m +} + +func (h *httpEvent) Topic() string { + return h.t +} + +func (h *httpSubscriber) Options() broker.SubscribeOptions { + return h.opts +} + +func (h *httpSubscriber) Topic() string { + return h.topic +} + +func (h *httpSubscriber) Unsubscribe() error { + return h.hb.unsubscribe(h) +} + +func (h *httpBroker) saveMessage(topic string, msg []byte) { + h.mtx.Lock() + defer h.mtx.Unlock() + + // get messages + c := h.inbox[topic] + + // save message + c = append(c, msg) + + // max length 64 + if len(c) > 64 { + c = c[:64] + } + + // save inbox + h.inbox[topic] = c +} + +func (h *httpBroker) getMessage(topic string, num int) [][]byte { + h.mtx.Lock() + defer h.mtx.Unlock() + + // get messages + c, ok := h.inbox[topic] + if !ok { + return nil + } + + // more message than requests + if len(c) >= num { + msg := c[:num] + h.inbox[topic] = c[num:] + return msg + } + + // reset inbox + h.inbox[topic] = nil + + // return all messages + return c +} + +func (h *httpBroker) subscribe(s *httpSubscriber) error { + h.Lock() + defer h.Unlock() + + if err := h.r.Register(s.svc, registry.RegisterTTL(registerTTL)); err != nil { + return err + } + + h.subscribers[s.topic] = append(h.subscribers[s.topic], s) + return nil +} + +func (h *httpBroker) unsubscribe(s *httpSubscriber) error { + h.Lock() + defer h.Unlock() + + //nolint:prealloc + var subscribers []*httpSubscriber + + // look for subscriber + for _, sub := range h.subscribers[s.topic] { + // deregister and skip forward + if sub == s { + _ = h.r.Deregister(sub.svc) + continue + } + // keep subscriber + subscribers = append(subscribers, sub) + } + + // set subscribers + h.subscribers[s.topic] = subscribers + + return nil +} + +func (h *httpBroker) run(l net.Listener) { + t := time.NewTicker(registerInterval) + defer t.Stop() + + for { + select { + // heartbeat for each subscriber + case <-t.C: + h.RLock() + for _, subs := range h.subscribers { + for _, sub := range subs { + _ = h.r.Register(sub.svc, registry.RegisterTTL(registerTTL)) + } + } + h.RUnlock() + // received exit signal + case ch := <-h.exit: + ch <- l.Close() + h.RLock() + for _, subs := range h.subscribers { + for _, sub := range subs { + _ = h.r.Deregister(sub.svc) + } + } + h.RUnlock() + return + } + } +} + +func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) { + if req.Method != "POST" { + err := merr.BadRequest("go.micro.broker", "Method not allowed") + http.Error(w, err.Error(), http.StatusMethodNotAllowed) + return + } + defer req.Body.Close() + + req.ParseForm() + + b, err := ioutil.ReadAll(req.Body) + if err != nil { + errr := merr.InternalServerError("go.micro.broker", "Error reading request body: %v", err) + w.WriteHeader(500) + w.Write([]byte(errr.Error())) + return + } + + var m *broker.Message + if err = h.opts.Codec.Unmarshal(b, &m); err != nil { + errr := merr.InternalServerError("go.micro.broker", "Error parsing request body: %v", err) + w.WriteHeader(500) + w.Write([]byte(errr.Error())) + return + } + + topic := m.Header[":topic"] + delete(m.Header, ":topic") + + if len(topic) == 0 { + errr := merr.InternalServerError("go.micro.broker", "Topic not found") + w.WriteHeader(500) + w.Write([]byte(errr.Error())) + return + } + + p := &httpEvent{m: m, t: topic} + id := req.Form.Get("id") + + //nolint:prealloc + var subs []broker.Handler + + h.RLock() + for _, subscriber := range h.subscribers[topic] { + if id != subscriber.id { + continue + } + subs = append(subs, subscriber.fn) + } + h.RUnlock() + + // execute the handler + for _, fn := range subs { + fn(p) + } +} + +func (h *httpBroker) Address() string { + h.RLock() + defer h.RUnlock() + return h.address +} + +func (h *httpBroker) Connect() error { + h.RLock() + if h.running { + h.RUnlock() + return nil + } + h.RUnlock() + + h.Lock() + defer h.Unlock() + + var l net.Listener + var err error + + if h.opts.Secure || h.opts.TLSConfig != nil { + config := h.opts.TLSConfig + + fn := func(addr string) (net.Listener, error) { + if config == nil { + hosts := []string{addr} + + // check if its a valid host:port + if host, _, err := net.SplitHostPort(addr); err == nil { + if len(host) == 0 { + hosts = maddr.IPs() + } else { + hosts = []string{host} + } + } + + // generate a certificate + cert, err := mls.Certificate(hosts...) + if err != nil { + return nil, err + } + config = &tls.Config{Certificates: []tls.Certificate{cert}} + } + return tls.Listen("tcp", addr, config) + } + + l, err = mnet.Listen(h.address, fn) + } else { + fn := func(addr string) (net.Listener, error) { + return net.Listen("tcp", addr) + } + + l, err = mnet.Listen(h.address, fn) + } + + if err != nil { + return err + } + + addr := h.address + h.address = l.Addr().String() + + go http.Serve(l, h.mux) + go func() { + h.run(l) + h.Lock() + h.opts.Addrs = []string{addr} + h.address = addr + h.Unlock() + }() + + // get registry + reg := h.opts.Registry + if reg == nil { + reg = registry.DefaultRegistry + } + // set cache + h.r = cache.New(reg) + + // set running + h.running = true + return nil +} + +func (h *httpBroker) Disconnect() error { + h.RLock() + if !h.running { + h.RUnlock() + return nil + } + h.RUnlock() + + h.Lock() + defer h.Unlock() + + // stop cache + rc, ok := h.r.(cache.Cache) + if ok { + rc.Stop() + } + + // exit and return err + ch := make(chan error) + h.exit <- ch + err := <-ch + + // set not running + h.running = false + return err +} + +func (h *httpBroker) Init(opts ...broker.Option) error { + h.RLock() + if h.running { + h.RUnlock() + return errors.New("cannot init while connected") + } + h.RUnlock() + + h.Lock() + defer h.Unlock() + + for _, o := range opts { + o(&h.opts) + } + + if len(h.opts.Addrs) > 0 && len(h.opts.Addrs[0]) > 0 { + h.address = h.opts.Addrs[0] + } + + if len(h.id) == 0 { + h.id = "go.micro.http.broker-" + uuid.New().String() + } + + // get registry + reg := h.opts.Registry + if reg == nil { + reg = registry.DefaultRegistry + } + + // get cache + if rc, ok := h.r.(cache.Cache); ok { + rc.Stop() + } + + // set registry + h.r = cache.New(reg) + + // reconfigure tls config + if c := h.opts.TLSConfig; c != nil { + h.c = &http.Client{ + Transport: newTransport(c), + } + } + + return nil +} + +func (h *httpBroker) Options() broker.Options { + return h.opts +} + +func (h *httpBroker) Publish(topic string, msg *broker.Message, opts ...broker.PublishOption) error { + // create the message first + m := &broker.Message{ + Header: make(map[string]string), + Body: msg.Body, + } + + for k, v := range msg.Header { + m.Header[k] = v + } + + m.Header[":topic"] = topic + + // encode the message + b, err := h.opts.Codec.Marshal(m) + if err != nil { + return err + } + + // save the message + h.saveMessage(topic, b) + + // now attempt to get the service + h.RLock() + s, err := h.r.GetService(serviceName) + if err != nil { + h.RUnlock() + return err + } + h.RUnlock() + + pub := func(node *registry.Node, t string, b []byte) error { + scheme := "http" + + // check if secure is added in metadata + if node.Metadata["secure"] == "true" { + scheme = "https" + } + + vals := url.Values{} + vals.Add("id", node.Id) + + uri := fmt.Sprintf("%s://%s%s?%s", scheme, node.Address, DefaultSubPath, vals.Encode()) + r, err := h.c.Post(uri, "application/json", bytes.NewReader(b)) + if err != nil { + return err + } + + // discard response body + io.Copy(ioutil.Discard, r.Body) + r.Body.Close() + return nil + } + + srv := func(s []*registry.Service, b []byte) { + for _, service := range s { + var nodes []*registry.Node + + for _, node := range service.Nodes { + // only use nodes tagged with broker http + if node.Metadata["broker"] != "http" { + continue + } + + // look for nodes for the topic + if node.Metadata["topic"] != topic { + continue + } + + nodes = append(nodes, node) + } + + // only process if we have nodes + if len(nodes) == 0 { + continue + } + + switch service.Version { + // broadcast version means broadcast to all nodes + case broadcastVersion: + var success bool + + // publish to all nodes + for _, node := range nodes { + // publish async + if err := pub(node, topic, b); err == nil { + success = true + } + } + + // save if it failed to publish at least once + if !success { + h.saveMessage(topic, b) + } + default: + // select node to publish to + node := nodes[rand.Int()%len(nodes)] + + // publish async to one node + if err := pub(node, topic, b); err != nil { + // if failed save it + h.saveMessage(topic, b) + } + } + } + } + + // do the rest async + go func() { + // get a third of the backlog + messages := h.getMessage(topic, 8) + delay := (len(messages) > 1) + + // publish all the messages + for _, msg := range messages { + // serialize here + srv(s, msg) + + // sending a backlog of messages + if delay { + time.Sleep(time.Millisecond * 100) + } + } + }() + + return nil +} + +func (h *httpBroker) Subscribe(topic string, handler broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) { + var err error + var host, port string + options := broker.NewSubscribeOptions(opts...) + + // parse address for host, port + host, port, err = net.SplitHostPort(h.Address()) + if err != nil { + return nil, err + } + + addr, err := maddr.Extract(host) + if err != nil { + return nil, err + } + + var secure bool + + if h.opts.Secure || h.opts.TLSConfig != nil { + secure = true + } + + // register service + node := ®istry.Node{ + Id: topic + "-" + h.id, + Address: mnet.HostPort(addr, port), + Metadata: map[string]string{ + "secure": fmt.Sprintf("%t", secure), + "broker": "http", + "topic": topic, + }, + } + + // check for queue group or broadcast queue + version := options.Queue + if len(version) == 0 { + version = broadcastVersion + } + + service := ®istry.Service{ + Name: serviceName, + Version: version, + Nodes: []*registry.Node{node}, + } + + // generate subscriber + subscriber := &httpSubscriber{ + opts: options, + hb: h, + id: node.Id, + topic: topic, + fn: handler, + svc: service, + } + + // subscribe now + if err := h.subscribe(subscriber); err != nil { + return nil, err + } + + // return the subscriber + return subscriber, nil +} + +func (h *httpBroker) String() string { + return "http" +} + // NewBroker returns a new http broker func NewBroker(opts ...broker.Option) broker.Broker { - return broker.NewBroker(opts...) + return newHttpBroker(opts...) } diff --git a/broker/http_broker_test.go b/broker/http/http_test.go similarity index 80% rename from broker/http_broker_test.go rename to broker/http/http_test.go index 3312a7f3..f3aec647 100644 --- a/broker/http_broker_test.go +++ b/broker/http/http_test.go @@ -1,4 +1,4 @@ -package broker +package http import ( "sync" @@ -6,12 +6,55 @@ import ( "time" "github.com/google/uuid" + "github.com/micro/go-micro/broker" "github.com/micro/go-micro/debug/log/noop" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry/memory" "github.com/micro/go-micro/util/log" ) +var ( + // mock data + testData = map[string][]*registry.Service{ + "foo": { + { + Name: "foo", + Version: "1.0.0", + Nodes: []*registry.Node{ + { + Id: "foo-1.0.0-123", + Address: "localhost:9999", + }, + { + Id: "foo-1.0.0-321", + Address: "localhost:9999", + }, + }, + }, + { + Name: "foo", + Version: "1.0.1", + Nodes: []*registry.Node{ + { + Id: "foo-1.0.1-321", + Address: "localhost:6666", + }, + }, + }, + { + Name: "foo", + Version: "1.0.3", + Nodes: []*registry.Node{ + { + Id: "foo-1.0.3-345", + Address: "localhost:8888", + }, + }, + }, + }, + } +) + func newTestRegistry() registry.Registry { return memory.NewRegistry(memory.Services(testData)) } @@ -23,7 +66,7 @@ func sub(be *testing.B, c int) { be.StopTimer() m := newTestRegistry() - b := NewBroker(Registry(m)) + b := NewBroker(broker.Registry(m)) topic := uuid.New().String() if err := b.Init(); err != nil { @@ -34,18 +77,18 @@ func sub(be *testing.B, c int) { be.Fatalf("Unexpected connect error: %v", err) } - msg := &Message{ + msg := &broker.Message{ Header: map[string]string{ "Content-Type": "application/json", }, Body: []byte(`{"message": "Hello World"}`), } - var subs []Subscriber + var subs []broker.Subscriber done := make(chan bool, c) for i := 0; i < c; i++ { - sub, err := b.Subscribe(topic, func(p Event) error { + sub, err := b.Subscribe(topic, func(p broker.Event) error { done <- true m := p.Message() @@ -54,7 +97,7 @@ func sub(be *testing.B, c int) { } return nil - }, Queue("shared")) + }, broker.Queue("shared")) if err != nil { be.Fatalf("Unexpected subscribe error: %v", err) } @@ -85,7 +128,7 @@ func pub(be *testing.B, c int) { be.StopTimer() m := newTestRegistry() - b := NewBroker(Registry(m)) + b := NewBroker(broker.Registry(m)) topic := uuid.New().String() if err := b.Init(); err != nil { @@ -96,7 +139,7 @@ func pub(be *testing.B, c int) { be.Fatalf("Unexpected connect error: %v", err) } - msg := &Message{ + msg := &broker.Message{ Header: map[string]string{ "Content-Type": "application/json", }, @@ -105,14 +148,14 @@ func pub(be *testing.B, c int) { done := make(chan bool, c*4) - sub, err := b.Subscribe(topic, func(p Event) error { + sub, err := b.Subscribe(topic, func(p broker.Event) error { done <- true m := p.Message() if string(m.Body) != string(msg.Body) { be.Fatalf("Unexpected msg %s, expected %s", string(m.Body), string(msg.Body)) } return nil - }, Queue("shared")) + }, broker.Queue("shared")) if err != nil { be.Fatalf("Unexpected subscribe error: %v", err) } @@ -154,7 +197,7 @@ func pub(be *testing.B, c int) { func TestBroker(t *testing.T) { m := newTestRegistry() - b := NewBroker(Registry(m)) + b := NewBroker(broker.Registry(m)) if err := b.Init(); err != nil { t.Fatalf("Unexpected init error: %v", err) @@ -164,7 +207,7 @@ func TestBroker(t *testing.T) { t.Fatalf("Unexpected connect error: %v", err) } - msg := &Message{ + msg := &broker.Message{ Header: map[string]string{ "Content-Type": "application/json", }, @@ -173,7 +216,7 @@ func TestBroker(t *testing.T) { done := make(chan bool) - sub, err := b.Subscribe("test", func(p Event) error { + sub, err := b.Subscribe("test", func(p broker.Event) error { m := p.Message() if string(m.Body) != string(msg.Body) { @@ -201,7 +244,7 @@ func TestBroker(t *testing.T) { func TestConcurrentSubBroker(t *testing.T) { m := newTestRegistry() - b := NewBroker(Registry(m)) + b := NewBroker(broker.Registry(m)) if err := b.Init(); err != nil { t.Fatalf("Unexpected init error: %v", err) @@ -211,18 +254,18 @@ func TestConcurrentSubBroker(t *testing.T) { t.Fatalf("Unexpected connect error: %v", err) } - msg := &Message{ + msg := &broker.Message{ Header: map[string]string{ "Content-Type": "application/json", }, Body: []byte(`{"message": "Hello World"}`), } - var subs []Subscriber + var subs []broker.Subscriber var wg sync.WaitGroup for i := 0; i < 10; i++ { - sub, err := b.Subscribe("test", func(p Event) error { + sub, err := b.Subscribe("test", func(p broker.Event) error { defer wg.Done() m := p.Message() @@ -258,7 +301,7 @@ func TestConcurrentSubBroker(t *testing.T) { func TestConcurrentPubBroker(t *testing.T) { m := newTestRegistry() - b := NewBroker(Registry(m)) + b := NewBroker(broker.Registry(m)) if err := b.Init(); err != nil { t.Fatalf("Unexpected init error: %v", err) @@ -268,7 +311,7 @@ func TestConcurrentPubBroker(t *testing.T) { t.Fatalf("Unexpected connect error: %v", err) } - msg := &Message{ + msg := &broker.Message{ Header: map[string]string{ "Content-Type": "application/json", }, @@ -277,7 +320,7 @@ func TestConcurrentPubBroker(t *testing.T) { var wg sync.WaitGroup - sub, err := b.Subscribe("test", func(p Event) error { + sub, err := b.Subscribe("test", func(p broker.Event) error { defer wg.Done() m := p.Message() diff --git a/broker/http_broker.go b/broker/http_broker.go deleted file mode 100644 index 98430dae..00000000 --- a/broker/http_broker.go +++ /dev/null @@ -1,698 +0,0 @@ -package broker - -import ( - "bytes" - "context" - "crypto/tls" - "errors" - "fmt" - "io" - "io/ioutil" - "math/rand" - "net" - "net/http" - "net/url" - "runtime" - "sync" - "time" - - "github.com/google/uuid" - "github.com/micro/go-micro/codec/json" - merr "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/registry/cache" - maddr "github.com/micro/go-micro/util/addr" - mnet "github.com/micro/go-micro/util/net" - mls "github.com/micro/go-micro/util/tls" - "golang.org/x/net/http2" -) - -// HTTP Broker is a point to point async broker -type httpBroker struct { - id string - address string - opts Options - - mux *http.ServeMux - - c *http.Client - r registry.Registry - - sync.RWMutex - subscribers map[string][]*httpSubscriber - running bool - exit chan chan error - - // offline message inbox - mtx sync.RWMutex - inbox map[string][][]byte -} - -type httpSubscriber struct { - opts SubscribeOptions - id string - topic string - fn Handler - svc *registry.Service - hb *httpBroker -} - -type httpEvent struct { - m *Message - t string -} - -var ( - DefaultSubPath = "/_sub" - serviceName = "go.micro.http.broker" - broadcastVersion = "ff.http.broadcast" - registerTTL = time.Minute - registerInterval = time.Second * 30 -) - -func init() { - rand.Seed(time.Now().Unix()) -} - -func newTransport(config *tls.Config) *http.Transport { - if config == nil { - config = &tls.Config{ - InsecureSkipVerify: true, - } - } - - dialTLS := func(network string, addr string) (net.Conn, error) { - return tls.Dial(network, addr, config) - } - - t := &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - }).Dial, - TLSHandshakeTimeout: 10 * time.Second, - DialTLS: dialTLS, - } - runtime.SetFinalizer(&t, func(tr **http.Transport) { - (*tr).CloseIdleConnections() - }) - - // setup http2 - http2.ConfigureTransport(t) - - return t -} - -func newHttpBroker(opts ...Option) Broker { - options := Options{ - Codec: json.Marshaler{}, - Context: context.TODO(), - Registry: registry.DefaultRegistry, - } - - for _, o := range opts { - o(&options) - } - - // set address - addr := ":0" - if len(options.Addrs) > 0 && len(options.Addrs[0]) > 0 { - addr = options.Addrs[0] - } - - h := &httpBroker{ - id: uuid.New().String(), - address: addr, - opts: options, - r: options.Registry, - c: &http.Client{Transport: newTransport(options.TLSConfig)}, - subscribers: make(map[string][]*httpSubscriber), - exit: make(chan chan error), - mux: http.NewServeMux(), - inbox: make(map[string][][]byte), - } - - // specify the message handler - h.mux.Handle(DefaultSubPath, h) - - // get optional handlers - if h.opts.Context != nil { - handlers, ok := h.opts.Context.Value("http_handlers").(map[string]http.Handler) - if ok { - for pattern, handler := range handlers { - h.mux.Handle(pattern, handler) - } - } - } - - return h -} - -func (h *httpEvent) Ack() error { - return nil -} - -func (h *httpEvent) Message() *Message { - return h.m -} - -func (h *httpEvent) Topic() string { - return h.t -} - -func (h *httpSubscriber) Options() SubscribeOptions { - return h.opts -} - -func (h *httpSubscriber) Topic() string { - return h.topic -} - -func (h *httpSubscriber) Unsubscribe() error { - return h.hb.unsubscribe(h) -} - -func (h *httpBroker) saveMessage(topic string, msg []byte) { - h.mtx.Lock() - defer h.mtx.Unlock() - - // get messages - c := h.inbox[topic] - - // save message - c = append(c, msg) - - // max length 64 - if len(c) > 64 { - c = c[:64] - } - - // save inbox - h.inbox[topic] = c -} - -func (h *httpBroker) getMessage(topic string, num int) [][]byte { - h.mtx.Lock() - defer h.mtx.Unlock() - - // get messages - c, ok := h.inbox[topic] - if !ok { - return nil - } - - // more message than requests - if len(c) >= num { - msg := c[:num] - h.inbox[topic] = c[num:] - return msg - } - - // reset inbox - h.inbox[topic] = nil - - // return all messages - return c -} - -func (h *httpBroker) subscribe(s *httpSubscriber) error { - h.Lock() - defer h.Unlock() - - if err := h.r.Register(s.svc, registry.RegisterTTL(registerTTL)); err != nil { - return err - } - - h.subscribers[s.topic] = append(h.subscribers[s.topic], s) - return nil -} - -func (h *httpBroker) unsubscribe(s *httpSubscriber) error { - h.Lock() - defer h.Unlock() - - //nolint:prealloc - var subscribers []*httpSubscriber - - // look for subscriber - for _, sub := range h.subscribers[s.topic] { - // deregister and skip forward - if sub == s { - _ = h.r.Deregister(sub.svc) - continue - } - // keep subscriber - subscribers = append(subscribers, sub) - } - - // set subscribers - h.subscribers[s.topic] = subscribers - - return nil -} - -func (h *httpBroker) run(l net.Listener) { - t := time.NewTicker(registerInterval) - defer t.Stop() - - for { - select { - // heartbeat for each subscriber - case <-t.C: - h.RLock() - for _, subs := range h.subscribers { - for _, sub := range subs { - _ = h.r.Register(sub.svc, registry.RegisterTTL(registerTTL)) - } - } - h.RUnlock() - // received exit signal - case ch := <-h.exit: - ch <- l.Close() - h.RLock() - for _, subs := range h.subscribers { - for _, sub := range subs { - _ = h.r.Deregister(sub.svc) - } - } - h.RUnlock() - return - } - } -} - -func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) { - if req.Method != "POST" { - err := merr.BadRequest("go.micro.broker", "Method not allowed") - http.Error(w, err.Error(), http.StatusMethodNotAllowed) - return - } - defer req.Body.Close() - - req.ParseForm() - - b, err := ioutil.ReadAll(req.Body) - if err != nil { - errr := merr.InternalServerError("go.micro.broker", "Error reading request body: %v", err) - w.WriteHeader(500) - w.Write([]byte(errr.Error())) - return - } - - var m *Message - if err = h.opts.Codec.Unmarshal(b, &m); err != nil { - errr := merr.InternalServerError("go.micro.broker", "Error parsing request body: %v", err) - w.WriteHeader(500) - w.Write([]byte(errr.Error())) - return - } - - topic := m.Header[":topic"] - delete(m.Header, ":topic") - - if len(topic) == 0 { - errr := merr.InternalServerError("go.micro.broker", "Topic not found") - w.WriteHeader(500) - w.Write([]byte(errr.Error())) - return - } - - p := &httpEvent{m: m, t: topic} - id := req.Form.Get("id") - - //nolint:prealloc - var subs []Handler - - h.RLock() - for _, subscriber := range h.subscribers[topic] { - if id != subscriber.id { - continue - } - subs = append(subs, subscriber.fn) - } - h.RUnlock() - - // execute the handler - for _, fn := range subs { - fn(p) - } -} - -func (h *httpBroker) Address() string { - h.RLock() - defer h.RUnlock() - return h.address -} - -func (h *httpBroker) Connect() error { - h.RLock() - if h.running { - h.RUnlock() - return nil - } - h.RUnlock() - - h.Lock() - defer h.Unlock() - - var l net.Listener - var err error - - if h.opts.Secure || h.opts.TLSConfig != nil { - config := h.opts.TLSConfig - - fn := func(addr string) (net.Listener, error) { - if config == nil { - hosts := []string{addr} - - // check if its a valid host:port - if host, _, err := net.SplitHostPort(addr); err == nil { - if len(host) == 0 { - hosts = maddr.IPs() - } else { - hosts = []string{host} - } - } - - // generate a certificate - cert, err := mls.Certificate(hosts...) - if err != nil { - return nil, err - } - config = &tls.Config{Certificates: []tls.Certificate{cert}} - } - return tls.Listen("tcp", addr, config) - } - - l, err = mnet.Listen(h.address, fn) - } else { - fn := func(addr string) (net.Listener, error) { - return net.Listen("tcp", addr) - } - - l, err = mnet.Listen(h.address, fn) - } - - if err != nil { - return err - } - - addr := h.address - h.address = l.Addr().String() - - go http.Serve(l, h.mux) - go func() { - h.run(l) - h.Lock() - h.opts.Addrs = []string{addr} - h.address = addr - h.Unlock() - }() - - // get registry - reg, ok := h.opts.Context.Value(registryKey).(registry.Registry) - if !ok { - reg = registry.DefaultRegistry - } - // set cache - h.r = cache.New(reg) - - // set running - h.running = true - return nil -} - -func (h *httpBroker) Disconnect() error { - h.RLock() - if !h.running { - h.RUnlock() - return nil - } - h.RUnlock() - - h.Lock() - defer h.Unlock() - - // stop cache - rc, ok := h.r.(cache.Cache) - if ok { - rc.Stop() - } - - // exit and return err - ch := make(chan error) - h.exit <- ch - err := <-ch - - // set not running - h.running = false - return err -} - -func (h *httpBroker) Init(opts ...Option) error { - h.RLock() - if h.running { - h.RUnlock() - return errors.New("cannot init while connected") - } - h.RUnlock() - - h.Lock() - defer h.Unlock() - - for _, o := range opts { - o(&h.opts) - } - - if len(h.opts.Addrs) > 0 && len(h.opts.Addrs[0]) > 0 { - h.address = h.opts.Addrs[0] - } - - if len(h.id) == 0 { - h.id = "go.micro.http.broker-" + uuid.New().String() - } - - // get registry - reg, ok := h.opts.Context.Value(registryKey).(registry.Registry) - if !ok { - reg = registry.DefaultRegistry - } - - // get cache - if rc, ok := h.r.(cache.Cache); ok { - rc.Stop() - } - - // set registry - h.r = cache.New(reg) - - // reconfigure tls config - if c := h.opts.TLSConfig; c != nil { - h.c = &http.Client{ - Transport: newTransport(c), - } - } - - return nil -} - -func (h *httpBroker) Options() Options { - return h.opts -} - -func (h *httpBroker) Publish(topic string, msg *Message, opts ...PublishOption) error { - // create the message first - m := &Message{ - Header: make(map[string]string), - Body: msg.Body, - } - - for k, v := range msg.Header { - m.Header[k] = v - } - - m.Header[":topic"] = topic - - // encode the message - b, err := h.opts.Codec.Marshal(m) - if err != nil { - return err - } - - // save the message - h.saveMessage(topic, b) - - // now attempt to get the service - h.RLock() - s, err := h.r.GetService(serviceName) - if err != nil { - h.RUnlock() - return err - } - h.RUnlock() - - pub := func(node *registry.Node, t string, b []byte) error { - scheme := "http" - - // check if secure is added in metadata - if node.Metadata["secure"] == "true" { - scheme = "https" - } - - vals := url.Values{} - vals.Add("id", node.Id) - - uri := fmt.Sprintf("%s://%s%s?%s", scheme, node.Address, DefaultSubPath, vals.Encode()) - r, err := h.c.Post(uri, "application/json", bytes.NewReader(b)) - if err != nil { - return err - } - - // discard response body - io.Copy(ioutil.Discard, r.Body) - r.Body.Close() - return nil - } - - srv := func(s []*registry.Service, b []byte) { - for _, service := range s { - var nodes []*registry.Node - - for _, node := range service.Nodes { - // only use nodes tagged with broker http - if node.Metadata["broker"] != "http" { - continue - } - - // look for nodes for the topic - if node.Metadata["topic"] != topic { - continue - } - - nodes = append(nodes, node) - } - - // only process if we have nodes - if len(nodes) == 0 { - continue - } - - switch service.Version { - // broadcast version means broadcast to all nodes - case broadcastVersion: - var success bool - - // publish to all nodes - for _, node := range nodes { - // publish async - if err := pub(node, topic, b); err == nil { - success = true - } - } - - // save if it failed to publish at least once - if !success { - h.saveMessage(topic, b) - } - default: - // select node to publish to - node := nodes[rand.Int()%len(nodes)] - - // publish async to one node - if err := pub(node, topic, b); err != nil { - // if failed save it - h.saveMessage(topic, b) - } - } - } - } - - // do the rest async - go func() { - // get a third of the backlog - messages := h.getMessage(topic, 8) - delay := (len(messages) > 1) - - // publish all the messages - for _, msg := range messages { - // serialize here - srv(s, msg) - - // sending a backlog of messages - if delay { - time.Sleep(time.Millisecond * 100) - } - } - }() - - return nil -} - -func (h *httpBroker) Subscribe(topic string, handler Handler, opts ...SubscribeOption) (Subscriber, error) { - var err error - var host, port string - options := NewSubscribeOptions(opts...) - - // parse address for host, port - host, port, err = net.SplitHostPort(h.Address()) - if err != nil { - return nil, err - } - - addr, err := maddr.Extract(host) - if err != nil { - return nil, err - } - - var secure bool - - if h.opts.Secure || h.opts.TLSConfig != nil { - secure = true - } - - // register service - node := ®istry.Node{ - Id: topic + "-" + h.id, - Address: mnet.HostPort(addr, port), - Metadata: map[string]string{ - "secure": fmt.Sprintf("%t", secure), - "broker": "http", - "topic": topic, - }, - } - - // check for queue group or broadcast queue - version := options.Queue - if len(version) == 0 { - version = broadcastVersion - } - - service := ®istry.Service{ - Name: serviceName, - Version: version, - Nodes: []*registry.Node{node}, - } - - // generate subscriber - subscriber := &httpSubscriber{ - opts: options, - hb: h, - id: node.Id, - topic: topic, - fn: handler, - svc: service, - } - - // subscribe now - if err := h.subscribe(subscriber); err != nil { - return nil, err - } - - // return the subscriber - return subscriber, nil -} - -func (h *httpBroker) String() string { - return "http" -} diff --git a/broker/service/service.go b/broker/service/service.go index fff207fd..00d6d0b5 100644 --- a/broker/service/service.go +++ b/broker/service/service.go @@ -124,9 +124,11 @@ func NewBroker(opts ...broker.Option) broker.Broker { addrs = []string{"127.0.0.1:8001"} } + cli := client.DefaultClient + return &serviceBroker{ Addrs: addrs, - Client: pb.NewBrokerService(DefaultName, client.DefaultClient), + Client: pb.NewBrokerService(DefaultName, cli), options: options, } } diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index f553f44b..43269291 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -8,23 +8,30 @@ import ( "time" "github.com/micro/cli" + "github.com/micro/go-micro/broker" + "github.com/micro/go-micro/client/selector" + "github.com/micro/go-micro/registry" "github.com/micro/go-micro/client" + "github.com/micro/go-micro/server" + "github.com/micro/go-micro/store" + "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/runtime" + "github.com/micro/go-micro/transport" + + // clients cgrpc "github.com/micro/go-micro/client/grpc" cmucp "github.com/micro/go-micro/client/mucp" - "github.com/micro/go-micro/server" + + // servers sgrpc "github.com/micro/go-micro/server/grpc" smucp "github.com/micro/go-micro/server/mucp" - "github.com/micro/go-micro/util/log" // brokers - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/broker/http" "github.com/micro/go-micro/broker/memory" "github.com/micro/go-micro/broker/nats" brokerSrv "github.com/micro/go-micro/broker/service" // registries - "github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry/etcd" kreg "github.com/micro/go-micro/registry/kubernetes" "github.com/micro/go-micro/registry/mdns" @@ -32,27 +39,20 @@ import ( regSrv "github.com/micro/go-micro/registry/service" // selectors - "github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/client/selector/dns" "github.com/micro/go-micro/client/selector/router" "github.com/micro/go-micro/client/selector/static" // transports - "github.com/micro/go-micro/transport" - tgrpc "github.com/micro/go-micro/transport/grpc" thttp "github.com/micro/go-micro/transport/http" tmem "github.com/micro/go-micro/transport/memory" - "github.com/micro/go-micro/transport/quic" // runtimes - "github.com/micro/go-micro/runtime" "github.com/micro/go-micro/runtime/kubernetes" // stores - "github.com/micro/go-micro/store" cfStore "github.com/micro/go-micro/store/cloudflare" ckStore "github.com/micro/go-micro/store/cockroach" - etcdStore "github.com/micro/go-micro/store/etcd" memStore "github.com/micro/go-micro/store/memory" svcStore "github.com/micro/go-micro/store/service" ) @@ -217,7 +217,6 @@ var ( DefaultBrokers = map[string]func(...broker.Option) broker.Broker{ "service": brokerSrv.NewBroker, - "http": http.NewBroker, "memory": memory.NewBroker, "nats": nats.NewBroker, } @@ -236,9 +235,7 @@ var ( } DefaultSelectors = map[string]func(...selector.Option) selector.Selector{ - "default": selector.NewSelector, "dns": dns.NewSelector, - "cache": selector.NewSelector, "router": router.NewSelector, "static": static.NewSelector, } @@ -251,8 +248,6 @@ var ( DefaultTransports = map[string]func(...transport.Option) transport.Transport{ "memory": tmem.NewTransport, "http": thttp.NewTransport, - "grpc": tgrpc.NewTransport, - "quic": quic.NewTransport, } DefaultRuntimes = map[string]func(...runtime.Option) runtime.Runtime{ @@ -263,7 +258,6 @@ var ( DefaultStores = map[string]func(...store.Option) store.Store{ "memory": memStore.NewStore, "cockroach": ckStore.NewStore, - "etcd": etcdStore.NewStore, "cloudflare": cfStore.NewStore, "service": svcStore.NewStore, } @@ -271,7 +265,7 @@ var ( // used for default selection as the fall back defaultClient = "grpc" defaultServer = "grpc" - defaultBroker = "nats" + defaultBroker = "enats" defaultRegistry = "mdns" defaultSelector = "registry" defaultTransport = "http" @@ -558,8 +552,12 @@ func (c *cmd) Init(opts ...Option) error { for _, o := range opts { o(&c.opts) } - c.app.Name = c.opts.Name - c.app.Version = c.opts.Version + if len(c.opts.Name) > 0 { + c.app.Name = c.opts.Name + } + if len(c.opts.Version) > 0 { + c.app.Version = c.opts.Version + } c.app.HideVersion = len(c.opts.Version) == 0 c.app.Usage = c.opts.Description c.app.RunAndExitOnError() diff --git a/defaults.go b/defaults.go index 1a83bcf0..0159f19c 100644 --- a/defaults.go +++ b/defaults.go @@ -1,28 +1,17 @@ package micro import ( - "github.com/micro/go-micro/broker" "github.com/micro/go-micro/client" "github.com/micro/go-micro/server" "github.com/micro/go-micro/store" // set defaults - "github.com/micro/go-micro/broker/nats" gcli "github.com/micro/go-micro/client/grpc" gsrv "github.com/micro/go-micro/server/grpc" memStore "github.com/micro/go-micro/store/memory" ) func init() { - // default broker - broker.DefaultBroker = nats.NewBroker( - // embedded nats server - nats.LocalServer(), - ) - // new client initialisation - client.NewClient = gcli.NewClient - // new server initialisation - server.NewServer = gsrv.NewServer // default client client.DefaultClient = gcli.NewClient() // default server diff --git a/runtime/service/service.go b/runtime/service/service.go index 91e62df8..4270d5ea 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -15,25 +15,6 @@ type svc struct { runtime pb.RuntimeService } -// NewRuntime creates new service runtime and returns it -func NewRuntime(opts ...runtime.Option) runtime.Runtime { - // get default options - options := runtime.Options{} - - // apply requested options - for _, o := range opts { - o(&options) - } - - // create default client - cli := client.DefaultClient - - return &svc{ - options: options, - runtime: pb.NewRuntimeService(runtime.DefaultName, cli), - } -} - // Init initializes runtime with given options func (s *svc) Init(opts ...runtime.Option) error { s.Lock() @@ -183,3 +164,23 @@ func (s *svc) Stop() error { func (s *svc) String() string { return "service" } + +// NewRuntime creates new service runtime and returns it +func NewRuntime(opts ...runtime.Option) runtime.Runtime { + // get default options + options := runtime.Options{} + + // apply requested options + for _, o := range opts { + o(&options) + } + + // create default client + cli := client.DefaultClient + + return &svc{ + options: options, + runtime: pb.NewRuntimeService(runtime.DefaultName, cli), + } +} + diff --git a/service.go b/service.go index f6844e33..abbf23c5 100644 --- a/service.go +++ b/service.go @@ -76,6 +76,11 @@ func (s *service) Init(opts ...Option) { } } + // set cmd name + if len(s.opts.Cmd.App().Name) == 0 { + s.opts.Cmd.App().Name = s.Server().Options().Name + } + // Initialise the command flags, overriding new service _ = s.opts.Cmd.Init( cmd.Broker(&s.opts.Broker), From cafd280718fffb7a08349ecded1fbf7b70b3d162 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 01:13:14 +0000 Subject: [PATCH 164/788] Default to grpc in registry service for now --- registry/service/service.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/registry/service/service.go b/registry/service/service.go index 5a70cee7..42aa89d8 100644 --- a/registry/service/service.go +++ b/registry/service/service.go @@ -6,6 +6,7 @@ import ( "time" "github.com/micro/go-micro/client" + "github.com/micro/go-micro/client/grpc" "github.com/micro/go-micro/registry" pb "github.com/micro/go-micro/registry/service/proto" ) @@ -149,7 +150,7 @@ func NewRegistry(opts ...registry.Option) registry.Registry { mReg := registry.NewRegistry() // create new client with mdns - cli := client.NewClient( + cli := grpc.NewClient( client.Registry(mReg), ) From fc08a9146cc6ef2dcc1d556f5396ac2de86b33eb Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 01:16:36 +0000 Subject: [PATCH 165/788] Add broker comments on server subscribe --- server/grpc/grpc.go | 1 + server/rpc_server.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 08c771e3..b039c021 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -653,6 +653,7 @@ func (g *grpcServer) Register() error { opts = append(opts, broker.DisableAutoAck()) } + log.Logf("Broker [%s] Subscribing to topic: %s", config.Broker.String(), sb.Topic()) sub, err := config.Broker.Subscribe(sb.Topic(), handler, opts...) if err != nil { return err diff --git a/server/rpc_server.go b/server/rpc_server.go index 7d1642ff..5f7f08d4 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -654,12 +654,12 @@ func (s *rpcServer) Register() error { opts = append(opts, broker.DisableAutoAck()) } + log.Logf("Broker [%s] Subscribing to topic: %s", config.Broker.String(), sub.Topic()) sub, err := config.Broker.Subscribe(sb.Topic(), s.HandleEvent, opts...) if err != nil { return err } - log.Logf("Subscribing %s to topic: %s", node.Id, sub.Topic()) s.subscribers[sb] = []broker.Subscriber{sub} } From 10093a0ea2a75dfb63b9decba4d8b77c39448677 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 01:29:00 +0000 Subject: [PATCH 166/788] set to nats-e --- broker/default.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/broker/default.go b/broker/default.go index 3f45c3ef..29dc1583 100644 --- a/broker/default.go +++ b/broker/default.go @@ -402,7 +402,7 @@ func (n *natsBroker) Subscribe(topic string, handler Handler, opts ...SubscribeO } func (n *natsBroker) String() string { - return "nats" + return "nats-e" } func (n *natsBroker) setOption(opts ...Option) { From 1983d607f36d8c5b6d23bfdc663a531811bd71e5 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 01:47:30 +0000 Subject: [PATCH 167/788] set nats-e --- config/cmd/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 43269291..1914fe59 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -265,7 +265,7 @@ var ( // used for default selection as the fall back defaultClient = "grpc" defaultServer = "grpc" - defaultBroker = "enats" + defaultBroker = "nats-e" defaultRegistry = "mdns" defaultSelector = "registry" defaultTransport = "http" From a82fd19209bb8bb67f5ec56d25626d54d9a1012e Mon Sep 17 00:00:00 2001 From: Allenxuxu <120582243@qq.com> Date: Sun, 19 Jan 2020 16:31:02 +0800 Subject: [PATCH 168/788] handle Loader.Load return value error --- config/config.go | 4 ++-- config/default.go | 9 ++++++--- config/default_test.go | 23 +++++++++++++++++------ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/config/config.go b/config/config.go index 020c71d5..b45215e8 100644 --- a/config/config.go +++ b/config/config.go @@ -43,11 +43,11 @@ type Option func(o *Options) var ( // Default Config Manager - DefaultConfig = NewConfig() + DefaultConfig, _ = NewConfig() ) // NewConfig returns new config -func NewConfig(opts ...Option) Config { +func NewConfig(opts ...Option) (Config, error) { return newConfig(opts...) } diff --git a/config/default.go b/config/default.go index c01da98c..09bccdc6 100644 --- a/config/default.go +++ b/config/default.go @@ -30,7 +30,7 @@ type watcher struct { value reader.Value } -func newConfig(opts ...Option) Config { +func newConfig(opts ...Option) (Config, error) { options := Options{ Loader: memory.NewLoader(), Reader: json.NewReader(), @@ -40,7 +40,10 @@ func newConfig(opts ...Option) Config { o(&options) } - options.Loader.Load(options.Source...) + if err := options.Loader.Load(options.Source...); err != nil { + return nil, err + } + snap, _ := options.Loader.Snapshot() vals, _ := options.Reader.Values(snap.ChangeSet) @@ -53,7 +56,7 @@ func newConfig(opts ...Option) Config { go c.run() - return c + return c, nil } func (c *config) run() { diff --git a/config/default_test.go b/config/default_test.go index b2ef0575..e53a877b 100644 --- a/config/default_test.go +++ b/config/default_test.go @@ -55,7 +55,10 @@ func TestConfigLoadWithGoodFile(t *testing.T) { }() // Create new config - conf := NewConfig() + conf, err := NewConfig() + if err != nil { + t.Fatalf("Expected no error but got %v", err) + } // Load file source if err := conf.Load(file.NewSource( file.WithPath(path), @@ -73,9 +76,12 @@ func TestConfigLoadWithInvalidFile(t *testing.T) { }() // Create new config - conf := NewConfig() + conf, err := NewConfig() + if err != nil { + t.Fatalf("Expected no error but got %v", err) + } // Load file source - err := conf.Load(file.NewSource( + err = conf.Load(file.NewSource( file.WithPath(path), file.WithPath("/i/do/not/exists.json"), )) @@ -105,13 +111,18 @@ func TestConfigMerge(t *testing.T) { }() os.Setenv("AMQP_HOST", "rabbit.testing.com") - conf := NewConfig() - conf.Load( + conf, err := NewConfig() + if err != nil { + t.Fatalf("Expected no error but got %v", err) + } + if err := conf.Load( file.NewSource( file.WithPath(path), ), env.NewSource(), - ) + ); err != nil { + t.Fatalf("Expected no error but got %v", err) + } actualHost := conf.Get("amqp", "host").String("backup") if actualHost != "rabbit.testing.com" { From ee7304a795702a05a1bc5b2aa383e8269b1ada13 Mon Sep 17 00:00:00 2001 From: Allenxuxu <120582243@qq.com> Date: Sun, 19 Jan 2020 16:42:05 +0800 Subject: [PATCH 169/788] NewConfig return value error --- config/default.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/config/default.go b/config/default.go index 09bccdc6..b4535ed9 100644 --- a/config/default.go +++ b/config/default.go @@ -44,8 +44,14 @@ func newConfig(opts ...Option) (Config, error) { return nil, err } - snap, _ := options.Loader.Snapshot() - vals, _ := options.Reader.Values(snap.ChangeSet) + snap, err := options.Loader.Snapshot() + if err != nil { + return nil, err + } + vals, err := options.Reader.Values(snap.ChangeSet) + if err != nil { + return nil, err + } c := &config{ exit: make(chan bool), From e75b99f89c5ccfda3b692ce35356947982889914 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 13:32:24 +0000 Subject: [PATCH 170/788] go fmt --- config/cmd/cmd.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 1914fe59..dfea3e59 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -9,14 +9,14 @@ import ( "github.com/micro/cli" "github.com/micro/go-micro/broker" + "github.com/micro/go-micro/client" "github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/client" + "github.com/micro/go-micro/runtime" "github.com/micro/go-micro/server" "github.com/micro/go-micro/store" - "github.com/micro/go-micro/util/log" - "github.com/micro/go-micro/runtime" "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/util/log" // clients cgrpc "github.com/micro/go-micro/client/grpc" @@ -235,9 +235,9 @@ var ( } DefaultSelectors = map[string]func(...selector.Option) selector.Selector{ - "dns": dns.NewSelector, - "router": router.NewSelector, - "static": static.NewSelector, + "dns": dns.NewSelector, + "router": router.NewSelector, + "static": static.NewSelector, } DefaultServers = map[string]func(...server.Option) server.Server{ From e1ca40c1fc8edd90e5b332bdee7a88ba855ea9a2 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 13:32:30 +0000 Subject: [PATCH 171/788] go fmt --- runtime/service/service.go | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/service/service.go b/runtime/service/service.go index 4270d5ea..5ecfb9ec 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -183,4 +183,3 @@ func NewRuntime(opts ...runtime.Option) runtime.Runtime { runtime: pb.NewRuntimeService(runtime.DefaultName, cli), } } - From 9a8c1b7ab8069b97cc8c62876757048d93f38745 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 13:35:23 +0000 Subject: [PATCH 172/788] update broker --- broker/default.go | 2 +- broker/http/http.go | 5 ++ go.mod | 28 +++++--- go.sum | 165 ++++++++++++++++++++++++++++++++++++-------- 4 files changed, 162 insertions(+), 38 deletions(-) diff --git a/broker/default.go b/broker/default.go index 29dc1583..8fd6214b 100644 --- a/broker/default.go +++ b/broker/default.go @@ -12,8 +12,8 @@ import ( "github.com/micro/go-micro/codec/json" "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/util/log" "github.com/micro/go-micro/util/addr" + "github.com/micro/go-micro/util/log" "github.com/nats-io/nats-server/v2/server" nats "github.com/nats-io/nats.go" ) diff --git a/broker/http/http.go b/broker/http/http.go index 7ae7ed7f..269bdba5 100644 --- a/broker/http/http.go +++ b/broker/http/http.go @@ -20,6 +20,7 @@ import ( "github.com/google/uuid" "github.com/micro/go-micro/broker" "github.com/micro/go-micro/codec/json" + "github.com/micro/go-micro/config/cmd" merr "github.com/micro/go-micro/errors" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry/cache" @@ -29,6 +30,10 @@ import ( "golang.org/x/net/http2" ) +func init() { + cmd.DefaultBrokers["http"] = NewBroker +} + // HTTP Broker is a point to point async broker type httpBroker struct { id string diff --git a/go.mod b/go.mod index 31f419f1..35d8ea72 100644 --- a/go.mod +++ b/go.mod @@ -6,46 +6,58 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/beevik/ntp v0.2.0 github.com/bitly/go-simplejson v0.5.0 + github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect github.com/bwmarrin/discordgo v0.20.2 + github.com/coreos/bbolt v1.3.3 // indirect github.com/coreos/etcd v3.3.18+incompatible + github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c github.com/fsnotify/fsnotify v1.4.7 github.com/fsouza/go-dockerclient v1.6.0 github.com/ghodss/yaml v1.0.0 - github.com/go-acme/lego/v3 v3.2.0 + github.com/go-acme/lego/v3 v3.3.0 github.com/go-playground/universal-translator v0.17.0 // indirect + github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect + github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 // indirect github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/websocket v1.4.1 + github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect + github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/hashicorp/hcl v1.0.0 github.com/imdario/mergo v0.3.8 + github.com/jonboulle/clockwork v0.1.0 // indirect github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 github.com/json-iterator/go v1.1.9 github.com/kr/pretty v0.1.0 github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 - github.com/mholt/certmagic v0.9.0 + github.com/mholt/certmagic v0.9.1 github.com/micro/cli v0.2.0 github.com/micro/mdns v0.3.0 - github.com/miekg/dns v1.1.26 + github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 - github.com/nats-io/gnatsd v1.4.1 // indirect - github.com/nats-io/nats-server v1.4.1 github.com/nats-io/nats-server/v2 v2.1.2 github.com/nats-io/nats.go v1.9.1 github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c - github.com/pkg/errors v0.8.1 + github.com/pkg/errors v0.9.1 + github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 github.com/technoweenie/multipartstreamer v1.0.1 // indirect + github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect + github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect + go.etcd.io/bbolt v1.3.3 // indirect go.uber.org/zap v1.13.0 - golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 - golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 + golang.org/x/crypto v0.0.0-20200117160349-530e935923ad + golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa google.golang.org/grpc v1.26.0 + gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 + sigs.k8s.io/yaml v1.1.0 // indirect ) diff --git a/go.sum b/go.sum index 568f4d11..aaadbeae 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,19 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= contrib.go.opencensus.io/exporter/ocagent v0.4.12/go.mod h1:450APlNTSR6FrvC3CTRqYosuDstRB9un7SOx2k/9ckA= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-autorest/autorest v0.1.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg= github.com/Azure/go-autorest/autorest v0.5.0/go.mod h1:9HLKlQjVBH6U3oDfsXOeVc56THsLPw1L03yban4xThw= @@ -18,20 +29,27 @@ github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6L github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvdeRAgDr0izn4z5Ij88= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 h1:ygIc8M6trr62pF5DucadTWGdEB4mEyvzi0e2nbcmcyA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= +github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/akamai/AkamaiOPEN-edgegrid-golang v0.9.0/go.mod h1:zpDJeKyp9ScW4NNrbdr+Eyxvry3ilGPewKoXw3XGN1k= +github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75 h1:3ILjVyslFbc4jl1w5TWuvvslFD/nDfR2H8tVaMVLrEY= github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75/go.mod h1:uAXEEpARkRhCZfEvy/y0Jcc888f9tHCc1W7/UeEtreE= +github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190808125512-07798873deee/go.mod h1:myCDvQSzCW+wB1WAlocEru4wMGJxy+vlxHdhegi1CDQ= github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= +github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aws/aws-sdk-go v1.23.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= @@ -39,10 +57,13 @@ github.com/beevik/ntp v0.2.0 h1:sGsd+kAXzT0bfVfzJfce04g+dSRfrs+tbQW8lweuYgw= github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y= github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= @@ -65,8 +86,12 @@ github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3/go.mod h1:IV7qH3hrUgRmyYrtgEeGWJfWbgcHL9CSRruz2Vqcph0= github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDGpgqzQIzDW1TphrGLssLDZp2GuS+X5DkEJB8o= github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= +github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= +github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= @@ -77,7 +102,7 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/decker502/dnspod-go v0.2.0/go.mod h1:qsurYu1FgxcDwfSwXJdLt4kRsBLZeosEb9uq4Sy+08g= +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= @@ -99,6 +124,7 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= +github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXju1m8W4lnEeIqTHPOzhTUO81a7yknM/xQR4= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= @@ -108,13 +134,13 @@ github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4 github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= -github.com/go-acme/lego v2.7.2+incompatible h1:ThhpPBgf6oa9X/vRd0kEmWOsX7+vmYdckmGZSb+FEp0= -github.com/go-acme/lego/v3 v3.1.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= -github.com/go-acme/lego/v3 v3.2.0 h1:z0zvNlL1niv/1qA06V5X1BRC5PeLoGKAlVaWthXQz9c= -github.com/go-acme/lego/v3 v3.2.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= +github.com/go-acme/lego/v3 v3.3.0 h1:6BePZsOiYA4/w+M7QDytxQtMfCipMPGnWAHs9pWks98= +github.com/go-acme/lego/v3 v3.3.0/go.mod h1:iGSY2vQrvQs3WezicSB/oVbO2eCrD88dpWPwb1qLqu0= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -124,6 +150,8 @@ github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTM github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU= +github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM= github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -131,9 +159,14 @@ github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 h1:5ZkaAPbicIKTF2I64qf5Fh8Aa83Q/dnOafMYV0OMwjA= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -141,13 +174,17 @@ github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -164,6 +201,11 @@ github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg= +github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.8.5 h1:2+KSC78XiO6Qy0hIjfc1OD9H+hsaJdJlb8Kqsd41CTE= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -173,6 +215,7 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= @@ -181,6 +224,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 h1:lnrOS18wZBYrzdDmnUeg1OVk+kQ3rxG8mZWU89DpMIA= github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1/go.mod h1:DFXrEwSRX0p/aSvxE21319menCBFeQO0jXpRj7LEZUA= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= @@ -199,6 +244,7 @@ github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/kolo/xmlrpc v0.0.0-20190717152603-07c4ee3fd181/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -226,17 +272,18 @@ github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mholt/certmagic v0.9.0 h1:dYh9sZPDBTcIiPhYM/Qtv3V623/zFH34FmpbrQTpMAc= -github.com/mholt/certmagic v0.9.0/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= +github.com/mholt/certmagic v0.9.1 h1:wPzyouOyE+30NIQETJuhTB5ZQWz+0Hy038vaR5WWQDE= +github.com/mholt/certmagic v0.9.1/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/miekg/dns v1.1.26 h1:gPxPSwALAeHJSjarOs00QjVdV9QoBvc1D2ujQUr5BzU= -github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= +github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= +github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed/go.mod h1:3rdaFaCv4AyBgu5ALFM0+tSuHrBh6v692nyQe3ikrq0= @@ -253,35 +300,30 @@ github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8d github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= -github.com/nats-io/gnatsd v1.4.1 h1:RconcfDeWpKCD6QIIwiVFcvForlXpWeJP7i5/lDLy44= -github.com/nats-io/gnatsd v1.4.1/go.mod h1:nqco77VO78hLCJpIcVfygDP2rPGfsEHkGTUk94uh5DQ= -github.com/nats-io/jwt v0.3.0 h1:xdnzwFETV++jNc4W1mw//qFyJGb2ABOombmZJQS4+Qo= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server v1.4.1 h1:Ul1oSOGNV/L8kjr4v6l2f9Yet6WY+LevH1/7cRZ/qyA= -github.com/nats-io/nats-server v1.4.1/go.mod h1:c8f/fHd2B6Hgms3LtCaI7y6pC4WD1f4SUxcCud5vhBc= github.com/nats-io/nats-server/v2 v2.1.2 h1:i2Ly0B+1+rzNZHHWtD4ZwKi+OU5l+uQo1iDHZ2PmiIc= github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= -github.com/nats-io/nkeys v0.1.0 h1:qMd4+pRHgdr1nAClu+2h/2a5F2TmKcCzjCDazVgRoX4= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= -github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA= -github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= +github.com/nrdcg/dnspod-go v0.3.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgPTGKr6KQ= github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2SwKQ= github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= @@ -293,6 +335,7 @@ github.com/opencontainers/runc v0.1.1 h1:GlxAyO6x8rfZYN9Tt0Kti5a/cP41iuiO2yYT0IJ github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/runtime-tools v0.0.0-20181011054405-1d69bd0f9c39/go.mod h1:r3f7wjNzSs2extwzU3Y+6pKfobzPh+kKFJ3ofN+3nfs= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/oracle/oci-go-sdk v7.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014/go.mod h1:joRatxRJaZBsY3JAOEMcoOp05CnZzsx4scTxi95DHyQ= @@ -301,25 +344,30 @@ github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwU github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.1.0 h1:BQ53HtBmfOitExawJ6LokA4x8ov/z0SYYb0+HxJfRI8= github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= +github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKcyumwBO6qip7RNQ5r77yrssm9bfCowcLEBcU5IA= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= @@ -338,11 +386,12 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -352,6 +401,8 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= @@ -363,17 +414,25 @@ github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2 github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= +go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -385,21 +444,34 @@ golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 h1:sKJQZMuxjOAR/Uo2LBfU90onWEf1dF4C+0hPJCc9Mpc= -golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg= +golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/net v0.0.0-20180611182652-db08ff08e862/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -414,13 +486,15 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -428,8 +502,9 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180622082034-63fc586f45fe/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -441,17 +516,19 @@ golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -468,43 +545,66 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= -golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 h1:RIIXAeV6GvDBuADKumTODatUqANFZ+5BPMnzsy4hulY= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1 h1:aQktFqmDE2yjveXJlVIfslDFmFnUXSqG0i6KRcJAeMc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= @@ -517,11 +617,13 @@ gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4 gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg= gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= +gopkg.in/src-d/go-git-fixtures.v3 v3.5.0 h1:ivZFOIltbce2Mo8IjzUHAFoq/IylO9WHhNOAJK+LsJg= gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE= gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= gopkg.in/telegram-bot-api.v4 v4.6.4 h1:hpHWhzn4jTCsAJZZ2loNKfy2QWyPDRJVl3aTFXeMW8g= gopkg.in/telegram-bot-api.v4 v4.6.4/go.mod h1:5DpGO5dbumb40px+dXcwCpcjmeHNYLpk0bp3XRNvWDM= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= @@ -529,11 +631,16 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= +sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= From 0c03bf064b533180e0cc083da7f6ef3e50c08d5b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 13:45:28 +0000 Subject: [PATCH 173/788] only connect broker if there are subscribers --- server/grpc/grpc.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index b039c021..d8a1cb89 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -752,16 +752,19 @@ func (g *grpcServer) Start() error { g.opts.Address = ts.Addr().String() g.Unlock() - // connect to the broker - if err := config.Broker.Connect(); err != nil { - return err + // only connect if we're subscribed + if len(g.subscribers) > 0 { + // connect to the broker + if err := config.Broker.Connect(); err != nil { + return err + } + + baddr := config.Broker.Address() + bname := config.Broker.String() + + log.Logf("Broker [%s] Connected to %s", bname, baddr) } - baddr := config.Broker.Address() - bname := config.Broker.String() - - log.Logf("Broker [%s] Connected to %s", bname, baddr) - // announce self to the world if err := g.Register(); err != nil { log.Log("Server register error: ", err) From bdd9ec560bbf53c8d49e956ed64d0ac4ab42ed3f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 13:47:14 +0000 Subject: [PATCH 174/788] strip sub comments --- server/grpc/grpc.go | 2 +- server/rpc_server.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index d8a1cb89..53674aa7 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -653,7 +653,7 @@ func (g *grpcServer) Register() error { opts = append(opts, broker.DisableAutoAck()) } - log.Logf("Broker [%s] Subscribing to topic: %s", config.Broker.String(), sb.Topic()) + log.Logf("Subscribing to topic: %s", sb.Topic()) sub, err := config.Broker.Subscribe(sb.Topic(), handler, opts...) if err != nil { return err diff --git a/server/rpc_server.go b/server/rpc_server.go index 5f7f08d4..a6ccd6a5 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -654,7 +654,7 @@ func (s *rpcServer) Register() error { opts = append(opts, broker.DisableAutoAck()) } - log.Logf("Broker [%s] Subscribing to topic: %s", config.Broker.String(), sub.Topic()) + log.Logf("Subscribing to topic: %s", sub.Topic()) sub, err := config.Broker.Subscribe(sb.Topic(), s.HandleEvent, opts...) if err != nil { return err From 43aa4e23bd2746b4c0d49209a46ad201dbade85f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 13:51:31 +0000 Subject: [PATCH 175/788] update readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 02763aa7..3e3dcacd 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,11 @@ and server handle this by default. This includes protobuf and json by default. - **Request/Response** - RPC based request/response with support for bidirectional streaming. We provide an abstraction for synchronous communication. A request made to a service will be automatically resolved, load balanced, dialled and streamed. The default -transport is http/1.1 or http2 when tls is enabled. +transport is [gRPC](https://grpc.io/). - **Async Messaging** - PubSub is built in as a first class citizen for asynchronous communication and event driven architectures. -Event notifications are a core pattern in micro service development. The default messaging is point-to-point http/1.1 or http2 when tls -is enabled. +Event notifications are a core pattern in micro service development. The default messaging system is an embedded [NATS](https://nats.io/) +server. - **Pluggable Interfaces** - Go Micro makes use of Go interfaces for each distributed system abstraction. Because of this these interfaces are pluggable and allows Go Micro to be runtime agnostic. You can plugin any underlying technology. Find plugins in From 7b6d560bec1040bab15a05079eb478f4462bc4b4 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 13:55:23 +0000 Subject: [PATCH 176/788] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e3dcacd..8e7d9ad8 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ but everything can be easily swapped out. Plugins are available at [github.com/micro/go-plugins](https://github.com/micro/go-plugins). -Follow us on [Twitter](https://twitter.com/microhq) or join the [Slack](https://micro.mu/slack) community. +Follow us on [Twitter](https://twitter.com/microhq) or join the [Community](https://micro.mu/slack). ## Features From 093bcedfe7d05783d46e8032fd51ca684df6b2aa Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 17:21:55 +0000 Subject: [PATCH 177/788] remove http broker --- broker/http/http.go | 710 --------------------------------------- broker/http/http_test.go | 392 --------------------- broker/http/options.go | 23 -- 3 files changed, 1125 deletions(-) delete mode 100644 broker/http/http.go delete mode 100644 broker/http/http_test.go delete mode 100644 broker/http/options.go diff --git a/broker/http/http.go b/broker/http/http.go deleted file mode 100644 index 269bdba5..00000000 --- a/broker/http/http.go +++ /dev/null @@ -1,710 +0,0 @@ -// Package http provides a http based message broker -package http - -import ( - "bytes" - "context" - "crypto/tls" - "errors" - "fmt" - "io" - "io/ioutil" - "math/rand" - "net" - "net/http" - "net/url" - "runtime" - "sync" - "time" - - "github.com/google/uuid" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/codec/json" - "github.com/micro/go-micro/config/cmd" - merr "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/registry/cache" - maddr "github.com/micro/go-micro/util/addr" - mnet "github.com/micro/go-micro/util/net" - mls "github.com/micro/go-micro/util/tls" - "golang.org/x/net/http2" -) - -func init() { - cmd.DefaultBrokers["http"] = NewBroker -} - -// HTTP Broker is a point to point async broker -type httpBroker struct { - id string - address string - opts broker.Options - - mux *http.ServeMux - - c *http.Client - r registry.Registry - - sync.RWMutex - subscribers map[string][]*httpSubscriber - running bool - exit chan chan error - - // offline message inbox - mtx sync.RWMutex - inbox map[string][][]byte -} - -type httpSubscriber struct { - opts broker.SubscribeOptions - id string - topic string - fn broker.Handler - svc *registry.Service - hb *httpBroker -} - -type httpEvent struct { - m *broker.Message - t string -} - -var ( - DefaultSubPath = "/_sub" - serviceName = "go.micro.http.broker" - broadcastVersion = "ff.http.broadcast" - registerTTL = time.Minute - registerInterval = time.Second * 30 -) - -func init() { - rand.Seed(time.Now().Unix()) -} - -func newTransport(config *tls.Config) *http.Transport { - if config == nil { - config = &tls.Config{ - InsecureSkipVerify: true, - } - } - - dialTLS := func(network string, addr string) (net.Conn, error) { - return tls.Dial(network, addr, config) - } - - t := &http.Transport{ - Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - }).Dial, - TLSHandshakeTimeout: 10 * time.Second, - DialTLS: dialTLS, - } - runtime.SetFinalizer(&t, func(tr **http.Transport) { - (*tr).CloseIdleConnections() - }) - - // setup http2 - http2.ConfigureTransport(t) - - return t -} - -func newHttpBroker(opts ...broker.Option) broker.Broker { - options := broker.Options{ - Codec: json.Marshaler{}, - Context: context.TODO(), - Registry: registry.DefaultRegistry, - } - - for _, o := range opts { - o(&options) - } - - // set address - addr := ":0" - if len(options.Addrs) > 0 && len(options.Addrs[0]) > 0 { - addr = options.Addrs[0] - } - - h := &httpBroker{ - id: uuid.New().String(), - address: addr, - opts: options, - r: options.Registry, - c: &http.Client{Transport: newTransport(options.TLSConfig)}, - subscribers: make(map[string][]*httpSubscriber), - exit: make(chan chan error), - mux: http.NewServeMux(), - inbox: make(map[string][][]byte), - } - - // specify the message handler - h.mux.Handle(DefaultSubPath, h) - - // get optional handlers - if h.opts.Context != nil { - handlers, ok := h.opts.Context.Value("http_handlers").(map[string]http.Handler) - if ok { - for pattern, handler := range handlers { - h.mux.Handle(pattern, handler) - } - } - } - - return h -} - -func (h *httpEvent) Ack() error { - return nil -} - -func (h *httpEvent) Message() *broker.Message { - return h.m -} - -func (h *httpEvent) Topic() string { - return h.t -} - -func (h *httpSubscriber) Options() broker.SubscribeOptions { - return h.opts -} - -func (h *httpSubscriber) Topic() string { - return h.topic -} - -func (h *httpSubscriber) Unsubscribe() error { - return h.hb.unsubscribe(h) -} - -func (h *httpBroker) saveMessage(topic string, msg []byte) { - h.mtx.Lock() - defer h.mtx.Unlock() - - // get messages - c := h.inbox[topic] - - // save message - c = append(c, msg) - - // max length 64 - if len(c) > 64 { - c = c[:64] - } - - // save inbox - h.inbox[topic] = c -} - -func (h *httpBroker) getMessage(topic string, num int) [][]byte { - h.mtx.Lock() - defer h.mtx.Unlock() - - // get messages - c, ok := h.inbox[topic] - if !ok { - return nil - } - - // more message than requests - if len(c) >= num { - msg := c[:num] - h.inbox[topic] = c[num:] - return msg - } - - // reset inbox - h.inbox[topic] = nil - - // return all messages - return c -} - -func (h *httpBroker) subscribe(s *httpSubscriber) error { - h.Lock() - defer h.Unlock() - - if err := h.r.Register(s.svc, registry.RegisterTTL(registerTTL)); err != nil { - return err - } - - h.subscribers[s.topic] = append(h.subscribers[s.topic], s) - return nil -} - -func (h *httpBroker) unsubscribe(s *httpSubscriber) error { - h.Lock() - defer h.Unlock() - - //nolint:prealloc - var subscribers []*httpSubscriber - - // look for subscriber - for _, sub := range h.subscribers[s.topic] { - // deregister and skip forward - if sub == s { - _ = h.r.Deregister(sub.svc) - continue - } - // keep subscriber - subscribers = append(subscribers, sub) - } - - // set subscribers - h.subscribers[s.topic] = subscribers - - return nil -} - -func (h *httpBroker) run(l net.Listener) { - t := time.NewTicker(registerInterval) - defer t.Stop() - - for { - select { - // heartbeat for each subscriber - case <-t.C: - h.RLock() - for _, subs := range h.subscribers { - for _, sub := range subs { - _ = h.r.Register(sub.svc, registry.RegisterTTL(registerTTL)) - } - } - h.RUnlock() - // received exit signal - case ch := <-h.exit: - ch <- l.Close() - h.RLock() - for _, subs := range h.subscribers { - for _, sub := range subs { - _ = h.r.Deregister(sub.svc) - } - } - h.RUnlock() - return - } - } -} - -func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) { - if req.Method != "POST" { - err := merr.BadRequest("go.micro.broker", "Method not allowed") - http.Error(w, err.Error(), http.StatusMethodNotAllowed) - return - } - defer req.Body.Close() - - req.ParseForm() - - b, err := ioutil.ReadAll(req.Body) - if err != nil { - errr := merr.InternalServerError("go.micro.broker", "Error reading request body: %v", err) - w.WriteHeader(500) - w.Write([]byte(errr.Error())) - return - } - - var m *broker.Message - if err = h.opts.Codec.Unmarshal(b, &m); err != nil { - errr := merr.InternalServerError("go.micro.broker", "Error parsing request body: %v", err) - w.WriteHeader(500) - w.Write([]byte(errr.Error())) - return - } - - topic := m.Header[":topic"] - delete(m.Header, ":topic") - - if len(topic) == 0 { - errr := merr.InternalServerError("go.micro.broker", "Topic not found") - w.WriteHeader(500) - w.Write([]byte(errr.Error())) - return - } - - p := &httpEvent{m: m, t: topic} - id := req.Form.Get("id") - - //nolint:prealloc - var subs []broker.Handler - - h.RLock() - for _, subscriber := range h.subscribers[topic] { - if id != subscriber.id { - continue - } - subs = append(subs, subscriber.fn) - } - h.RUnlock() - - // execute the handler - for _, fn := range subs { - fn(p) - } -} - -func (h *httpBroker) Address() string { - h.RLock() - defer h.RUnlock() - return h.address -} - -func (h *httpBroker) Connect() error { - h.RLock() - if h.running { - h.RUnlock() - return nil - } - h.RUnlock() - - h.Lock() - defer h.Unlock() - - var l net.Listener - var err error - - if h.opts.Secure || h.opts.TLSConfig != nil { - config := h.opts.TLSConfig - - fn := func(addr string) (net.Listener, error) { - if config == nil { - hosts := []string{addr} - - // check if its a valid host:port - if host, _, err := net.SplitHostPort(addr); err == nil { - if len(host) == 0 { - hosts = maddr.IPs() - } else { - hosts = []string{host} - } - } - - // generate a certificate - cert, err := mls.Certificate(hosts...) - if err != nil { - return nil, err - } - config = &tls.Config{Certificates: []tls.Certificate{cert}} - } - return tls.Listen("tcp", addr, config) - } - - l, err = mnet.Listen(h.address, fn) - } else { - fn := func(addr string) (net.Listener, error) { - return net.Listen("tcp", addr) - } - - l, err = mnet.Listen(h.address, fn) - } - - if err != nil { - return err - } - - addr := h.address - h.address = l.Addr().String() - - go http.Serve(l, h.mux) - go func() { - h.run(l) - h.Lock() - h.opts.Addrs = []string{addr} - h.address = addr - h.Unlock() - }() - - // get registry - reg := h.opts.Registry - if reg == nil { - reg = registry.DefaultRegistry - } - // set cache - h.r = cache.New(reg) - - // set running - h.running = true - return nil -} - -func (h *httpBroker) Disconnect() error { - h.RLock() - if !h.running { - h.RUnlock() - return nil - } - h.RUnlock() - - h.Lock() - defer h.Unlock() - - // stop cache - rc, ok := h.r.(cache.Cache) - if ok { - rc.Stop() - } - - // exit and return err - ch := make(chan error) - h.exit <- ch - err := <-ch - - // set not running - h.running = false - return err -} - -func (h *httpBroker) Init(opts ...broker.Option) error { - h.RLock() - if h.running { - h.RUnlock() - return errors.New("cannot init while connected") - } - h.RUnlock() - - h.Lock() - defer h.Unlock() - - for _, o := range opts { - o(&h.opts) - } - - if len(h.opts.Addrs) > 0 && len(h.opts.Addrs[0]) > 0 { - h.address = h.opts.Addrs[0] - } - - if len(h.id) == 0 { - h.id = "go.micro.http.broker-" + uuid.New().String() - } - - // get registry - reg := h.opts.Registry - if reg == nil { - reg = registry.DefaultRegistry - } - - // get cache - if rc, ok := h.r.(cache.Cache); ok { - rc.Stop() - } - - // set registry - h.r = cache.New(reg) - - // reconfigure tls config - if c := h.opts.TLSConfig; c != nil { - h.c = &http.Client{ - Transport: newTransport(c), - } - } - - return nil -} - -func (h *httpBroker) Options() broker.Options { - return h.opts -} - -func (h *httpBroker) Publish(topic string, msg *broker.Message, opts ...broker.PublishOption) error { - // create the message first - m := &broker.Message{ - Header: make(map[string]string), - Body: msg.Body, - } - - for k, v := range msg.Header { - m.Header[k] = v - } - - m.Header[":topic"] = topic - - // encode the message - b, err := h.opts.Codec.Marshal(m) - if err != nil { - return err - } - - // save the message - h.saveMessage(topic, b) - - // now attempt to get the service - h.RLock() - s, err := h.r.GetService(serviceName) - if err != nil { - h.RUnlock() - return err - } - h.RUnlock() - - pub := func(node *registry.Node, t string, b []byte) error { - scheme := "http" - - // check if secure is added in metadata - if node.Metadata["secure"] == "true" { - scheme = "https" - } - - vals := url.Values{} - vals.Add("id", node.Id) - - uri := fmt.Sprintf("%s://%s%s?%s", scheme, node.Address, DefaultSubPath, vals.Encode()) - r, err := h.c.Post(uri, "application/json", bytes.NewReader(b)) - if err != nil { - return err - } - - // discard response body - io.Copy(ioutil.Discard, r.Body) - r.Body.Close() - return nil - } - - srv := func(s []*registry.Service, b []byte) { - for _, service := range s { - var nodes []*registry.Node - - for _, node := range service.Nodes { - // only use nodes tagged with broker http - if node.Metadata["broker"] != "http" { - continue - } - - // look for nodes for the topic - if node.Metadata["topic"] != topic { - continue - } - - nodes = append(nodes, node) - } - - // only process if we have nodes - if len(nodes) == 0 { - continue - } - - switch service.Version { - // broadcast version means broadcast to all nodes - case broadcastVersion: - var success bool - - // publish to all nodes - for _, node := range nodes { - // publish async - if err := pub(node, topic, b); err == nil { - success = true - } - } - - // save if it failed to publish at least once - if !success { - h.saveMessage(topic, b) - } - default: - // select node to publish to - node := nodes[rand.Int()%len(nodes)] - - // publish async to one node - if err := pub(node, topic, b); err != nil { - // if failed save it - h.saveMessage(topic, b) - } - } - } - } - - // do the rest async - go func() { - // get a third of the backlog - messages := h.getMessage(topic, 8) - delay := (len(messages) > 1) - - // publish all the messages - for _, msg := range messages { - // serialize here - srv(s, msg) - - // sending a backlog of messages - if delay { - time.Sleep(time.Millisecond * 100) - } - } - }() - - return nil -} - -func (h *httpBroker) Subscribe(topic string, handler broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) { - var err error - var host, port string - options := broker.NewSubscribeOptions(opts...) - - // parse address for host, port - host, port, err = net.SplitHostPort(h.Address()) - if err != nil { - return nil, err - } - - addr, err := maddr.Extract(host) - if err != nil { - return nil, err - } - - var secure bool - - if h.opts.Secure || h.opts.TLSConfig != nil { - secure = true - } - - // register service - node := ®istry.Node{ - Id: topic + "-" + h.id, - Address: mnet.HostPort(addr, port), - Metadata: map[string]string{ - "secure": fmt.Sprintf("%t", secure), - "broker": "http", - "topic": topic, - }, - } - - // check for queue group or broadcast queue - version := options.Queue - if len(version) == 0 { - version = broadcastVersion - } - - service := ®istry.Service{ - Name: serviceName, - Version: version, - Nodes: []*registry.Node{node}, - } - - // generate subscriber - subscriber := &httpSubscriber{ - opts: options, - hb: h, - id: node.Id, - topic: topic, - fn: handler, - svc: service, - } - - // subscribe now - if err := h.subscribe(subscriber); err != nil { - return nil, err - } - - // return the subscriber - return subscriber, nil -} - -func (h *httpBroker) String() string { - return "http" -} - -// NewBroker returns a new http broker -func NewBroker(opts ...broker.Option) broker.Broker { - return newHttpBroker(opts...) -} diff --git a/broker/http/http_test.go b/broker/http/http_test.go deleted file mode 100644 index f3aec647..00000000 --- a/broker/http/http_test.go +++ /dev/null @@ -1,392 +0,0 @@ -package http - -import ( - "sync" - "testing" - "time" - - "github.com/google/uuid" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/debug/log/noop" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/registry/memory" - "github.com/micro/go-micro/util/log" -) - -var ( - // mock data - testData = map[string][]*registry.Service{ - "foo": { - { - Name: "foo", - Version: "1.0.0", - Nodes: []*registry.Node{ - { - Id: "foo-1.0.0-123", - Address: "localhost:9999", - }, - { - Id: "foo-1.0.0-321", - Address: "localhost:9999", - }, - }, - }, - { - Name: "foo", - Version: "1.0.1", - Nodes: []*registry.Node{ - { - Id: "foo-1.0.1-321", - Address: "localhost:6666", - }, - }, - }, - { - Name: "foo", - Version: "1.0.3", - Nodes: []*registry.Node{ - { - Id: "foo-1.0.3-345", - Address: "localhost:8888", - }, - }, - }, - }, - } -) - -func newTestRegistry() registry.Registry { - return memory.NewRegistry(memory.Services(testData)) -} - -func sub(be *testing.B, c int) { - // set no op logger - log.SetLogger(noop.NewLog()) - - be.StopTimer() - m := newTestRegistry() - - b := NewBroker(broker.Registry(m)) - topic := uuid.New().String() - - if err := b.Init(); err != nil { - be.Fatalf("Unexpected init error: %v", err) - } - - if err := b.Connect(); err != nil { - be.Fatalf("Unexpected connect error: %v", err) - } - - msg := &broker.Message{ - Header: map[string]string{ - "Content-Type": "application/json", - }, - Body: []byte(`{"message": "Hello World"}`), - } - - var subs []broker.Subscriber - done := make(chan bool, c) - - for i := 0; i < c; i++ { - sub, err := b.Subscribe(topic, func(p broker.Event) error { - done <- true - m := p.Message() - - if string(m.Body) != string(msg.Body) { - be.Fatalf("Unexpected msg %s, expected %s", string(m.Body), string(msg.Body)) - } - - return nil - }, broker.Queue("shared")) - if err != nil { - be.Fatalf("Unexpected subscribe error: %v", err) - } - subs = append(subs, sub) - } - - for i := 0; i < be.N; i++ { - be.StartTimer() - if err := b.Publish(topic, msg); err != nil { - be.Fatalf("Unexpected publish error: %v", err) - } - <-done - be.StopTimer() - } - - for _, sub := range subs { - sub.Unsubscribe() - } - - if err := b.Disconnect(); err != nil { - be.Fatalf("Unexpected disconnect error: %v", err) - } -} - -func pub(be *testing.B, c int) { - // set no op logger - log.SetLogger(noop.NewLog()) - - be.StopTimer() - m := newTestRegistry() - b := NewBroker(broker.Registry(m)) - topic := uuid.New().String() - - if err := b.Init(); err != nil { - be.Fatalf("Unexpected init error: %v", err) - } - - if err := b.Connect(); err != nil { - be.Fatalf("Unexpected connect error: %v", err) - } - - msg := &broker.Message{ - Header: map[string]string{ - "Content-Type": "application/json", - }, - Body: []byte(`{"message": "Hello World"}`), - } - - done := make(chan bool, c*4) - - sub, err := b.Subscribe(topic, func(p broker.Event) error { - done <- true - m := p.Message() - if string(m.Body) != string(msg.Body) { - be.Fatalf("Unexpected msg %s, expected %s", string(m.Body), string(msg.Body)) - } - return nil - }, broker.Queue("shared")) - if err != nil { - be.Fatalf("Unexpected subscribe error: %v", err) - } - - var wg sync.WaitGroup - ch := make(chan int, c*4) - be.StartTimer() - - for i := 0; i < c; i++ { - go func() { - for range ch { - if err := b.Publish(topic, msg); err != nil { - be.Fatalf("Unexpected publish error: %v", err) - } - select { - case <-done: - case <-time.After(time.Second): - } - wg.Done() - } - }() - } - - for i := 0; i < be.N; i++ { - wg.Add(1) - ch <- i - } - - wg.Wait() - be.StopTimer() - sub.Unsubscribe() - close(ch) - close(done) - - if err := b.Disconnect(); err != nil { - be.Fatalf("Unexpected disconnect error: %v", err) - } -} - -func TestBroker(t *testing.T) { - m := newTestRegistry() - b := NewBroker(broker.Registry(m)) - - if err := b.Init(); err != nil { - t.Fatalf("Unexpected init error: %v", err) - } - - if err := b.Connect(); err != nil { - t.Fatalf("Unexpected connect error: %v", err) - } - - msg := &broker.Message{ - Header: map[string]string{ - "Content-Type": "application/json", - }, - Body: []byte(`{"message": "Hello World"}`), - } - - done := make(chan bool) - - sub, err := b.Subscribe("test", func(p broker.Event) error { - m := p.Message() - - if string(m.Body) != string(msg.Body) { - t.Fatalf("Unexpected msg %s, expected %s", string(m.Body), string(msg.Body)) - } - - close(done) - return nil - }) - if err != nil { - t.Fatalf("Unexpected subscribe error: %v", err) - } - - if err := b.Publish("test", msg); err != nil { - t.Fatalf("Unexpected publish error: %v", err) - } - - <-done - sub.Unsubscribe() - - if err := b.Disconnect(); err != nil { - t.Fatalf("Unexpected disconnect error: %v", err) - } -} - -func TestConcurrentSubBroker(t *testing.T) { - m := newTestRegistry() - b := NewBroker(broker.Registry(m)) - - if err := b.Init(); err != nil { - t.Fatalf("Unexpected init error: %v", err) - } - - if err := b.Connect(); err != nil { - t.Fatalf("Unexpected connect error: %v", err) - } - - msg := &broker.Message{ - Header: map[string]string{ - "Content-Type": "application/json", - }, - Body: []byte(`{"message": "Hello World"}`), - } - - var subs []broker.Subscriber - var wg sync.WaitGroup - - for i := 0; i < 10; i++ { - sub, err := b.Subscribe("test", func(p broker.Event) error { - defer wg.Done() - - m := p.Message() - - if string(m.Body) != string(msg.Body) { - t.Fatalf("Unexpected msg %s, expected %s", string(m.Body), string(msg.Body)) - } - - return nil - }) - if err != nil { - t.Fatalf("Unexpected subscribe error: %v", err) - } - - wg.Add(1) - subs = append(subs, sub) - } - - if err := b.Publish("test", msg); err != nil { - t.Fatalf("Unexpected publish error: %v", err) - } - - wg.Wait() - - for _, sub := range subs { - sub.Unsubscribe() - } - - if err := b.Disconnect(); err != nil { - t.Fatalf("Unexpected disconnect error: %v", err) - } -} - -func TestConcurrentPubBroker(t *testing.T) { - m := newTestRegistry() - b := NewBroker(broker.Registry(m)) - - if err := b.Init(); err != nil { - t.Fatalf("Unexpected init error: %v", err) - } - - if err := b.Connect(); err != nil { - t.Fatalf("Unexpected connect error: %v", err) - } - - msg := &broker.Message{ - Header: map[string]string{ - "Content-Type": "application/json", - }, - Body: []byte(`{"message": "Hello World"}`), - } - - var wg sync.WaitGroup - - sub, err := b.Subscribe("test", func(p broker.Event) error { - defer wg.Done() - - m := p.Message() - - if string(m.Body) != string(msg.Body) { - t.Fatalf("Unexpected msg %s, expected %s", string(m.Body), string(msg.Body)) - } - - return nil - }) - if err != nil { - t.Fatalf("Unexpected subscribe error: %v", err) - } - - for i := 0; i < 10; i++ { - wg.Add(1) - - if err := b.Publish("test", msg); err != nil { - t.Fatalf("Unexpected publish error: %v", err) - } - } - - wg.Wait() - - sub.Unsubscribe() - - if err := b.Disconnect(); err != nil { - t.Fatalf("Unexpected disconnect error: %v", err) - } -} - -func BenchmarkSub1(b *testing.B) { - sub(b, 1) -} -func BenchmarkSub8(b *testing.B) { - sub(b, 8) -} - -func BenchmarkSub32(b *testing.B) { - sub(b, 32) -} - -func BenchmarkSub64(b *testing.B) { - sub(b, 64) -} - -func BenchmarkSub128(b *testing.B) { - sub(b, 128) -} - -func BenchmarkPub1(b *testing.B) { - pub(b, 1) -} - -func BenchmarkPub8(b *testing.B) { - pub(b, 8) -} - -func BenchmarkPub32(b *testing.B) { - pub(b, 32) -} - -func BenchmarkPub64(b *testing.B) { - pub(b, 64) -} - -func BenchmarkPub128(b *testing.B) { - pub(b, 128) -} diff --git a/broker/http/options.go b/broker/http/options.go deleted file mode 100644 index 03240c42..00000000 --- a/broker/http/options.go +++ /dev/null @@ -1,23 +0,0 @@ -package http - -import ( - "context" - "net/http" - - "github.com/micro/go-micro/broker" -) - -// Handle registers the handler for the given pattern. -func Handle(pattern string, handler http.Handler) broker.Option { - return func(o *broker.Options) { - if o.Context == nil { - o.Context = context.Background() - } - handlers, ok := o.Context.Value("http_handlers").(map[string]http.Handler) - if !ok { - handlers = make(map[string]http.Handler) - } - handlers[pattern] = handler - o.Context = context.WithValue(o.Context, "http_handlers", handlers) - } -} From a47ff65529234033dea02cd9ec4024734b8ff96a Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 17:24:22 +0000 Subject: [PATCH 178/788] remove mock client --- client/mock/context.go | 16 ----- client/mock/mock.go | 150 --------------------------------------- client/mock/mock_test.go | 67 ----------------- client/mock/options.go | 17 ----- 4 files changed, 250 deletions(-) delete mode 100644 client/mock/context.go delete mode 100644 client/mock/mock.go delete mode 100644 client/mock/mock_test.go delete mode 100644 client/mock/options.go diff --git a/client/mock/context.go b/client/mock/context.go deleted file mode 100644 index 27550502..00000000 --- a/client/mock/context.go +++ /dev/null @@ -1,16 +0,0 @@ -package mock - -import ( - "context" -) - -type responseKey struct{} - -func fromContext(ctx context.Context) (map[string][]MockResponse, bool) { - r, ok := ctx.Value(responseKey{}).(map[string][]MockResponse) - return r, ok -} - -func newContext(ctx context.Context, r map[string][]MockResponse) context.Context { - return context.WithValue(ctx, responseKey{}, r) -} diff --git a/client/mock/mock.go b/client/mock/mock.go deleted file mode 100644 index ba182478..00000000 --- a/client/mock/mock.go +++ /dev/null @@ -1,150 +0,0 @@ -// Package mock provides a mock client for testing -package mock - -import ( - "context" - "fmt" - "reflect" - "sync" - - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/errors" -) - -var ( - _ client.Client = NewClient() -) - -type MockResponse struct { - Endpoint string - Response interface{} - Error error -} - -type MockClient struct { - Client client.Client - Opts client.Options - - sync.Mutex - Response map[string][]MockResponse -} - -func (m *MockClient) Init(opts ...client.Option) error { - m.Lock() - defer m.Unlock() - - for _, opt := range opts { - opt(&m.Opts) - } - - r, ok := fromContext(m.Opts.Context) - if !ok { - r = make(map[string][]MockResponse) - } - m.Response = r - - return nil -} - -func (m *MockClient) Options() client.Options { - return m.Opts -} - -func (m *MockClient) NewMessage(topic string, msg interface{}, opts ...client.MessageOption) client.Message { - return m.Client.NewMessage(topic, msg, opts...) -} - -func (m *MockClient) NewRequest(service, endpoint string, req interface{}, reqOpts ...client.RequestOption) client.Request { - return m.Client.NewRequest(service, endpoint, req, reqOpts...) -} - -func (m *MockClient) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { - m.Lock() - defer m.Unlock() - - response, ok := m.Response[req.Service()] - if !ok { - return errors.NotFound("go.micro.client.mock", "service not found") - } - - for _, r := range response { - if r.Endpoint != req.Endpoint() { - continue - } - - if r.Error != nil { - return r.Error - } - - v := reflect.ValueOf(rsp) - - if t := reflect.TypeOf(rsp); t.Kind() == reflect.Ptr { - v = reflect.Indirect(v) - } - response := r.Response - if t := reflect.TypeOf(r.Response); t.Kind() == reflect.Func { - var request []reflect.Value - switch t.NumIn() { - case 1: - // one input params: (req) - request = append(request, reflect.ValueOf(req.Body())) - case 2: - // two input params: (ctx, req) - request = append(request, reflect.ValueOf(ctx), reflect.ValueOf(req.Body())) - } - - responseValue := reflect.ValueOf(r.Response).Call(request) - response = responseValue[0].Interface() - if len(responseValue) == 2 { - // make it possible to return error in response function - respErr, ok := responseValue[1].Interface().(error) - if ok && respErr != nil { - return respErr - } - } - } - - v.Set(reflect.ValueOf(response)) - - return nil - } - - return fmt.Errorf("rpc: can't find service %s", req.Endpoint()) -} - -func (m *MockClient) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) { - m.Lock() - defer m.Unlock() - - // TODO: mock stream - return nil, nil -} - -func (m *MockClient) Publish(ctx context.Context, p client.Message, opts ...client.PublishOption) error { - return nil -} - -func (m *MockClient) String() string { - return "mock" -} - -func NewClient(opts ...client.Option) *MockClient { - options := client.Options{ - Context: context.TODO(), - } - - for _, opt := range opts { - opt(&options) - } - - r, ok := fromContext(options.Context) - if !ok { - r = make(map[string][]MockResponse) - } - - return &MockClient{ - Client: client.DefaultClient, - Opts: options, - Response: r, - } -} diff --git a/client/mock/mock_test.go b/client/mock/mock_test.go deleted file mode 100644 index 0730610f..00000000 --- a/client/mock/mock_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package mock - -import ( - "context" - "fmt" - "testing" - - "github.com/micro/go-micro/errors" -) - -func TestClient(t *testing.T) { - type TestResponse struct { - Param string - } - - response := []MockResponse{ - {Endpoint: "Foo.Bar", Response: map[string]interface{}{"foo": "bar"}}, - {Endpoint: "Foo.Struct", Response: &TestResponse{Param: "aparam"}}, - {Endpoint: "Foo.Fail", Error: errors.InternalServerError("go.mock", "failed")}, - {Endpoint: "Foo.Func", Response: func() string { return "string" }}, - {Endpoint: "Foo.FuncStruct", Response: func() *TestResponse { return &TestResponse{Param: "aparam"} }}, - {Endpoint: "Foo.FuncWithReqBody", Response: func(req interface{}) string { - if req.(map[string]string)["foo"] == "bar" { - return "string" - } - return "wrong" - }}, - {Endpoint: "Foo.FuncWithRequestContextAndResponse", Response: func(ctx context.Context, req interface{}) string { - return "something" - }}, - {Endpoint: "Foo.FuncWithRequestContextAndResponseError", Response: func(ctx context.Context, req interface{}) (string, error) { - return "something", fmt.Errorf("mock error") - }}, - } - - c := NewClient(Response("go.mock", response)) - - for _, r := range response { - req := c.NewRequest("go.mock", r.Endpoint, map[string]string{"foo": "bar"}) - var rsp interface{} - - err := c.Call(context.TODO(), req, &rsp) - - if err != r.Error { - if r.Endpoint != "Foo.FuncWithRequestContextAndResponseError" { - t.Fatalf("Expecter error %v got %v", r.Error, err) - } - } - - t.Log(rsp) - if r.Endpoint == "Foo.FuncWithReqBody" { - req := c.NewRequest("go.mock", r.Endpoint, map[string]string{"foo": "wrong"}) - var rsp interface{} - - err := c.Call(context.TODO(), req, &rsp) - - if err != r.Error { - t.Fatalf("Expecter error %v got %v", r.Error, err) - } - if rsp.(string) != "wrong" { - t.Fatalf("Expecter response 'wrong' got %v", rsp) - } - t.Log(rsp) - } - } - -} diff --git a/client/mock/options.go b/client/mock/options.go deleted file mode 100644 index 9011cd16..00000000 --- a/client/mock/options.go +++ /dev/null @@ -1,17 +0,0 @@ -package mock - -import ( - "github.com/micro/go-micro/client" -) - -// Response sets the response methods for a service -func Response(service string, response []MockResponse) client.Option { - return func(o *client.Options) { - r, ok := fromContext(o.Context) - if !ok { - r = make(map[string][]MockResponse) - } - r[service] = response - o.Context = newContext(o.Context, r) - } -} From fac75866d947d3b0158607e26fcda1986ca23f8c Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 17:30:49 +0000 Subject: [PATCH 179/788] Move pool to util --- client/rpc_client.go | 2 +- {client => util}/pool/default.go | 0 {client => util}/pool/default_test.go | 0 {client => util}/pool/options.go | 0 {client => util}/pool/pool.go | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename {client => util}/pool/default.go (100%) rename {client => util}/pool/default_test.go (100%) rename {client => util}/pool/options.go (100%) rename {client => util}/pool/pool.go (100%) diff --git a/client/rpc_client.go b/client/rpc_client.go index 34590f26..d8f24f1c 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -10,7 +10,7 @@ import ( "github.com/google/uuid" "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/client/pool" + "github.com/micro/go-micro/util/pool" "github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/codec" raw "github.com/micro/go-micro/codec/bytes" diff --git a/client/pool/default.go b/util/pool/default.go similarity index 100% rename from client/pool/default.go rename to util/pool/default.go diff --git a/client/pool/default_test.go b/util/pool/default_test.go similarity index 100% rename from client/pool/default_test.go rename to util/pool/default_test.go diff --git a/client/pool/options.go b/util/pool/options.go similarity index 100% rename from client/pool/options.go rename to util/pool/options.go diff --git a/client/pool/pool.go b/util/pool/pool.go similarity index 100% rename from client/pool/pool.go rename to util/pool/pool.go From 54fb61bba42dcad466ae3d4cf5547db847070e82 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 17:31:24 +0000 Subject: [PATCH 180/788] Move proto to service/ --- client/{ => service}/proto/client.pb.go | 0 client/{ => service}/proto/client.pb.micro.go | 0 client/{ => service}/proto/client.proto | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename client/{ => service}/proto/client.pb.go (100%) rename client/{ => service}/proto/client.pb.micro.go (100%) rename client/{ => service}/proto/client.proto (100%) diff --git a/client/proto/client.pb.go b/client/service/proto/client.pb.go similarity index 100% rename from client/proto/client.pb.go rename to client/service/proto/client.pb.go diff --git a/client/proto/client.pb.micro.go b/client/service/proto/client.pb.micro.go similarity index 100% rename from client/proto/client.pb.micro.go rename to client/service/proto/client.pb.micro.go diff --git a/client/proto/client.proto b/client/service/proto/client.proto similarity index 100% rename from client/proto/client.proto rename to client/service/proto/client.proto From d9186943467032dcaca5e3d8b0eb0041b820eed1 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 17:47:27 +0000 Subject: [PATCH 181/788] reorganise runtime --- runtime/{ => local}/build/build.go | 2 +- runtime/{ => local}/build/docker/docker.go | 2 +- runtime/{ => local}/build/go/golang.go | 2 +- runtime/{ => local}/build/options.go | 0 runtime/{ => local}/process/options.go | 0 runtime/{ => local}/process/os/os.go | 2 +- runtime/{ => local}/process/os/os_windows.go | 0 runtime/{ => local}/process/os/process.go | 2 +- runtime/{ => local}/process/process.go | 2 +- runtime/{ => local}/source/git/git.go | 2 +- runtime/{ => local}/source/go/golang.go | 2 +- runtime/{ => local}/source/options.go | 0 runtime/{ => local}/source/source.go | 0 runtime/service.go | 7 +++---- 14 files changed, 11 insertions(+), 12 deletions(-) rename runtime/{ => local}/build/build.go (92%) rename runtime/{ => local}/build/docker/docker.go (97%) rename runtime/{ => local}/build/go/golang.go (96%) rename runtime/{ => local}/build/options.go (100%) rename runtime/{ => local}/process/options.go (100%) rename runtime/{ => local}/process/os/os.go (96%) rename runtime/{ => local}/process/os/os_windows.go (100%) rename runtime/{ => local}/process/os/process.go (76%) rename runtime/{ => local}/process/process.go (93%) rename runtime/{ => local}/source/git/git.go (96%) rename runtime/{ => local}/source/go/golang.go (96%) rename runtime/{ => local}/source/options.go (100%) rename runtime/{ => local}/source/source.go (100%) diff --git a/runtime/build/build.go b/runtime/local/build/build.go similarity index 92% rename from runtime/build/build.go rename to runtime/local/build/build.go index 41a4beeb..a179ec0e 100644 --- a/runtime/build/build.go +++ b/runtime/local/build/build.go @@ -2,7 +2,7 @@ package build import ( - "github.com/micro/go-micro/runtime/source" + "github.com/micro/go-micro/runtime/local/source" ) // Builder builds binaries diff --git a/runtime/build/docker/docker.go b/runtime/local/build/docker/docker.go similarity index 97% rename from runtime/build/docker/docker.go rename to runtime/local/build/docker/docker.go index d71c53ef..84b163d4 100644 --- a/runtime/build/docker/docker.go +++ b/runtime/local/build/docker/docker.go @@ -9,7 +9,7 @@ import ( "path/filepath" docker "github.com/fsouza/go-dockerclient" - "github.com/micro/go-micro/runtime/build" + "github.com/micro/go-micro/runtime/local/build" "github.com/micro/go-micro/util/log" ) diff --git a/runtime/build/go/golang.go b/runtime/local/build/go/golang.go similarity index 96% rename from runtime/build/go/golang.go rename to runtime/local/build/go/golang.go index 435da0b5..c11430c0 100644 --- a/runtime/build/go/golang.go +++ b/runtime/local/build/go/golang.go @@ -6,7 +6,7 @@ import ( "os/exec" "path/filepath" - "github.com/micro/go-micro/runtime/build" + "github.com/micro/go-micro/runtime/local/build" ) type Builder struct { diff --git a/runtime/build/options.go b/runtime/local/build/options.go similarity index 100% rename from runtime/build/options.go rename to runtime/local/build/options.go diff --git a/runtime/process/options.go b/runtime/local/process/options.go similarity index 100% rename from runtime/process/options.go rename to runtime/local/process/options.go diff --git a/runtime/process/os/os.go b/runtime/local/process/os/os.go similarity index 96% rename from runtime/process/os/os.go rename to runtime/local/process/os/os.go index dda05ab9..1fb9f231 100644 --- a/runtime/process/os/os.go +++ b/runtime/local/process/os/os.go @@ -10,7 +10,7 @@ import ( "strconv" "syscall" - "github.com/micro/go-micro/runtime/process" + "github.com/micro/go-micro/runtime/local/process" ) func (p *Process) Exec(exe *process.Executable) error { diff --git a/runtime/process/os/os_windows.go b/runtime/local/process/os/os_windows.go similarity index 100% rename from runtime/process/os/os_windows.go rename to runtime/local/process/os/os_windows.go diff --git a/runtime/process/os/process.go b/runtime/local/process/os/process.go similarity index 76% rename from runtime/process/os/process.go rename to runtime/local/process/os/process.go index e756a84c..71f85a2c 100644 --- a/runtime/process/os/process.go +++ b/runtime/local/process/os/process.go @@ -2,7 +2,7 @@ package os import ( - "github.com/micro/go-micro/runtime/process" + "github.com/micro/go-micro/runtime/local/process" ) type Process struct{} diff --git a/runtime/process/process.go b/runtime/local/process/process.go similarity index 93% rename from runtime/process/process.go rename to runtime/local/process/process.go index 8ab78483..8d2bdf7e 100644 --- a/runtime/process/process.go +++ b/runtime/local/process/process.go @@ -4,7 +4,7 @@ package process import ( "io" - "github.com/micro/go-micro/runtime/build" + "github.com/micro/go-micro/runtime/local/build" ) // Process manages a running process diff --git a/runtime/source/git/git.go b/runtime/local/source/git/git.go similarity index 96% rename from runtime/source/git/git.go rename to runtime/local/source/git/git.go index deaaa7ef..516e8857 100644 --- a/runtime/source/git/git.go +++ b/runtime/local/source/git/git.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "github.com/micro/go-micro/runtime/source" + "github.com/micro/go-micro/runtime/local/source" git "gopkg.in/src-d/go-git.v4" ) diff --git a/runtime/source/go/golang.go b/runtime/local/source/go/golang.go similarity index 96% rename from runtime/source/go/golang.go rename to runtime/local/source/go/golang.go index 6265cfc1..95abdc60 100644 --- a/runtime/source/go/golang.go +++ b/runtime/local/source/go/golang.go @@ -7,7 +7,7 @@ import ( "path/filepath" "strings" - "github.com/micro/go-micro/runtime/source" + "github.com/micro/go-micro/runtime/local/source" ) type Source struct { diff --git a/runtime/source/options.go b/runtime/local/source/options.go similarity index 100% rename from runtime/source/options.go rename to runtime/local/source/options.go diff --git a/runtime/source/source.go b/runtime/local/source/source.go similarity index 100% rename from runtime/source/source.go rename to runtime/local/source/source.go diff --git a/runtime/service.go b/runtime/service.go index c2b89394..efd499a3 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -5,10 +5,9 @@ import ( "sync" "time" - "github.com/micro/go-micro/runtime/build" - - "github.com/micro/go-micro/runtime/process" - proc "github.com/micro/go-micro/runtime/process/os" + "github.com/micro/go-micro/runtime/local/build" + "github.com/micro/go-micro/runtime/local/process" + proc "github.com/micro/go-micro/runtime/local/process/os" "github.com/micro/go-micro/util/log" ) From 3f3c1919f479e4d41291dac02fa0930d2e5a14d7 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 17:56:59 +0000 Subject: [PATCH 182/788] strip certain plugins --- config/cmd/cmd.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index dfea3e59..ad3fa35a 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -47,12 +47,7 @@ import ( thttp "github.com/micro/go-micro/transport/http" tmem "github.com/micro/go-micro/transport/memory" - // runtimes - "github.com/micro/go-micro/runtime/kubernetes" - // stores - cfStore "github.com/micro/go-micro/store/cloudflare" - ckStore "github.com/micro/go-micro/store/cockroach" memStore "github.com/micro/go-micro/store/memory" svcStore "github.com/micro/go-micro/store/service" ) @@ -252,13 +247,10 @@ var ( DefaultRuntimes = map[string]func(...runtime.Option) runtime.Runtime{ "local": runtime.NewRuntime, - "kubernetes": kubernetes.NewRuntime, } DefaultStores = map[string]func(...store.Option) store.Store{ "memory": memStore.NewStore, - "cockroach": ckStore.NewStore, - "cloudflare": cfStore.NewStore, "service": svcStore.NewStore, } From 9df19e826ef83ab1ef4b7030db7ee261b10fa4d7 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 22:53:56 +0000 Subject: [PATCH 183/788] cancel stream --- client/grpc/grpc.go | 6 +++++- client/grpc/stream.go | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index f00a12b0..1d4eea04 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -212,7 +212,10 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client grpcCallOptions = append(grpcCallOptions, opts...) } - st, err := cc.NewStream(ctx, desc, methodToGRPC(req.Service(), req.Endpoint()), grpcCallOptions...) + // create a new cancelling context + newCtx, cancel := context.WithCancel(ctx) + + st, err := cc.NewStream(newCtx, desc, methodToGRPC(req.Service(), req.Endpoint()), grpcCallOptions...) if err != nil { return nil, errors.InternalServerError("go.micro.client", fmt.Sprintf("Error creating stream: %v", err)) } @@ -240,6 +243,7 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client response: rsp, stream: st, conn: cc, + cancel: cancel, }, nil } diff --git a/client/grpc/stream.go b/client/grpc/stream.go index ea9da43f..e5ebd156 100644 --- a/client/grpc/stream.go +++ b/client/grpc/stream.go @@ -19,6 +19,7 @@ type grpcStream struct { request client.Request response client.Response context context.Context + cancel func() } func (g *grpcStream) Context() context.Context { @@ -79,7 +80,8 @@ func (g *grpcStream) Close() error { if g.closed { return nil } - + // cancel the context + g.cancel() g.closed = true g.stream.CloseSend() return g.conn.Close() From 04cf86070c6b7d183d8cdd478b1dc01efa820fe1 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 22:55:57 +0000 Subject: [PATCH 184/788] close stream --- router/service/watcher.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/router/service/watcher.go b/router/service/watcher.go index 663d0fce..2e1f52b4 100644 --- a/router/service/watcher.go +++ b/router/service/watcher.go @@ -42,8 +42,6 @@ func newWatcher(rsp pb.Router_WatchService, opts router.WatchOptions) (*watcher, // watchRouter watches router and send events to all registered watchers func (w *watcher) watch(stream pb.Router_WatchService) error { - defer stream.Close() - var watchErr error for { @@ -110,6 +108,7 @@ func (w *watcher) Stop() { case <-w.done: return default: + w.stream.Close() close(w.done) } } From 97928e88f83fb36698eddc76da765bf59149383d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 23:15:57 +0000 Subject: [PATCH 185/788] stop watcher --- proxy/mucp/mucp.go | 1 + 1 file changed, 1 insertion(+) diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index f8baaf91..54041bfd 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -281,6 +281,7 @@ func (p *Proxy) watchRoutes() { if err != nil { return } + defer w.Stop() for { event, err := w.Next() From ed2bd68d2852167737a3fdf51b15b13bfee807de Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 23:22:41 +0000 Subject: [PATCH 186/788] fix break in router service --- router/service/watcher.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/router/service/watcher.go b/router/service/watcher.go index 2e1f52b4..38780f0e 100644 --- a/router/service/watcher.go +++ b/router/service/watcher.go @@ -14,6 +14,7 @@ type watcher struct { opts router.WatchOptions resChan chan *router.Event done chan struct{} + stream pb.Router_WatchService } func newWatcher(rsp pb.Router_WatchService, opts router.WatchOptions) (*watcher, error) { @@ -21,6 +22,7 @@ func newWatcher(rsp pb.Router_WatchService, opts router.WatchOptions) (*watcher, opts: opts, resChan: make(chan *router.Event), done: make(chan struct{}), + stream: rsp, } go func() { From fa0d884cfe276da7526bd70e80a56c505c49bf7b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 23:31:09 +0000 Subject: [PATCH 187/788] fix bad import --- runtime/local/process/os/os_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/local/process/os/os_windows.go b/runtime/local/process/os/os_windows.go index d4420968..38ff70a5 100644 --- a/runtime/local/process/os/os_windows.go +++ b/runtime/local/process/os/os_windows.go @@ -7,7 +7,7 @@ import ( "os/exec" "strconv" - "github.com/micro/go-micro/runtime/process" + "github.com/micro/go-micro/runtime/local/process" ) func (p *Process) Exec(exe *process.Executable) error { From 94bb0f4c085f89a2609f31b48c8ef445fe9b7a20 Mon Sep 17 00:00:00 2001 From: shu xian Date: Mon, 20 Jan 2020 18:31:18 +0800 Subject: [PATCH 188/788] watch supports path --- config/source/service/options.go | 24 ++++++- .../{service.pb.micro.go => service.micro.go} | 0 config/source/service/proto/service.pb.go | 64 +++++++++++-------- config/source/service/proto/service.proto | 1 + config/source/service/service.go | 21 +++++- 5 files changed, 78 insertions(+), 32 deletions(-) rename config/source/service/proto/{service.pb.micro.go => service.micro.go} (100%) diff --git a/config/source/service/options.go b/config/source/service/options.go index ac4079e9..1075a4ac 100644 --- a/config/source/service/options.go +++ b/config/source/service/options.go @@ -7,12 +7,32 @@ import ( ) type serviceNameKey struct{} +type keyKey struct{} +type pathKey struct{} -func ServiceName(a string) source.Option { +func ServiceName(name string) source.Option { return func(o *source.Options) { if o.Context == nil { o.Context = context.Background() } - o.Context = context.WithValue(o.Context, serviceNameKey{}, a) + o.Context = context.WithValue(o.Context, serviceNameKey{}, name) + } +} + +func Key(key string) source.Option { + return func(o *source.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, keyKey{}, key) + } +} + +func Path(path string) source.Option { + return func(o *source.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, pathKey{}, path) } } diff --git a/config/source/service/proto/service.pb.micro.go b/config/source/service/proto/service.micro.go similarity index 100% rename from config/source/service/proto/service.pb.micro.go rename to config/source/service/proto/service.micro.go diff --git a/config/source/service/proto/service.pb.go b/config/source/service/proto/service.pb.go index 85ba138f..667d3c76 100644 --- a/config/source/service/proto/service.pb.go +++ b/config/source/service/proto/service.pb.go @@ -514,6 +514,7 @@ func (m *ReadResponse) GetChange() *Change { type WatchRequest struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -551,6 +552,13 @@ func (m *WatchRequest) GetKey() string { return "" } +func (m *WatchRequest) GetPath() string { + if m != nil { + return m.Path + } + return "" +} + type WatchResponse struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` ChangeSet *ChangeSet `protobuf:"bytes,2,opt,name=changeSet,proto3" json:"changeSet,omitempty"` @@ -618,32 +626,32 @@ func init() { func init() { proto.RegisterFile("proto/service.proto", fileDescriptor_c33392ef2c1961ba) } var fileDescriptor_c33392ef2c1961ba = []byte{ - // 425 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xdb, 0x6a, 0xdb, 0x40, - 0x10, 0x86, 0x2d, 0xdb, 0x51, 0xaa, 0xb1, 0x24, 0x87, 0x29, 0x14, 0x21, 0x0a, 0x15, 0x0b, 0x05, - 0xd3, 0xc2, 0x26, 0x38, 0x8f, 0x90, 0xde, 0xb5, 0x57, 0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x76, 0x11, 0x7c, 0x0b, 0xed, 0xa7, 0x7d, 0xf9, 0x37, 0x00, 0x00, 0xff, - 0xff, 0x85, 0xa3, 0x8e, 0x20, 0xf1, 0x03, 0x00, 0x00, + // 427 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xcf, 0x6a, 0xdb, 0x40, + 0x10, 0xc6, 0x2d, 0xdb, 0x51, 0xaa, 0xb1, 0x24, 0x87, 0x29, 0x14, 0x21, 0x0a, 0x35, 0x0b, 0x05, + 0xd3, 0xc2, 0x26, 0x38, 0x7d, 0x83, 0xf4, 0xd6, 0x9e, 0x36, 0x94, 0xf6, 0xba, 0x95, 0xa7, 0xb5, + 0x49, 0x14, 0xa9, 0xda, 0x55, 0xa0, 0x8f, 0xd0, 0x3e, 0x75, 0xd9, 0x3f, 0x8a, 0x24, 0x17, 0x4c, + 0x7c, 0xdb, 0x99, 0xd9, 0xf9, 0xe6, 0xd3, 0xfc, 0x56, 0xf0, 0xb2, 0x6e, 0x2a, 0x5d, 0x5d, 0x2a, + 0x6a, 0x1e, 0xf7, 0x05, 0x71, 0x1b, 0xb1, 0x3f, 0x01, 0x44, 0x37, 0x3b, 0xf9, 0xf0, 0x93, 0x6e, + 0x49, 0x23, 0xc2, 0x7c, 0x2b, 0xb5, 0xcc, 0x82, 0x55, 0xb0, 0x8e, 0x85, 0x3d, 0x63, 0x0e, 0x2f, + 0x8a, 0x1d, 0x15, 0x77, 0xaa, 0x2d, 0xb3, 0xe9, 0x2a, 0x58, 0x47, 0xe2, 0x29, 0xc6, 0x57, 0x10, + 0xfe, 0xa8, 0x9a, 0x52, 0xea, 0x6c, 0x66, 0x2b, 0x3e, 0x32, 0x79, 0x55, 0xb5, 0x4d, 0x41, 0xd9, + 0xdc, 0xe5, 0x5d, 0x84, 0xaf, 0x21, 0xd2, 0xfb, 0x92, 0x94, 0x96, 0x65, 0x9d, 0x9d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0x98, 0xcb, 0x8e, 0x1b, 0xa6, 0x7c, 0x84, 0x3c, 0x5f, 0xf2, 0x03, 0xa0, + 0xf6, 0xb2, 0x03, 0x84, 0x29, 0x1f, 0xb1, 0xcd, 0x97, 0xfc, 0x80, 0xdc, 0x04, 0xdf, 0xc2, 0xdc, + 0xc0, 0xc2, 0x98, 0x0f, 0x10, 0xe6, 0x09, 0x1f, 0x12, 0x74, 0xd7, 0xcc, 0xb6, 0x31, 0xe6, 0x03, + 0x52, 0x79, 0xc2, 0x87, 0x08, 0xd8, 0x04, 0xdf, 0xc1, 0x99, 0xdd, 0x16, 0x26, 0x7c, 0xb8, 0xeb, + 0x3c, 0xe5, 0xa3, 0x25, 0xb2, 0xc9, 0x55, 0xf0, 0x3d, 0xb4, 0xbf, 0xfb, 0xf5, 0xbf, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xc3, 0x45, 0xac, 0x57, 0x05, 0x04, 0x00, 0x00, } diff --git a/config/source/service/proto/service.proto b/config/source/service/proto/service.proto index bce92dbe..1ffcaec3 100644 --- a/config/source/service/proto/service.proto +++ b/config/source/service/proto/service.proto @@ -58,6 +58,7 @@ message ReadResponse { message WatchRequest { string key = 1; + string path = 2; } message WatchResponse { diff --git a/config/source/service/service.go b/config/source/service/service.go index 9d053126..67cb20e1 100644 --- a/config/source/service/service.go +++ b/config/source/service/service.go @@ -11,18 +11,21 @@ import ( var ( DefaultName = "go.micro.config" + DefaultKey = "NAMESPACE:CONFIG" + DefaultPath = "" DefaultClient = client.DefaultClient ) type service struct { serviceName string key string + path string opts source.Options client proto.Service } func (m *service) Read() (set *source.ChangeSet, err error) { - req, err := m.client.Read(context.Background(), &proto.ReadRequest{Path: m.key}) + req, err := m.client.Read(context.Background(), &proto.ReadRequest{Key: m.key, Path: m.path}) if err != nil { return nil, err } @@ -31,7 +34,7 @@ func (m *service) Read() (set *source.ChangeSet, err error) { } func (m *service) Watch() (w source.Watcher, err error) { - stream, err := m.client.Watch(context.Background(), &proto.WatchRequest{Key: m.key}) + stream, err := m.client.Watch(context.Background(), &proto.WatchRequest{Key: m.key, Path: m.path}) if err != nil { log.Error("watch err: ", err) return @@ -55,17 +58,31 @@ func NewSource(opts ...source.Option) source.Source { } addr := DefaultName + key := DefaultKey + path := DefaultPath if options.Context != nil { a, ok := options.Context.Value(serviceNameKey{}).(string) if ok { addr = a } + + k, ok := options.Context.Value(keyKey{}).(string) + if ok { + key = k + } + + p, ok := options.Context.Value(pathKey{}).(string) + if ok { + path = p + } } s := &service{ serviceName: addr, opts: options, + key: key, + path: path, client: proto.NewService(addr, DefaultClient), } From 7a17a221ff5121d46f60a8efaa3bf21c55b0b7ac Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Mon, 20 Jan 2020 10:09:27 -0800 Subject: [PATCH 189/788] server: remove unused invalidRequest --- server/rpc_router.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server/rpc_router.go b/server/rpc_router.go index b67417bf..70fe1104 100644 --- a/server/rpc_router.go +++ b/server/rpc_router.go @@ -25,10 +25,6 @@ import ( var ( lastStreamResponseError = errors.New("EOS") - // A value sent as a placeholder for the server's response value when the server - // receives an invalid request. It is never decoded by the client since the Response - // contains an error when it is used. - invalidRequest = struct{}{} // Precompute the reflect type for error. Can't use error directly // because Typeof takes an empty interface value. This is annoying. From 9f7d37469198fa0da83a1344bd7bba7cf308dab0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 21 Jan 2020 12:36:05 +0000 Subject: [PATCH 190/788] avoid connecting to self --- network/default.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/network/default.go b/network/default.go index f52ba563..77b31f32 100644 --- a/network/default.go +++ b/network/default.go @@ -382,8 +382,23 @@ func (n *network) initNodes(startup bool) { return } + // strip self + var init []string + + // our current address + advertised := n.server.Options().Advertise + + for _, node := range nodes { + // skip self + if node == advertised { + continue + } + // add the node + init = append(init, node) + } + // initialize the tunnel - log.Tracef("Network initialising nodes %+v\n", nodes) + log.Tracef("Network initialising nodes %+v\n", init) n.tunnel.Init( tunnel.Nodes(nodes...), From 29c1076950f777d890625f2c6c88c21d5ce25c5f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 22 Jan 2020 16:33:31 +0000 Subject: [PATCH 191/788] refactor and cleanup some router code --- router/default.go | 389 +++++++++--------------- router/default_test.go | 1 - router/router.go | 30 -- router/service/proto/router.pb.go | 221 ++++---------- router/service/proto/router.pb.micro.go | 19 +- router/service/proto/router.proto | 10 - router/service/service.go | 85 +----- 7 files changed, 219 insertions(+), 536 deletions(-) diff --git a/router/default.go b/router/default.go index 07bddc0d..f699651c 100644 --- a/router/default.go +++ b/router/default.go @@ -1,6 +1,7 @@ package router import ( + "errors" "fmt" "math" "sort" @@ -16,8 +17,6 @@ import ( var ( // AdvertiseEventsTick is time interval in which the router advertises route updates AdvertiseEventsTick = 10 * time.Second - // AdvertiseTableTick is time interval in which router advertises all routes found in routing table - AdvertiseTableTick = 2 * time.Minute // DefaultAdvertTTL is default advertisement TTL DefaultAdvertTTL = 2 * time.Minute // AdvertSuppress is advert suppression threshold @@ -37,14 +36,12 @@ var ( // router implements default router type router struct { sync.RWMutex - options Options - status Status + + running bool table *table - exit chan struct{} - errChan chan error + options Options + exit chan bool eventChan chan *Event - advertWg *sync.WaitGroup - wg *sync.WaitGroup // advert subscribers sub sync.RWMutex @@ -61,15 +58,9 @@ func newRouter(opts ...Option) Router { o(&options) } - // set initial status to Stopped - status := Status{Code: Stopped, Error: nil} - return &router{ options: options, - status: status, table: newTable(), - advertWg: &sync.WaitGroup{}, - wg: &sync.WaitGroup{}, subscribers: make(map[string]chan *Advert), } } @@ -125,7 +116,7 @@ func (r *router) manageRoute(route Route, action string) error { // manageServiceRoutes applies action to all routes of the service. // It returns error of the action fails with error. -func (r *router) manageServiceRoutes(service *registry.Service, action string) error { +func (r *router) manageRoutes(service *registry.Service, action string) error { // action is the routing table action action = strings.ToLower(action) @@ -166,7 +157,7 @@ func (r *router) manageRegistryRoutes(reg registry.Registry, action string) erro } // manage the routes for all returned services for _, srv := range srvs { - if err := r.manageServiceRoutes(srv, action); err != nil { + if err := r.manageRoutes(srv, action); err != nil { return err } } @@ -181,42 +172,35 @@ func (r *router) watchRegistry(w registry.Watcher) error { exit := make(chan bool) defer func() { - // close the exit channel when the go routine finishes close(exit) }() - // wait in the background for the router to stop - // when the router stops, stop the watcher and exit - r.wg.Add(1) go func() { defer w.Stop() - defer r.wg.Done() select { - case <-r.exit: - return case <-exit: return + case <-r.exit: + return } }() - var watchErr error - for { res, err := w.Next() if err != nil { if err != registry.ErrWatcherStopped { - watchErr = err + return err } break } - if err := r.manageServiceRoutes(res.Service, res.Action); err != nil { + if err := r.manageRoutes(res.Service, res.Action); err != nil { return err } } - return watchErr + return nil } // watchTable watches routing table entries and either adds or deletes locally registered service to/from network registry @@ -225,16 +209,13 @@ func (r *router) watchTable(w Watcher) error { exit := make(chan bool) defer func() { - // close the exit channel when the go routine finishes close(exit) }() // wait in the background for the router to stop // when the router stops, stop the watcher and exit - r.wg.Add(1) go func() { defer w.Stop() - defer r.wg.Done() select { case <-r.exit: @@ -244,13 +225,11 @@ func (r *router) watchTable(w Watcher) error { } }() - var watchErr error - for { event, err := w.Next() if err != nil { if err != ErrWatcherStopped { - watchErr = err + return err } break } @@ -260,13 +239,11 @@ func (r *router) watchTable(w Watcher) error { close(r.eventChan) return nil case r.eventChan <- event: + // process event } } - // close event channel on error - close(r.eventChan) - - return watchErr + return nil } // publishAdvert publishes router advert to advert channel @@ -292,36 +269,6 @@ func (r *router) publishAdvert(advType AdvertType, events []*Event) { r.sub.RUnlock() } -// advertiseTable advertises the whole routing table to the network -func (r *router) advertiseTable() error { - // create table advertisement ticker - ticker := time.NewTicker(AdvertiseTableTick) - defer ticker.Stop() - - for { - select { - case <-ticker.C: - // do full table flush - events, err := r.flushRouteEvents(Update) - if err != nil { - return fmt.Errorf("failed flushing routes: %s", err) - } - - // advertise routes to subscribers - if len(events) > 0 { - log.Debugf("Router flushing table with %d events: %s", len(events), r.options.Id) - r.advertWg.Add(1) - go func() { - defer r.advertWg.Done() - r.publishAdvert(RouteUpdate, events) - }() - } - case <-r.exit: - return nil - } - } -} - // advert contains a route event to be advertised type advert struct { // event received from routing table @@ -392,17 +339,39 @@ func (r *router) advertiseEvents() error { adverts := make(adverts) // routing table watcher - tableWatcher, err := r.Watch() + w, err := r.Watch() if err != nil { - return fmt.Errorf("failed creating routing table watcher: %v", err) + return err } + defer w.Stop() - r.wg.Add(1) go func() { - defer r.wg.Done() - select { - case r.errChan <- r.watchTable(tableWatcher): - case <-r.exit: + var err error + + for { + select { + case <-r.exit: + return + default: + if w == nil { + // routing table watcher + w, err = r.Watch() + if err != nil { + log.Logf("Error creating watcher: %v", err) + time.Sleep(time.Second) + continue + } + } + + if err := r.watchTable(w); err != nil { + log.Logf("Error watching table: %v", err) + time.Sleep(time.Second) + } + + // reset + w.Stop() + w = nil + } } }() @@ -446,11 +415,7 @@ func (r *router) advertiseEvents() error { // advertise events to subscribers if len(events) > 0 { log.Debugf("Router publishing %d events", len(events)) - r.advertWg.Add(1) - go func() { - defer r.advertWg.Done() - r.publishAdvert(RouteUpdate, events) - }() + go r.publishAdvert(RouteUpdate, events) } case e := <-r.eventChan: // if event is nil, continue @@ -502,65 +467,19 @@ func (r *router) advertiseEvents() error { a.penalty += Penalty log.Debugf("Router advert %d for route %s %s event penalty: %f", hash, a.event.Route.Service, a.event.Route.Address, a.penalty) case <-r.exit: - // first wait for the advertiser to finish - r.advertWg.Wait() + w.Stop() return nil } } } -// close closes exit channels -func (r *router) close() { - log.Debugf("Router closing remaining channels") - // drain the advertise channel only if advertising - if r.status.Code == Advertising { - // drain the event channel - for range r.eventChan { - } - - // close advert subscribers - for id, sub := range r.subscribers { - select { - case <-sub: - default: - } - - // close the channel - close(sub) - - // delete the subscriber - r.sub.Lock() - delete(r.subscribers, id) - r.sub.Unlock() - } - } - - // mark the router as Stopped and set its Error to nil - r.status = Status{Code: Stopped, Error: nil} -} - -// watchErrors watches router errors and takes appropriate actions -func (r *router) watchErrors() { - var err error - - select { - case <-r.exit: - return - case err = <-r.errChan: - } - - r.Lock() - defer r.Unlock() - // if the router is not stopped, stop it - if r.status.Code != Stopped { - // notify all goroutines to finish - close(r.exit) - - // close all the channels - r.close() - // set the status error - if err != nil { - r.status.Error = err +// drain all the events, only called on Stop +func (r *router) drain() { + for { + select { + case <-r.eventChan: + default: + return } } } @@ -570,16 +489,13 @@ func (r *router) Start() error { r.Lock() defer r.Unlock() - // only start if we're stopped - if r.status.Code != Stopped { + if r.running { return nil } // add all local service routes into the routing table if err := r.manageRegistryRoutes(r.options.Registry, "create"); err != nil { - e := fmt.Errorf("failed adding registry routes: %s", err) - r.status = Status{Code: Error, Error: e} - return e + return fmt.Errorf("failed adding registry routes: %s", err) } // add default gateway into routing table @@ -595,42 +511,49 @@ func (r *router) Start() error { Metric: DefaultLocalMetric, } if err := r.table.Create(route); err != nil { - e := fmt.Errorf("failed adding default gateway route: %s", err) - r.status = Status{Code: Error, Error: e} - return e + return fmt.Errorf("failed adding default gateway route: %s", err) } } // create error and exit channels - r.errChan = make(chan error, 1) - r.exit = make(chan struct{}) + r.exit = make(chan bool) // registry watcher - regWatcher, err := r.options.Registry.Watch() + w, err := r.options.Registry.Watch() if err != nil { - e := fmt.Errorf("failed creating registry watcher: %v", err) - r.status = Status{Code: Error, Error: e} - return e + return fmt.Errorf("failed creating registry watcher: %v", err) } - r.wg.Add(1) go func() { - defer r.wg.Done() - select { - case r.errChan <- r.watchRegistry(regWatcher): - case <-r.exit: + var err error + + for { + select { + case <-r.exit: + w.Stop() + return + default: + if w == nil { + w, err = r.options.Registry.Watch() + if err != nil { + log.Logf("failed creating registry watcher: %v", err) + time.Sleep(time.Second) + continue + } + } + + if err := r.watchRegistry(w); err != nil { + log.Logf("Error watching the registry: %v", err) + time.Sleep(time.Second) + } + + w.Stop() + w = nil + } } }() - // watch for errors and cleanup - r.wg.Add(1) - go func() { - defer r.wg.Done() - r.watchErrors() - }() - - // mark router as Running - r.status = Status{Code: Running, Error: nil} + r.running = true return nil } @@ -642,61 +565,46 @@ func (r *router) Advertise() (<-chan *Advert, error) { r.Lock() defer r.Unlock() - switch r.status.Code { - case Advertising: - advertChan := make(chan *Advert, 128) - r.subscribers[uuid.New().String()] = advertChan - return advertChan, nil - case Running: - // list all the routes and pack them into even slice to advertise - events, err := r.flushRouteEvents(Create) - if err != nil { - return nil, fmt.Errorf("failed to flush routes: %s", err) - } - - // create event channels - r.eventChan = make(chan *Event) - - // create advert channel - advertChan := make(chan *Advert, 128) - r.subscribers[uuid.New().String()] = advertChan - - // advertise your presence - r.advertWg.Add(1) - go func() { - defer r.advertWg.Done() - r.publishAdvert(Announce, events) - }() - - r.wg.Add(1) - go func() { - defer r.wg.Done() - select { - case r.errChan <- r.advertiseEvents(): - case <-r.exit: - } - }() - - r.advertWg.Add(1) - go func() { - defer r.advertWg.Done() - // advertise the whole routing table - select { - case r.errChan <- r.advertiseTable(): - case <-r.exit: - } - }() - - // mark router as Running and set its Error to nil - r.status = Status{Code: Advertising, Error: nil} - - log.Debugf("Router starting to advertise") - return advertChan, nil - case Stopped: - return nil, fmt.Errorf("not running") + if !r.running { + return nil, errors.New("not running") } - return nil, fmt.Errorf("error: %s", r.status.Error) + // already advertising + if r.eventChan != nil { + advertChan := make(chan *Advert, 128) + r.subscribers[uuid.New().String()] = advertChan + return advertChan, nil + } + + // list all the routes and pack them into even slice to advertise + events, err := r.flushRouteEvents(Create) + if err != nil { + return nil, fmt.Errorf("failed to flush routes: %s", err) + } + + // create event channels + r.eventChan = make(chan *Event) + + // create advert channel + advertChan := make(chan *Advert, 128) + r.subscribers[uuid.New().String()] = advertChan + + // advertise your presence + go r.publishAdvert(Announce, events) + + go func() { + select { + case <-r.exit: + return + default: + if err := r.advertiseEvents(); err != nil { + log.Logf("Error adveritising events: %v", err) + } + } + }() + + return advertChan, nil + } // Process updates the routing table using the advertised values @@ -774,48 +682,39 @@ func (r *router) Watch(opts ...WatchOption) (Watcher, error) { return r.table.Watch(opts...) } -// Status returns router status -func (r *router) Status() Status { - r.RLock() - defer r.RUnlock() - - // make a copy of the status - status := r.status - - return status -} - // Stop stops the router func (r *router) Stop() error { r.Lock() + defer r.Unlock() - log.Debugf("Router shutting down") - - switch r.status.Code { - case Stopped, Error: - r.Unlock() - return r.status.Error - case Running, Advertising: - // notify all goroutines to finish + select { + case <-r.exit: + return nil + default: close(r.exit) - // close all the channels - // NOTE: close marks the router status as Stopped - r.close() + // extract the events + r.drain() + + // close advert subscribers + for id, sub := range r.subscribers { + // close the channel + close(sub) + + // delete the subscriber + r.sub.Lock() + delete(r.subscribers, id) + r.sub.Unlock() + } } - r.Unlock() - log.Tracef("Router waiting for all goroutines to finish") - - // wait for all goroutines to finish - r.wg.Wait() - - log.Debugf("Router successfully stopped") + // remove event chan + r.eventChan = nil return nil } // String prints debugging information about router func (r *router) String() string { - return "memory" + return "registry" } diff --git a/router/default_test.go b/router/default_test.go index 9427ecbc..581ef7ae 100644 --- a/router/default_test.go +++ b/router/default_test.go @@ -38,7 +38,6 @@ func TestRouterAdvertise(t *testing.T) { // lower the advertise interval AdvertiseEventsTick = 500 * time.Millisecond - AdvertiseTableTick = 1 * time.Second if err := r.Start(); err != nil { t.Errorf("failed to start router: %v", err) diff --git a/router/router.go b/router/router.go index b71cbcac..20316477 100644 --- a/router/router.go +++ b/router/router.go @@ -34,8 +34,6 @@ type Router interface { Watch(opts ...WatchOption) (Watcher, error) // Start starts the router Start() error - // Status returns router status - Status() Status // Stop stops the router Stop() error // Returns the router implementation @@ -73,34 +71,6 @@ const ( Error ) -func (s StatusCode) String() string { - switch s { - case Running: - return "running" - case Advertising: - return "advertising" - case Stopped: - return "stopped" - case Error: - return "error" - default: - return "unknown" - } -} - -// Status is router status -type Status struct { - // Code defines router status - Code StatusCode - // Error contains error description - Error error -} - -// String returns human readable status -func (s Status) String() string { - return s.Code.String() -} - // AdvertType is route advertisement type type AdvertType int diff --git a/router/service/proto/router.pb.go b/router/service/proto/router.pb.go index 29904323..c6259a72 100644 --- a/router/service/proto/router.pb.go +++ b/router/service/proto/router.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: router.proto +// source: micro/go-micro/router/service/proto/router.proto package go_micro_router @@ -43,7 +43,7 @@ func (x AdvertType) String() string { } func (AdvertType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{0} + return fileDescriptor_c2b04f200fb3e806, []int{0} } // EventType defines the type of event @@ -72,7 +72,7 @@ func (x EventType) String() string { } func (EventType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{1} + return fileDescriptor_c2b04f200fb3e806, []int{1} } // Empty request @@ -86,7 +86,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{0} + return fileDescriptor_c2b04f200fb3e806, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { @@ -118,7 +118,7 @@ func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{1} + return fileDescriptor_c2b04f200fb3e806, []int{1} } func (m *Response) XXX_Unmarshal(b []byte) error { @@ -151,7 +151,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{2} + return fileDescriptor_c2b04f200fb3e806, []int{2} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -191,7 +191,7 @@ func (m *LookupRequest) Reset() { *m = LookupRequest{} } func (m *LookupRequest) String() string { return proto.CompactTextString(m) } func (*LookupRequest) ProtoMessage() {} func (*LookupRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{3} + return fileDescriptor_c2b04f200fb3e806, []int{3} } func (m *LookupRequest) XXX_Unmarshal(b []byte) error { @@ -231,7 +231,7 @@ func (m *LookupResponse) Reset() { *m = LookupResponse{} } func (m *LookupResponse) String() string { return proto.CompactTextString(m) } func (*LookupResponse) ProtoMessage() {} func (*LookupResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{4} + return fileDescriptor_c2b04f200fb3e806, []int{4} } func (m *LookupResponse) XXX_Unmarshal(b []byte) error { @@ -271,7 +271,7 @@ func (m *QueryRequest) Reset() { *m = QueryRequest{} } func (m *QueryRequest) String() string { return proto.CompactTextString(m) } func (*QueryRequest) ProtoMessage() {} func (*QueryRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{5} + return fileDescriptor_c2b04f200fb3e806, []int{5} } func (m *QueryRequest) XXX_Unmarshal(b []byte) error { @@ -311,7 +311,7 @@ func (m *QueryResponse) Reset() { *m = QueryResponse{} } func (m *QueryResponse) String() string { return proto.CompactTextString(m) } func (*QueryResponse) ProtoMessage() {} func (*QueryResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{6} + return fileDescriptor_c2b04f200fb3e806, []int{6} } func (m *QueryResponse) XXX_Unmarshal(b []byte) error { @@ -350,7 +350,7 @@ func (m *WatchRequest) Reset() { *m = WatchRequest{} } func (m *WatchRequest) String() string { return proto.CompactTextString(m) } func (*WatchRequest) ProtoMessage() {} func (*WatchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{7} + return fileDescriptor_c2b04f200fb3e806, []int{7} } func (m *WatchRequest) XXX_Unmarshal(b []byte) error { @@ -392,7 +392,7 @@ func (m *Advert) Reset() { *m = Advert{} } func (m *Advert) String() string { return proto.CompactTextString(m) } func (*Advert) ProtoMessage() {} func (*Advert) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{8} + return fileDescriptor_c2b04f200fb3e806, []int{8} } func (m *Advert) XXX_Unmarshal(b []byte) error { @@ -459,7 +459,7 @@ func (m *ProcessResponse) Reset() { *m = ProcessResponse{} } func (m *ProcessResponse) String() string { return proto.CompactTextString(m) } func (*ProcessResponse) ProtoMessage() {} func (*ProcessResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{9} + return fileDescriptor_c2b04f200fb3e806, []int{9} } func (m *ProcessResponse) XXX_Unmarshal(b []byte) error { @@ -491,7 +491,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{10} + return fileDescriptor_c2b04f200fb3e806, []int{10} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -523,7 +523,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{11} + return fileDescriptor_c2b04f200fb3e806, []int{11} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -555,7 +555,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{12} + return fileDescriptor_c2b04f200fb3e806, []int{12} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -593,7 +593,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{13} + return fileDescriptor_c2b04f200fb3e806, []int{13} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -652,7 +652,7 @@ func (m *Query) Reset() { *m = Query{} } func (m *Query) String() string { return proto.CompactTextString(m) } func (*Query) ProtoMessage() {} func (*Query) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{14} + return fileDescriptor_c2b04f200fb3e806, []int{14} } func (m *Query) XXX_Unmarshal(b []byte) error { @@ -719,7 +719,7 @@ func (m *Route) Reset() { *m = Route{} } func (m *Route) String() string { return proto.CompactTextString(m) } func (*Route) ProtoMessage() {} func (*Route) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{15} + return fileDescriptor_c2b04f200fb3e806, []int{15} } func (m *Route) XXX_Unmarshal(b []byte) error { @@ -789,92 +789,6 @@ func (m *Route) GetMetric() int64 { return 0 } -type Status struct { - Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` - Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Status) Reset() { *m = Status{} } -func (m *Status) String() string { return proto.CompactTextString(m) } -func (*Status) ProtoMessage() {} -func (*Status) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{16} -} - -func (m *Status) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Status.Unmarshal(m, b) -} -func (m *Status) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Status.Marshal(b, m, deterministic) -} -func (m *Status) XXX_Merge(src proto.Message) { - xxx_messageInfo_Status.Merge(m, src) -} -func (m *Status) XXX_Size() int { - return xxx_messageInfo_Status.Size(m) -} -func (m *Status) XXX_DiscardUnknown() { - xxx_messageInfo_Status.DiscardUnknown(m) -} - -var xxx_messageInfo_Status proto.InternalMessageInfo - -func (m *Status) GetCode() string { - if m != nil { - return m.Code - } - return "" -} - -func (m *Status) GetError() string { - if m != nil { - return m.Error - } - return "" -} - -type StatusResponse struct { - Status *Status `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *StatusResponse) Reset() { *m = StatusResponse{} } -func (m *StatusResponse) String() string { return proto.CompactTextString(m) } -func (*StatusResponse) ProtoMessage() {} -func (*StatusResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_367072455c71aedc, []int{17} -} - -func (m *StatusResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_StatusResponse.Unmarshal(m, b) -} -func (m *StatusResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_StatusResponse.Marshal(b, m, deterministic) -} -func (m *StatusResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_StatusResponse.Merge(m, src) -} -func (m *StatusResponse) XXX_Size() int { - return xxx_messageInfo_StatusResponse.Size(m) -} -func (m *StatusResponse) XXX_DiscardUnknown() { - xxx_messageInfo_StatusResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_StatusResponse proto.InternalMessageInfo - -func (m *StatusResponse) GetStatus() *Status { - if m != nil { - return m.Status - } - return nil -} - func init() { proto.RegisterEnum("go.micro.router.AdvertType", AdvertType_name, AdvertType_value) proto.RegisterEnum("go.micro.router.EventType", EventType_name, EventType_value) @@ -894,56 +808,53 @@ func init() { proto.RegisterType((*Event)(nil), "go.micro.router.Event") proto.RegisterType((*Query)(nil), "go.micro.router.Query") proto.RegisterType((*Route)(nil), "go.micro.router.Route") - proto.RegisterType((*Status)(nil), "go.micro.router.Status") - proto.RegisterType((*StatusResponse)(nil), "go.micro.router.StatusResponse") } -func init() { proto.RegisterFile("router.proto", fileDescriptor_367072455c71aedc) } - -var fileDescriptor_367072455c71aedc = []byte{ - // 693 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0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dc, 0xaa, 0xf9, 0x2e, 0xcf, 0xf8, 0xa0, 0x61, - 0xae, 0x7c, 0xe3, 0x85, 0x89, 0x87, 0xd0, 0x53, 0xd7, 0x4b, 0x39, 0xa1, 0x57, 0x27, 0xac, 0x86, - 0xd8, 0x6c, 0x98, 0x7e, 0x89, 0xf1, 0x01, 0xba, 0x7a, 0x2e, 0xb1, 0xc9, 0x6f, 0x30, 0xac, 0x19, - 0x56, 0x47, 0xd9, 0xc0, 0xe3, 0x05, 0x07, 0x9a, 0x0b, 0xd9, 0x69, 0xea, 0xe8, 0x02, 0x66, 0xf4, - 0xbb, 0x05, 0xd6, 0x69, 0x74, 0x3e, 0x21, 0x3c, 0xaa, 0x9a, 0x83, 0x0d, 0xa3, 0x78, 0x0f, 0xdc, - 0xca, 0x3a, 0x31, 0x4a, 0x10, 0xd5, 0xd5, 0x47, 0x80, 0xac, 0x6c, 0x20, 0x09, 0xa2, 0xe8, 0xf0, - 0x08, 0x90, 0x95, 0xa5, 0x65, 0xe0, 0x18, 0x3a, 0xe5, 0xbf, 0xef, 0x81, 0xd7, 0xa9, 0x13, 0x61, - 0xf9, 0x67, 0xe9, 0x1b, 0xf8, 0xb1, 0xda, 0x39, 0x5b, 0x0d, 0xff, 0x19, 0x0d, 0xb4, 0xdd, 0x64, - 0xae, 0x90, 0xce, 0x6d, 0xf9, 0xdf, 0x7e, 0xf9, 0x37, 0x00, 0x00, 0xff, 0xff, 0x86, 0x75, 0x28, - 0x0b, 0xc7, 0x07, 0x00, 0x00, +func init() { + proto.RegisterFile("micro/go-micro/router/service/proto/router.proto", fileDescriptor_c2b04f200fb3e806) +} + +var fileDescriptor_c2b04f200fb3e806 = []byte{ + // 646 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcb, 0x4e, 0xdb, 0x4c, + 0x14, 0xb6, 0x9d, 0xd8, 0xf9, 0x7d, 0xfe, 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xb0, 0x9a, 0x2a, 0x36, 0x1c, 0xf3, 0x1d, + 0xe3, 0x59, 0x21, 0xa4, 0x25, 0x41, 0xf4, 0x3a, 0x1e, 0x00, 0xb2, 0xc2, 0x61, 0x05, 0xa2, 0xf7, + 0xf8, 0x00, 0x90, 0x15, 0xda, 0x5b, 0xb8, 0x0f, 0x6d, 0xf9, 0xf5, 0xb8, 0x67, 0xbe, 0xf5, 0x0d, + 0x2e, 0x7f, 0x6e, 0x22, 0x0b, 0x3f, 0x57, 0xac, 0xdd, 0x6c, 0xf8, 0xa7, 0x36, 0x40, 0x5b, 0x4d, + 0xe6, 0x0a, 0xe9, 0xd4, 0x53, 0x5f, 0xbe, 0x57, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x53, 0xd8, + 0xc9, 0xf6, 0x2d, 0x07, 0x00, 0x00, } diff --git a/router/service/proto/router.pb.micro.go b/router/service/proto/router.pb.micro.go index 3c0059f8..ae8143bc 100644 --- a/router/service/proto/router.pb.micro.go +++ b/router/service/proto/router.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: router.proto +// source: micro/go-micro/router/service/proto/router.proto package go_micro_router @@ -38,7 +38,6 @@ type RouterService interface { Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Router_WatchService, error) Advertise(ctx context.Context, in *Request, opts ...client.CallOption) (Router_AdvertiseService, error) Process(ctx context.Context, in *Advert, opts ...client.CallOption) (*ProcessResponse, error) - Status(ctx context.Context, in *Request, opts ...client.CallOption) (*StatusResponse, error) } type routerService struct { @@ -167,16 +166,6 @@ func (c *routerService) Process(ctx context.Context, in *Advert, opts ...client. return out, nil } -func (c *routerService) Status(ctx context.Context, in *Request, opts ...client.CallOption) (*StatusResponse, error) { - req := c.c.NewRequest(c.name, "Router.Status", in) - out := new(StatusResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - // Server API for Router service type RouterHandler interface { @@ -184,7 +173,6 @@ type RouterHandler interface { Watch(context.Context, *WatchRequest, Router_WatchStream) error Advertise(context.Context, *Request, Router_AdvertiseStream) error Process(context.Context, *Advert, *ProcessResponse) error - Status(context.Context, *Request, *StatusResponse) error } func RegisterRouterHandler(s server.Server, hdlr RouterHandler, opts ...server.HandlerOption) error { @@ -193,7 +181,6 @@ func RegisterRouterHandler(s server.Server, hdlr RouterHandler, opts ...server.H Watch(ctx context.Context, stream server.Stream) error Advertise(ctx context.Context, stream server.Stream) error Process(ctx context.Context, in *Advert, out *ProcessResponse) error - Status(ctx context.Context, in *Request, out *StatusResponse) error } type Router struct { router @@ -284,10 +271,6 @@ func (h *routerHandler) Process(ctx context.Context, in *Advert, out *ProcessRes return h.RouterHandler.Process(ctx, in, out) } -func (h *routerHandler) Status(ctx context.Context, in *Request, out *StatusResponse) error { - return h.RouterHandler.Status(ctx, in, out) -} - // Client API for Table service type TableService interface { diff --git a/router/service/proto/router.proto b/router/service/proto/router.proto index 44539332..ec2de13b 100644 --- a/router/service/proto/router.proto +++ b/router/service/proto/router.proto @@ -8,7 +8,6 @@ service Router { rpc Watch(WatchRequest) returns (stream Event) {}; rpc Advertise(Request) returns (stream Advert) {}; rpc Process(Advert) returns (ProcessResponse) {}; - rpc Status(Request) returns (StatusResponse) {}; } service Table { @@ -129,12 +128,3 @@ message Route { // the metric / score of this route int64 metric = 7; } - -message Status { - string code = 1; - string error = 2; -} - -message StatusResponse { - Status status = 1; -} diff --git a/router/service/service.go b/router/service/service.go index b92a03fd..3184283d 100644 --- a/router/service/service.go +++ b/router/service/service.go @@ -2,7 +2,6 @@ package service import ( "context" - "errors" "fmt" "io" "sync" @@ -19,7 +18,6 @@ type svc struct { callOpts []client.CallOption router pb.RouterService table *table - status *router.Status exit chan bool errChan chan error advertChan chan *router.Advert @@ -43,16 +41,9 @@ func NewRouter(opts ...router.Option) router.Router { cli = options.Client } - // set the status to Stopped - status := &router.Status{ - Code: router.Stopped, - Error: nil, - } - // NOTE: should we have Client/Service option in router.Options? s := &svc{ opts: options, - status: status, router: pb.NewRouterService(router.DefaultName, cli), } @@ -98,12 +89,6 @@ func (s *svc) Table() router.Table { func (s *svc) Start() error { s.Lock() defer s.Unlock() - - s.status = &router.Status{ - Code: router.Running, - Error: nil, - } - return nil } @@ -169,21 +154,16 @@ func (s *svc) Advertise() (<-chan *router.Advert, error) { s.Lock() defer s.Unlock() - switch s.status.Code { - case router.Running, router.Advertising: - stream, err := s.router.Advertise(context.Background(), &pb.Request{}, s.callOpts...) - if err != nil { - return nil, fmt.Errorf("failed getting advert stream: %s", err) - } - // create advertise and event channels - advertChan := make(chan *router.Advert) - go s.advertiseEvents(advertChan, stream) - return advertChan, nil - case router.Stopped: - return nil, fmt.Errorf("not running") + stream, err := s.router.Advertise(context.Background(), &pb.Request{}, s.callOpts...) + if err != nil { + return nil, fmt.Errorf("failed getting advert stream: %s", err) } - return nil, fmt.Errorf("error: %s", s.status.Error) + // create advertise and event channels + advertChan := make(chan *router.Advert) + go s.advertiseEvents(advertChan, stream) + + return advertChan, nil } // Process processes incoming adverts @@ -220,55 +200,6 @@ func (s *svc) Process(advert *router.Advert) error { return nil } -// Status returns router status -func (s *svc) Status() router.Status { - s.Lock() - defer s.Unlock() - - // check if its stopped - select { - case <-s.exit: - return router.Status{ - Code: router.Stopped, - Error: nil, - } - default: - // don't block - } - - // check the remote router - rsp, err := s.router.Status(context.Background(), &pb.Request{}, s.callOpts...) - if err != nil { - return router.Status{ - Code: router.Error, - Error: err, - } - } - - code := router.Running - var serr error - - switch rsp.Status.Code { - case "running": - code = router.Running - case "advertising": - code = router.Advertising - case "stopped": - code = router.Stopped - case "error": - code = router.Error - } - - if len(rsp.Status.Error) > 0 { - serr = errors.New(rsp.Status.Error) - } - - return router.Status{ - Code: code, - Error: serr, - } -} - // Remote router cannot be stopped func (s *svc) Stop() error { s.Lock() From 3e24276eb1847a6eeb9ca42fbf5bc8e6b9dc6202 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 22 Jan 2020 16:44:34 +0000 Subject: [PATCH 192/788] fix break --- proxy/mucp/mucp.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index 54041bfd..e42a13fd 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -203,10 +203,6 @@ func (p *Proxy) cacheRoutes(service string) ([]router.Route, error) { // lookup the routes in the router results, err := p.Router.Lookup(router.QueryService(service)) if err != nil { - // check the status of the router - if status := p.Router.Status(); status.Code == router.Error { - return nil, status.Error - } // otherwise return the error return nil, err } From 009c598049bc37809968c51bc1330d45c6053c67 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 22 Jan 2020 17:03:38 +0000 Subject: [PATCH 193/788] Change version to latest --- server/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/server.go b/server/server.go index 8e2d8473..54336a4e 100644 --- a/server/server.go +++ b/server/server.go @@ -129,7 +129,7 @@ type Option func(*Options) var ( DefaultAddress = ":0" DefaultName = "go.micro.server" - DefaultVersion = time.Now().Format("2006.01.02.15.04") + DefaultVersion = "latest", DefaultId = uuid.New().String() DefaultServer Server = newRpcServer() DefaultRouter = newRpcRouter() From 6d636b7ab3036fba7fa7babd99c1bc7d4be71796 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 22 Jan 2020 17:07:56 +0000 Subject: [PATCH 194/788] whoa bad commit, bad asim --- server/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/server.go b/server/server.go index 54336a4e..f494ef0b 100644 --- a/server/server.go +++ b/server/server.go @@ -129,7 +129,7 @@ type Option func(*Options) var ( DefaultAddress = ":0" DefaultName = "go.micro.server" - DefaultVersion = "latest", + DefaultVersion = "latest" DefaultId = uuid.New().String() DefaultServer Server = newRpcServer() DefaultRouter = newRpcRouter() From 1c19678d04181658118155030ba67306319565fa Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 23 Jan 2020 11:37:54 +0000 Subject: [PATCH 195/788] Update proto Service => Config --- config/source/service/proto/service.pb.go | 95 ++++++++------- .../{service.micro.go => service.pb.micro.go} | 112 +++++++++--------- config/source/service/proto/service.proto | 16 +-- config/source/service/service.go | 4 +- config/source/service/watcher.go | 4 +- 5 files changed, 117 insertions(+), 114 deletions(-) rename config/source/service/proto/{service.micro.go => service.pb.micro.go} (53%) diff --git a/config/source/service/proto/service.pb.go b/config/source/service/proto/service.pb.go index 667d3c76..47ab08e5 100644 --- a/config/source/service/proto/service.pb.go +++ b/config/source/service/proto/service.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: proto/service.proto +// source: go-micro/config/source/service/proto/service.proto package service @@ -35,7 +35,7 @@ func (m *ChangeSet) Reset() { *m = ChangeSet{} } func (m *ChangeSet) String() string { return proto.CompactTextString(m) } func (*ChangeSet) ProtoMessage() {} func (*ChangeSet) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{0} + return fileDescriptor_05971a9aaecb0484, []int{0} } func (m *ChangeSet) XXX_Unmarshal(b []byte) error { @@ -104,7 +104,7 @@ func (m *Change) Reset() { *m = Change{} } func (m *Change) String() string { return proto.CompactTextString(m) } func (*Change) ProtoMessage() {} func (*Change) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{1} + return fileDescriptor_05971a9aaecb0484, []int{1} } func (m *Change) XXX_Unmarshal(b []byte) error { @@ -157,7 +157,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{2} + return fileDescriptor_05971a9aaecb0484, []int{2} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -195,7 +195,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{3} + return fileDescriptor_05971a9aaecb0484, []int{3} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -227,7 +227,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{4} + return fileDescriptor_05971a9aaecb0484, []int{4} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -265,7 +265,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{5} + return fileDescriptor_05971a9aaecb0484, []int{5} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -297,7 +297,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{6} + return fileDescriptor_05971a9aaecb0484, []int{6} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -335,7 +335,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{7} + return fileDescriptor_05971a9aaecb0484, []int{7} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -366,7 +366,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{8} + return fileDescriptor_05971a9aaecb0484, []int{8} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -398,7 +398,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{9} + return fileDescriptor_05971a9aaecb0484, []int{9} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -438,7 +438,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{10} + return fileDescriptor_05971a9aaecb0484, []int{10} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -484,7 +484,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{11} + return fileDescriptor_05971a9aaecb0484, []int{11} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -524,7 +524,7 @@ func (m *WatchRequest) Reset() { *m = WatchRequest{} } func (m *WatchRequest) String() string { return proto.CompactTextString(m) } func (*WatchRequest) ProtoMessage() {} func (*WatchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{12} + return fileDescriptor_05971a9aaecb0484, []int{12} } func (m *WatchRequest) XXX_Unmarshal(b []byte) error { @@ -571,7 +571,7 @@ func (m *WatchResponse) Reset() { *m = WatchResponse{} } func (m *WatchResponse) String() string { return proto.CompactTextString(m) } func (*WatchResponse) ProtoMessage() {} func (*WatchResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c33392ef2c1961ba, []int{13} + return fileDescriptor_05971a9aaecb0484, []int{13} } func (m *WatchResponse) XXX_Unmarshal(b []byte) error { @@ -623,35 +623,38 @@ func init() { proto.RegisterType((*WatchResponse)(nil), "WatchResponse") } -func init() { proto.RegisterFile("proto/service.proto", fileDescriptor_c33392ef2c1961ba) } - -var fileDescriptor_c33392ef2c1961ba = []byte{ - // 427 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xcf, 0x6a, 0xdb, 0x40, - 0x10, 0xc6, 0x2d, 0xdb, 0x51, 0xaa, 0xb1, 0x24, 0x87, 0x29, 0x14, 0x21, 0x0a, 0x35, 0x0b, 0x05, - 0xd3, 0xc2, 0x26, 0x38, 0x7d, 0x83, 0xf4, 0xd6, 0x9e, 0x36, 0x94, 0xf6, 0xba, 0x95, 0xa7, 0xb5, - 0x49, 0x14, 0xa9, 0xda, 0x55, 0xa0, 0x8f, 0xd0, 0x3e, 0x75, 0xd9, 0x3f, 0x8a, 0x24, 0x17, 0x4c, - 0x7c, 0xdb, 0x99, 0xd9, 0xf9, 0xe6, 0xd3, 0xfc, 0x56, 0xf0, 0xb2, 0x6e, 0x2a, 0x5d, 0x5d, 0x2a, - 0x6a, 0x1e, 0xf7, 0x05, 0x71, 0x1b, 0xb1, 0x3f, 0x01, 0x44, 0x37, 0x3b, 0xf9, 0xf0, 0x93, 0x6e, - 0x49, 0x23, 0xc2, 0x7c, 0x2b, 0xb5, 0xcc, 0x82, 0x55, 0xb0, 0x8e, 0x85, 0x3d, 0x63, 0x0e, 0x2f, - 0x8a, 0x1d, 0x15, 0x77, 0xaa, 0x2d, 0xb3, 0xe9, 0x2a, 0x58, 0x47, 0xe2, 0x29, 0xc6, 0x57, 0x10, - 0xfe, 0xa8, 0x9a, 0x52, 0xea, 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, 0x8f, 0x40, 0xdf, 0xfc, - 0x9d, 0xc2, 0xf9, 0xad, 0x7b, 0xec, 0xf8, 0x1e, 0x42, 0x87, 0x13, 0x53, 0x3e, 0x7a, 0x09, 0xf9, - 0x92, 0x1f, 0x70, 0x9e, 0x98, 0xcb, 0x8e, 0x1b, 0xa6, 0x7c, 0x84, 0x3c, 0x5f, 0xf2, 0x03, 0xa0, - 0xf6, 0xb2, 0x03, 0x84, 0x29, 0x1f, 0xb1, 0xcd, 0x97, 0xfc, 0x80, 0xdc, 0x04, 0xdf, 0xc2, 0xdc, - 0xc0, 0xc2, 0x98, 0x0f, 0x10, 0xe6, 0x09, 0x1f, 0x12, 0x74, 0xd7, 0xcc, 0xb6, 0x31, 0xe6, 0x03, - 0x52, 0x79, 0xc2, 0x87, 0x08, 0xd8, 0x04, 0xdf, 0xc1, 0x99, 0xdd, 0x16, 0x26, 0x7c, 0xb8, 0xeb, - 0x3c, 0xe5, 0xa3, 0x25, 0xb2, 0xc9, 0x55, 0xf0, 0x3d, 0xb4, 0xbf, 0xfb, 0xf5, 0xbf, 0x00, 0x00, - 0x00, 0xff, 0xff, 0xc3, 0x45, 0xac, 0x57, 0x05, 0x04, 0x00, 0x00, +func init() { + proto.RegisterFile("go-micro/config/source/service/proto/service.proto", fileDescriptor_05971a9aaecb0484) +} + +var fileDescriptor_05971a9aaecb0484 = []byte{ + // 443 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xcf, 0x6a, 0xdb, 0x40, + 0x10, 0xc6, 0x2d, 0xdb, 0x51, 0xab, 0xb1, 0x24, 0x87, 0x39, 0x14, 0x21, 0x0a, 0x35, 0x82, 0x82, + 0x69, 0xe9, 0x2a, 0x38, 0x7d, 0x03, 0xf7, 0xd6, 0x9e, 0x54, 0x4a, 0x7b, 0xdd, 0xca, 0x13, 0x5b, + 0x24, 0xf2, 0xaa, 0xda, 0x75,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0xd3, 0x98, 0x0d, 0x76, 0x98, 0x8d, 0x6e, 0xbc, 0xdf, 0xbe, 0x79, 0xed, 0xb7, 0xff, 0x02, 0x00, + 0x00, 0xff, 0xff, 0xea, 0xa0, 0x1e, 0x8e, 0x23, 0x04, 0x00, 0x00, } diff --git a/config/source/service/proto/service.micro.go b/config/source/service/proto/service.pb.micro.go similarity index 53% rename from config/source/service/proto/service.micro.go rename to config/source/service/proto/service.pb.micro.go index e3847a25..238b6112 100644 --- a/config/source/service/proto/service.micro.go +++ b/config/source/service/proto/service.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: proto/service.proto +// source: go-micro/config/source/service/proto/service.proto package service @@ -31,37 +31,37 @@ var _ context.Context var _ client.Option var _ server.Option -// Client API for Service service +// Client API for Config service -type Service interface { +type ConfigService interface { Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) - Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Service_WatchService, error) + Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Config_WatchService, error) } -type service struct { +type configService struct { c client.Client name string } -func NewService(name string, c client.Client) Service { +func NewConfigService(name string, c client.Client) ConfigService { if c == nil { c = client.NewClient() } if len(name) == 0 { - name = "service" + name = "config" } - return &service{ + return &configService{ c: c, name: name, } } -func (c *service) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { - req := c.c.NewRequest(c.name, "Service.Create", in) +func (c *configService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { + req := c.c.NewRequest(c.name, "Config.Create", in) out := new(CreateResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -70,8 +70,8 @@ func (c *service) Create(ctx context.Context, in *CreateRequest, opts ...client. return out, nil } -func (c *service) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) { - req := c.c.NewRequest(c.name, "Service.Update", in) +func (c *configService) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) { + req := c.c.NewRequest(c.name, "Config.Update", in) out := new(UpdateResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -80,8 +80,8 @@ func (c *service) Update(ctx context.Context, in *UpdateRequest, opts ...client. return out, nil } -func (c *service) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { - req := c.c.NewRequest(c.name, "Service.Delete", in) +func (c *configService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { + req := c.c.NewRequest(c.name, "Config.Delete", in) out := new(DeleteResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -90,8 +90,8 @@ func (c *service) Delete(ctx context.Context, in *DeleteRequest, opts ...client. return out, nil } -func (c *service) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { - req := c.c.NewRequest(c.name, "Service.List", in) +func (c *configService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { + req := c.c.NewRequest(c.name, "Config.List", in) out := new(ListResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -100,8 +100,8 @@ func (c *service) List(ctx context.Context, in *ListRequest, opts ...client.Call return out, nil } -func (c *service) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) { - req := c.c.NewRequest(c.name, "Service.Read", in) +func (c *configService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) { + req := c.c.NewRequest(c.name, "Config.Read", in) out := new(ReadResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { @@ -110,8 +110,8 @@ func (c *service) Read(ctx context.Context, in *ReadRequest, opts ...client.Call return out, nil } -func (c *service) Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Service_WatchService, error) { - req := c.c.NewRequest(c.name, "Service.Watch", &WatchRequest{}) +func (c *configService) Watch(ctx context.Context, in *WatchRequest, opts ...client.CallOption) (Config_WatchService, error) { + req := c.c.NewRequest(c.name, "Config.Watch", &WatchRequest{}) stream, err := c.c.Stream(ctx, req, opts...) if err != nil { return nil, err @@ -119,33 +119,33 @@ func (c *service) Watch(ctx context.Context, in *WatchRequest, opts ...client.Ca if err := stream.Send(in); err != nil { return nil, err } - return &serviceWatch{stream}, nil + return &configServiceWatch{stream}, nil } -type Service_WatchService interface { +type Config_WatchService interface { SendMsg(interface{}) error RecvMsg(interface{}) error Close() error Recv() (*WatchResponse, error) } -type serviceWatch struct { +type configServiceWatch struct { stream client.Stream } -func (x *serviceWatch) Close() error { +func (x *configServiceWatch) Close() error { return x.stream.Close() } -func (x *serviceWatch) SendMsg(m interface{}) error { +func (x *configServiceWatch) SendMsg(m interface{}) error { return x.stream.Send(m) } -func (x *serviceWatch) RecvMsg(m interface{}) error { +func (x *configServiceWatch) RecvMsg(m interface{}) error { return x.stream.Recv(m) } -func (x *serviceWatch) Recv() (*WatchResponse, error) { +func (x *configServiceWatch) Recv() (*WatchResponse, error) { m := new(WatchResponse) err := x.stream.Recv(m) if err != nil { @@ -154,19 +154,19 @@ func (x *serviceWatch) Recv() (*WatchResponse, error) { return m, nil } -// Server API for Service service +// Server API for Config service -type ServiceHandler interface { +type ConfigHandler interface { Create(context.Context, *CreateRequest, *CreateResponse) error Update(context.Context, *UpdateRequest, *UpdateResponse) error Delete(context.Context, *DeleteRequest, *DeleteResponse) error List(context.Context, *ListRequest, *ListResponse) error Read(context.Context, *ReadRequest, *ReadResponse) error - Watch(context.Context, *WatchRequest, Service_WatchStream) error + Watch(context.Context, *WatchRequest, Config_WatchStream) error } -func RegisterServiceHandler(s server.Server, hdlr ServiceHandler, opts ...server.HandlerOption) error { - type service interface { +func RegisterConfigHandler(s server.Server, hdlr ConfigHandler, opts ...server.HandlerOption) error { + type config interface { Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error @@ -174,68 +174,68 @@ func RegisterServiceHandler(s server.Server, hdlr ServiceHandler, opts ...server Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error Watch(ctx context.Context, stream server.Stream) error } - type Service struct { - service + type Config struct { + config } - h := &serviceHandler{hdlr} - return s.Handle(s.NewHandler(&Service{h}, opts...)) + h := &configHandler{hdlr} + return s.Handle(s.NewHandler(&Config{h}, opts...)) } -type serviceHandler struct { - ServiceHandler +type configHandler struct { + ConfigHandler } -func (h *serviceHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { - return h.ServiceHandler.Create(ctx, in, out) +func (h *configHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { + return h.ConfigHandler.Create(ctx, in, out) } -func (h *serviceHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error { - return h.ServiceHandler.Update(ctx, in, out) +func (h *configHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error { + return h.ConfigHandler.Update(ctx, in, out) } -func (h *serviceHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { - return h.ServiceHandler.Delete(ctx, in, out) +func (h *configHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { + return h.ConfigHandler.Delete(ctx, in, out) } -func (h *serviceHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { - return h.ServiceHandler.List(ctx, in, out) +func (h *configHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { + return h.ConfigHandler.List(ctx, in, out) } -func (h *serviceHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error { - return h.ServiceHandler.Read(ctx, in, out) +func (h *configHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error { + return h.ConfigHandler.Read(ctx, in, out) } -func (h *serviceHandler) Watch(ctx context.Context, stream server.Stream) error { +func (h *configHandler) Watch(ctx context.Context, stream server.Stream) error { m := new(WatchRequest) if err := stream.Recv(m); err != nil { return err } - return h.ServiceHandler.Watch(ctx, m, &serviceWatchStream{stream}) + return h.ConfigHandler.Watch(ctx, m, &configWatchStream{stream}) } -type Service_WatchStream interface { +type Config_WatchStream interface { SendMsg(interface{}) error RecvMsg(interface{}) error Close() error Send(*WatchResponse) error } -type serviceWatchStream struct { +type configWatchStream struct { stream server.Stream } -func (x *serviceWatchStream) Close() error { +func (x *configWatchStream) Close() error { return x.stream.Close() } -func (x *serviceWatchStream) SendMsg(m interface{}) error { +func (x *configWatchStream) SendMsg(m interface{}) error { return x.stream.Send(m) } -func (x *serviceWatchStream) RecvMsg(m interface{}) error { +func (x *configWatchStream) RecvMsg(m interface{}) error { return x.stream.Recv(m) } -func (x *serviceWatchStream) Send(m *WatchResponse) error { +func (x *configWatchStream) Send(m *WatchResponse) error { return x.stream.Send(m) } diff --git a/config/source/service/proto/service.proto b/config/source/service/proto/service.proto index 1ffcaec3..ac0359ce 100644 --- a/config/source/service/proto/service.proto +++ b/config/source/service/proto/service.proto @@ -1,12 +1,12 @@ syntax = "proto3"; -service Service { - rpc Create (CreateRequest) returns (CreateResponse) {} - rpc Update (UpdateRequest) returns (UpdateResponse) {} - rpc Delete (DeleteRequest) returns (DeleteResponse) {} - rpc List (ListRequest) returns (ListResponse) {} - rpc Read (ReadRequest) returns (ReadResponse) {} - rpc Watch (WatchRequest) returns (stream WatchResponse) {} +service Config { + rpc Create (CreateRequest) returns (CreateResponse) {} + rpc Update (UpdateRequest) returns (UpdateResponse) {} + rpc Delete (DeleteRequest) returns (DeleteResponse) {} + rpc List (ListRequest) returns (ListResponse) {} + rpc Read (ReadRequest) returns (ReadResponse) {} + rpc Watch (WatchRequest) returns (stream WatchResponse) {} } message ChangeSet { @@ -64,4 +64,4 @@ message WatchRequest { message WatchResponse { string key = 1; ChangeSet changeSet = 2; -} \ No newline at end of file +} diff --git a/config/source/service/service.go b/config/source/service/service.go index 67cb20e1..caf1eebe 100644 --- a/config/source/service/service.go +++ b/config/source/service/service.go @@ -21,7 +21,7 @@ type service struct { key string path string opts source.Options - client proto.Service + client proto.ConfigService } func (m *service) Read() (set *source.ChangeSet, err error) { @@ -83,7 +83,7 @@ func NewSource(opts ...source.Option) source.Source { opts: options, key: key, path: path, - client: proto.NewService(addr, DefaultClient), + client: proto.NewConfigService(addr, DefaultClient), } return s diff --git a/config/source/service/watcher.go b/config/source/service/watcher.go index d604dddf..2806d427 100644 --- a/config/source/service/watcher.go +++ b/config/source/service/watcher.go @@ -6,10 +6,10 @@ import ( ) type watcher struct { - stream proto.Service_WatchService + stream proto.Config_WatchService } -func newWatcher(stream proto.Service_WatchService) (source.Watcher, error) { +func newWatcher(stream proto.Config_WatchService) (source.Watcher, error) { return &watcher{stream: stream}, nil } From 77c2a021dab81e62b6da1842d43844c6df982a5c Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 23 Jan 2020 11:44:06 +0000 Subject: [PATCH 196/788] Add event id to router events --- router/service/proto/router.pb.go | 99 +++++++++++++++++-------------- router/service/proto/router.proto | 8 ++- router/service/service.go | 2 + router/service/watcher.go | 1 + router/table.go | 4 ++ router/watcher.go | 2 + 6 files changed, 68 insertions(+), 48 deletions(-) diff --git a/router/service/proto/router.pb.go b/router/service/proto/router.pb.go index c6259a72..153e9530 100644 --- a/router/service/proto/router.pb.go +++ b/router/service/proto/router.pb.go @@ -578,12 +578,14 @@ var xxx_messageInfo_UpdateResponse proto.InternalMessageInfo // Event is routing table event type Event struct { + // the unique event id + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // type of event - Type EventType `protobuf:"varint,1,opt,name=type,proto3,enum=go.micro.router.EventType" json:"type,omitempty"` + Type EventType `protobuf:"varint,2,opt,name=type,proto3,enum=go.micro.router.EventType" json:"type,omitempty"` // unix timestamp of event - Timestamp int64 `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Timestamp int64 `protobuf:"varint,3,opt,name=timestamp,proto3" json:"timestamp,omitempty"` // service route - Route *Route `protobuf:"bytes,3,opt,name=route,proto3" json:"route,omitempty"` + Route *Route `protobuf:"bytes,4,opt,name=route,proto3" json:"route,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -614,6 +616,13 @@ func (m *Event) XXX_DiscardUnknown() { var xxx_messageInfo_Event proto.InternalMessageInfo +func (m *Event) GetId() string { + if m != nil { + return m.Id + } + return "" +} + func (m *Event) GetType() EventType { if m != nil { return m.Type @@ -815,46 +824,46 @@ func init() { } var fileDescriptor_c2b04f200fb3e806 = []byte{ - // 646 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcb, 0x4e, 0xdb, 0x4c, - 0x14, 0xb6, 0x9d, 0xd8, 0xf9, 0x7d, 0xfe, 0x10, 0xdc, 0xb3, 0xa0, 0x56, 0x5a, 0x68, 0xe4, 0x15, - 0x42, 0xd4, 0x41, 0xe9, 0xb6, 0x37, 0xa0, 0xad, 0x2a, 0x95, 0x45, 0x6b, 0x81, 0xba, 0x36, 0xc9, - 0x11, 0xb5, 0x48, 0x6c, 0x33, 0x33, 0x01, 0x65, 0xdd, 0x67, 0xe9, 0xa2, 0xeb, 0x3e, 0x52, 0x5f, - 0xa4, 0x9a, 0x8b, 0x21, 0xc4, 0x18, 0x09, 0x56, 0x99, 0x73, 0xfb, 0xce, 0xf5, 0x8b, 0x61, 0x6f, - 0x96, 0x8d, 0x59, 0x31, 0x3c, 0x2b, 0x5e, 0xea, 0x07, 0x2b, 0xe6, 0x82, 0xd8, 0x90, 0x13, 0xbb, - 0xc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0xf6, 0x2d, 0x07, 0x00, 0x00, + // 645 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcd, 0x4e, 0xdb, 0x40, + 0x10, 0xb6, 0x93, 0xd8, 0xa9, 0xa7, 0x21, 0xb8, 0x73, 0xa0, 0x56, 0x5a, 0x68, 0xe4, 0x13, 0x42, + 0xd4, 0x41, 0xe9, 0xb5, 0x7f, 0x40, 0x5b, 0x55, 0x2a, 0x87, 0xd6, 0x02, 0xf5, 0x6c, 0x92, 0x11, + 0xb5, 0x48, 0x6c, 0xb3, 0xbb, 0x01, 0xe5, 0x39, 0xfa, 0x0c, 0x3d, 0xf4, 0xdc, 0x47, 0xea, 0x8b, + 0x54, 0xfb, 0x63, 0x48, 0x62, 0x8c, 0x0a, 0x27, 0xef, 0xfc, 0x7d, 0x33, 0x3b, 0x33, 0x9f, 0x17, + 0xf6, 0xa6, 0xe9, 0x88, 0xe5, 0x83, 0xb3, 0xfc, 0xa5, 0x3e, 0xb0, 0x7c, 0x26, 0x88, 0x0d, 0x38, + 0xb1, 0xcb, 0x74, 0x44, 0x83, 0x82, 0xe5, 0xa2, 0x54, 0x46, 0x4a, 0xc0, 0xf5, 0xb3, 0x3c, 0x52, + 0xbe, 0x91, 0x56, 0x87, 0x1e, 0xb4, 0x63, 0xba, 0x98, 0x11, 0x17, 0x21, 0xc0, 0xa3, 0x98, 0x78, + 0x91, 0x67, 0x9c, 0xc2, 0xb7, 0xd0, 0x39, 0x4a, 0xb9, 0x28, 0x65, 0x8c, 0xc0, 0x55, 0x01, 0x3c, + 0xb0, 0xfb, 0xcd, 0xed, 0xc7, 0xc3, 0x8d, 0x68, 0x05, 0x28, 0x8a, 0xe5, 0x27, 0x36, 0x5e, 0xe1, + 0x1b, 0x58, 0x3b, 0xca, 0xf3, 0xf3, 0x59, 0x61, 0xc0, 0x71, 0x17, 0x9c, 0x8b, 0x19, 0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, 0x9b, 0x63, 0x20, 0x9e, 0xd6, 0xd0, 0x52, + 0x61, 0x7c, 0x82, 0xb6, 0x21, 0x0c, 0xd6, 0xf9, 0xf5, 0xfa, 0x15, 0xc3, 0x2a, 0xc7, 0xac, 0xe1, + 0xdf, 0x06, 0x38, 0xc7, 0xc9, 0xe9, 0x84, 0xf0, 0xb0, 0xec, 0x2a, 0xd6, 0x2c, 0xf3, 0x2d, 0xed, + 0x59, 0x21, 0xa8, 0x25, 0x41, 0xf4, 0x38, 0xee, 0x01, 0xb2, 0xc2, 0x69, 0x05, 0xa2, 0xe7, 0x78, + 0x0f, 0x90, 0x95, 0xdf, 0x80, 0x85, 0xfb, 0xd0, 0x92, 0xaf, 0xc9, 0x1d, 0xfd, 0xad, 0x4e, 0x70, + 0xf1, 0xf9, 0x09, 0x2d, 0xfc, 0x5c, 0xb2, 0x76, 0xb3, 0xe6, 0xcf, 0x6d, 0x80, 0xb6, 0xea, 0xcc, + 0x25, 0xd2, 0xa9, 0xab, 0x5e, 0xc2, 0x57, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x5a, 0x08, 0x7e, + 0xf4, 0x3d, 0x07, 0x00, 0x00, } diff --git a/router/service/proto/router.proto b/router/service/proto/router.proto index ec2de13b..a0926762 100644 --- a/router/service/proto/router.proto +++ b/router/service/proto/router.proto @@ -93,12 +93,14 @@ enum EventType { // Event is routing table event message Event { + // the unique event id + string id = 1; // type of event - EventType type = 1; + EventType type = 2; // unix timestamp of event - int64 timestamp = 2; + int64 timestamp = 3; // service route - Route route = 3; + Route route = 4; } // Query is passed in a LookupRequest diff --git a/router/service/service.go b/router/service/service.go index 3184283d..1de462a7 100644 --- a/router/service/service.go +++ b/router/service/service.go @@ -121,6 +121,7 @@ func (s *svc) advertiseEvents(advertChan chan *router.Advert, stream pb.Router_A } events[i] = &router.Event{ + Id: event.Id, Type: router.EventType(event.Type), Timestamp: time.Unix(0, event.Timestamp), Route: route, @@ -179,6 +180,7 @@ func (s *svc) Process(advert *router.Advert) error { Metric: event.Route.Metric, } e := &pb.Event{ + Id: event.Id, Type: pb.EventType(event.Type), Timestamp: event.Timestamp.UnixNano(), Route: route, diff --git a/router/service/watcher.go b/router/service/watcher.go index 38780f0e..2ffc7ada 100644 --- a/router/service/watcher.go +++ b/router/service/watcher.go @@ -65,6 +65,7 @@ func (w *watcher) watch(stream pb.Router_WatchService) error { } event := &router.Event{ + Id: resp.Id, Type: router.EventType(resp.Type), Timestamp: time.Unix(0, resp.Timestamp), Route: route, diff --git a/router/table.go b/router/table.go index 1f3c96ef..8ee853ec 100644 --- a/router/table.go +++ b/router/table.go @@ -38,6 +38,10 @@ func (t *table) sendEvent(e *Event) { t.RLock() defer t.RUnlock() + if len(e.Id) == 0 { + e.Id = uuid.New().String() + } + for _, w := range t.watchers { select { case w.resChan <- e: diff --git a/router/watcher.go b/router/watcher.go index 148b88d4..4b259fba 100644 --- a/router/watcher.go +++ b/router/watcher.go @@ -39,6 +39,8 @@ func (t EventType) String() string { // Event is returned by a call to Next on the watcher. type Event struct { + // Unique id of the event + Id string // Type defines type of event Type EventType // Timestamp is event timestamp From ae08e9c106dcedc017afa678d1268dd4abe3388c Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 23 Jan 2020 12:41:22 +0000 Subject: [PATCH 197/788] check if event is nil --- network/default.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/network/default.go b/network/default.go index 77b31f32..48e6f9ee 100644 --- a/network/default.go +++ b/network/default.go @@ -655,6 +655,11 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { var events []*router.Event for _, event := range pbRtrAdvert.Events { + // for backwards compatibility reasons + if event == nil || event.Route == nil { + continue + } + // we know the advertising node is not the origin of the route if pbRtrAdvert.Id != event.Route.Router { // if the origin router is not the advertising node peer From add78f29673efb6fc6eb20fb56dbb3b47aaced3f Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Thu, 23 Jan 2020 12:51:57 -0800 Subject: [PATCH 198/788] broker: drop unused registryKey variable --- broker/options.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/broker/options.go b/broker/options.go index f0877a27..348857f3 100644 --- a/broker/options.go +++ b/broker/options.go @@ -46,10 +46,6 @@ type PublishOption func(*PublishOptions) type SubscribeOption func(*SubscribeOptions) -var ( - registryKey = "github.com/micro/go-micro/registry" -) - func NewSubscribeOptions(opts ...SubscribeOption) SubscribeOptions { opt := SubscribeOptions{ AutoAck: true, From 8d2dc8a822e6e312de271dd75b4c9501e1ac64c3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 24 Jan 2020 21:24:51 +0000 Subject: [PATCH 199/788] trace Read endpoint --- debug/trace/default.go | 22 ++++++++++++++++++++-- debug/trace/options.go | 7 +++++++ debug/trace/trace.go | 4 ++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/debug/trace/default.go b/debug/trace/default.go index abbf1c15..05fd9d97 100644 --- a/debug/trace/default.go +++ b/debug/trace/default.go @@ -16,7 +16,25 @@ type trace struct { } func (t *trace) Read(opts ...ReadOption) ([]*Span, error) { - return []*Span{}, nil + var options ReadOptions + for _, o := range opts { + o(&options) + } + + sp := t.buffer.Get(t.buffer.Size()) + + var spans []*Span + + for _, span := range sp { + val := span.Value.(*Span) + // skip if trace id is specified and doesn't match + if len(options.Trace) > 0 && val.Trace != options.Trace { + continue + } + spans = append(spans, val) + } + + return spans, nil } func (t *trace) Start(ctx context.Context, name string) *Span { @@ -49,7 +67,7 @@ func (t *trace) Start(ctx context.Context, name string) *Span { func (t *trace) Finish(s *Span) error { // set finished time - s.Finished = time.Now() + s.Duration = time.Since(s.Started) // save the span t.buffer.Put(s) diff --git a/debug/trace/options.go b/debug/trace/options.go index d92abad9..7a0af631 100644 --- a/debug/trace/options.go +++ b/debug/trace/options.go @@ -10,3 +10,10 @@ type ReadOptions struct { } type ReadOption func(o *ReadOptions) + +// Read the given trace +func ReadTrace(t string) ReadOption { + return func(o *ReadOptions) { + o.Trace = t + } +} diff --git a/debug/trace/trace.go b/debug/trace/trace.go index 4a4471c3..5cefad2e 100644 --- a/debug/trace/trace.go +++ b/debug/trace/trace.go @@ -28,8 +28,8 @@ type Span struct { Parent string // Start time Started time.Time - // Finish time - Finished time.Time + // Duration in nano seconds + Duration time.Duration // associated data Metadata map[string]string } From 49cc022ca24395ec42a0cf5a449ac6a79d3d59d3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 24 Jan 2020 21:29:29 +0000 Subject: [PATCH 200/788] add trace to handler --- debug/service/handler/debug.go | 24 +++ debug/service/proto/debug.pb.go | 241 +++++++++++++++++++++++--- debug/service/proto/debug.pb.micro.go | 17 ++ debug/service/proto/debug.proto | 28 +++ 4 files changed, 282 insertions(+), 28 deletions(-) diff --git a/debug/service/handler/debug.go b/debug/service/handler/debug.go index 7fd42632..b2b7b9d3 100644 --- a/debug/service/handler/debug.go +++ b/debug/service/handler/debug.go @@ -8,6 +8,7 @@ import ( "github.com/micro/go-micro/debug/log" proto "github.com/micro/go-micro/debug/service/proto" "github.com/micro/go-micro/debug/stats" + "github.com/micro/go-micro/debug/trace" "github.com/micro/go-micro/server" ) @@ -23,6 +24,8 @@ type Debug struct { log log.Log // the stats collector stats stats.Stats + // the tracer + trace trace.Trace } func newDebug() *Debug { @@ -60,6 +63,27 @@ func (d *Debug) Stats(ctx context.Context, req *proto.StatsRequest, rsp *proto.S return nil } +func (d *Debug) Trace(ctx context.Context, req *proto.TraceRequest, rsp *proto.TraceResponse) error { + traces, err := d.trace.Read(trace.ReadTrace(req.Id)) + if err != nil { + return err + } + + for _, trace := range traces { + rsp.Spans = append(rsp.Spans, &proto.Span{ + Trace: trace.Trace, + Id: trace.Id, + Parent: trace.Parent, + Name: trace.Name, + Started: uint64(trace.Started.UnixNano()), + Duration: uint64(trace.Duration.Nanoseconds()), + Metadata: trace.Metadata, + }) + } + + return nil +} + func (d *Debug) Log(ctx context.Context, stream server.Stream) error { req := new(proto.LogRequest) if err := stream.Recv(req); err != nil { diff --git a/debug/service/proto/debug.pb.go b/debug/service/proto/debug.pb.go index 263f21ec..6e513462 100644 --- a/debug/service/proto/debug.pb.go +++ b/debug/service/proto/debug.pb.go @@ -372,6 +372,179 @@ func (m *Record) GetMessage() string { return "" } +type TraceRequest struct { + // trace id to retrieve + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *TraceRequest) Reset() { *m = TraceRequest{} } +func (m *TraceRequest) String() string { return proto.CompactTextString(m) } +func (*TraceRequest) ProtoMessage() {} +func (*TraceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_dea322649cde1ef2, []int{6} +} + +func (m *TraceRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_TraceRequest.Unmarshal(m, b) +} +func (m *TraceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_TraceRequest.Marshal(b, m, deterministic) +} +func (m *TraceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_TraceRequest.Merge(m, src) +} +func (m *TraceRequest) XXX_Size() int { + return xxx_messageInfo_TraceRequest.Size(m) +} +func (m *TraceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_TraceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_TraceRequest proto.InternalMessageInfo + +func (m *TraceRequest) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +type TraceResponse struct { + Spans []*Span `protobuf:"bytes,1,rep,name=spans,proto3" json:"spans,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *TraceResponse) Reset() { *m = TraceResponse{} } +func (m *TraceResponse) String() string { return proto.CompactTextString(m) } +func (*TraceResponse) ProtoMessage() {} +func (*TraceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_dea322649cde1ef2, []int{7} +} + +func (m *TraceResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_TraceResponse.Unmarshal(m, b) +} +func (m *TraceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_TraceResponse.Marshal(b, m, deterministic) +} +func (m *TraceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_TraceResponse.Merge(m, src) +} +func (m *TraceResponse) XXX_Size() int { + return xxx_messageInfo_TraceResponse.Size(m) +} +func (m *TraceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_TraceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_TraceResponse proto.InternalMessageInfo + +func (m *TraceResponse) GetSpans() []*Span { + if m != nil { + return m.Spans + } + return nil +} + +type Span struct { + // the trace id + Trace string `protobuf:"bytes,1,opt,name=trace,proto3" json:"trace,omitempty"` + // id of the span + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + // parent span + Parent string `protobuf:"bytes,3,opt,name=parent,proto3" json:"parent,omitempty"` + // name of the resource + Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` + // time of start in nanoseconds + Started uint64 `protobuf:"varint,5,opt,name=started,proto3" json:"started,omitempty"` + // duration of the execution in nanoseconds + Duration uint64 `protobuf:"varint,6,opt,name=duration,proto3" json:"duration,omitempty"` + // associated metadata + Metadata map[string]string `protobuf:"bytes,7,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Span) Reset() { *m = Span{} } +func (m *Span) String() string { return proto.CompactTextString(m) } +func (*Span) ProtoMessage() {} +func (*Span) Descriptor() ([]byte, []int) { + return fileDescriptor_dea322649cde1ef2, []int{8} +} + +func (m *Span) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Span.Unmarshal(m, b) +} +func (m *Span) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Span.Marshal(b, m, deterministic) +} +func (m *Span) XXX_Merge(src proto.Message) { + xxx_messageInfo_Span.Merge(m, src) +} +func (m *Span) XXX_Size() int { + return xxx_messageInfo_Span.Size(m) +} +func (m *Span) XXX_DiscardUnknown() { + xxx_messageInfo_Span.DiscardUnknown(m) +} + +var xxx_messageInfo_Span proto.InternalMessageInfo + +func (m *Span) GetTrace() string { + if m != nil { + return m.Trace + } + return "" +} + +func (m *Span) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *Span) GetParent() string { + if m != nil { + return m.Parent + } + return "" +} + +func (m *Span) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *Span) GetStarted() uint64 { + if m != nil { + return m.Started + } + return 0 +} + +func (m *Span) GetDuration() uint64 { + if m != nil { + return m.Duration + } + return 0 +} + +func (m *Span) GetMetadata() map[string]string { + if m != nil { + return m.Metadata + } + return nil +} + func init() { proto.RegisterType((*HealthRequest)(nil), "HealthRequest") proto.RegisterType((*HealthResponse)(nil), "HealthResponse") @@ -380,6 +553,10 @@ func init() { proto.RegisterType((*LogRequest)(nil), "LogRequest") proto.RegisterType((*Record)(nil), "Record") proto.RegisterMapType((map[string]string)(nil), "Record.MetadataEntry") + proto.RegisterType((*TraceRequest)(nil), "TraceRequest") + proto.RegisterType((*TraceResponse)(nil), "TraceResponse") + proto.RegisterType((*Span)(nil), "Span") + proto.RegisterMapType((map[string]string)(nil), "Span.MetadataEntry") } func init() { @@ -387,32 +564,40 @@ func init() { } var fileDescriptor_dea322649cde1ef2 = []byte{ - // 427 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcd, 0x6e, 0x13, 0x31, - 0x14, 0x85, 0x33, 0x33, 0xcd, 0x24, 0xb9, 0x25, 0x01, 0x59, 0x80, 0xac, 0x11, 0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 0xba, 0xb0, 0x03, 0x3b, 0x95, 0x77, - 0x3f, 0xa1, 0x99, 0xe5, 0xac, 0x62, 0xf2, 0xb6, 0xb8, 0xac, 0x63, 0xfb, 0xdf, 0xff, 0x0b, 0x00, - 0x00, 0xff, 0xff, 0x69, 0xc0, 0x33, 0x21, 0x2f, 0x03, 0x00, 0x00, + // 554 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcd, 0x6e, 0xd4, 0x30, + 0x10, 0xde, 0x24, 0x9b, 0xdd, 0xcd, 0xb4, 0x09, 0xc8, 0xfc, 0x28, 0x0a, 0x08, 0x2a, 0x9f, 0x16, + 0x01, 0x5e, 0x28, 0x17, 0x04, 0x57, 0x90, 0x38, 0x94, 0x8b, 0xcb, 0x0b, 0xb8, 0x89, 0x95, 0x06, + 0x9a, 0x38, 0xd8, 0x4e, 0xa5, 0x7d, 0x24, 0x6e, 0xbc, 0x0c, 0x6f, 0xc3, 0x01, 0xf9, 0x27, 0xdb, + 0x44, 0x08, 0xf5, 0xc0, 0xcd, 0xdf, 0xe7, 0x99, 0x2f, 0x33, 0x9f, 0x67, 0x02, 0xa4, 0x6d, 0x4a, + 0x29, 0x76, 0xb5, 0x78, 0xe9, 0x0e, 0x15, 0xbf, 0x18, 0xea, 0x9d, 0xe2, 0xf2, 0xba, 0x29, 0xf9, + 0xae, 0x97, 0x42, 0x7b, 0x8e, 0xd8, 0x33, 0x7e, 0x06, 0xe9, 0x27, 0xce, 0xae, 0xf4, 0x25, 0xe5, + 0xdf, 0x07, 0xae, 0x34, 0xca, 0x61, 0xed, 0xa3, 0xf3, 0xe0, 0x24, 0xd8, 0x26, 0x74, 0x84, 0x78, + 0x0b, 0xd9, 0x18, 0xaa, 0x7a, 0xd1, 0x29, 0x8e, 0x1e, 0xc2, 0x4a, 0x69, 0xa6, 0x07, 0xe5, 0x43, + 0x3d, 0xc2, 0x5b,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0x91, 0x2e, 0xd6, 0x7e, 0x72, 0xf0, 0xe2, 0x55, 0x60, 0xa4, 0xec, 0x73, 0xa1, 0x94, 0x4c, 0x9f, + 0xb5, 0xc8, 0xc8, 0xec, 0x15, 0xf1, 0xe2, 0x62, 0x65, 0xff, 0x3a, 0x6f, 0xfe, 0x04, 0x00, 0x00, + 0xff, 0xff, 0x02, 0xa2, 0x4d, 0xc9, 0xa7, 0x04, 0x00, 0x00, } diff --git a/debug/service/proto/debug.pb.micro.go b/debug/service/proto/debug.pb.micro.go index 45a26bac..2144f1b4 100644 --- a/debug/service/proto/debug.pb.micro.go +++ b/debug/service/proto/debug.pb.micro.go @@ -37,6 +37,7 @@ type DebugService interface { Health(ctx context.Context, in *HealthRequest, opts ...client.CallOption) (*HealthResponse, error) Stats(ctx context.Context, in *StatsRequest, opts ...client.CallOption) (*StatsResponse, error) Log(ctx context.Context, in *LogRequest, opts ...client.CallOption) (Debug_LogService, error) + Trace(ctx context.Context, in *TraceRequest, opts ...client.CallOption) (*TraceResponse, error) } type debugService struct { @@ -121,12 +122,23 @@ func (x *debugServiceLog) Recv() (*Record, error) { return m, nil } +func (c *debugService) Trace(ctx context.Context, in *TraceRequest, opts ...client.CallOption) (*TraceResponse, error) { + req := c.c.NewRequest(c.name, "Debug.Trace", in) + out := new(TraceResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for Debug service type DebugHandler interface { Health(context.Context, *HealthRequest, *HealthResponse) error Stats(context.Context, *StatsRequest, *StatsResponse) error Log(context.Context, *LogRequest, Debug_LogStream) error + Trace(context.Context, *TraceRequest, *TraceResponse) error } func RegisterDebugHandler(s server.Server, hdlr DebugHandler, opts ...server.HandlerOption) error { @@ -134,6 +146,7 @@ func RegisterDebugHandler(s server.Server, hdlr DebugHandler, opts ...server.Han Health(ctx context.Context, in *HealthRequest, out *HealthResponse) error Stats(ctx context.Context, in *StatsRequest, out *StatsResponse) error Log(ctx context.Context, stream server.Stream) error + Trace(ctx context.Context, in *TraceRequest, out *TraceResponse) error } type Debug struct { debug @@ -188,3 +201,7 @@ func (x *debugLogStream) RecvMsg(m interface{}) error { func (x *debugLogStream) Send(m *Record) error { return x.stream.Send(m) } + +func (h *debugHandler) Trace(ctx context.Context, in *TraceRequest, out *TraceResponse) error { + return h.DebugHandler.Trace(ctx, in, out) +} diff --git a/debug/service/proto/debug.proto b/debug/service/proto/debug.proto index 54358608..140b2d91 100644 --- a/debug/service/proto/debug.proto +++ b/debug/service/proto/debug.proto @@ -4,6 +4,7 @@ service Debug { rpc Health(HealthRequest) returns (HealthResponse) {}; rpc Stats(StatsRequest) returns (StatsResponse) {}; rpc Log(LogRequest) returns (stream Record) {}; + rpc Trace(TraceRequest) returns (TraceResponse) {}; } message HealthRequest { @@ -63,3 +64,30 @@ message Record { // message string message = 3; } + +message TraceRequest { + // trace id to retrieve + string id = 1; +} + +message TraceResponse { + repeated Span spans = 1; +} + + +message Span { + // the trace id + string trace = 1; + // id of the span + string id = 2; + // parent span + string parent = 3; + // name of the resource + string name = 4; + // time of start in nanoseconds + uint64 started = 5; + // duration of the execution in nanoseconds + uint64 duration = 6; + // associated metadata + map metadata = 7; +} From 2b1844971cf44c0c371ed939574611393077ff71 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 24 Jan 2020 21:31:57 +0000 Subject: [PATCH 201/788] go fmt --- client/rpc_client.go | 2 +- config/cmd/cmd.go | 6 +++--- debug/trace/trace.go | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/client/rpc_client.go b/client/rpc_client.go index d8f24f1c..63d20d7b 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -10,7 +10,6 @@ import ( "github.com/google/uuid" "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/util/pool" "github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/codec" raw "github.com/micro/go-micro/codec/bytes" @@ -19,6 +18,7 @@ import ( "github.com/micro/go-micro/registry" "github.com/micro/go-micro/transport" "github.com/micro/go-micro/util/buf" + "github.com/micro/go-micro/util/pool" ) type rpcClient struct { diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index ad3fa35a..b8ef8abb 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -246,12 +246,12 @@ var ( } DefaultRuntimes = map[string]func(...runtime.Option) runtime.Runtime{ - "local": runtime.NewRuntime, + "local": runtime.NewRuntime, } DefaultStores = map[string]func(...store.Option) store.Store{ - "memory": memStore.NewStore, - "service": svcStore.NewStore, + "memory": memStore.NewStore, + "service": svcStore.NewStore, } // used for default selection as the fall back diff --git a/debug/trace/trace.go b/debug/trace/trace.go index 5cefad2e..229ce981 100644 --- a/debug/trace/trace.go +++ b/debug/trace/trace.go @@ -36,6 +36,11 @@ type Span struct { type spanKey struct{} +var ( + // Default tracer + DefaultTrace = NewTrace() +) + // FromContext returns a span from context func FromContext(ctx context.Context) (*Span, bool) { s, ok := ctx.Value(spanKey{}).(*Span) From 2d28ff72d74b355cc45336f2878fc55ccd26d230 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 24 Jan 2020 21:32:07 +0000 Subject: [PATCH 202/788] add trace --- debug/service/handler/debug.go | 1 + 1 file changed, 1 insertion(+) diff --git a/debug/service/handler/debug.go b/debug/service/handler/debug.go index b2b7b9d3..ad0a7cbe 100644 --- a/debug/service/handler/debug.go +++ b/debug/service/handler/debug.go @@ -32,6 +32,7 @@ func newDebug() *Debug { return &Debug{ log: log.DefaultLog, stats: stats.DefaultStats, + trace: trace.DefaultTrace, } } From a997a86e49cbf7bb08bcdaca3dea7aca703ba6d0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 24 Jan 2020 21:44:48 +0000 Subject: [PATCH 203/788] add trace context --- debug/trace/default.go | 8 ++++---- debug/trace/trace.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/debug/trace/default.go b/debug/trace/default.go index 05fd9d97..65e3aa84 100644 --- a/debug/trace/default.go +++ b/debug/trace/default.go @@ -37,7 +37,7 @@ func (t *trace) Read(opts ...ReadOption) ([]*Span, error) { return spans, nil } -func (t *trace) Start(ctx context.Context, name string) *Span { +func (t *trace) Start(ctx context.Context, name string) (context.Context, *Span) { span := &Span{ Name: name, Trace: uuid.New().String(), @@ -48,12 +48,12 @@ func (t *trace) Start(ctx context.Context, name string) *Span { // return span if no context if ctx == nil { - return span + return context.Background(), span } s, ok := FromContext(ctx) if !ok { - return span + return ctx, span } // set trace id @@ -62,7 +62,7 @@ func (t *trace) Start(ctx context.Context, name string) *Span { span.Parent = s.Id // return the sapn - return span + return ctx, span } func (t *trace) Finish(s *Span) error { diff --git a/debug/trace/trace.go b/debug/trace/trace.go index 229ce981..a4287213 100644 --- a/debug/trace/trace.go +++ b/debug/trace/trace.go @@ -9,7 +9,7 @@ import ( // Trace is an interface for distributed tracing type Trace interface { // Start a trace - Start(ctx context.Context, name string) *Span + Start(ctx context.Context, name string) (context.Context, *Span) // Finish the trace Finish(*Span) error // Read the traces From 4a6570a772721a9c885773a0d8fc8a7a9b4f492e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 24 Jan 2020 21:58:29 +0000 Subject: [PATCH 204/788] trace wrapper --- util/wrapper/wrapper.go | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 371bcb66..17d985c4 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -5,6 +5,7 @@ import ( "github.com/micro/go-micro/client" "github.com/micro/go-micro/debug/stats" + "github.com/micro/go-micro/debug/trace" "github.com/micro/go-micro/metadata" "github.com/micro/go-micro/server" ) @@ -14,6 +15,13 @@ type clientWrapper struct { headers metadata.Metadata } +type traceWrapper struct { + client.Client + + name string + trace trace.Trace +} + var ( HeaderPrefix = "Micro-" ) @@ -48,6 +56,20 @@ func (c *clientWrapper) Publish(ctx context.Context, p client.Message, opts ...c return c.Client.Publish(ctx, p, opts...) } +func (c *traceWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { + newCtx, s := c.trace.Start(ctx, req.Service()+"."+req.Endpoint()) + + err := c.Client.Call(newCtx, req, rsp, opts...) + if err != nil { + s.Metadata["error"] = err.Error() + } + + // finish the trace + c.trace.Finish(s) + + return err +} + // FromService wraps a client to inject From-Service header into metadata func FromService(name string, c client.Client) client.Client { return &clientWrapper{ @@ -73,3 +95,34 @@ func HandlerStats(stats stats.Stats) server.HandlerWrapper { } } } + +// TraceCall is a call tracing wrapper +func TraceCall(name string, t trace.Trace, c client.Client) client.Client { + return &traceWrapper{ + name: name, + trace: t, + Client: c, + } +} + +// TraceHandler wraps a server handler to perform tracing +func TraceHandler(t trace.Trace) server.HandlerWrapper { + // return a handler wrapper + return func(h server.HandlerFunc) server.HandlerFunc { + // return a function that returns a function + return func(ctx context.Context, req server.Request, rsp interface{}) error { + // get the span + newCtx, s := t.Start(ctx, req.Service()+"."+req.Endpoint()) + + err := h(newCtx, req, rsp) + if err != nil { + s.Metadata["error"] = err.Error() + } + + // finish + t.Finish(s) + + return err + } + } +} From 1d00f2f771540c8b90d4cbacd3771fdcf3ecf23c Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 24 Jan 2020 22:02:35 +0000 Subject: [PATCH 205/788] add trace handler --- service.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/service.go b/service.go index abbf23c5..521135e7 100644 --- a/service.go +++ b/service.go @@ -15,6 +15,7 @@ import ( "github.com/micro/go-micro/debug/profile/pprof" "github.com/micro/go-micro/debug/service/handler" "github.com/micro/go-micro/debug/stats" + "github.com/micro/go-micro/debug/trace" "github.com/micro/go-micro/plugin" "github.com/micro/go-micro/server" "github.com/micro/go-micro/util/log" @@ -36,8 +37,15 @@ func newService(opts ...Option) Service { // wrap client to inject From-Service header on any calls options.Client = wrapper.FromService(serviceName, options.Client) + // wrap client to inject From-Service header on any calls + options.Client = wrapper.TraceCall(serviceName, trace.DefaultTrace, options.Client) + // wrap the server to provide handler stats - options.Server.Init(server.WrapHandler(wrapper.HandlerStats(stats.DefaultStats))) + options.Server.Init( + server.WrapHandler(wrapper.HandlerStats(stats.DefaultStats)), + server.WrapHandler(wrapper.TraceHandler(trace.DefaultTrace)), + ) + return &service{ opts: options, From e6a34bcbe7b4f9370751a25db9b45c149090fd59 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 25 Jan 2020 13:41:25 +0300 Subject: [PATCH 206/788] update micro/cli to urfave/cli/v2 and fix go-micro Signed-off-by: Vasiliy Tolstov --- agent/input/discord/discord.go | 28 ++-- agent/input/input.go | 2 +- agent/input/slack/slack.go | 18 +-- agent/input/telegram/telegram.go | 26 ++-- config/cmd/cmd.go | 228 ++++++++++++++++--------------- config/source/cli/cli.go | 7 +- config/source/cli/cli_test.go | 7 +- config/source/cli/options.go | 2 +- config/source/cli/util.go | 4 +- go.mod | 6 +- go.sum | 19 ++- options.go | 4 +- web/options.go | 2 +- web/service.go | 6 +- 14 files changed, 183 insertions(+), 176 deletions(-) diff --git a/agent/input/discord/discord.go b/agent/input/discord/discord.go index 05eb816a..39ff21f3 100644 --- a/agent/input/discord/discord.go +++ b/agent/input/discord/discord.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/bwmarrin/discordgo" - "github.com/micro/cli" "github.com/micro/go-micro/agent/input" + "github.com/micro/cli/v2" ) func init() { @@ -36,21 +36,21 @@ type discordInput struct { func (d *discordInput) Flags() []cli.Flag { return []cli.Flag{ - cli.StringFlag{ - Name: "discord_token", - EnvVar: "MICRO_DISCORD_TOKEN", - Usage: "Discord token (prefix with Bot if it's for bot account)", + &cli.StringFlag{ + Name: "discord_token", + EnvVars: []string{"MICRO_DISCORD_TOKEN"}, + Usage: "Discord token (prefix with Bot if it's for bot account)", }, - cli.StringFlag{ - Name: "discord_whitelist", - EnvVar: "MICRO_DISCORD_WHITELIST", - Usage: "Discord Whitelist (seperated by ,)", + &cli.StringFlag{ + Name: "discord_whitelist", + EnvVars: []string{"MICRO_DISCORD_WHITELIST"}, + Usage: "Discord Whitelist (seperated by ,)", }, - cli.StringFlag{ - Name: "discord_prefix", - Usage: "Discord Prefix", - EnvVar: "MICRO_DISCORD_PREFIX", - Value: "Micro ", + &cli.StringFlag{ + Name: "discord_prefix", + Usage: "Discord Prefix", + EnvVars: []string{"MICRO_DISCORD_PREFIX"}, + Value: "Micro ", }, } } diff --git a/agent/input/input.go b/agent/input/input.go index 2b1d9aab..58a2ba10 100644 --- a/agent/input/input.go +++ b/agent/input/input.go @@ -2,7 +2,7 @@ package input import ( - "github.com/micro/cli" + "github.com/micro/cli/v2" ) type EventType string diff --git a/agent/input/slack/slack.go b/agent/input/slack/slack.go index 9e67b2ed..8336b1d8 100644 --- a/agent/input/slack/slack.go +++ b/agent/input/slack/slack.go @@ -4,9 +4,9 @@ import ( "errors" "sync" - "github.com/micro/cli" "github.com/micro/go-micro/agent/input" "github.com/nlopes/slack" + "github.com/micro/cli/v2" ) type slackInput struct { @@ -26,15 +26,15 @@ func init() { func (p *slackInput) Flags() []cli.Flag { return []cli.Flag{ - cli.BoolFlag{ - Name: "slack_debug", - Usage: "Slack debug output", - EnvVar: "MICRO_SLACK_DEBUG", + &cli.BoolFlag{ + Name: "slack_debug", + Usage: "Slack debug output", + EnvVars: []string{"MICRO_SLACK_DEBUG"}, }, - cli.StringFlag{ - Name: "slack_token", - Usage: "Slack token", - EnvVar: "MICRO_SLACK_TOKEN", + &cli.StringFlag{ + Name: "slack_token", + Usage: "Slack token", + EnvVars: []string{"MICRO_SLACK_TOKEN"}, }, } } diff --git a/agent/input/telegram/telegram.go b/agent/input/telegram/telegram.go index a1510527..eced5d5a 100644 --- a/agent/input/telegram/telegram.go +++ b/agent/input/telegram/telegram.go @@ -5,8 +5,8 @@ import ( "strings" "sync" - "github.com/micro/cli" "github.com/micro/go-micro/agent/input" + "github.com/micro/cli/v2" tgbotapi "gopkg.in/telegram-bot-api.v4" ) @@ -34,20 +34,20 @@ func init() { func (ti *telegramInput) Flags() []cli.Flag { return []cli.Flag{ - cli.BoolFlag{ - Name: "telegram_debug", - EnvVar: "MICRO_TELEGRAM_DEBUG", - Usage: "Telegram debug output", + &cli.BoolFlag{ + Name: "telegram_debug", + EnvVars: []string{"MICRO_TELEGRAM_DEBUG"}, + Usage: "Telegram debug output", }, - cli.StringFlag{ - Name: "telegram_token", - EnvVar: "MICRO_TELEGRAM_TOKEN", - Usage: "Telegram token", + &cli.StringFlag{ + Name: "telegram_token", + EnvVars: []string{"MICRO_TELEGRAM_TOKEN"}, + Usage: "Telegram token", }, - cli.StringFlag{ - Name: "telegram_whitelist", - EnvVar: "MICRO_TELEGRAM_WHITELIST", - Usage: "Telegram bot's users (comma-separated values)", + &cli.StringFlag{ + Name: "telegram_whitelist", + EnvVars: []string{"MICRO_TELEGRAM_WHITELIST"}, + Usage: "Telegram bot's users (comma-separated values)", }, } } diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index b8ef8abb..72117a18 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -7,7 +7,6 @@ import ( "strings" "time" - "github.com/micro/cli" "github.com/micro/go-micro/broker" "github.com/micro/go-micro/client" "github.com/micro/go-micro/client/selector" @@ -25,6 +24,7 @@ import ( // servers sgrpc "github.com/micro/go-micro/server/grpc" smucp "github.com/micro/go-micro/server/mucp" + "github.com/micro/cli/v2" // brokers "github.com/micro/go-micro/broker/memory" @@ -73,140 +73,140 @@ var ( DefaultCmd = newCmd() DefaultFlags = []cli.Flag{ - cli.StringFlag{ - Name: "client", - EnvVar: "MICRO_CLIENT", - Usage: "Client for go-micro; rpc", + &cli.StringFlag{ + Name: "client", + EnvVars: []string{"MICRO_CLIENT"}, + Usage: "Client for go-micro; rpc", }, - cli.StringFlag{ - Name: "client_request_timeout", - EnvVar: "MICRO_CLIENT_REQUEST_TIMEOUT", - Usage: "Sets the client request timeout. e.g 500ms, 5s, 1m. Default: 5s", + &cli.StringFlag{ + Name: "client_request_timeout", + EnvVars: []string{"MICRO_CLIENT_REQUEST_TIMEOUT"}, + Usage: "Sets the client request timeout. e.g 500ms, 5s, 1m. Default: 5s", }, - cli.IntFlag{ - Name: "client_retries", - EnvVar: "MICRO_CLIENT_RETRIES", - Value: client.DefaultRetries, - Usage: "Sets the client retries. Default: 1", + &cli.IntFlag{ + Name: "client_retries", + EnvVars: []string{"MICRO_CLIENT_RETRIES"}, + Value: client.DefaultRetries, + Usage: "Sets the client retries. Default: 1", }, - cli.IntFlag{ - Name: "client_pool_size", - EnvVar: "MICRO_CLIENT_POOL_SIZE", - Usage: "Sets the client connection pool size. Default: 1", + &cli.IntFlag{ + Name: "client_pool_size", + EnvVars: []string{"MICRO_CLIENT_POOL_SIZE"}, + Usage: "Sets the client connection pool size. Default: 1", }, - cli.StringFlag{ - Name: "client_pool_ttl", - EnvVar: "MICRO_CLIENT_POOL_TTL", - Usage: "Sets the client connection pool ttl. e.g 500ms, 5s, 1m. Default: 1m", + &cli.StringFlag{ + Name: "client_pool_ttl", + EnvVars: []string{"MICRO_CLIENT_POOL_TTL"}, + Usage: "Sets the client connection pool ttl. e.g 500ms, 5s, 1m. Default: 1m", }, - cli.IntFlag{ - Name: "register_ttl", - EnvVar: "MICRO_REGISTER_TTL", - Value: 60, - Usage: "Register TTL in seconds", + &cli.IntFlag{ + Name: "register_ttl", + EnvVars: []string{"MICRO_REGISTER_TTL"}, + Value: 60, + Usage: "Register TTL in seconds", }, - cli.IntFlag{ - Name: "register_interval", - EnvVar: "MICRO_REGISTER_INTERVAL", - Value: 30, - Usage: "Register interval in seconds", + &cli.IntFlag{ + Name: "register_interval", + EnvVars: []string{"MICRO_REGISTER_INTERVAL"}, + Value: 30, + Usage: "Register interval in seconds", }, - cli.StringFlag{ - Name: "server", - EnvVar: "MICRO_SERVER", - Usage: "Server for go-micro; rpc", + &cli.StringFlag{ + Name: "server", + EnvVars: []string{"MICRO_SERVER"}, + Usage: "Server for go-micro; rpc", }, - cli.StringFlag{ - Name: "server_name", - EnvVar: "MICRO_SERVER_NAME", - Usage: "Name of the server. go.micro.srv.example", + &cli.StringFlag{ + Name: "server_name", + EnvVars: []string{"MICRO_SERVER_NAME"}, + Usage: "Name of the server. go.micro.srv.example", }, - cli.StringFlag{ - Name: "server_version", - EnvVar: "MICRO_SERVER_VERSION", - Usage: "Version of the server. 1.1.0", + &cli.StringFlag{ + Name: "server_version", + EnvVars: []string{"MICRO_SERVER_VERSION"}, + Usage: "Version of the server. 1.1.0", }, - cli.StringFlag{ - Name: "server_id", - EnvVar: "MICRO_SERVER_ID", - Usage: "Id of the server. Auto-generated if not specified", + &cli.StringFlag{ + Name: "server_id", + EnvVars: []string{"MICRO_SERVER_ID"}, + Usage: "Id of the server. Auto-generated if not specified", }, - cli.StringFlag{ - Name: "server_address", - EnvVar: "MICRO_SERVER_ADDRESS", - Usage: "Bind address for the server. 127.0.0.1:8080", + &cli.StringFlag{ + Name: "server_address", + EnvVars: []string{"MICRO_SERVER_ADDRESS"}, + Usage: "Bind address for the server. 127.0.0.1:8080", }, - cli.StringFlag{ - Name: "server_advertise", - EnvVar: "MICRO_SERVER_ADVERTISE", - Usage: "Used instead of the server_address when registering with discovery. 127.0.0.1:8080", + &cli.StringFlag{ + Name: "server_advertise", + EnvVars: []string{"MICRO_SERVER_ADVERTISE"}, + Usage: "Used instead of the server_address when registering with discovery. 127.0.0.1:8080", }, - cli.StringSliceFlag{ - Name: "server_metadata", - EnvVar: "MICRO_SERVER_METADATA", - Value: &cli.StringSlice{}, - Usage: "A list of key-value pairs defining metadata. version=1.0.0", + &cli.StringSliceFlag{ + Name: "server_metadata", + EnvVars: []string{"MICRO_SERVER_METADATA"}, + Value: &cli.StringSlice{}, + Usage: "A list of key-value pairs defining metadata. version=1.0.0", }, - cli.StringFlag{ - Name: "broker", - EnvVar: "MICRO_BROKER", - Usage: "Broker for pub/sub. http, nats, rabbitmq", + &cli.StringFlag{ + Name: "broker", + EnvVars: []string{"MICRO_BROKER"}, + Usage: "Broker for pub/sub. http, nats, rabbitmq", }, - cli.StringFlag{ - Name: "broker_address", - EnvVar: "MICRO_BROKER_ADDRESS", - Usage: "Comma-separated list of broker addresses", + &cli.StringFlag{ + Name: "broker_address", + EnvVars: []string{"MICRO_BROKER_ADDRESS"}, + Usage: "Comma-separated list of broker addresses", }, - cli.StringFlag{ - Name: "profile", - Usage: "Debug profiler for cpu and memory stats", - EnvVar: "MICRO_DEBUG_PROFILE", + &cli.StringFlag{ + Name: "profile", + Usage: "Debug profiler for cpu and memory stats", + EnvVars: []string{"MICRO_DEBUG_PROFILE"}, }, - cli.StringFlag{ - Name: "registry", - EnvVar: "MICRO_REGISTRY", - Usage: "Registry for discovery. etcd, mdns", + &cli.StringFlag{ + Name: "registry", + EnvVars: []string{"MICRO_REGISTRY"}, + Usage: "Registry for discovery. etcd, mdns", }, - cli.StringFlag{ - Name: "registry_address", - EnvVar: "MICRO_REGISTRY_ADDRESS", - Usage: "Comma-separated list of registry addresses", + &cli.StringFlag{ + Name: "registry_address", + EnvVars: []string{"MICRO_REGISTRY_ADDRESS"}, + Usage: "Comma-separated list of registry addresses", }, - cli.StringFlag{ - Name: "runtime", - Usage: "Runtime for building and running services e.g local, kubernetes", - EnvVar: "MICRO_RUNTIME", - Value: "local", + &cli.StringFlag{ + Name: "runtime", + Usage: "Runtime for building and running services e.g local, kubernetes", + EnvVars: []string{"MICRO_RUNTIME"}, + Value: "local", }, - cli.StringFlag{ - Name: "selector", - EnvVar: "MICRO_SELECTOR", - Usage: "Selector used to pick nodes for querying", + &cli.StringFlag{ + Name: "selector", + EnvVars: []string{"MICRO_SELECTOR"}, + Usage: "Selector used to pick nodes for querying", }, - cli.StringFlag{ - Name: "store", - EnvVar: "MICRO_STORE", - Usage: "Store used for key-value storage", + &cli.StringFlag{ + Name: "store", + EnvVars: []string{"MICRO_STORE"}, + Usage: "Store used for key-value storage", }, - cli.StringFlag{ - Name: "store_address", - EnvVar: "MICRO_STORE_ADDRESS", - Usage: "Comma-separated list of store addresses", + &cli.StringFlag{ + Name: "store_address", + EnvVars: []string{"MICRO_STORE_ADDRESS"}, + Usage: "Comma-separated list of store addresses", }, - cli.StringFlag{ - Name: "store_namespace", - EnvVar: "MICRO_STORE_NAMESPACE", - Usage: "Namespace for store data", + &cli.StringFlag{ + Name: "store_namespace", + EnvVars: []string{"MICRO_STORE_NAMESPACE"}, + Usage: "Namespace for store data", }, - cli.StringFlag{ - Name: "transport", - EnvVar: "MICRO_TRANSPORT", - Usage: "Transport mechanism used; http", + &cli.StringFlag{ + Name: "transport", + EnvVars: []string{"MICRO_TRANSPORT"}, + Usage: "Transport mechanism used; http", }, - cli.StringFlag{ - Name: "transport_address", - EnvVar: "MICRO_TRANSPORT_ADDRESS", - Usage: "Comma-separated list of transport addresses", + &cli.StringFlag{ + Name: "transport_address", + EnvVars: []string{"MICRO_TRANSPORT_ADDRESS"}, + Usage: "Comma-separated list of transport addresses", }, } @@ -306,7 +306,9 @@ func newCmd(opts ...Option) Cmd { cmd.app.Usage = cmd.opts.Description cmd.app.Before = cmd.Before cmd.app.Flags = DefaultFlags - cmd.app.Action = func(c *cli.Context) {} + cmd.app.Action = func(c *cli.Context) error { + return nil + } if len(options.Version) == 0 { cmd.app.HideVersion = true @@ -489,11 +491,11 @@ func (c *cmd) Before(ctx *cli.Context) error { serverOpts = append(serverOpts, server.Advertise(ctx.String("server_advertise"))) } - if ttl := time.Duration(ctx.GlobalInt("register_ttl")); ttl >= 0 { + if ttl := time.Duration(ctx.Int("register_ttl")); ttl >= 0 { serverOpts = append(serverOpts, server.RegisterTTL(ttl*time.Second)) } - if val := time.Duration(ctx.GlobalInt("register_interval")); val >= 0 { + if val := time.Duration(ctx.Int("register_interval")); val >= 0 { serverOpts = append(serverOpts, server.RegisterInterval(val*time.Second)) } diff --git a/config/source/cli/cli.go b/config/source/cli/cli.go index 6d6a8fbb..ea9a3048 100644 --- a/config/source/cli/cli.go +++ b/config/source/cli/cli.go @@ -8,9 +8,9 @@ import ( "time" "github.com/imdario/mergo" - "github.com/micro/cli" "github.com/micro/go-micro/config/cmd" "github.com/micro/go-micro/config/source" + "github.com/micro/cli/v2" ) type cliSource struct { @@ -21,11 +21,6 @@ type cliSource struct { func (c *cliSource) Read() (*source.ChangeSet, error) { var changes map[string]interface{} - for _, name := range c.ctx.GlobalFlagNames() { - tmp := toEntry(name, c.ctx.GlobalGeneric(name)) - mergo.Map(&changes, tmp) // need to sort error handling - } - for _, name := range c.ctx.FlagNames() { tmp := toEntry(name, c.ctx.Generic(name)) mergo.Map(&changes, tmp) // need to sort error handling diff --git a/config/source/cli/cli_test.go b/config/source/cli/cli_test.go index 8e1b743c..a460befa 100644 --- a/config/source/cli/cli_test.go +++ b/config/source/cli/cli_test.go @@ -5,9 +5,9 @@ import ( "os" "testing" - "github.com/micro/cli" "github.com/micro/go-micro/config/cmd" "github.com/micro/go-micro/config/source" + "github.com/micro/cli/v2" ) func test(t *testing.T, withContext bool) { @@ -17,14 +17,15 @@ func test(t *testing.T, withContext bool) { app := cmd.App() app.Name = "testapp" app.Flags = []cli.Flag{ - cli.StringFlag{Name: "db-host"}, + &cli.StringFlag{Name: "db-host"}, } // with context if withContext { // set action - app.Action = func(c *cli.Context) { + app.Action = func(c *cli.Context) error { src = WithContext(c) + return nil } // run app diff --git a/config/source/cli/options.go b/config/source/cli/options.go index 0ee463c7..274d9760 100644 --- a/config/source/cli/options.go +++ b/config/source/cli/options.go @@ -3,7 +3,7 @@ package cli import ( "context" - "github.com/micro/cli" + "github.com/micro/cli/v2" "github.com/micro/go-micro/config/source" ) diff --git a/config/source/cli/util.go b/config/source/cli/util.go index c6274068..1eb9a8b0 100644 --- a/config/source/cli/util.go +++ b/config/source/cli/util.go @@ -5,7 +5,7 @@ import ( "flag" "strings" - "github.com/micro/cli" + "github.com/micro/cli/v2" ) func copyFlag(name string, ff *flag.Flag, set *flag.FlagSet) { @@ -22,7 +22,7 @@ func normalizeFlags(flags []cli.Flag, set *flag.FlagSet) error { visited[f.Name] = true }) for _, f := range flags { - parts := strings.Split(f.GetName(), ",") + parts := f.Names() if len(parts) == 1 { continue } diff --git a/go.mod b/go.mod index 35d8ea72..8dfa1e41 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/go-acme/lego/v3 v3.3.0 github.com/go-playground/universal-translator v0.17.0 // indirect github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect - github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 // indirect + github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 @@ -36,7 +36,7 @@ require ( github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 github.com/mholt/certmagic v0.9.1 - github.com/micro/cli v0.2.0 + github.com/micro/cli/v2 v2.1.1 github.com/micro/mdns v0.3.0 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 @@ -48,7 +48,7 @@ require ( github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 github.com/technoweenie/multipartstreamer v1.0.1 // indirect - github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect + github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect go.etcd.io/bbolt v1.3.3 // indirect go.uber.org/zap v1.13.0 diff --git a/go.sum b/go.sum index aaadbeae..27172711 100644 --- a/go.sum +++ b/go.sum @@ -97,6 +97,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7 github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpu/goacmedns v0.0.1/go.mod h1:sesf/pNnCYwUevQEQfEwY0Y3DydlQWSGZbaMElOWxok= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -161,9 +162,10 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 h1:5ZkaAPbicIKTF2I64qf5Fh8Aa83Q/dnOafMYV0OMwjA= -github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= @@ -173,6 +175,7 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -276,8 +279,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mholt/certmagic v0.9.1 h1:wPzyouOyE+30NIQETJuhTB5ZQWz+0Hy038vaR5WWQDE= github.com/mholt/certmagic v0.9.1/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= -github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= -github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= +github.com/micro/cli/v2 v2.1.1 h1:uFw0SMIKmGuyHIm8lXns/NOn7V62bM5y7DnlxUM+BEQ= +github.com/micro/cli/v2 v2.1.1/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= @@ -373,11 +376,13 @@ github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKc github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sacloud/libsacloud v1.26.1/go.mod h1:79ZwATmHLIFZIMd7sxA3LwzVy/B77uj3LDoToVTxDoQ= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= @@ -401,8 +406,8 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc h1:yUaosFVTJwnltaHbSNC3i82I92quFs+OFPRl8kNMVwo= +github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= @@ -464,6 +469,7 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= @@ -559,6 +565,7 @@ golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= diff --git a/options.go b/options.go index 673d1bfd..f73a3a45 100644 --- a/options.go +++ b/options.go @@ -4,7 +4,6 @@ import ( "context" "time" - "github.com/micro/cli" "github.com/micro/go-micro/broker" "github.com/micro/go-micro/client" "github.com/micro/go-micro/client/selector" @@ -12,6 +11,7 @@ import ( "github.com/micro/go-micro/registry" "github.com/micro/go-micro/server" "github.com/micro/go-micro/transport" + "github.com/micro/cli/v2" ) type Options struct { @@ -166,7 +166,7 @@ func Flags(flags ...cli.Flag) Option { } } -func Action(a func(*cli.Context)) Option { +func Action(a func(*cli.Context) error) Option { return func(o *Options) { o.Cmd.App().Action = a } diff --git a/web/options.go b/web/options.go index 0570f7ba..ec4e1a6b 100644 --- a/web/options.go +++ b/web/options.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - "github.com/micro/cli" + "github.com/micro/cli/v2" "github.com/micro/go-micro" "github.com/micro/go-micro/registry" ) diff --git a/web/service.go b/web/service.go index b76b13b9..46936b9c 100644 --- a/web/service.go +++ b/web/service.go @@ -14,7 +14,6 @@ import ( "syscall" "time" - "github.com/micro/cli" "github.com/micro/go-micro" "github.com/micro/go-micro/registry" maddr "github.com/micro/go-micro/util/addr" @@ -22,6 +21,7 @@ import ( "github.com/micro/go-micro/util/log" mnet "github.com/micro/go-micro/util/net" mls "github.com/micro/go-micro/util/tls" + "github.com/micro/cli/v2" ) type service struct { @@ -327,7 +327,7 @@ func (s *service) Init(opts ...Option) error { serviceOpts = append(serviceOpts, micro.Registry(s.opts.Registry)) } - serviceOpts = append(serviceOpts, micro.Action(func(ctx *cli.Context) { + serviceOpts = append(serviceOpts, micro.Action(func(ctx *cli.Context) error { if ttl := ctx.Int("register_ttl"); ttl > 0 { s.opts.RegisterTTL = time.Duration(ttl) * time.Second } @@ -359,6 +359,8 @@ func (s *service) Init(opts ...Option) error { if s.opts.Action != nil { s.opts.Action(ctx) } + + return nil })) s.opts.Service.Init(serviceOpts...) From 6a9f5fac610aea3ded1f7c5ee0c10e58a0d8e1c8 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 25 Jan 2020 23:16:00 +0000 Subject: [PATCH 207/788] fire send in a go routine to prevent blocking other requests --- tunnel/default.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tunnel/default.go b/tunnel/default.go index 798bc886..d146cb34 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -433,7 +433,7 @@ func (t *tun) process() { } // send the message - t.sendTo(sendTo, msg) + go t.sendTo(sendTo, msg) case <-t.closed: return } From 101017a29c7fb3e61ceb417efe1aa2cb8bd797eb Mon Sep 17 00:00:00 2001 From: shu xian Date: Wed, 29 Jan 2020 00:47:41 +0800 Subject: [PATCH 208/788] cockroach supports URL connection string --- store/cockroach/cockroach.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index bbfadf07..d60a60f5 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -4,6 +4,7 @@ package cockroach import ( "database/sql" "fmt" + "net/url" "strings" "time" "unicode" @@ -212,8 +213,13 @@ func (s *sqlStore) configure() error { } source := nodes[0] - if !strings.Contains(source, " ") { - source = fmt.Sprintf("host=%s", source) + // check if it is a standard connection string eg: host=%s port=%d user=%s password=%s dbname=%s sslmode=disable + // if err is nil which means it would be a URL like postgre://xxxx?yy=zz + _, err := url.Parse(source) + if err != nil { + if !strings.Contains(source, " ") { + source = fmt.Sprintf("host=%s", source) + } } // create source from first node From 895aa896bce8f5a7f51ecd0b0c0ca577519b891f Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Tue, 28 Jan 2020 11:38:55 -0800 Subject: [PATCH 209/788] config/reader/json: remove unused newValue() --- config/reader/json/values.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/config/reader/json/values.go b/config/reader/json/values.go index e955e455..926cfd04 100644 --- a/config/reader/json/values.go +++ b/config/reader/json/values.go @@ -30,13 +30,6 @@ func newValues(ch *source.ChangeSet) (reader.Values, error) { return &jsonValues{ch, sj}, nil } -func newValue(s *simple.Json) reader.Value { - if s == nil { - s = simple.New() - } - return &jsonValue{s} -} - func (j *jsonValues) Get(path ...string) reader.Value { return &jsonValue{j.sj.GetPath(path...)} } From 62c067adcd1c209ac5438877829e0adbeba13096 Mon Sep 17 00:00:00 2001 From: Micro Date: Wed, 29 Jan 2020 15:45:11 +0000 Subject: [PATCH 210/788] Refactor debug/trace ready for Jaeger --- config/cmd/cmd.go | 36 ++++++++++++++++++-- config/cmd/options.go | 16 +++++++++ debug/service/handler/debug.go | 4 +-- debug/trace/{default.go => memory/memory.go} | 29 ++++++++-------- debug/trace/options.go | 17 ++++++++- debug/trace/trace.go | 31 +++++++++++++---- options.go | 10 +++++- server/options.go | 9 +++++ service.go | 8 ++--- util/wrapper/wrapper.go | 6 ++-- 10 files changed, 130 insertions(+), 36 deletions(-) rename debug/trace/{default.go => memory/memory.go} (65%) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 72117a18..6972a8c0 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -10,6 +10,7 @@ import ( "github.com/micro/go-micro/broker" "github.com/micro/go-micro/client" "github.com/micro/go-micro/client/selector" + "github.com/micro/go-micro/debug/trace" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/runtime" "github.com/micro/go-micro/server" @@ -22,9 +23,9 @@ import ( cmucp "github.com/micro/go-micro/client/mucp" // servers + "github.com/micro/cli/v2" sgrpc "github.com/micro/go-micro/server/grpc" smucp "github.com/micro/go-micro/server/mucp" - "github.com/micro/cli/v2" // brokers "github.com/micro/go-micro/broker/memory" @@ -50,6 +51,10 @@ import ( // stores memStore "github.com/micro/go-micro/store/memory" svcStore "github.com/micro/go-micro/store/service" + + // tracers + // jTracer "github.com/micro/go-micro/debug/trace/jaeger" + memTracer "github.com/micro/go-micro/debug/trace/memory" ) type Cmd interface { @@ -208,6 +213,16 @@ var ( EnvVars: []string{"MICRO_TRANSPORT_ADDRESS"}, Usage: "Comma-separated list of transport addresses", }, + &cli.StringFlag{ + Name: "tracer", + EnvVars: []string{"MICRO_TRACER"}, + Usage: "Tracer for distributed tracing, e.g. memory, jaeger", + }, + &cli.StringFlag{ + Name: "tracer_address", + EnvVars: []string{"MICRO_TRACER_ADDRESS"}, + Usage: "Comma-separated list of tracer addresses", + }, } DefaultBrokers = map[string]func(...broker.Option) broker.Broker{ @@ -254,6 +269,11 @@ var ( "service": svcStore.NewStore, } + DefaultTracers = map[string]func(...trace.Option) trace.Tracer{ + "memory": memTracer.NewTracer, + // "jaeger": jTracer.NewTracer, + } + // used for default selection as the fall back defaultClient = "grpc" defaultServer = "grpc" @@ -279,6 +299,7 @@ func newCmd(opts ...Option) Cmd { Transport: &transport.DefaultTransport, Runtime: &runtime.DefaultRuntime, Store: &store.DefaultStore, + Tracer: &trace.DefaultTracer, Brokers: DefaultBrokers, Clients: DefaultClients, @@ -288,6 +309,7 @@ func newCmd(opts ...Option) Cmd { Transports: DefaultTransports, Runtimes: DefaultRuntimes, Stores: DefaultStores, + Tracers: DefaultTracers, } for _, o := range opts { @@ -330,7 +352,7 @@ func (c *cmd) Before(ctx *cli.Context) error { var serverOpts []server.Option var clientOpts []client.Option - // Set the runtime + // Set the store if name := ctx.String("store"); len(name) > 0 { s, ok := c.opts.Stores[name] if !ok { @@ -350,6 +372,16 @@ func (c *cmd) Before(ctx *cli.Context) error { *c.opts.Runtime = r() } + // Set the tracer + if name := ctx.String("tracer"); len(name) > 0 { + r, ok := c.opts.Tracers[name] + if !ok { + return fmt.Errorf("Unsupported tracer: %s", name) + } + + *c.opts.Tracer = r() + } + // Set the client if name := ctx.String("client"); len(name) > 0 { // only change if we have the client and type differs diff --git a/config/cmd/options.go b/config/cmd/options.go index b6bf0ede..68f4b135 100644 --- a/config/cmd/options.go +++ b/config/cmd/options.go @@ -6,6 +6,7 @@ import ( "github.com/micro/go-micro/broker" "github.com/micro/go-micro/client" "github.com/micro/go-micro/client/selector" + "github.com/micro/go-micro/debug/trace" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/runtime" "github.com/micro/go-micro/server" @@ -28,6 +29,7 @@ type Options struct { Server *server.Server Runtime *runtime.Runtime Store *store.Store + Tracer *trace.Tracer Brokers map[string]func(...broker.Option) broker.Broker Clients map[string]func(...client.Option) client.Client @@ -37,6 +39,7 @@ type Options struct { Transports map[string]func(...transport.Option) transport.Transport Runtimes map[string]func(...runtime.Option) runtime.Runtime Stores map[string]func(...store.Option) store.Store + Tracers map[string]func(...trace.Option) trace.Tracer // Other options for implementations of the interface // can be stored in a context @@ -100,6 +103,12 @@ func Server(s *server.Server) Option { } } +func Tracer(t *trace.Tracer) Option { + return func(o *Options) { + o.Tracer = t + } +} + // New broker func func NewBroker(name string, b func(...broker.Option) broker.Broker) Option { return func(o *Options) { @@ -148,3 +157,10 @@ func NewRuntime(name string, r func(...runtime.Option) runtime.Runtime) Option { o.Runtimes[name] = r } } + +// New tracer func +func NewTracer(name string, t func(...trace.Option) trace.Tracer) Option { + return func(o *Options) { + o.Tracers[name] = t + } +} diff --git a/debug/service/handler/debug.go b/debug/service/handler/debug.go index ad0a7cbe..f9258abc 100644 --- a/debug/service/handler/debug.go +++ b/debug/service/handler/debug.go @@ -25,14 +25,14 @@ type Debug struct { // the stats collector stats stats.Stats // the tracer - trace trace.Trace + trace trace.Tracer } func newDebug() *Debug { return &Debug{ log: log.DefaultLog, stats: stats.DefaultStats, - trace: trace.DefaultTrace, + trace: trace.DefaultTracer, } } diff --git a/debug/trace/default.go b/debug/trace/memory/memory.go similarity index 65% rename from debug/trace/default.go rename to debug/trace/memory/memory.go index 65e3aa84..20420fa7 100644 --- a/debug/trace/default.go +++ b/debug/trace/memory/memory.go @@ -1,32 +1,33 @@ -package trace +package memory import ( "context" "time" "github.com/google/uuid" + "github.com/micro/go-micro/debug/trace" "github.com/micro/go-micro/util/ring" ) -type trace struct { - opts Options +type Tracer struct { + opts trace.Options // ring buffer of traces buffer *ring.Buffer } -func (t *trace) Read(opts ...ReadOption) ([]*Span, error) { - var options ReadOptions +func (t *Tracer) Read(opts ...trace.ReadOption) ([]*trace.Span, error) { + var options trace.ReadOptions for _, o := range opts { o(&options) } sp := t.buffer.Get(t.buffer.Size()) - var spans []*Span + var spans []*trace.Span for _, span := range sp { - val := span.Value.(*Span) + val := span.Value.(*trace.Span) // skip if trace id is specified and doesn't match if len(options.Trace) > 0 && val.Trace != options.Trace { continue @@ -37,8 +38,8 @@ func (t *trace) Read(opts ...ReadOption) ([]*Span, error) { return spans, nil } -func (t *trace) Start(ctx context.Context, name string) (context.Context, *Span) { - span := &Span{ +func (t *Tracer) Start(ctx context.Context, name string) (context.Context, *trace.Span) { + span := &trace.Span{ Name: name, Trace: uuid.New().String(), Id: uuid.New().String(), @@ -51,7 +52,7 @@ func (t *trace) Start(ctx context.Context, name string) (context.Context, *Span) return context.Background(), span } - s, ok := FromContext(ctx) + s, ok := trace.FromContext(ctx) if !ok { return ctx, span } @@ -65,7 +66,7 @@ func (t *trace) Start(ctx context.Context, name string) (context.Context, *Span) return ctx, span } -func (t *trace) Finish(s *Span) error { +func (t *Tracer) Finish(s *trace.Span) error { // set finished time s.Duration = time.Since(s.Started) @@ -75,13 +76,13 @@ func (t *trace) Finish(s *Span) error { return nil } -func NewTrace(opts ...Option) Trace { - var options Options +func NewTracer(opts ...trace.Option) trace.Tracer { + var options trace.Options for _, o := range opts { o(&options) } - return &trace{ + return &Tracer{ opts: options, // the last 64 requests buffer: ring.New(64), diff --git a/debug/trace/options.go b/debug/trace/options.go index 7a0af631..c7a6285f 100644 --- a/debug/trace/options.go +++ b/debug/trace/options.go @@ -1,6 +1,9 @@ package trace -type Options struct{} +type Options struct { + // Size is the size of ring buffer + Size int +} type Option func(o *Options) @@ -17,3 +20,15 @@ func ReadTrace(t string) ReadOption { o.Trace = t } } + +const ( + // DefaultSize of the buffer + DefaultSize = 64 +) + +// DefaultOptions returns default options +func DefaultOptions() Options { + return Options{ + Size: DefaultSize, + } +} diff --git a/debug/trace/trace.go b/debug/trace/trace.go index a4287213..1c1f85bc 100644 --- a/debug/trace/trace.go +++ b/debug/trace/trace.go @@ -6,8 +6,8 @@ import ( "time" ) -// Trace is an interface for distributed tracing -type Trace interface { +// Tracer is an interface for distributed tracing +type Tracer interface { // Start a trace Start(ctx context.Context, name string) (context.Context, *Span) // Finish the trace @@ -36,11 +36,6 @@ type Span struct { type spanKey struct{} -var ( - // Default tracer - DefaultTrace = NewTrace() -) - // FromContext returns a span from context func FromContext(ctx context.Context) (*Span, bool) { s, ok := ctx.Value(spanKey{}).(*Span) @@ -51,3 +46,25 @@ func FromContext(ctx context.Context) (*Span, bool) { func NewContext(ctx context.Context, s *Span) context.Context { return context.WithValue(ctx, spanKey{}, s) } + +var ( + DefaultTracer Tracer = new(noop) +) + +type noop struct{} + +func (n *noop) Init(...Option) error { + return nil +} + +func (n *noop) Start(ctx context.Context, name string) (context.Context, *Span) { + return nil, nil +} + +func (n *noop) Finish(*Span) error { + return nil +} + +func (n *noop) Read(...ReadOption) ([]*Span, error) { + return nil, nil +} diff --git a/options.go b/options.go index f73a3a45..1642704d 100644 --- a/options.go +++ b/options.go @@ -4,14 +4,15 @@ import ( "context" "time" + "github.com/micro/cli/v2" "github.com/micro/go-micro/broker" "github.com/micro/go-micro/client" "github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/config/cmd" + "github.com/micro/go-micro/debug/trace" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/server" "github.com/micro/go-micro/transport" - "github.com/micro/cli/v2" ) type Options struct { @@ -112,6 +113,13 @@ func Registry(r registry.Registry) Option { } } +// Tracer sets the tracer for the service +func Tracer(t trace.Tracer) Option { + return func(o *Options) { + o.Server.Init(server.Tracer(t)) + } +} + // Selector sets the selector for the service client func Selector(s selector.Selector) Option { return func(o *Options) { diff --git a/server/options.go b/server/options.go index cbced938..42eeccc6 100644 --- a/server/options.go +++ b/server/options.go @@ -7,6 +7,7 @@ import ( "github.com/micro/go-micro/broker" "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/debug/trace" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/transport" ) @@ -15,6 +16,7 @@ type Options struct { Codecs map[string]codec.NewCodec Broker broker.Broker Registry registry.Registry + Tracer trace.Tracer Transport transport.Transport Metadata map[string]string Name string @@ -152,6 +154,13 @@ func Registry(r registry.Registry) Option { } } +// Tracer mechanism for distributed tracking +func Tracer(t trace.Tracer) Option { + return func(o *Options) { + o.Tracer = t + } +} + // Transport mechanism for communication e.g http, rabbitmq, etc func Transport(t transport.Transport) Option { return func(o *Options) { diff --git a/service.go b/service.go index 521135e7..9d2a955b 100644 --- a/service.go +++ b/service.go @@ -15,7 +15,6 @@ import ( "github.com/micro/go-micro/debug/profile/pprof" "github.com/micro/go-micro/debug/service/handler" "github.com/micro/go-micro/debug/stats" - "github.com/micro/go-micro/debug/trace" "github.com/micro/go-micro/plugin" "github.com/micro/go-micro/server" "github.com/micro/go-micro/util/log" @@ -36,17 +35,14 @@ func newService(opts ...Option) Service { // wrap client to inject From-Service header on any calls options.Client = wrapper.FromService(serviceName, options.Client) - - // wrap client to inject From-Service header on any calls - options.Client = wrapper.TraceCall(serviceName, trace.DefaultTrace, options.Client) + options.Client = wrapper.TraceCall(serviceName, options.Server.Options().Tracer, options.Client) // wrap the server to provide handler stats options.Server.Init( server.WrapHandler(wrapper.HandlerStats(stats.DefaultStats)), - server.WrapHandler(wrapper.TraceHandler(trace.DefaultTrace)), + server.WrapHandler(wrapper.TraceHandler(options.Server.Options().Tracer)), ) - return &service{ opts: options, } diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 17d985c4..d6d2814a 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -19,7 +19,7 @@ type traceWrapper struct { client.Client name string - trace trace.Trace + trace trace.Tracer } var ( @@ -97,7 +97,7 @@ func HandlerStats(stats stats.Stats) server.HandlerWrapper { } // TraceCall is a call tracing wrapper -func TraceCall(name string, t trace.Trace, c client.Client) client.Client { +func TraceCall(name string, t trace.Tracer, c client.Client) client.Client { return &traceWrapper{ name: name, trace: t, @@ -106,7 +106,7 @@ func TraceCall(name string, t trace.Trace, c client.Client) client.Client { } // TraceHandler wraps a server handler to perform tracing -func TraceHandler(t trace.Trace) server.HandlerWrapper { +func TraceHandler(t trace.Tracer) server.HandlerWrapper { // return a handler wrapper return func(h server.HandlerFunc) server.HandlerFunc { // return a function that returns a function From a09eea8d4d06a4793fb5493ff064d57693f95863 Mon Sep 17 00:00:00 2001 From: Micro Date: Wed, 29 Jan 2020 16:05:58 +0000 Subject: [PATCH 211/788] Update the Debug Handler to use the servers tracer --- debug/service/handler/debug.go | 20 ++++++++------------ service.go | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/debug/service/handler/debug.go b/debug/service/handler/debug.go index f9258abc..a6a4dbff 100644 --- a/debug/service/handler/debug.go +++ b/debug/service/handler/debug.go @@ -12,10 +12,14 @@ import ( "github.com/micro/go-micro/server" ) -var ( - // DefaultHandler is default debug handler - DefaultHandler = newDebug() -) +// NewHandler returns an instance of the Debug Handler +func NewHandler(srv server.Server) *Debug { + return &Debug{ + log: log.DefaultLog, + stats: stats.DefaultStats, + trace: srv.Options().Tracer, + } +} type Debug struct { // must honour the debug handler @@ -28,14 +32,6 @@ type Debug struct { trace trace.Tracer } -func newDebug() *Debug { - return &Debug{ - log: log.DefaultLog, - stats: stats.DefaultStats, - trace: trace.DefaultTracer, - } -} - func (d *Debug) Health(ctx context.Context, req *proto.HealthRequest, rsp *proto.HealthResponse) error { rsp.Status = "ok" return nil diff --git a/service.go b/service.go index 9d2a955b..231faae9 100644 --- a/service.go +++ b/service.go @@ -158,7 +158,7 @@ func (s *service) Run() error { // register the debug handler s.opts.Server.Handle( s.opts.Server.NewHandler( - handler.DefaultHandler, + handler.NewHandler(s.Options().Server), server.InternalHandler(true), ), ) From b2980aecb740ff1aae7fa3fff0f911682ea9ada3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 29 Jan 2020 22:31:57 +0000 Subject: [PATCH 212/788] fix debug handler in proxy --- util/mux/mux.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/mux/mux.go b/util/mux/mux.go index e10368ec..7655f802 100644 --- a/util/mux/mux.go +++ b/util/mux/mux.go @@ -40,8 +40,9 @@ func New(name string, p proxy.Proxy) *Server { // only register this once once.Do(func() { server.DefaultRouter.Handle( + // inject the debug handler server.DefaultRouter.NewHandler( - handler.DefaultHandler, + handler.NewHandler(), server.InternalHandler(true), ), ) From 1be8258721b3970a36f07dd20c76dd2ac62ad871 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 29 Jan 2020 22:39:31 +0000 Subject: [PATCH 213/788] fix initialisation --- service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service.go b/service.go index 231faae9..2d1f9631 100644 --- a/service.go +++ b/service.go @@ -158,7 +158,7 @@ func (s *service) Run() error { // register the debug handler s.opts.Server.Handle( s.opts.Server.NewHandler( - handler.NewHandler(s.Options().Server), + handler.NewHandler(), server.InternalHandler(true), ), ) From 49b86c56e373b6295c16c82dc84dd102b5d9c934 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 29 Jan 2020 22:40:43 +0000 Subject: [PATCH 214/788] go fmt --- agent/input/discord/discord.go | 2 +- agent/input/slack/slack.go | 2 +- agent/input/telegram/telegram.go | 2 +- config/source/cli/cli.go | 2 +- config/source/cli/cli_test.go | 2 +- debug/service/handler/debug.go | 4 ++-- defaults.go | 4 ++++ web/service.go | 2 +- 8 files changed, 12 insertions(+), 8 deletions(-) diff --git a/agent/input/discord/discord.go b/agent/input/discord/discord.go index 39ff21f3..f30a45b8 100644 --- a/agent/input/discord/discord.go +++ b/agent/input/discord/discord.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/bwmarrin/discordgo" - "github.com/micro/go-micro/agent/input" "github.com/micro/cli/v2" + "github.com/micro/go-micro/agent/input" ) func init() { diff --git a/agent/input/slack/slack.go b/agent/input/slack/slack.go index 8336b1d8..53472c87 100644 --- a/agent/input/slack/slack.go +++ b/agent/input/slack/slack.go @@ -4,9 +4,9 @@ import ( "errors" "sync" + "github.com/micro/cli/v2" "github.com/micro/go-micro/agent/input" "github.com/nlopes/slack" - "github.com/micro/cli/v2" ) type slackInput struct { diff --git a/agent/input/telegram/telegram.go b/agent/input/telegram/telegram.go index eced5d5a..f7839714 100644 --- a/agent/input/telegram/telegram.go +++ b/agent/input/telegram/telegram.go @@ -5,8 +5,8 @@ import ( "strings" "sync" - "github.com/micro/go-micro/agent/input" "github.com/micro/cli/v2" + "github.com/micro/go-micro/agent/input" tgbotapi "gopkg.in/telegram-bot-api.v4" ) diff --git a/config/source/cli/cli.go b/config/source/cli/cli.go index ea9a3048..96e58331 100644 --- a/config/source/cli/cli.go +++ b/config/source/cli/cli.go @@ -8,9 +8,9 @@ import ( "time" "github.com/imdario/mergo" + "github.com/micro/cli/v2" "github.com/micro/go-micro/config/cmd" "github.com/micro/go-micro/config/source" - "github.com/micro/cli/v2" ) type cliSource struct { diff --git a/config/source/cli/cli_test.go b/config/source/cli/cli_test.go index a460befa..53985860 100644 --- a/config/source/cli/cli_test.go +++ b/config/source/cli/cli_test.go @@ -5,9 +5,9 @@ import ( "os" "testing" + "github.com/micro/cli/v2" "github.com/micro/go-micro/config/cmd" "github.com/micro/go-micro/config/source" - "github.com/micro/cli/v2" ) func test(t *testing.T, withContext bool) { diff --git a/debug/service/handler/debug.go b/debug/service/handler/debug.go index a6a4dbff..e66c8fb2 100644 --- a/debug/service/handler/debug.go +++ b/debug/service/handler/debug.go @@ -13,11 +13,11 @@ import ( ) // NewHandler returns an instance of the Debug Handler -func NewHandler(srv server.Server) *Debug { +func NewHandler() *Debug { return &Debug{ log: log.DefaultLog, stats: stats.DefaultStats, - trace: srv.Options().Tracer, + trace: trace.DefaultTracer, } } diff --git a/defaults.go b/defaults.go index 0159f19c..01854ff3 100644 --- a/defaults.go +++ b/defaults.go @@ -2,11 +2,13 @@ package micro import ( "github.com/micro/go-micro/client" + "github.com/micro/go-micro/debug/trace" "github.com/micro/go-micro/server" "github.com/micro/go-micro/store" // set defaults gcli "github.com/micro/go-micro/client/grpc" + memTrace "github.com/micro/go-micro/debug/trace/memory" gsrv "github.com/micro/go-micro/server/grpc" memStore "github.com/micro/go-micro/store/memory" ) @@ -18,4 +20,6 @@ func init() { server.DefaultServer = gsrv.NewServer() // default store store.DefaultStore = memStore.NewStore() + // set default trace + trace.DefaultTracer = memTrace.NewTracer() } diff --git a/web/service.go b/web/service.go index 46936b9c..c717e9e0 100644 --- a/web/service.go +++ b/web/service.go @@ -14,6 +14,7 @@ import ( "syscall" "time" + "github.com/micro/cli/v2" "github.com/micro/go-micro" "github.com/micro/go-micro/registry" maddr "github.com/micro/go-micro/util/addr" @@ -21,7 +22,6 @@ import ( "github.com/micro/go-micro/util/log" mnet "github.com/micro/go-micro/util/net" mls "github.com/micro/go-micro/util/tls" - "github.com/micro/cli/v2" ) type service struct { From dc257f506666fc8d0b46ff0774b4575ece7bccee Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 29 Jan 2020 22:43:40 +0000 Subject: [PATCH 215/788] update to fix tracer --- service.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/service.go b/service.go index 2d1f9631..de5697f7 100644 --- a/service.go +++ b/service.go @@ -15,6 +15,7 @@ import ( "github.com/micro/go-micro/debug/profile/pprof" "github.com/micro/go-micro/debug/service/handler" "github.com/micro/go-micro/debug/stats" + "github.com/micro/go-micro/debug/trace" "github.com/micro/go-micro/plugin" "github.com/micro/go-micro/server" "github.com/micro/go-micro/util/log" @@ -35,12 +36,12 @@ func newService(opts ...Option) Service { // wrap client to inject From-Service header on any calls options.Client = wrapper.FromService(serviceName, options.Client) - options.Client = wrapper.TraceCall(serviceName, options.Server.Options().Tracer, options.Client) + options.Client = wrapper.TraceCall(serviceName, trace.DefaultTracer, options.Client) // wrap the server to provide handler stats options.Server.Init( server.WrapHandler(wrapper.HandlerStats(stats.DefaultStats)), - server.WrapHandler(wrapper.TraceHandler(options.Server.Options().Tracer)), + server.WrapHandler(wrapper.TraceHandler(trace.DefaultTracer)), ) return &service{ From 5969cc358e2d52cad030f66122328c798c25d007 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 29 Jan 2020 23:14:05 +0000 Subject: [PATCH 216/788] nats-e => eats --- broker/default.go | 2 +- config/cmd/cmd.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/broker/default.go b/broker/default.go index 8fd6214b..f35bd9fc 100644 --- a/broker/default.go +++ b/broker/default.go @@ -402,7 +402,7 @@ func (n *natsBroker) Subscribe(topic string, handler Handler, opts ...SubscribeO } func (n *natsBroker) String() string { - return "nats-e" + return "eats" } func (n *natsBroker) setOption(opts ...Option) { diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 6972a8c0..befaea4c 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -277,7 +277,7 @@ var ( // used for default selection as the fall back defaultClient = "grpc" defaultServer = "grpc" - defaultBroker = "nats-e" + defaultBroker = "eats" defaultRegistry = "mdns" defaultSelector = "registry" defaultTransport = "http" From d9f12731e1dfd5a30a6b664fafec531c81fb20b7 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 30 Jan 2020 07:53:31 +0000 Subject: [PATCH 217/788] Fix null tracer bug --- config/cmd/cmd.go | 1 + 1 file changed, 1 insertion(+) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 6972a8c0..e4e09f56 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -217,6 +217,7 @@ var ( Name: "tracer", EnvVars: []string{"MICRO_TRACER"}, Usage: "Tracer for distributed tracing, e.g. memory, jaeger", + Value: "memory", }, &cli.StringFlag{ Name: "tracer_address", From a648c0d99cde132e41a1ab333e593d1bd9feaedd Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Thu, 30 Jan 2020 10:27:21 +0000 Subject: [PATCH 218/788] Bump dep to fix platform web using new debug.Stats proto fields --- go.mod | 19 +---------- go.sum | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 8dfa1e41..a1b9bd89 100644 --- a/go.mod +++ b/go.mod @@ -6,38 +6,28 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/beevik/ntp v0.2.0 github.com/bitly/go-simplejson v0.5.0 - github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect github.com/bwmarrin/discordgo v0.20.2 - github.com/coreos/bbolt v1.3.3 // indirect github.com/coreos/etcd v3.3.18+incompatible - github.com/coreos/go-semver v0.3.0 // indirect - github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c github.com/fsnotify/fsnotify v1.4.7 github.com/fsouza/go-dockerclient v1.6.0 github.com/ghodss/yaml v1.0.0 github.com/go-acme/lego/v3 v3.3.0 - github.com/go-playground/universal-translator v0.17.0 // indirect - github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect - github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/websocket v1.4.1 - github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect - github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/hashicorp/hcl v1.0.0 github.com/imdario/mergo v0.3.8 - github.com/jonboulle/clockwork v0.1.0 // indirect github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 github.com/json-iterator/go v1.1.9 github.com/kr/pretty v0.1.0 - github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 github.com/mholt/certmagic v0.9.1 github.com/micro/cli/v2 v2.1.1 github.com/micro/mdns v0.3.0 + github.com/micro/micro v1.18.1-0.20200129112143-c64a2f7745fe // indirect github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 github.com/nats-io/nats-server/v2 v2.1.2 @@ -45,19 +35,12 @@ require ( github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/pkg/errors v0.9.1 - github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 - github.com/technoweenie/multipartstreamer v1.0.1 // indirect - github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect - github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect - go.etcd.io/bbolt v1.3.3 // indirect go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200117160349-530e935923ad golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa google.golang.org/grpc v1.26.0 - gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 - sigs.k8s.io/yaml v1.1.0 // indirect ) diff --git a/go.sum b/go.sum index 27172711..c6923077 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,10 @@ github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvd github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 h1:ygIc8M6trr62pF5DucadTWGdEB4mEyvzi0e2nbcmcyA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= +github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= @@ -64,6 +66,9 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= +github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= +github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= +github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= @@ -72,14 +77,21 @@ github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.10.2 h1:VBodKICVPnwmDxstcW3biKcDSpFIfS/RELUXsZSBYK4= github.com/cloudflare/cloudflare-go v0.10.2/go.mod h1:qhVI5MKwBGhdNU89ZRz2plgYutcJ5PCekLxXn56w6SY= +github.com/cloudflare/cloudflare-go v0.10.9 h1:d8KOgLpYiC+Xq3T4tuO+/goM+RZvuO+T4pojuv8giL8= +github.com/cloudflare/cloudflare-go v0.10.9/go.mod h1:5TrsWH+3f4NV6WjtS5QFp+DifH81rph40gU374Sh0dQ= github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko= github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0 h1:xjvXQWABwS2uiv3TWgQt5Uth60Gu86LTGZXMJkjc7rY= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= +github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVlf61smEIq1nwLLAjQVEK2EADoW3CX9AuT+8= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= @@ -88,12 +100,15 @@ github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDG github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c= +github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpu/goacmedns v0.0.1/go.mod h1:sesf/pNnCYwUevQEQfEwY0Y3DydlQWSGZbaMElOWxok= @@ -103,6 +118,7 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decker502/dnspod-go v0.2.0/go.mod h1:qsurYu1FgxcDwfSwXJdLt4kRsBLZeosEb9uq4Sy+08g= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= @@ -110,6 +126,7 @@ github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s9 github.com/dnsimple/dnsimple-go v0.30.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v1.4.2-0.20190710153559-aa8249ae1b8b/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23 h1:oqgGT9O61YAYvI41EBsLePOr+LE6roB0xY4gpkZuFSE= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= @@ -119,8 +136,11 @@ github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/eknkc/basex v1.0.0 h1:R2zGRGJAcqEES03GqHU9leUF5n4Pg6ahazPbSTQWCWc= +github.com/eknkc/basex v1.0.0/go.mod h1:k/F/exNEHFdbs3ZHuasoP2E7zeWwZblG84Y7Z59vQRo= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= @@ -129,14 +149,17 @@ github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjr github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXju1m8W4lnEeIqTHPOzhTUO81a7yknM/xQR4= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= +github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsouza/go-dockerclient v1.4.4/go.mod h1:PrwszSL5fbmsESocROrOGq/NULMXRw+bajY0ltzD6MA= github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4GGn3Hig= github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= +github.com/go-acme/lego/v3 v3.1.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= github.com/go-acme/lego/v3 v3.3.0 h1:6BePZsOiYA4/w+M7QDytxQtMfCipMPGnWAHs9pWks98= github.com/go-acme/lego/v3 v3.3.0/go.mod h1:iGSY2vQrvQs3WezicSB/oVbO2eCrD88dpWPwb1qLqu0= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= @@ -144,10 +167,13 @@ github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-log/log v0.1.0/go.mod h1:4mBwpdRMFLiuXZDCwU2lKQFsoSCo72j3HqBK9d81N2M= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -162,6 +188,7 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -183,12 +210,14 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -199,6 +228,7 @@ github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51 github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg= github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= @@ -210,7 +240,10 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92Bcuy github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.8.5 h1:2+KSC78XiO6Qy0hIjfc1OD9H+hsaJdJlb8Kqsd41CTE= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.9.2/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= +github.com/hako/branca v0.0.0-20180808000428-10b799466ada h1:RjbRG4Xq2N5UaUUL9/v+yGBhgLgQwlHk582Pr0j0g00= +github.com/hako/branca v0.0.0-20180808000428-10b799466ada/go.mod h1:tOPn4gvKEUWqIJNE+zpTeTALaRAXnrRqqSnPlO3VpEo= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -221,6 +254,7 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= +github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd/go.mod h1:3LVOLeyx9XVvwPgrt2be44XgSqndprz1G18rSk8KD84= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= @@ -258,33 +292,52 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= +github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ= +github.com/lucas-clemente/quic-go v0.12.1/go.mod h1:UXJJPE4RfFef/xPO5wQm0tITK8gNfqwTxjbE7s3Vb8s= github.com/lucas-clemente/quic-go v0.14.1 h1:c1aKoBZKOPA+49q96B1wGkibyPP0AxYh45WuAoq+87E= github.com/lucas-clemente/quic-go v0.14.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= +github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ= github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE= github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= +github.com/marten-seemann/qtls v0.3.2/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= +github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mholt/certmagic v0.7.5/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= github.com/mholt/certmagic v0.9.1 h1:wPzyouOyE+30NIQETJuhTB5ZQWz+0Hy038vaR5WWQDE= github.com/mholt/certmagic v0.9.1/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= +github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= +github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= github.com/micro/cli/v2 v2.1.1 h1:uFw0SMIKmGuyHIm8lXns/NOn7V62bM5y7DnlxUM+BEQ= github.com/micro/cli/v2 v2.1.1/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= +github.com/micro/go-micro v1.16.0/go.mod h1:A0F58bHLh2m0LAI9QyhvmbN8c1cxhAZo3cM6s+iDsrM= +github.com/micro/go-micro v1.18.1-0.20200126191206-1108cc5e91fd/go.mod h1:0+5RR/STHnkuTUsHpJqRh66M5RZNlYqEkf85cKlnRdc= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= +github.com/micro/micro v1.18.1-0.20200129112143-c64a2f7745fe h1:7wltlc6/cQmh7RGLA1jnRUsxB0kbu9HFh/u2o6yMVcA= +github.com/micro/micro v1.18.1-0.20200129112143-c64a2f7745fe/go.mod h1:MMXpJO0CpKHOk2myP+DF06FfHJlbI465OjXjBbI5Rhc= +github.com/micro/protoc-gen-micro v1.0.0/go.mod h1:C8ij4DJhapBmypcT00AXdb0cZ675/3PqUO02buWWqbE= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -306,16 +359,21 @@ github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= +github.com/nats-io/nats-server/v2 v2.1.0/go.mod h1:r5y0WgCag0dTj/qiHkHrXAcKQ/f5GMOZaEGdoxxnJ4I= github.com/nats-io/nats-server/v2 v2.1.2 h1:i2Ly0B+1+rzNZHHWtD4ZwKi+OU5l+uQo1iDHZ2PmiIc= github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= +github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= +github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= +github.com/netdata/go-orchestrator v0.0.0-20190905093727-c793edba0e8f/go.mod h1:ECF8anFVCt/TfTIWVPgPrNaYJXtAtpAOF62ugDbw41A= +github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= @@ -323,11 +381,16 @@ github.com/nrdcg/dnspod-go v0.3.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgP github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2SwKQ= github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/olekukonko/tablewriter v0.0.3/go.mod h1:YZeBtGzYYEsCHp2LST/u/0NDwGkRoBtmn1cIWCJiS6M= +github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8= +github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= @@ -344,6 +407,9 @@ github.com/oracle/oci-go-sdk v7.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukw github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014/go.mod h1:joRatxRJaZBsY3JAOEMcoOp05CnZzsx4scTxi95DHyQ= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= +github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= +github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g= +github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -352,6 +418,7 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pquerna/otp v1.2.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= @@ -380,6 +447,8 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sacloud/libsacloud v1.26.1/go.mod h1:79ZwATmHLIFZIMd7sxA3LwzVy/B77uj3LDoToVTxDoQ= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516 h1:ofR1ZdrNSkiWcMsRrubK9tb2/SlZVWttAfqUjJi6QYc= +github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= @@ -390,6 +459,7 @@ github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= @@ -406,12 +476,14 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc h1:yUaosFVTJwnltaHbSNC3i82I92quFs+OFPRl8kNMVwo= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= @@ -421,6 +493,8 @@ github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca h1:1CFlNzQhALwjS9mBAUkycX616GzgsuYUOCHA5+HSlXI= +github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= @@ -432,6 +506,7 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.2.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= @@ -443,17 +518,22 @@ go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg= golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -498,12 +578,16 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -522,6 +606,8 @@ golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -531,12 +617,16 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 h1:Hynbrlo6LbYI3H1IqXpkVDOcX/3HiPdhVEuyj5a59RM= +golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= @@ -545,6 +635,8 @@ golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 h1:xQwXv67TxFo9nC1GJFyab5eq/5B590r6RlnL/G8Sz7w= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -562,6 +654,7 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -592,6 +685,7 @@ google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1 h1:aQktFqmDE2yjveXJlVIfslDFmFnUXSqG0i6KRcJAeMc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= @@ -601,9 +695,12 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -612,12 +709,15 @@ gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ns1/ns1-go.v2 v2.0.0-20190730140822-b51389932cbc/go.mod h1:VV+3haRsgDiVLxyifmMBrBIuCWFBPYKbRssXB9z67Hw= +gopkg.in/olivere/elastic.v5 v5.0.83/go.mod h1:LXF6q9XNBxpMqrcgax95C6xyARXWbbCXUrtTxrNrxJI= gopkg.in/resty.v1 v1.9.1/go.mod h1:vo52Hzryw9PnPHcJfPsBiFW62XhNx5OczbV9y+IMpgc= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4= From 2b1e0a6fd672160cd3c698d4cf35fd2063e5cfdc Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 30 Jan 2020 10:33:40 +0000 Subject: [PATCH 219/788] go mod tidy --- go.mod | 19 ++++++++++- go.sum | 99 ---------------------------------------------------------- 2 files changed, 18 insertions(+), 100 deletions(-) diff --git a/go.mod b/go.mod index a1b9bd89..8dfa1e41 100644 --- a/go.mod +++ b/go.mod @@ -6,28 +6,38 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/beevik/ntp v0.2.0 github.com/bitly/go-simplejson v0.5.0 + github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect github.com/bwmarrin/discordgo v0.20.2 + github.com/coreos/bbolt v1.3.3 // indirect github.com/coreos/etcd v3.3.18+incompatible + github.com/coreos/go-semver v0.3.0 // indirect + github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c github.com/fsnotify/fsnotify v1.4.7 github.com/fsouza/go-dockerclient v1.6.0 github.com/ghodss/yaml v1.0.0 github.com/go-acme/lego/v3 v3.3.0 + github.com/go-playground/universal-translator v0.17.0 // indirect + github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect + github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/websocket v1.4.1 + github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect + github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/hashicorp/hcl v1.0.0 github.com/imdario/mergo v0.3.8 + github.com/jonboulle/clockwork v0.1.0 // indirect github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 github.com/json-iterator/go v1.1.9 github.com/kr/pretty v0.1.0 + github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 github.com/mholt/certmagic v0.9.1 github.com/micro/cli/v2 v2.1.1 github.com/micro/mdns v0.3.0 - github.com/micro/micro v1.18.1-0.20200129112143-c64a2f7745fe // indirect github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 github.com/nats-io/nats-server/v2 v2.1.2 @@ -35,12 +45,19 @@ require ( github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/pkg/errors v0.9.1 + github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 + github.com/technoweenie/multipartstreamer v1.0.1 // indirect + github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect + github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect + go.etcd.io/bbolt v1.3.3 // indirect go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200117160349-530e935923ad golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa google.golang.org/grpc v1.26.0 + gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 + sigs.k8s.io/yaml v1.1.0 // indirect ) diff --git a/go.sum b/go.sum index c6923077..05236368 100644 --- a/go.sum +++ b/go.sum @@ -30,10 +30,8 @@ github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvd github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 h1:ygIc8M6trr62pF5DucadTWGdEB4mEyvzi0e2nbcmcyA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= -github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= @@ -66,9 +64,6 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= -github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= -github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= -github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= @@ -77,21 +72,14 @@ github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.10.2 h1:VBodKICVPnwmDxstcW3biKcDSpFIfS/RELUXsZSBYK4= github.com/cloudflare/cloudflare-go v0.10.2/go.mod h1:qhVI5MKwBGhdNU89ZRz2plgYutcJ5PCekLxXn56w6SY= -github.com/cloudflare/cloudflare-go v0.10.9 h1:d8KOgLpYiC+Xq3T4tuO+/goM+RZvuO+T4pojuv8giL8= -github.com/cloudflare/cloudflare-go v0.10.9/go.mod h1:5TrsWH+3f4NV6WjtS5QFp+DifH81rph40gU374Sh0dQ= github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko= github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0 h1:xjvXQWABwS2uiv3TWgQt5Uth60Gu86LTGZXMJkjc7rY= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= -github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVlf61smEIq1nwLLAjQVEK2EADoW3CX9AuT+8= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= @@ -100,15 +88,12 @@ github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDG github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c= -github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpu/goacmedns v0.0.1/go.mod h1:sesf/pNnCYwUevQEQfEwY0Y3DydlQWSGZbaMElOWxok= @@ -118,7 +103,6 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/decker502/dnspod-go v0.2.0/go.mod h1:qsurYu1FgxcDwfSwXJdLt4kRsBLZeosEb9uq4Sy+08g= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= @@ -126,7 +110,6 @@ github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s9 github.com/dnsimple/dnsimple-go v0.30.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v1.4.2-0.20190710153559-aa8249ae1b8b/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23 h1:oqgGT9O61YAYvI41EBsLePOr+LE6roB0xY4gpkZuFSE= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= @@ -136,11 +119,8 @@ github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= -github.com/eknkc/basex v1.0.0 h1:R2zGRGJAcqEES03GqHU9leUF5n4Pg6ahazPbSTQWCWc= -github.com/eknkc/basex v1.0.0/go.mod h1:k/F/exNEHFdbs3ZHuasoP2E7zeWwZblG84Y7Z59vQRo= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= @@ -149,17 +129,14 @@ github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjr github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXju1m8W4lnEeIqTHPOzhTUO81a7yknM/xQR4= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= -github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsouza/go-dockerclient v1.4.4/go.mod h1:PrwszSL5fbmsESocROrOGq/NULMXRw+bajY0ltzD6MA= github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4GGn3Hig= github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= -github.com/go-acme/lego/v3 v3.1.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= github.com/go-acme/lego/v3 v3.3.0 h1:6BePZsOiYA4/w+M7QDytxQtMfCipMPGnWAHs9pWks98= github.com/go-acme/lego/v3 v3.3.0/go.mod h1:iGSY2vQrvQs3WezicSB/oVbO2eCrD88dpWPwb1qLqu0= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= @@ -167,13 +144,10 @@ github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-log/log v0.1.0/go.mod h1:4mBwpdRMFLiuXZDCwU2lKQFsoSCo72j3HqBK9d81N2M= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -188,7 +162,6 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -210,14 +183,12 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -240,10 +211,7 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92Bcuy github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.8.5 h1:2+KSC78XiO6Qy0hIjfc1OD9H+hsaJdJlb8Kqsd41CTE= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/grpc-ecosystem/grpc-gateway v1.9.2/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= -github.com/hako/branca v0.0.0-20180808000428-10b799466ada h1:RjbRG4Xq2N5UaUUL9/v+yGBhgLgQwlHk582Pr0j0g00= -github.com/hako/branca v0.0.0-20180808000428-10b799466ada/go.mod h1:tOPn4gvKEUWqIJNE+zpTeTALaRAXnrRqqSnPlO3VpEo= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -254,7 +222,6 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= -github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd/go.mod h1:3LVOLeyx9XVvwPgrt2be44XgSqndprz1G18rSk8KD84= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= @@ -292,52 +259,33 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= -github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ= -github.com/lucas-clemente/quic-go v0.12.1/go.mod h1:UXJJPE4RfFef/xPO5wQm0tITK8gNfqwTxjbE7s3Vb8s= github.com/lucas-clemente/quic-go v0.14.1 h1:c1aKoBZKOPA+49q96B1wGkibyPP0AxYh45WuAoq+87E= github.com/lucas-clemente/quic-go v0.14.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= -github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ= github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE= github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= -github.com/marten-seemann/qtls v0.3.2/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= -github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mholt/certmagic v0.7.5/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= github.com/mholt/certmagic v0.9.1 h1:wPzyouOyE+30NIQETJuhTB5ZQWz+0Hy038vaR5WWQDE= github.com/mholt/certmagic v0.9.1/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= -github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= -github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= github.com/micro/cli/v2 v2.1.1 h1:uFw0SMIKmGuyHIm8lXns/NOn7V62bM5y7DnlxUM+BEQ= github.com/micro/cli/v2 v2.1.1/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= -github.com/micro/go-micro v1.16.0/go.mod h1:A0F58bHLh2m0LAI9QyhvmbN8c1cxhAZo3cM6s+iDsrM= -github.com/micro/go-micro v1.18.1-0.20200126191206-1108cc5e91fd/go.mod h1:0+5RR/STHnkuTUsHpJqRh66M5RZNlYqEkf85cKlnRdc= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= -github.com/micro/micro v1.18.1-0.20200129112143-c64a2f7745fe h1:7wltlc6/cQmh7RGLA1jnRUsxB0kbu9HFh/u2o6yMVcA= -github.com/micro/micro v1.18.1-0.20200129112143-c64a2f7745fe/go.mod h1:MMXpJO0CpKHOk2myP+DF06FfHJlbI465OjXjBbI5Rhc= -github.com/micro/protoc-gen-micro v1.0.0/go.mod h1:C8ij4DJhapBmypcT00AXdb0cZ675/3PqUO02buWWqbE= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -359,21 +307,16 @@ github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server/v2 v2.1.0/go.mod h1:r5y0WgCag0dTj/qiHkHrXAcKQ/f5GMOZaEGdoxxnJ4I= github.com/nats-io/nats-server/v2 v2.1.2 h1:i2Ly0B+1+rzNZHHWtD4ZwKi+OU5l+uQo1iDHZ2PmiIc= github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= -github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= -github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= -github.com/netdata/go-orchestrator v0.0.0-20190905093727-c793edba0e8f/go.mod h1:ECF8anFVCt/TfTIWVPgPrNaYJXtAtpAOF62ugDbw41A= -github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= @@ -381,16 +324,11 @@ github.com/nrdcg/dnspod-go v0.3.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgP github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2SwKQ= github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= -github.com/olekukonko/tablewriter v0.0.3/go.mod h1:YZeBtGzYYEsCHp2LST/u/0NDwGkRoBtmn1cIWCJiS6M= -github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8= -github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= @@ -407,9 +345,6 @@ github.com/oracle/oci-go-sdk v7.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukw github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014/go.mod h1:joRatxRJaZBsY3JAOEMcoOp05CnZzsx4scTxi95DHyQ= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= -github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= -github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g= -github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -418,7 +353,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/pquerna/otp v1.2.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= @@ -447,8 +381,6 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sacloud/libsacloud v1.26.1/go.mod h1:79ZwATmHLIFZIMd7sxA3LwzVy/B77uj3LDoToVTxDoQ= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516 h1:ofR1ZdrNSkiWcMsRrubK9tb2/SlZVWttAfqUjJi6QYc= -github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= @@ -459,7 +391,6 @@ github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= @@ -476,14 +407,12 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc h1:yUaosFVTJwnltaHbSNC3i82I92quFs+OFPRl8kNMVwo= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= @@ -493,8 +422,6 @@ github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca h1:1CFlNzQhALwjS9mBAUkycX616GzgsuYUOCHA5+HSlXI= -github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= @@ -506,7 +433,6 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.2.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= @@ -518,22 +444,17 @@ go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg= golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -578,16 +499,12 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -606,8 +523,6 @@ golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -617,16 +532,12 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 h1:Hynbrlo6LbYI3H1IqXpkVDOcX/3HiPdhVEuyj5a59RM= -golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= @@ -635,8 +546,6 @@ golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 h1:xQwXv67TxFo9nC1GJFyab5eq/5B590r6RlnL/G8Sz7w= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -654,7 +563,6 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -685,7 +593,6 @@ google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1 h1:aQktFqmDE2yjveXJlVIfslDFmFnUXSqG0i6KRcJAeMc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= @@ -695,12 +602,9 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= -gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -709,15 +613,12 @@ gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= -gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= -gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ns1/ns1-go.v2 v2.0.0-20190730140822-b51389932cbc/go.mod h1:VV+3haRsgDiVLxyifmMBrBIuCWFBPYKbRssXB9z67Hw= -gopkg.in/olivere/elastic.v5 v5.0.83/go.mod h1:LXF6q9XNBxpMqrcgax95C6xyARXWbbCXUrtTxrNrxJI= gopkg.in/resty.v1 v1.9.1/go.mod h1:vo52Hzryw9PnPHcJfPsBiFW62XhNx5OczbV9y+IMpgc= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4= From f23638c0360a542c1b814d5ef3429439ba6d8807 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 30 Jan 2020 14:39:00 +0300 Subject: [PATCH 220/788] fix import paths for v2 release Signed-off-by: Vasiliy Tolstov --- agent/input/discord/conn.go | 4 +- agent/input/discord/discord.go | 2 +- agent/input/slack/conn.go | 2 +- agent/input/slack/slack.go | 2 +- agent/input/telegram/conn.go | 4 +- agent/input/telegram/telegram.go | 2 +- agent/proto/bot.pb.go | 4 +- agent/proto/bot.pb.micro.go | 6 +- api/api.go | 4 +- api/handler/api/api.go | 14 ++--- api/handler/api/util.go | 6 +- api/handler/broker/broker.go | 6 +- api/handler/cloudevents/cloudevents.go | 4 +- api/handler/event/event.go | 6 +- api/handler/http/http.go | 6 +- api/handler/http/http_test.go | 10 +-- api/handler/options.go | 4 +- api/handler/registry/registry.go | 4 +- api/handler/rpc/rpc.go | 22 +++---- api/handler/rpc/rpc_test.go | 2 +- api/handler/web/web.go | 6 +- api/proto/api.pb.go | 4 +- api/proto/api.pb.micro.go | 2 +- api/resolver/grpc/grpc.go | 2 +- api/resolver/host/host.go | 2 +- api/resolver/micro/micro.go | 2 +- api/resolver/path/path.go | 2 +- api/resolver/vpath/vpath.go | 2 +- api/router/options.go | 6 +- api/router/registry/registry.go | 8 +-- api/router/registry/registry_test.go | 2 +- api/router/router.go | 2 +- api/server/acme/autocert/autocert.go | 2 +- api/server/acme/certmagic/certmagic.go | 2 +- api/server/acme/certmagic/certmagic_test.go | 6 +- api/server/acme/certmagic/storage.go | 4 +- api/server/http/http.go | 4 +- api/server/options.go | 2 +- broker/default.go | 8 +-- broker/memory/memory.go | 6 +- broker/memory/memory_test.go | 2 +- broker/nats/context.go | 2 +- broker/nats/nats.go | 10 +-- broker/nats/nats_test.go | 2 +- broker/nats/options.go | 2 +- broker/options.go | 4 +- broker/service/proto/broker.pb.micro.go | 4 +- broker/service/service.go | 8 +-- broker/service/subscriber.go | 6 +- client/client.go | 2 +- client/common_test.go | 2 +- client/grpc/codec.go | 4 +- client/grpc/error.go | 2 +- client/grpc/grpc.go | 14 ++--- client/grpc/grpc_test.go | 8 +-- client/grpc/message.go | 2 +- client/grpc/options.go | 2 +- client/grpc/request.go | 4 +- client/grpc/response.go | 4 +- client/grpc/stream.go | 2 +- client/mucp/mucp.go | 2 +- client/options.go | 10 +-- client/options_test.go | 2 +- client/retry.go | 2 +- client/rpc_client.go | 20 +++--- client/rpc_client_test.go | 8 +-- client/rpc_codec.go | 20 +++--- client/rpc_request.go | 2 +- client/rpc_response.go | 4 +- client/rpc_stream.go | 2 +- client/selector/common_test.go | 2 +- client/selector/default.go | 4 +- client/selector/default_test.go | 2 +- client/selector/dns/dns.go | 4 +- client/selector/filter.go | 2 +- client/selector/filter_test.go | 2 +- client/selector/options.go | 2 +- client/selector/registry/options.go | 2 +- client/selector/registry/registry.go | 2 +- client/selector/router/router.go | 10 +-- client/selector/selector.go | 2 +- client/selector/static/static.go | 4 +- client/selector/strategy.go | 2 +- client/selector/strategy_test.go | 2 +- client/service/proto/client.pb.go | 4 +- client/service/proto/client.pb.micro.go | 6 +- client/wrapper.go | 2 +- codec/bytes/bytes.go | 2 +- codec/grpc/grpc.go | 2 +- codec/json/json.go | 2 +- codec/jsonrpc/client.go | 2 +- codec/jsonrpc/jsonrpc.go | 2 +- codec/jsonrpc/server.go | 2 +- codec/proto/proto.go | 2 +- codec/protorpc/protorpc.go | 2 +- codec/text/text.go | 2 +- config/cmd/cmd.go | 62 +++++++++---------- config/cmd/options.go | 18 +++--- config/config.go | 8 +-- config/default.go | 10 +-- config/default_test.go | 4 +- config/encoder/hcl/hcl.go | 2 +- config/encoder/json/json.go | 2 +- config/encoder/toml/toml.go | 2 +- config/encoder/xml/xml.go | 2 +- config/encoder/yaml/yaml.go | 2 +- config/loader/loader.go | 4 +- config/loader/memory/memory.go | 8 +-- config/loader/memory/options.go | 6 +- config/options.go | 6 +- config/reader/json/json.go | 8 +-- config/reader/json/json_test.go | 2 +- config/reader/json/values.go | 4 +- config/reader/json/values_test.go | 2 +- config/reader/options.go | 12 ++-- config/reader/reader.go | 2 +- config/source/cli/cli.go | 4 +- config/source/cli/cli_test.go | 4 +- config/source/cli/options.go | 2 +- config/source/env/env.go | 2 +- config/source/env/env_test.go | 2 +- config/source/env/options.go | 2 +- config/source/env/watcher.go | 2 +- config/source/etcd/etcd.go | 2 +- config/source/etcd/options.go | 2 +- config/source/etcd/util.go | 2 +- config/source/etcd/watcher.go | 2 +- config/source/file/file.go | 2 +- config/source/file/format.go | 2 +- config/source/file/format_test.go | 2 +- config/source/file/options.go | 2 +- config/source/file/watcher.go | 2 +- config/source/file/watcher_linux.go | 2 +- config/source/flag/flag.go | 2 +- config/source/flag/options.go | 2 +- config/source/memory/memory.go | 2 +- config/source/memory/options.go | 2 +- config/source/memory/watcher.go | 2 +- config/source/options.go | 4 +- config/source/service/options.go | 2 +- .../source/service/proto/service.pb.micro.go | 4 +- config/source/service/service.go | 8 +-- config/source/service/util.go | 4 +- config/source/service/watcher.go | 4 +- config/value.go | 2 +- debug/log/kubernetes/kubernetes.go | 6 +- debug/log/kubernetes/kubernetes_test.go | 2 +- debug/log/kubernetes/stream.go | 2 +- debug/log/memory/memory.go | 4 +- debug/log/memory/memory_test.go | 2 +- debug/log/memory/stream.go | 2 +- debug/log/noop/noop.go | 2 +- debug/log/os.go | 2 +- debug/profile/http/http.go | 2 +- debug/profile/pprof/pprof.go | 2 +- debug/service/client.go | 6 +- debug/service/handler/debug.go | 10 +-- debug/service/proto/debug.pb.micro.go | 4 +- debug/service/service.go | 4 +- debug/service/stream.go | 2 +- debug/stats/default.go | 2 +- debug/trace/memory/memory.go | 4 +- defaults.go | 16 ++--- event.go | 2 +- function.go | 2 +- function_test.go | 6 +- go.mod | 18 +----- go.sum | 58 +++++++++++++++++ micro.go | 4 +- monitor/default.go | 8 +-- monitor/options.go | 4 +- network/default.go | 34 +++++----- network/network.go | 4 +- network/node.go | 2 +- network/node_test.go | 2 +- network/options.go | 12 ++-- network/resolver/dns/dns.go | 2 +- network/resolver/dnssrv/dnssrv.go | 2 +- network/resolver/http/http.go | 2 +- network/resolver/registry/registry.go | 4 +- network/resolver/static/static.go | 2 +- network/service/proto/network.pb.go | 2 +- network/service/proto/network.pb.micro.go | 6 +- options.go | 16 ++--- plugin/default.go | 14 ++--- plugin/template.go | 2 +- proxy/grpc/grpc.go | 10 +-- proxy/http/http.go | 6 +- proxy/http/http_test.go | 8 +-- proxy/mucp/mucp.go | 20 +++--- proxy/options.go | 4 +- proxy/proxy.go | 2 +- registry/cache/cache.go | 4 +- registry/etcd/etcd.go | 4 +- registry/etcd/options.go | 2 +- registry/etcd/watcher.go | 2 +- registry/kubernetes/kubernetes.go | 4 +- registry/kubernetes/watcher.go | 6 +- registry/mdns/mdns.go | 2 +- registry/memory/memory.go | 4 +- registry/memory/memory_test.go | 2 +- registry/memory/memory_watcher.go | 2 +- registry/memory/options.go | 2 +- registry/memory/util.go | 2 +- registry/memory/watcher.go | 2 +- registry/memory/watcher_test.go | 2 +- registry/service/proto/registry.pb.micro.go | 4 +- registry/service/service.go | 8 +-- registry/service/util.go | 4 +- registry/service/watcher.go | 4 +- router/default.go | 4 +- router/default_test.go | 4 +- router/options.go | 4 +- router/service/proto/router.pb.micro.go | 4 +- router/service/service.go | 6 +- router/service/table.go | 6 +- router/service/watcher.go | 4 +- router/table.go | 2 +- runtime/default.go | 2 +- runtime/kubernetes/kubernetes.go | 6 +- runtime/kubernetes/service.go | 8 +-- runtime/local/build/build.go | 2 +- runtime/local/build/docker/docker.go | 4 +- runtime/local/build/go/golang.go | 2 +- runtime/local/process/os/os.go | 2 +- runtime/local/process/os/os_windows.go | 2 +- runtime/local/process/os/process.go | 2 +- runtime/local/process/process.go | 2 +- runtime/local/source/git/git.go | 2 +- runtime/local/source/go/golang.go | 2 +- runtime/service.go | 8 +-- runtime/service/proto/runtime.pb.micro.go | 4 +- runtime/service/service.go | 6 +- server/extractor.go | 2 +- server/extractor_test.go | 2 +- server/grpc/codec.go | 8 +-- server/grpc/error.go | 2 +- server/grpc/extractor.go | 2 +- server/grpc/extractor_test.go | 2 +- server/grpc/grpc.go | 20 +++--- server/grpc/grpc_test.go | 6 +- server/grpc/handler.go | 4 +- server/grpc/options.go | 10 +-- server/grpc/proto/test.micro.go | 4 +- server/grpc/request.go | 4 +- server/grpc/response.go | 2 +- server/grpc/server.go | 4 +- server/grpc/stream.go | 2 +- server/grpc/subscriber.go | 12 ++-- server/mock/mock.go | 2 +- server/mock/mock_handler.go | 4 +- server/mock/mock_subscriber.go | 4 +- server/mock/mock_test.go | 2 +- server/mucp/mucp.go | 2 +- server/options.go | 10 +-- server/proto/server.pb.go | 4 +- server/proto/server.pb.micro.go | 6 +- server/rpc_codec.go | 16 ++--- server/rpc_codec_test.go | 4 +- server/rpc_event.go | 4 +- server/rpc_handler.go | 2 +- server/rpc_request.go | 6 +- server/rpc_response.go | 4 +- server/rpc_router.go | 6 +- server/rpc_server.go | 20 +++--- server/rpc_stream.go | 2 +- server/rpc_stream_test.go | 4 +- server/server.go | 6 +- server/subscriber.go | 2 +- service.go | 24 +++---- service/grpc/grpc.go | 10 +-- service/grpc/grpc_test.go | 8 +-- service/grpc/options.go | 6 +- service/grpc/proto/test.micro.go | 4 +- service/mucp/mucp.go | 10 +-- service/options.go | 10 +-- service/service.go | 4 +- service_test.go | 12 ++-- store/cloudflare/cloudflare.go | 2 +- store/cloudflare/cloudflare_test.go | 2 +- store/cloudflare/options.go | 2 +- store/cockroach/cockroach.go | 4 +- store/cockroach/cockroach_test.go | 2 +- store/etcd/etcd.go | 2 +- store/memory/memory.go | 2 +- store/memory/memory_test.go | 2 +- store/service/proto/store.pb.micro.go | 4 +- store/service/service.go | 8 +-- sync/cron.go | 8 +-- sync/leader/etcd/etcd.go | 2 +- sync/lock/etcd/etcd.go | 2 +- sync/lock/http/http.go | 2 +- sync/lock/http/server/server.go | 4 +- sync/lock/memory/memory.go | 2 +- sync/map.go | 6 +- sync/options.go | 8 +-- sync/sync.go | 10 +-- sync/task/broker/broker.go | 4 +- sync/task/local/local.go | 2 +- sync/time/local/local.go | 2 +- sync/time/ntp/ntp.go | 2 +- transport/grpc/grpc.go | 10 +-- transport/grpc/grpc_test.go | 2 +- transport/grpc/handler.go | 8 +-- transport/grpc/proto/transport.micro.go | 4 +- transport/grpc/socket.go | 4 +- transport/http/http.go | 2 +- transport/http/http_test.go | 2 +- transport/http/options.go | 2 +- transport/http_transport.go | 8 +-- transport/memory/memory.go | 6 +- transport/memory/memory_test.go | 2 +- transport/options.go | 2 +- transport/quic/quic.go | 4 +- tunnel/broker/broker.go | 6 +- tunnel/default.go | 4 +- tunnel/link.go | 4 +- tunnel/listener.go | 2 +- tunnel/options.go | 4 +- tunnel/session.go | 4 +- tunnel/transport/listener.go | 4 +- tunnel/transport/transport.go | 4 +- tunnel/tunnel.go | 2 +- tunnel/tunnel_test.go | 2 +- util/ctx/ctx.go | 2 +- util/ctx/ctx_test.go | 2 +- util/http/http.go | 4 +- util/http/http_test.go | 4 +- util/http/options.go | 2 +- util/http/roundtripper.go | 2 +- util/io/io.go | 2 +- util/kubernetes/client/client.go | 4 +- util/kubernetes/client/watch.go | 2 +- util/log/log.go | 2 +- util/mux/mux.go | 6 +- util/pool/default.go | 2 +- util/pool/default_test.go | 4 +- util/pool/options.go | 2 +- util/pool/pool.go | 2 +- util/proto/proto.go | 4 +- util/socket/socket.go | 2 +- util/test/test.go | 2 +- util/wrapper/wrapper.go | 10 +-- util/wrapper/wrapper_test.go | 2 +- web/options.go | 4 +- web/service.go | 14 ++--- web/service_test.go | 4 +- 347 files changed, 864 insertions(+), 820 deletions(-) diff --git a/agent/input/discord/conn.go b/agent/input/discord/conn.go index cadc69d0..c7ca09ba 100644 --- a/agent/input/discord/conn.go +++ b/agent/input/discord/conn.go @@ -6,8 +6,8 @@ import ( "sync" "github.com/bwmarrin/discordgo" - "github.com/micro/go-micro/agent/input" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/agent/input" + "github.com/micro/go-micro/v2/util/log" ) type discordConn struct { diff --git a/agent/input/discord/discord.go b/agent/input/discord/discord.go index f30a45b8..3c25f568 100644 --- a/agent/input/discord/discord.go +++ b/agent/input/discord/discord.go @@ -9,7 +9,7 @@ import ( "github.com/bwmarrin/discordgo" "github.com/micro/cli/v2" - "github.com/micro/go-micro/agent/input" + "github.com/micro/go-micro/v2/agent/input" ) func init() { diff --git a/agent/input/slack/conn.go b/agent/input/slack/conn.go index ee640922..1bc4bbdb 100644 --- a/agent/input/slack/conn.go +++ b/agent/input/slack/conn.go @@ -7,7 +7,7 @@ import ( "sync" "time" - "github.com/micro/go-micro/agent/input" + "github.com/micro/go-micro/v2/agent/input" "github.com/nlopes/slack" ) diff --git a/agent/input/slack/slack.go b/agent/input/slack/slack.go index 53472c87..1475f23a 100644 --- a/agent/input/slack/slack.go +++ b/agent/input/slack/slack.go @@ -5,7 +5,7 @@ import ( "sync" "github.com/micro/cli/v2" - "github.com/micro/go-micro/agent/input" + "github.com/micro/go-micro/v2/agent/input" "github.com/nlopes/slack" ) diff --git a/agent/input/telegram/conn.go b/agent/input/telegram/conn.go index 78a8ff3a..9dd594c8 100644 --- a/agent/input/telegram/conn.go +++ b/agent/input/telegram/conn.go @@ -6,8 +6,8 @@ import ( "sync" "github.com/forestgiant/sliceutil" - "github.com/micro/go-micro/agent/input" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/agent/input" + "github.com/micro/go-micro/v2/util/log" tgbotapi "gopkg.in/telegram-bot-api.v4" ) diff --git a/agent/input/telegram/telegram.go b/agent/input/telegram/telegram.go index f7839714..c0fff91b 100644 --- a/agent/input/telegram/telegram.go +++ b/agent/input/telegram/telegram.go @@ -6,7 +6,7 @@ import ( "sync" "github.com/micro/cli/v2" - "github.com/micro/go-micro/agent/input" + "github.com/micro/go-micro/v2/agent/input" tgbotapi "gopkg.in/telegram-bot-api.v4" ) diff --git a/agent/proto/bot.pb.go b/agent/proto/bot.pb.go index b51da305..db35f945 100644 --- a/agent/proto/bot.pb.go +++ b/agent/proto/bot.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/agent/proto/bot.proto +// source: github.com/micro/go-micro/v2/agent/proto/bot.proto package go_micro_bot @@ -192,7 +192,7 @@ func init() { } func init() { - proto.RegisterFile("github.com/micro/go-micro/agent/proto/bot.proto", fileDescriptor_018e8d5b14a89d12) + proto.RegisterFile("github.com/micro/go-micro/v2/agent/proto/bot.proto", fileDescriptor_018e8d5b14a89d12) } var fileDescriptor_018e8d5b14a89d12 = []byte{ diff --git a/agent/proto/bot.pb.micro.go b/agent/proto/bot.pb.micro.go index 1c04fe59..61e678db 100644 --- a/agent/proto/bot.pb.micro.go +++ b/agent/proto/bot.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/agent/proto/bot.proto +// source: github.com/micro/go-micro/v2/agent/proto/bot.proto package go_micro_bot @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/api/api.go b/api/api.go index 160c2dfd..f04d67e0 100644 --- a/api/api.go +++ b/api/api.go @@ -5,8 +5,8 @@ import ( "regexp" "strings" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/server" ) // Endpoint is a mapping between an RPC method and HTTP endpoint diff --git a/api/handler/api/api.go b/api/handler/api/api.go index 0798f337..7a14fb4f 100644 --- a/api/handler/api/api.go +++ b/api/handler/api/api.go @@ -4,13 +4,13 @@ package api import ( "net/http" - goapi "github.com/micro/go-micro/api" - "github.com/micro/go-micro/api/handler" - api "github.com/micro/go-micro/api/proto" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/util/ctx" + goapi "github.com/micro/go-micro/v2/api" + "github.com/micro/go-micro/v2/api/handler" + api "github.com/micro/go-micro/v2/api/proto" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/util/ctx" ) type apiHandler struct { diff --git a/api/handler/api/util.go b/api/handler/api/util.go index 824ec5da..f66f611b 100644 --- a/api/handler/api/util.go +++ b/api/handler/api/util.go @@ -8,9 +8,9 @@ import ( "net/http" "strings" - api "github.com/micro/go-micro/api/proto" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/registry" + api "github.com/micro/go-micro/v2/api/proto" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/registry" ) func requestToProto(r *http.Request) (*api.Request, error) { diff --git a/api/handler/broker/broker.go b/api/handler/broker/broker.go index 2d2905d9..bf4ccf60 100644 --- a/api/handler/broker/broker.go +++ b/api/handler/broker/broker.go @@ -11,9 +11,9 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/micro/go-micro/api/handler" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/api/handler" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/util/log" ) const ( diff --git a/api/handler/cloudevents/cloudevents.go b/api/handler/cloudevents/cloudevents.go index 9b4a6293..2eec44ef 100644 --- a/api/handler/cloudevents/cloudevents.go +++ b/api/handler/cloudevents/cloudevents.go @@ -7,8 +7,8 @@ import ( "regexp" "strings" - "github.com/micro/go-micro/api/handler" - "github.com/micro/go-micro/util/ctx" + "github.com/micro/go-micro/v2/api/handler" + "github.com/micro/go-micro/v2/util/ctx" ) type event struct { diff --git a/api/handler/event/event.go b/api/handler/event/event.go index 8eb65aa1..a819d947 100644 --- a/api/handler/event/event.go +++ b/api/handler/event/event.go @@ -12,9 +12,9 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/api/handler" - proto "github.com/micro/go-micro/api/proto" - "github.com/micro/go-micro/util/ctx" + "github.com/micro/go-micro/v2/api/handler" + proto "github.com/micro/go-micro/v2/api/proto" + "github.com/micro/go-micro/v2/util/ctx" ) type event struct { diff --git a/api/handler/http/http.go b/api/handler/http/http.go index ad2b1c66..52108a40 100644 --- a/api/handler/http/http.go +++ b/api/handler/http/http.go @@ -8,9 +8,9 @@ import ( "net/http/httputil" "net/url" - "github.com/micro/go-micro/api" - "github.com/micro/go-micro/api/handler" - "github.com/micro/go-micro/client/selector" + "github.com/micro/go-micro/v2/api" + "github.com/micro/go-micro/v2/api/handler" + "github.com/micro/go-micro/v2/client/selector" ) const ( diff --git a/api/handler/http/http_test.go b/api/handler/http/http_test.go index 608b521f..6f094874 100644 --- a/api/handler/http/http_test.go +++ b/api/handler/http/http_test.go @@ -6,11 +6,11 @@ import ( "net/http/httptest" "testing" - "github.com/micro/go-micro/api/handler" - "github.com/micro/go-micro/api/router" - regRouter "github.com/micro/go-micro/api/router/registry" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/registry/memory" + "github.com/micro/go-micro/v2/api/handler" + "github.com/micro/go-micro/v2/api/router" + regRouter "github.com/micro/go-micro/v2/api/router/registry" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/registry/memory" ) func testHttp(t *testing.T, path, service, ns string) { diff --git a/api/handler/options.go b/api/handler/options.go index 6ce0f99a..d7403270 100644 --- a/api/handler/options.go +++ b/api/handler/options.go @@ -1,8 +1,8 @@ package handler import ( - "github.com/micro/go-micro" - "github.com/micro/go-micro/api/router" + "github.com/micro/go-micro/v2" + "github.com/micro/go-micro/v2/api/router" ) type Options struct { diff --git a/api/handler/registry/registry.go b/api/handler/registry/registry.go index 0a840793..4aca36da 100644 --- a/api/handler/registry/registry.go +++ b/api/handler/registry/registry.go @@ -9,8 +9,8 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/micro/go-micro/api/handler" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/api/handler" + "github.com/micro/go-micro/v2/registry" ) const ( diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 0c01e10d..76e60dc2 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -10,17 +10,17 @@ import ( "strings" "github.com/joncalhoun/qson" - "github.com/micro/go-micro/api" - "github.com/micro/go-micro/api/handler" - proto "github.com/micro/go-micro/api/internal/proto" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/codec/jsonrpc" - "github.com/micro/go-micro/codec/protorpc" - "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/util/ctx" + "github.com/micro/go-micro/v2/api" + "github.com/micro/go-micro/v2/api/handler" + proto "github.com/micro/go-micro/v2/api/internal/proto" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/codec/jsonrpc" + "github.com/micro/go-micro/v2/codec/protorpc" + "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/util/ctx" ) const ( diff --git a/api/handler/rpc/rpc_test.go b/api/handler/rpc/rpc_test.go index f50cdedf..ba943a4d 100644 --- a/api/handler/rpc/rpc_test.go +++ b/api/handler/rpc/rpc_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/golang/protobuf/proto" - go_api "github.com/micro/go-micro/api/proto" + go_api "github.com/micro/go-micro/v2/api/proto" ) func TestRequestPayloadFromRequest(t *testing.T) { diff --git a/api/handler/web/web.go b/api/handler/web/web.go index 77a0f6af..ab4e7ebb 100644 --- a/api/handler/web/web.go +++ b/api/handler/web/web.go @@ -11,9 +11,9 @@ import ( "net/url" "strings" - "github.com/micro/go-micro/api" - "github.com/micro/go-micro/api/handler" - "github.com/micro/go-micro/client/selector" + "github.com/micro/go-micro/v2/api" + "github.com/micro/go-micro/v2/api/handler" + "github.com/micro/go-micro/v2/client/selector" ) const ( diff --git a/api/proto/api.pb.go b/api/proto/api.pb.go index 9e912f49..b9dba1fb 100644 --- a/api/proto/api.pb.go +++ b/api/proto/api.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/api/proto/api.proto +// source: github.com/micro/go-micro/v2/api/proto/api.proto package go_api @@ -304,7 +304,7 @@ func init() { } func init() { - proto.RegisterFile("github.com/micro/go-micro/api/proto/api.proto", fileDescriptor_7b6696ef87ec1943) + proto.RegisterFile("github.com/micro/go-micro/v2/api/proto/api.proto", fileDescriptor_7b6696ef87ec1943) } var fileDescriptor_7b6696ef87ec1943 = []byte{ diff --git a/api/proto/api.pb.micro.go b/api/proto/api.pb.micro.go index a05f98b1..494a7ce5 100644 --- a/api/proto/api.pb.micro.go +++ b/api/proto/api.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/api/proto/api.proto +// source: github.com/micro/go-micro/v2/api/proto/api.proto package go_api diff --git a/api/resolver/grpc/grpc.go b/api/resolver/grpc/grpc.go index 9f23dcd4..97ea279f 100644 --- a/api/resolver/grpc/grpc.go +++ b/api/resolver/grpc/grpc.go @@ -6,7 +6,7 @@ import ( "net/http" "strings" - "github.com/micro/go-micro/api/resolver" + "github.com/micro/go-micro/v2/api/resolver" ) type Resolver struct{} diff --git a/api/resolver/host/host.go b/api/resolver/host/host.go index ba0d1945..157c138f 100644 --- a/api/resolver/host/host.go +++ b/api/resolver/host/host.go @@ -4,7 +4,7 @@ package host import ( "net/http" - "github.com/micro/go-micro/api/resolver" + "github.com/micro/go-micro/v2/api/resolver" ) type Resolver struct{} diff --git a/api/resolver/micro/micro.go b/api/resolver/micro/micro.go index 418f7a97..9d940887 100644 --- a/api/resolver/micro/micro.go +++ b/api/resolver/micro/micro.go @@ -4,7 +4,7 @@ package micro import ( "net/http" - "github.com/micro/go-micro/api/resolver" + "github.com/micro/go-micro/v2/api/resolver" ) // default resolver for legacy purposes diff --git a/api/resolver/path/path.go b/api/resolver/path/path.go index 635cbceb..fec80f62 100644 --- a/api/resolver/path/path.go +++ b/api/resolver/path/path.go @@ -6,7 +6,7 @@ import ( "net/http" "strings" - "github.com/micro/go-micro/api/resolver" + "github.com/micro/go-micro/v2/api/resolver" ) type Resolver struct{} diff --git a/api/resolver/vpath/vpath.go b/api/resolver/vpath/vpath.go index a9baeecb..45f6faaf 100644 --- a/api/resolver/vpath/vpath.go +++ b/api/resolver/vpath/vpath.go @@ -7,7 +7,7 @@ import ( "regexp" "strings" - "github.com/micro/go-micro/api/resolver" + "github.com/micro/go-micro/v2/api/resolver" ) type Resolver struct{} diff --git a/api/router/options.go b/api/router/options.go index a48f3e39..cbba2028 100644 --- a/api/router/options.go +++ b/api/router/options.go @@ -1,9 +1,9 @@ package router import ( - "github.com/micro/go-micro/api/resolver" - "github.com/micro/go-micro/api/resolver/micro" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/api/resolver" + "github.com/micro/go-micro/v2/api/resolver/micro" + "github.com/micro/go-micro/v2/registry" ) type Options struct { diff --git a/api/router/registry/registry.go b/api/router/registry/registry.go index 368e31d4..51cbd8fc 100644 --- a/api/router/registry/registry.go +++ b/api/router/registry/registry.go @@ -11,10 +11,10 @@ import ( "sync" "time" - "github.com/micro/go-micro/api" - "github.com/micro/go-micro/api/router" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/registry/cache" + "github.com/micro/go-micro/v2/api" + "github.com/micro/go-micro/v2/api/router" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/registry/cache" ) // router is the default router diff --git a/api/router/registry/registry_test.go b/api/router/registry/registry_test.go index b2e9a59e..45646234 100644 --- a/api/router/registry/registry_test.go +++ b/api/router/registry/registry_test.go @@ -6,7 +6,7 @@ import ( "net/url" "testing" - "github.com/micro/go-micro/api" + "github.com/micro/go-micro/v2/api" ) func TestSetNamespace(t *testing.T) { diff --git a/api/router/router.go b/api/router/router.go index 3135cf40..7a2dc24a 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -4,7 +4,7 @@ package router import ( "net/http" - "github.com/micro/go-micro/api" + "github.com/micro/go-micro/v2/api" ) // Router is used to determine an endpoint for a request diff --git a/api/server/acme/autocert/autocert.go b/api/server/acme/autocert/autocert.go index ad5bf0bd..48152517 100644 --- a/api/server/acme/autocert/autocert.go +++ b/api/server/acme/autocert/autocert.go @@ -5,7 +5,7 @@ package autocert import ( "net" - "github.com/micro/go-micro/api/server/acme" + "github.com/micro/go-micro/v2/api/server/acme" "golang.org/x/crypto/acme/autocert" ) diff --git a/api/server/acme/certmagic/certmagic.go b/api/server/acme/certmagic/certmagic.go index 4a3a464b..febe56a7 100644 --- a/api/server/acme/certmagic/certmagic.go +++ b/api/server/acme/certmagic/certmagic.go @@ -9,7 +9,7 @@ import ( "github.com/mholt/certmagic" - "github.com/micro/go-micro/api/server/acme" + "github.com/micro/go-micro/v2/api/server/acme" ) type certmagicProvider struct { diff --git a/api/server/acme/certmagic/certmagic_test.go b/api/server/acme/certmagic/certmagic_test.go index 1739f5f2..cf3c515a 100644 --- a/api/server/acme/certmagic/certmagic_test.go +++ b/api/server/acme/certmagic/certmagic_test.go @@ -10,9 +10,9 @@ import ( "github.com/go-acme/lego/v3/providers/dns/cloudflare" "github.com/mholt/certmagic" - "github.com/micro/go-micro/api/server/acme" - cfstore "github.com/micro/go-micro/store/cloudflare" - "github.com/micro/go-micro/sync/lock/memory" + "github.com/micro/go-micro/v2/api/server/acme" + cfstore "github.com/micro/go-micro/v2/store/cloudflare" + "github.com/micro/go-micro/v2/sync/lock/memory" ) func TestCertMagic(t *testing.T) { diff --git a/api/server/acme/certmagic/storage.go b/api/server/acme/certmagic/storage.go index 24d187f5..204269e6 100644 --- a/api/server/acme/certmagic/storage.go +++ b/api/server/acme/certmagic/storage.go @@ -10,8 +10,8 @@ import ( "time" "github.com/mholt/certmagic" - "github.com/micro/go-micro/store" - "github.com/micro/go-micro/sync/lock" + "github.com/micro/go-micro/v2/store" + "github.com/micro/go-micro/v2/sync/lock" ) // File represents a "File" that will be stored in store.Store - the contents and last modified time diff --git a/api/server/http/http.go b/api/server/http/http.go index 3ff93b1a..ecf3d499 100644 --- a/api/server/http/http.go +++ b/api/server/http/http.go @@ -9,8 +9,8 @@ import ( "sync" "github.com/gorilla/handlers" - "github.com/micro/go-micro/api/server" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/api/server" + "github.com/micro/go-micro/v2/util/log" ) type httpServer struct { diff --git a/api/server/options.go b/api/server/options.go index b94c3da8..687e0926 100644 --- a/api/server/options.go +++ b/api/server/options.go @@ -3,7 +3,7 @@ package server import ( "crypto/tls" - "github.com/micro/go-micro/api/server/acme" + "github.com/micro/go-micro/v2/api/server/acme" ) type Option func(o *Options) diff --git a/broker/default.go b/broker/default.go index f35bd9fc..dd4a95ab 100644 --- a/broker/default.go +++ b/broker/default.go @@ -10,10 +10,10 @@ import ( "sync" "time" - "github.com/micro/go-micro/codec/json" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/util/addr" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/codec/json" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/util/addr" + "github.com/micro/go-micro/v2/util/log" "github.com/nats-io/nats-server/v2/server" nats "github.com/nats-io/nats.go" ) diff --git a/broker/memory/memory.go b/broker/memory/memory.go index effb22f3..36554237 100644 --- a/broker/memory/memory.go +++ b/broker/memory/memory.go @@ -8,9 +8,9 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/broker" - maddr "github.com/micro/go-micro/util/addr" - mnet "github.com/micro/go-micro/util/net" + "github.com/micro/go-micro/v2/broker" + maddr "github.com/micro/go-micro/v2/util/addr" + mnet "github.com/micro/go-micro/v2/util/net" ) type memoryBroker struct { diff --git a/broker/memory/memory_test.go b/broker/memory/memory_test.go index 625c7ee7..74e7941a 100644 --- a/broker/memory/memory_test.go +++ b/broker/memory/memory_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/micro/go-micro/broker" + "github.com/micro/go-micro/v2/broker" ) func TestMemoryBroker(t *testing.T) { diff --git a/broker/nats/context.go b/broker/nats/context.go index 0f009e8b..d4c1a3b0 100644 --- a/broker/nats/context.go +++ b/broker/nats/context.go @@ -3,7 +3,7 @@ package nats import ( "context" - "github.com/micro/go-micro/broker" + "github.com/micro/go-micro/v2/broker" ) // setSubscribeOption returns a function to setup a context with given value diff --git a/broker/nats/nats.go b/broker/nats/nats.go index 67833092..f4e00fce 100644 --- a/broker/nats/nats.go +++ b/broker/nats/nats.go @@ -11,11 +11,11 @@ import ( "sync" "time" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/codec/json" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/util/addr" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/codec/json" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/util/addr" + "github.com/micro/go-micro/v2/util/log" "github.com/nats-io/nats-server/v2/server" nats "github.com/nats-io/nats.go" ) diff --git a/broker/nats/nats_test.go b/broker/nats/nats_test.go index e58362e5..109c192c 100644 --- a/broker/nats/nats_test.go +++ b/broker/nats/nats_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/micro/go-micro/broker" + "github.com/micro/go-micro/v2/broker" nats "github.com/nats-io/nats.go" ) diff --git a/broker/nats/options.go b/broker/nats/options.go index ae8ca80d..ba127e73 100644 --- a/broker/nats/options.go +++ b/broker/nats/options.go @@ -1,7 +1,7 @@ package nats import ( - "github.com/micro/go-micro/broker" + "github.com/micro/go-micro/v2/broker" nats "github.com/nats-io/nats.go" ) diff --git a/broker/options.go b/broker/options.go index 348857f3..3fdc4dbc 100644 --- a/broker/options.go +++ b/broker/options.go @@ -4,8 +4,8 @@ import ( "context" "crypto/tls" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/registry" ) type Options struct { diff --git a/broker/service/proto/broker.pb.micro.go b/broker/service/proto/broker.pb.micro.go index c0229fb6..4ce6cd52 100644 --- a/broker/service/proto/broker.pb.micro.go +++ b/broker/service/proto/broker.pb.micro.go @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/broker/service/service.go b/broker/service/service.go index 00d6d0b5..81c1fb28 100644 --- a/broker/service/service.go +++ b/broker/service/service.go @@ -5,10 +5,10 @@ import ( "context" "time" - "github.com/micro/go-micro/broker" - pb "github.com/micro/go-micro/broker/service/proto" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/broker" + pb "github.com/micro/go-micro/v2/broker/service/proto" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/util/log" ) type serviceBroker struct { diff --git a/broker/service/subscriber.go b/broker/service/subscriber.go index 085b578a..36de7275 100644 --- a/broker/service/subscriber.go +++ b/broker/service/subscriber.go @@ -1,9 +1,9 @@ package service import ( - "github.com/micro/go-micro/broker" - pb "github.com/micro/go-micro/broker/service/proto" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/broker" + pb "github.com/micro/go-micro/v2/broker/service/proto" + "github.com/micro/go-micro/v2/util/log" ) type serviceSub struct { diff --git a/client/client.go b/client/client.go index b09ae3af..d16b1bda 100644 --- a/client/client.go +++ b/client/client.go @@ -5,7 +5,7 @@ import ( "context" "time" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) // Client is the interface used to make requests to services. diff --git a/client/common_test.go b/client/common_test.go index 25b2b09c..d1b347e6 100644 --- a/client/common_test.go +++ b/client/common_test.go @@ -1,7 +1,7 @@ package client import ( - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) var ( diff --git a/client/grpc/codec.go b/client/grpc/codec.go index 70ef0b99..4b224a71 100644 --- a/client/grpc/codec.go +++ b/client/grpc/codec.go @@ -9,8 +9,8 @@ import ( "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" jsoniter "github.com/json-iterator/go" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/codec/bytes" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/codec/bytes" "google.golang.org/grpc" "google.golang.org/grpc/encoding" ) diff --git a/client/grpc/error.go b/client/grpc/error.go index 47832527..07a31c77 100644 --- a/client/grpc/error.go +++ b/client/grpc/error.go @@ -1,7 +1,7 @@ package grpc import ( - "github.com/micro/go-micro/errors" + "github.com/micro/go-micro/v2/errors" "google.golang.org/grpc/status" ) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 1d4eea04..dc790760 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -9,13 +9,13 @@ import ( "sync" "time" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/client/selector" - raw "github.com/micro/go-micro/codec/bytes" - "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/metadata" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/selector" + raw "github.com/micro/go-micro/v2/codec/bytes" + "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/metadata" + "github.com/micro/go-micro/v2/registry" "google.golang.org/grpc" "google.golang.org/grpc/credentials" diff --git a/client/grpc/grpc_test.go b/client/grpc/grpc_test.go index 6d975ca3..16d34e79 100644 --- a/client/grpc/grpc_test.go +++ b/client/grpc/grpc_test.go @@ -5,10 +5,10 @@ import ( "net" "testing" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/registry/memory" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/registry/memory" pgrpc "google.golang.org/grpc" pb "google.golang.org/grpc/examples/helloworld/helloworld" ) diff --git a/client/grpc/message.go b/client/grpc/message.go index 5691868e..ddc8b926 100644 --- a/client/grpc/message.go +++ b/client/grpc/message.go @@ -1,7 +1,7 @@ package grpc import ( - "github.com/micro/go-micro/client" + "github.com/micro/go-micro/v2/client" ) type grpcEvent struct { diff --git a/client/grpc/options.go b/client/grpc/options.go index 146e42b0..28222f85 100644 --- a/client/grpc/options.go +++ b/client/grpc/options.go @@ -5,7 +5,7 @@ import ( "context" "crypto/tls" - "github.com/micro/go-micro/client" + "github.com/micro/go-micro/v2/client" "google.golang.org/grpc" "google.golang.org/grpc/encoding" ) diff --git a/client/grpc/request.go b/client/grpc/request.go index 066577ce..d7555727 100644 --- a/client/grpc/request.go +++ b/client/grpc/request.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/codec" ) type grpcRequest struct { diff --git a/client/grpc/response.go b/client/grpc/response.go index c870fad9..5fd40169 100644 --- a/client/grpc/response.go +++ b/client/grpc/response.go @@ -3,8 +3,8 @@ package grpc import ( "strings" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/codec/bytes" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/codec/bytes" "google.golang.org/grpc" "google.golang.org/grpc/encoding" ) diff --git a/client/grpc/stream.go b/client/grpc/stream.go index e5ebd156..ae13bbcf 100644 --- a/client/grpc/stream.go +++ b/client/grpc/stream.go @@ -5,7 +5,7 @@ import ( "io" "sync" - "github.com/micro/go-micro/client" + "github.com/micro/go-micro/v2/client" "google.golang.org/grpc" ) diff --git a/client/mucp/mucp.go b/client/mucp/mucp.go index 67b43dbd..ddd1f7cb 100644 --- a/client/mucp/mucp.go +++ b/client/mucp/mucp.go @@ -2,7 +2,7 @@ package mucp import ( - "github.com/micro/go-micro/client" + "github.com/micro/go-micro/v2/client" ) // NewClient returns a new micro client interface diff --git a/client/options.go b/client/options.go index 50ec3951..6f854d17 100644 --- a/client/options.go +++ b/client/options.go @@ -4,11 +4,11 @@ import ( "context" "time" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/transport" ) type Options struct { diff --git a/client/options_test.go b/client/options_test.go index 8d209e21..83c3a557 100644 --- a/client/options_test.go +++ b/client/options_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) func TestCallOptions(t *testing.T) { diff --git a/client/retry.go b/client/retry.go index 46466d48..92ba4c07 100644 --- a/client/retry.go +++ b/client/retry.go @@ -3,7 +3,7 @@ package client import ( "context" - "github.com/micro/go-micro/errors" + "github.com/micro/go-micro/v2/errors" ) // note that returning either false or a non-nil error will result in the call not being retried diff --git a/client/rpc_client.go b/client/rpc_client.go index 63d20d7b..61c3fabb 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -9,16 +9,16 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/codec" - raw "github.com/micro/go-micro/codec/bytes" - "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/metadata" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/util/buf" - "github.com/micro/go-micro/util/pool" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/codec" + raw "github.com/micro/go-micro/v2/codec/bytes" + "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/metadata" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/util/buf" + "github.com/micro/go-micro/v2/util/pool" ) type rpcClient struct { diff --git a/client/rpc_client_test.go b/client/rpc_client_test.go index ace08fff..721c4950 100644 --- a/client/rpc_client_test.go +++ b/client/rpc_client_test.go @@ -5,10 +5,10 @@ import ( "fmt" "testing" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/registry/memory" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/registry/memory" ) func newTestRegistry() registry.Registry { diff --git a/client/rpc_codec.go b/client/rpc_codec.go index c3729be2..c22b9d28 100644 --- a/client/rpc_codec.go +++ b/client/rpc_codec.go @@ -4,16 +4,16 @@ import ( "bytes" errs "errors" - "github.com/micro/go-micro/codec" - raw "github.com/micro/go-micro/codec/bytes" - "github.com/micro/go-micro/codec/grpc" - "github.com/micro/go-micro/codec/json" - "github.com/micro/go-micro/codec/jsonrpc" - "github.com/micro/go-micro/codec/proto" - "github.com/micro/go-micro/codec/protorpc" - "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/codec" + raw "github.com/micro/go-micro/v2/codec/bytes" + "github.com/micro/go-micro/v2/codec/grpc" + "github.com/micro/go-micro/v2/codec/json" + "github.com/micro/go-micro/v2/codec/jsonrpc" + "github.com/micro/go-micro/v2/codec/proto" + "github.com/micro/go-micro/v2/codec/protorpc" + "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/transport" ) const ( diff --git a/client/rpc_request.go b/client/rpc_request.go index 7fd5762b..97ca50f7 100644 --- a/client/rpc_request.go +++ b/client/rpc_request.go @@ -1,7 +1,7 @@ package client import ( - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) type rpcRequest struct { diff --git a/client/rpc_response.go b/client/rpc_response.go index 08aaa84d..d7faaea6 100644 --- a/client/rpc_response.go +++ b/client/rpc_response.go @@ -1,8 +1,8 @@ package client import ( - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/transport" ) type rpcResponse struct { diff --git a/client/rpc_stream.go b/client/rpc_stream.go index abc4f5f1..7c880d88 100644 --- a/client/rpc_stream.go +++ b/client/rpc_stream.go @@ -5,7 +5,7 @@ import ( "io" "sync" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) // Implements the streamer interface diff --git a/client/selector/common_test.go b/client/selector/common_test.go index 1af55c1c..da084daf 100644 --- a/client/selector/common_test.go +++ b/client/selector/common_test.go @@ -1,7 +1,7 @@ package selector import ( - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) var ( diff --git a/client/selector/default.go b/client/selector/default.go index 870bea2a..2692d8ba 100644 --- a/client/selector/default.go +++ b/client/selector/default.go @@ -3,8 +3,8 @@ package selector import ( "time" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/registry/cache" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/registry/cache" ) type registrySelector struct { diff --git a/client/selector/default_test.go b/client/selector/default_test.go index 948eedcd..d3b50003 100644 --- a/client/selector/default_test.go +++ b/client/selector/default_test.go @@ -3,7 +3,7 @@ package selector import ( "testing" - "github.com/micro/go-micro/registry/memory" + "github.com/micro/go-micro/v2/registry/memory" ) func TestRegistrySelector(t *testing.T) { diff --git a/client/selector/dns/dns.go b/client/selector/dns/dns.go index 450ae412..114fe590 100644 --- a/client/selector/dns/dns.go +++ b/client/selector/dns/dns.go @@ -6,8 +6,8 @@ import ( "net" "strconv" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/registry" ) type dnsSelector struct { diff --git a/client/selector/filter.go b/client/selector/filter.go index 53c5af39..11c3a165 100644 --- a/client/selector/filter.go +++ b/client/selector/filter.go @@ -1,7 +1,7 @@ package selector import ( - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) // FilterEndpoint is an endpoint based Select Filter which will diff --git a/client/selector/filter_test.go b/client/selector/filter_test.go index 035feed3..375bdc45 100644 --- a/client/selector/filter_test.go +++ b/client/selector/filter_test.go @@ -3,7 +3,7 @@ package selector import ( "testing" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) func TestFilterEndpoint(t *testing.T) { diff --git a/client/selector/options.go b/client/selector/options.go index 7ceb5290..898d2cc1 100644 --- a/client/selector/options.go +++ b/client/selector/options.go @@ -3,7 +3,7 @@ package selector import ( "context" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) type Options struct { diff --git a/client/selector/registry/options.go b/client/selector/registry/options.go index 007c5023..ae739ef1 100644 --- a/client/selector/registry/options.go +++ b/client/selector/registry/options.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/micro/go-micro/client/selector" + "github.com/micro/go-micro/v2/client/selector" ) // Set the registry cache ttl diff --git a/client/selector/registry/registry.go b/client/selector/registry/registry.go index fe8373a7..ab83e996 100644 --- a/client/selector/registry/registry.go +++ b/client/selector/registry/registry.go @@ -2,7 +2,7 @@ package registry import ( - "github.com/micro/go-micro/client/selector" + "github.com/micro/go-micro/v2/client/selector" ) // NewSelector returns a new registry selector diff --git a/client/selector/router/router.go b/client/selector/router/router.go index d8e8aae3..e93fd08b 100644 --- a/client/selector/router/router.go +++ b/client/selector/router/router.go @@ -7,11 +7,11 @@ import ( "sort" "sync" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/router" - pb "github.com/micro/go-micro/router/service/proto" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/router" + pb "github.com/micro/go-micro/v2/router/service/proto" ) type routerSelector struct { diff --git a/client/selector/selector.go b/client/selector/selector.go index 83d82974..3e86ade8 100644 --- a/client/selector/selector.go +++ b/client/selector/selector.go @@ -4,7 +4,7 @@ package selector import ( "errors" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) // Selector builds on the registry as a mechanism to pick nodes diff --git a/client/selector/static/static.go b/client/selector/static/static.go index 9bd18f03..dc256d2d 100644 --- a/client/selector/static/static.go +++ b/client/selector/static/static.go @@ -2,8 +2,8 @@ package static import ( - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/registry" ) // staticSelector is a static selector diff --git a/client/selector/strategy.go b/client/selector/strategy.go index 5014d25d..e68b9f23 100644 --- a/client/selector/strategy.go +++ b/client/selector/strategy.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) func init() { diff --git a/client/selector/strategy_test.go b/client/selector/strategy_test.go index 2529a6b7..07bf30b6 100644 --- a/client/selector/strategy_test.go +++ b/client/selector/strategy_test.go @@ -3,7 +3,7 @@ package selector import ( "testing" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) func TestStrategies(t *testing.T) { diff --git a/client/service/proto/client.pb.go b/client/service/proto/client.pb.go index bd5b3702..071c1c16 100644 --- a/client/service/proto/client.pb.go +++ b/client/service/proto/client.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/client/proto/client.proto +// source: github.com/micro/go-micro/v2/client/proto/client.proto package go_micro_client @@ -184,7 +184,7 @@ func init() { } func init() { - proto.RegisterFile("github.com/micro/go-micro/client/proto/client.proto", fileDescriptor_d418333f021a3308) + proto.RegisterFile("github.com/micro/go-micro/v2/client/proto/client.proto", fileDescriptor_d418333f021a3308) } var fileDescriptor_d418333f021a3308 = []byte{ diff --git a/client/service/proto/client.pb.micro.go b/client/service/proto/client.pb.micro.go index 140d9b45..029a6c73 100644 --- a/client/service/proto/client.pb.micro.go +++ b/client/service/proto/client.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/client/proto/client.proto +// source: github.com/micro/go-micro/v2/client/proto/client.proto package go_micro_client @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/client/wrapper.go b/client/wrapper.go index ab86dcd1..d5138bcc 100644 --- a/client/wrapper.go +++ b/client/wrapper.go @@ -3,7 +3,7 @@ package client import ( "context" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) // CallFunc represents the individual call func diff --git a/codec/bytes/bytes.go b/codec/bytes/bytes.go index 69d36235..23a6c6fc 100644 --- a/codec/bytes/bytes.go +++ b/codec/bytes/bytes.go @@ -6,7 +6,7 @@ import ( "io" "io/ioutil" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) type Codec struct { diff --git a/codec/grpc/grpc.go b/codec/grpc/grpc.go index f044b55f..90bf4eb6 100644 --- a/codec/grpc/grpc.go +++ b/codec/grpc/grpc.go @@ -9,7 +9,7 @@ import ( "strings" "github.com/golang/protobuf/proto" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) type Codec struct { diff --git a/codec/json/json.go b/codec/json/json.go index 5af47a07..7db36a50 100644 --- a/codec/json/json.go +++ b/codec/json/json.go @@ -7,7 +7,7 @@ import ( "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) type Codec struct { diff --git a/codec/jsonrpc/client.go b/codec/jsonrpc/client.go index f5ec5636..f1e320a0 100644 --- a/codec/jsonrpc/client.go +++ b/codec/jsonrpc/client.go @@ -6,7 +6,7 @@ import ( "io" "sync" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) type clientCodec struct { diff --git a/codec/jsonrpc/jsonrpc.go b/codec/jsonrpc/jsonrpc.go index d7e0e1c9..fcf2ac65 100644 --- a/codec/jsonrpc/jsonrpc.go +++ b/codec/jsonrpc/jsonrpc.go @@ -7,7 +7,7 @@ import ( "fmt" "io" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) type jsonCodec struct { diff --git a/codec/jsonrpc/server.go b/codec/jsonrpc/server.go index 53f681ef..48b71e64 100644 --- a/codec/jsonrpc/server.go +++ b/codec/jsonrpc/server.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) type serverCodec struct { diff --git a/codec/proto/proto.go b/codec/proto/proto.go index d79d5166..c2c4f382 100644 --- a/codec/proto/proto.go +++ b/codec/proto/proto.go @@ -6,7 +6,7 @@ import ( "io/ioutil" "github.com/golang/protobuf/proto" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) type Codec struct { diff --git a/codec/protorpc/protorpc.go b/codec/protorpc/protorpc.go index 255b93a4..4e4b2ee8 100644 --- a/codec/protorpc/protorpc.go +++ b/codec/protorpc/protorpc.go @@ -9,7 +9,7 @@ import ( "sync" "github.com/golang/protobuf/proto" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) type flusher interface { diff --git a/codec/text/text.go b/codec/text/text.go index 799cf6c1..86be2068 100644 --- a/codec/text/text.go +++ b/codec/text/text.go @@ -6,7 +6,7 @@ import ( "io" "io/ioutil" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) type Codec struct { diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index da2ed12f..c576df2d 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -7,54 +7,54 @@ import ( "strings" "time" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/debug/trace" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/runtime" - "github.com/micro/go-micro/server" - "github.com/micro/go-micro/store" - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/debug/trace" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/runtime" + "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/store" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/util/log" // clients - cgrpc "github.com/micro/go-micro/client/grpc" - cmucp "github.com/micro/go-micro/client/mucp" + cgrpc "github.com/micro/go-micro/v2/client/grpc" + cmucp "github.com/micro/go-micro/v2/client/mucp" // servers "github.com/micro/cli/v2" - sgrpc "github.com/micro/go-micro/server/grpc" - smucp "github.com/micro/go-micro/server/mucp" + sgrpc "github.com/micro/go-micro/v2/server/grpc" + smucp "github.com/micro/go-micro/v2/server/mucp" // brokers - "github.com/micro/go-micro/broker/memory" - "github.com/micro/go-micro/broker/nats" - brokerSrv "github.com/micro/go-micro/broker/service" + "github.com/micro/go-micro/v2/broker/memory" + "github.com/micro/go-micro/v2/broker/nats" + brokerSrv "github.com/micro/go-micro/v2/broker/service" // registries - "github.com/micro/go-micro/registry/etcd" - kreg "github.com/micro/go-micro/registry/kubernetes" - "github.com/micro/go-micro/registry/mdns" - rmem "github.com/micro/go-micro/registry/memory" - regSrv "github.com/micro/go-micro/registry/service" + "github.com/micro/go-micro/v2/registry/etcd" + kreg "github.com/micro/go-micro/v2/registry/kubernetes" + "github.com/micro/go-micro/v2/registry/mdns" + rmem "github.com/micro/go-micro/v2/registry/memory" + regSrv "github.com/micro/go-micro/v2/registry/service" // selectors - "github.com/micro/go-micro/client/selector/dns" - "github.com/micro/go-micro/client/selector/router" - "github.com/micro/go-micro/client/selector/static" + "github.com/micro/go-micro/v2/client/selector/dns" + "github.com/micro/go-micro/v2/client/selector/router" + "github.com/micro/go-micro/v2/client/selector/static" // transports - thttp "github.com/micro/go-micro/transport/http" - tmem "github.com/micro/go-micro/transport/memory" + thttp "github.com/micro/go-micro/v2/transport/http" + tmem "github.com/micro/go-micro/v2/transport/memory" // stores - memStore "github.com/micro/go-micro/store/memory" - svcStore "github.com/micro/go-micro/store/service" + memStore "github.com/micro/go-micro/v2/store/memory" + svcStore "github.com/micro/go-micro/v2/store/service" // tracers - // jTracer "github.com/micro/go-micro/debug/trace/jaeger" - memTracer "github.com/micro/go-micro/debug/trace/memory" + // jTracer "github.com/micro/go-micro/v2/debug/trace/jaeger" + memTracer "github.com/micro/go-micro/v2/debug/trace/memory" ) type Cmd interface { diff --git a/config/cmd/options.go b/config/cmd/options.go index 68f4b135..695e8ccf 100644 --- a/config/cmd/options.go +++ b/config/cmd/options.go @@ -3,15 +3,15 @@ package cmd import ( "context" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/debug/trace" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/runtime" - "github.com/micro/go-micro/server" - "github.com/micro/go-micro/store" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/debug/trace" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/runtime" + "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/store" + "github.com/micro/go-micro/v2/transport" ) type Options struct { diff --git a/config/config.go b/config/config.go index b45215e8..bd780874 100644 --- a/config/config.go +++ b/config/config.go @@ -4,10 +4,10 @@ package config import ( "context" - "github.com/micro/go-micro/config/loader" - "github.com/micro/go-micro/config/reader" - "github.com/micro/go-micro/config/source" - "github.com/micro/go-micro/config/source/file" + "github.com/micro/go-micro/v2/config/loader" + "github.com/micro/go-micro/v2/config/reader" + "github.com/micro/go-micro/v2/config/source" + "github.com/micro/go-micro/v2/config/source/file" ) // Config is an interface abstraction for dynamic configuration diff --git a/config/default.go b/config/default.go index b4535ed9..2c050462 100644 --- a/config/default.go +++ b/config/default.go @@ -5,11 +5,11 @@ import ( "sync" "time" - "github.com/micro/go-micro/config/loader" - "github.com/micro/go-micro/config/loader/memory" - "github.com/micro/go-micro/config/reader" - "github.com/micro/go-micro/config/reader/json" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/loader" + "github.com/micro/go-micro/v2/config/loader/memory" + "github.com/micro/go-micro/v2/config/reader" + "github.com/micro/go-micro/v2/config/reader/json" + "github.com/micro/go-micro/v2/config/source" ) type config struct { diff --git a/config/default_test.go b/config/default_test.go index e53a877b..0ee8d84a 100644 --- a/config/default_test.go +++ b/config/default_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - "github.com/micro/go-micro/config/source/env" - "github.com/micro/go-micro/config/source/file" + "github.com/micro/go-micro/v2/config/source/env" + "github.com/micro/go-micro/v2/config/source/file" ) var ( diff --git a/config/encoder/hcl/hcl.go b/config/encoder/hcl/hcl.go index 7fa02b2c..efde9d92 100644 --- a/config/encoder/hcl/hcl.go +++ b/config/encoder/hcl/hcl.go @@ -4,7 +4,7 @@ import ( "encoding/json" "github.com/hashicorp/hcl" - "github.com/micro/go-micro/config/encoder" + "github.com/micro/go-micro/v2/config/encoder" ) type hclEncoder struct{} diff --git a/config/encoder/json/json.go b/config/encoder/json/json.go index a5b3557b..67714dfe 100644 --- a/config/encoder/json/json.go +++ b/config/encoder/json/json.go @@ -3,7 +3,7 @@ package json import ( "encoding/json" - "github.com/micro/go-micro/config/encoder" + "github.com/micro/go-micro/v2/config/encoder" ) type jsonEncoder struct{} diff --git a/config/encoder/toml/toml.go b/config/encoder/toml/toml.go index f9688966..baca12e4 100644 --- a/config/encoder/toml/toml.go +++ b/config/encoder/toml/toml.go @@ -4,7 +4,7 @@ import ( "bytes" "github.com/BurntSushi/toml" - "github.com/micro/go-micro/config/encoder" + "github.com/micro/go-micro/v2/config/encoder" ) type tomlEncoder struct{} diff --git a/config/encoder/xml/xml.go b/config/encoder/xml/xml.go index e970d8f1..7b9c55f4 100644 --- a/config/encoder/xml/xml.go +++ b/config/encoder/xml/xml.go @@ -3,7 +3,7 @@ package xml import ( "encoding/xml" - "github.com/micro/go-micro/config/encoder" + "github.com/micro/go-micro/v2/config/encoder" ) type xmlEncoder struct{} diff --git a/config/encoder/yaml/yaml.go b/config/encoder/yaml/yaml.go index efecbf0c..b671fcab 100644 --- a/config/encoder/yaml/yaml.go +++ b/config/encoder/yaml/yaml.go @@ -2,7 +2,7 @@ package yaml import ( "github.com/ghodss/yaml" - "github.com/micro/go-micro/config/encoder" + "github.com/micro/go-micro/v2/config/encoder" ) type yamlEncoder struct{} diff --git a/config/loader/loader.go b/config/loader/loader.go index 93029243..1dcb1450 100644 --- a/config/loader/loader.go +++ b/config/loader/loader.go @@ -4,8 +4,8 @@ package loader import ( "context" - "github.com/micro/go-micro/config/reader" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/reader" + "github.com/micro/go-micro/v2/config/source" ) // Loader manages loading sources diff --git a/config/loader/memory/memory.go b/config/loader/memory/memory.go index 60af473a..65c586bf 100644 --- a/config/loader/memory/memory.go +++ b/config/loader/memory/memory.go @@ -9,10 +9,10 @@ import ( "sync" "time" - "github.com/micro/go-micro/config/loader" - "github.com/micro/go-micro/config/reader" - "github.com/micro/go-micro/config/reader/json" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/loader" + "github.com/micro/go-micro/v2/config/reader" + "github.com/micro/go-micro/v2/config/reader/json" + "github.com/micro/go-micro/v2/config/source" ) type memory struct { diff --git a/config/loader/memory/options.go b/config/loader/memory/options.go index 5d778d66..cbf9d497 100644 --- a/config/loader/memory/options.go +++ b/config/loader/memory/options.go @@ -1,9 +1,9 @@ package memory import ( - "github.com/micro/go-micro/config/loader" - "github.com/micro/go-micro/config/reader" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/loader" + "github.com/micro/go-micro/v2/config/reader" + "github.com/micro/go-micro/v2/config/source" ) // WithSource appends a source to list of sources diff --git a/config/options.go b/config/options.go index a21cf945..34e176a4 100644 --- a/config/options.go +++ b/config/options.go @@ -1,9 +1,9 @@ package config import ( - "github.com/micro/go-micro/config/loader" - "github.com/micro/go-micro/config/reader" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/loader" + "github.com/micro/go-micro/v2/config/reader" + "github.com/micro/go-micro/v2/config/source" ) // WithLoader sets the loader for manager config diff --git a/config/reader/json/json.go b/config/reader/json/json.go index 7f3058f8..96b2c7aa 100644 --- a/config/reader/json/json.go +++ b/config/reader/json/json.go @@ -5,10 +5,10 @@ import ( "time" "github.com/imdario/mergo" - "github.com/micro/go-micro/config/encoder" - "github.com/micro/go-micro/config/encoder/json" - "github.com/micro/go-micro/config/reader" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/encoder" + "github.com/micro/go-micro/v2/config/encoder/json" + "github.com/micro/go-micro/v2/config/reader" + "github.com/micro/go-micro/v2/config/source" ) type jsonReader struct { diff --git a/config/reader/json/json_test.go b/config/reader/json/json_test.go index 965e346d..2afff0fc 100644 --- a/config/reader/json/json_test.go +++ b/config/reader/json/json_test.go @@ -3,7 +3,7 @@ package json import ( "testing" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) func TestReader(t *testing.T) { diff --git a/config/reader/json/values.go b/config/reader/json/values.go index 926cfd04..ce7601c7 100644 --- a/config/reader/json/values.go +++ b/config/reader/json/values.go @@ -8,8 +8,8 @@ import ( "time" simple "github.com/bitly/go-simplejson" - "github.com/micro/go-micro/config/reader" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/reader" + "github.com/micro/go-micro/v2/config/source" ) type jsonValues struct { diff --git a/config/reader/json/values_test.go b/config/reader/json/values_test.go index 166d9ae0..3ace3eb9 100644 --- a/config/reader/json/values_test.go +++ b/config/reader/json/values_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) func TestValues(t *testing.T) { diff --git a/config/reader/options.go b/config/reader/options.go index 71b525b9..23f9c3fd 100644 --- a/config/reader/options.go +++ b/config/reader/options.go @@ -1,12 +1,12 @@ package reader import ( - "github.com/micro/go-micro/config/encoder" - "github.com/micro/go-micro/config/encoder/hcl" - "github.com/micro/go-micro/config/encoder/json" - "github.com/micro/go-micro/config/encoder/toml" - "github.com/micro/go-micro/config/encoder/xml" - "github.com/micro/go-micro/config/encoder/yaml" + "github.com/micro/go-micro/v2/config/encoder" + "github.com/micro/go-micro/v2/config/encoder/hcl" + "github.com/micro/go-micro/v2/config/encoder/json" + "github.com/micro/go-micro/v2/config/encoder/toml" + "github.com/micro/go-micro/v2/config/encoder/xml" + "github.com/micro/go-micro/v2/config/encoder/yaml" ) type Options struct { diff --git a/config/reader/reader.go b/config/reader/reader.go index 9d6fbb1a..e10ff6df 100644 --- a/config/reader/reader.go +++ b/config/reader/reader.go @@ -4,7 +4,7 @@ package reader import ( "time" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) // Reader is an interface for merging changesets diff --git a/config/source/cli/cli.go b/config/source/cli/cli.go index 96e58331..6ca71709 100644 --- a/config/source/cli/cli.go +++ b/config/source/cli/cli.go @@ -9,8 +9,8 @@ import ( "github.com/imdario/mergo" "github.com/micro/cli/v2" - "github.com/micro/go-micro/config/cmd" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/cmd" + "github.com/micro/go-micro/v2/config/source" ) type cliSource struct { diff --git a/config/source/cli/cli_test.go b/config/source/cli/cli_test.go index 53985860..45022a95 100644 --- a/config/source/cli/cli_test.go +++ b/config/source/cli/cli_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/micro/cli/v2" - "github.com/micro/go-micro/config/cmd" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/cmd" + "github.com/micro/go-micro/v2/config/source" ) func test(t *testing.T, withContext bool) { diff --git a/config/source/cli/options.go b/config/source/cli/options.go index 274d9760..28d28720 100644 --- a/config/source/cli/options.go +++ b/config/source/cli/options.go @@ -4,7 +4,7 @@ import ( "context" "github.com/micro/cli/v2" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type contextKey struct{} diff --git a/config/source/env/env.go b/config/source/env/env.go index c971945c..25f5b827 100644 --- a/config/source/env/env.go +++ b/config/source/env/env.go @@ -7,7 +7,7 @@ import ( "time" "github.com/imdario/mergo" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) var ( diff --git a/config/source/env/env_test.go b/config/source/env/env_test.go index 4c22122e..7b0f99d4 100644 --- a/config/source/env/env_test.go +++ b/config/source/env/env_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) func TestEnv_Read(t *testing.T) { diff --git a/config/source/env/options.go b/config/source/env/options.go index 495672b5..27f99241 100644 --- a/config/source/env/options.go +++ b/config/source/env/options.go @@ -5,7 +5,7 @@ import ( "strings" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type strippedPrefixKey struct{} diff --git a/config/source/env/watcher.go b/config/source/env/watcher.go index 4ffe783c..bf7fb481 100644 --- a/config/source/env/watcher.go +++ b/config/source/env/watcher.go @@ -1,7 +1,7 @@ package env import ( - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type watcher struct { diff --git a/config/source/etcd/etcd.go b/config/source/etcd/etcd.go index 9dc0c0c2..db9c50f0 100644 --- a/config/source/etcd/etcd.go +++ b/config/source/etcd/etcd.go @@ -8,7 +8,7 @@ import ( cetcd "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) // Currently a single etcd reader diff --git a/config/source/etcd/options.go b/config/source/etcd/options.go index 325d2f46..79e0ab61 100644 --- a/config/source/etcd/options.go +++ b/config/source/etcd/options.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type addressKey struct{} diff --git a/config/source/etcd/util.go b/config/source/etcd/util.go index 31887fc9..6186befa 100644 --- a/config/source/etcd/util.go +++ b/config/source/etcd/util.go @@ -5,7 +5,7 @@ import ( "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/mvcc/mvccpb" - "github.com/micro/go-micro/config/encoder" + "github.com/micro/go-micro/v2/config/encoder" ) func makeEvMap(e encoder.Encoder, data map[string]interface{}, kv []*clientv3.Event, stripPrefix string) map[string]interface{} { diff --git a/config/source/etcd/watcher.go b/config/source/etcd/watcher.go index 2f9b3189..d43f2987 100644 --- a/config/source/etcd/watcher.go +++ b/config/source/etcd/watcher.go @@ -7,7 +7,7 @@ import ( "time" cetcd "github.com/coreos/etcd/clientv3" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type watcher struct { diff --git a/config/source/file/file.go b/config/source/file/file.go index 15b9b860..f04d67c6 100644 --- a/config/source/file/file.go +++ b/config/source/file/file.go @@ -5,7 +5,7 @@ import ( "io/ioutil" "os" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type file struct { diff --git a/config/source/file/format.go b/config/source/file/format.go index 63f51bd9..09f10071 100644 --- a/config/source/file/format.go +++ b/config/source/file/format.go @@ -3,7 +3,7 @@ package file import ( "strings" - "github.com/micro/go-micro/config/encoder" + "github.com/micro/go-micro/v2/config/encoder" ) func format(p string, e encoder.Encoder) string { diff --git a/config/source/file/format_test.go b/config/source/file/format_test.go index 47f09836..8383f84a 100644 --- a/config/source/file/format_test.go +++ b/config/source/file/format_test.go @@ -3,7 +3,7 @@ package file import ( "testing" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) func TestFormat(t *testing.T) { diff --git a/config/source/file/options.go b/config/source/file/options.go index e9b16e90..e2f67bb4 100644 --- a/config/source/file/options.go +++ b/config/source/file/options.go @@ -3,7 +3,7 @@ package file import ( "context" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type filePathKey struct{} diff --git a/config/source/file/watcher.go b/config/source/file/watcher.go index d9595e27..f26cc6e4 100644 --- a/config/source/file/watcher.go +++ b/config/source/file/watcher.go @@ -6,7 +6,7 @@ import ( "os" "github.com/fsnotify/fsnotify" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type watcher struct { diff --git a/config/source/file/watcher_linux.go b/config/source/file/watcher_linux.go index 82d45154..13efbde5 100644 --- a/config/source/file/watcher_linux.go +++ b/config/source/file/watcher_linux.go @@ -6,7 +6,7 @@ import ( "os" "github.com/fsnotify/fsnotify" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type watcher struct { diff --git a/config/source/flag/flag.go b/config/source/flag/flag.go index 98ff4d91..3cd3dcf6 100644 --- a/config/source/flag/flag.go +++ b/config/source/flag/flag.go @@ -4,7 +4,7 @@ import ( "errors" "flag" "github.com/imdario/mergo" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" "strings" "time" ) diff --git a/config/source/flag/options.go b/config/source/flag/options.go index 369cccb6..85ccfd83 100644 --- a/config/source/flag/options.go +++ b/config/source/flag/options.go @@ -3,7 +3,7 @@ package flag import ( "context" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type includeUnsetKey struct{} diff --git a/config/source/memory/memory.go b/config/source/memory/memory.go index e6a25d2a..bb3f2b73 100644 --- a/config/source/memory/memory.go +++ b/config/source/memory/memory.go @@ -6,7 +6,7 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type memory struct { diff --git a/config/source/memory/options.go b/config/source/memory/options.go index 674bee58..d7ec6309 100644 --- a/config/source/memory/options.go +++ b/config/source/memory/options.go @@ -3,7 +3,7 @@ package memory import ( "context" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type changeSetKey struct{} diff --git a/config/source/memory/watcher.go b/config/source/memory/watcher.go index 4cdc09e1..c04714b1 100644 --- a/config/source/memory/watcher.go +++ b/config/source/memory/watcher.go @@ -1,7 +1,7 @@ package memory import ( - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type watcher struct { diff --git a/config/source/options.go b/config/source/options.go index 0f8f7943..d4a2ba09 100644 --- a/config/source/options.go +++ b/config/source/options.go @@ -3,8 +3,8 @@ package source import ( "context" - "github.com/micro/go-micro/config/encoder" - "github.com/micro/go-micro/config/encoder/json" + "github.com/micro/go-micro/v2/config/encoder" + "github.com/micro/go-micro/v2/config/encoder/json" ) type Options struct { diff --git a/config/source/service/options.go b/config/source/service/options.go index 1075a4ac..ea80e1bd 100644 --- a/config/source/service/options.go +++ b/config/source/service/options.go @@ -3,7 +3,7 @@ package service import ( "context" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-micro/v2/config/source" ) type serviceNameKey struct{} diff --git a/config/source/service/proto/service.pb.micro.go b/config/source/service/proto/service.pb.micro.go index 238b6112..f88a9b15 100644 --- a/config/source/service/proto/service.pb.micro.go +++ b/config/source/service/proto/service.pb.micro.go @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/config/source/service/service.go b/config/source/service/service.go index caf1eebe..567db30a 100644 --- a/config/source/service/service.go +++ b/config/source/service/service.go @@ -3,10 +3,10 @@ package service import ( "context" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/config/source" - proto "github.com/micro/go-micro/config/source/service/proto" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/config/source" + proto "github.com/micro/go-micro/v2/config/source/service/proto" + "github.com/micro/go-micro/v2/util/log" ) var ( diff --git a/config/source/service/util.go b/config/source/service/util.go index eb248356..a2f71e45 100644 --- a/config/source/service/util.go +++ b/config/source/service/util.go @@ -3,8 +3,8 @@ package service import ( "time" - "github.com/micro/go-micro/config/source" - proto "github.com/micro/go-micro/config/source/service/proto" + "github.com/micro/go-micro/v2/config/source" + proto "github.com/micro/go-micro/v2/config/source/service/proto" ) func toChangeSet(c *proto.ChangeSet) *source.ChangeSet { diff --git a/config/source/service/watcher.go b/config/source/service/watcher.go index 2806d427..c99e5f7c 100644 --- a/config/source/service/watcher.go +++ b/config/source/service/watcher.go @@ -1,8 +1,8 @@ package service import ( - "github.com/micro/go-micro/config/source" - proto "github.com/micro/go-micro/config/source/service/proto" + "github.com/micro/go-micro/v2/config/source" + proto "github.com/micro/go-micro/v2/config/source/service/proto" ) type watcher struct { diff --git a/config/value.go b/config/value.go index 929d671b..90710bad 100644 --- a/config/value.go +++ b/config/value.go @@ -3,7 +3,7 @@ package config import ( "time" - "github.com/micro/go-micro/config/reader" + "github.com/micro/go-micro/v2/config/reader" ) type value struct{} diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go index 861dbc46..d81aba23 100644 --- a/debug/log/kubernetes/kubernetes.go +++ b/debug/log/kubernetes/kubernetes.go @@ -1,4 +1,4 @@ -// Package kubernetes is a logger implementing (github.com/micro/go-micro/debug/log).Log +// Package kubernetes is a logger implementing (github.com/micro/go-micro/v2/debug/log).Log package kubernetes import ( @@ -10,8 +10,8 @@ import ( "strconv" "time" - "github.com/micro/go-micro/debug/log" - "github.com/micro/go-micro/util/kubernetes/client" + "github.com/micro/go-micro/v2/debug/log" + "github.com/micro/go-micro/v2/util/kubernetes/client" ) type klog struct { diff --git a/debug/log/kubernetes/kubernetes_test.go b/debug/log/kubernetes/kubernetes_test.go index 955e5d46..97749869 100644 --- a/debug/log/kubernetes/kubernetes_test.go +++ b/debug/log/kubernetes/kubernetes_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/micro/go-micro/debug/log" + "github.com/micro/go-micro/v2/debug/log" "github.com/stretchr/testify/assert" ) diff --git a/debug/log/kubernetes/stream.go b/debug/log/kubernetes/stream.go index eed76d3e..e8fd3e98 100644 --- a/debug/log/kubernetes/stream.go +++ b/debug/log/kubernetes/stream.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - "github.com/micro/go-micro/debug/log" + "github.com/micro/go-micro/v2/debug/log" ) func write(l log.Record) error { diff --git a/debug/log/memory/memory.go b/debug/log/memory/memory.go index 18215701..b168addd 100644 --- a/debug/log/memory/memory.go +++ b/debug/log/memory/memory.go @@ -4,8 +4,8 @@ package memory import ( "fmt" - "github.com/micro/go-micro/debug/log" - "github.com/micro/go-micro/util/ring" + "github.com/micro/go-micro/v2/debug/log" + "github.com/micro/go-micro/v2/util/ring" ) var ( diff --git a/debug/log/memory/memory_test.go b/debug/log/memory/memory_test.go index db907f75..8fc861ac 100644 --- a/debug/log/memory/memory_test.go +++ b/debug/log/memory/memory_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/micro/go-micro/debug/log" + "github.com/micro/go-micro/v2/debug/log" ) func TestLogger(t *testing.T) { diff --git a/debug/log/memory/stream.go b/debug/log/memory/stream.go index a7992230..ae6493ae 100644 --- a/debug/log/memory/stream.go +++ b/debug/log/memory/stream.go @@ -1,7 +1,7 @@ package memory import ( - "github.com/micro/go-micro/debug/log" + "github.com/micro/go-micro/v2/debug/log" ) type logStream struct { diff --git a/debug/log/noop/noop.go b/debug/log/noop/noop.go index 2d8a40da..1cbeba6a 100644 --- a/debug/log/noop/noop.go +++ b/debug/log/noop/noop.go @@ -1,7 +1,7 @@ package noop import ( - "github.com/micro/go-micro/debug/log" + "github.com/micro/go-micro/v2/debug/log" ) type noop struct{} diff --git a/debug/log/os.go b/debug/log/os.go index ed96668d..3073eacf 100644 --- a/debug/log/os.go +++ b/debug/log/os.go @@ -10,7 +10,7 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/util/ring" + "github.com/micro/go-micro/v2/util/ring" ) // Should stream from OS diff --git a/debug/profile/http/http.go b/debug/profile/http/http.go index 66cbf49c..a21bc2eb 100644 --- a/debug/profile/http/http.go +++ b/debug/profile/http/http.go @@ -7,7 +7,7 @@ import ( "net/http/pprof" "sync" - "github.com/micro/go-micro/debug/profile" + "github.com/micro/go-micro/v2/debug/profile" ) type httpProfile struct { diff --git a/debug/profile/pprof/pprof.go b/debug/profile/pprof/pprof.go index 5dfd49ba..42761efe 100644 --- a/debug/profile/pprof/pprof.go +++ b/debug/profile/pprof/pprof.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/micro/go-micro/debug/profile" + "github.com/micro/go-micro/v2/debug/profile" ) type profiler struct { diff --git a/debug/service/client.go b/debug/service/client.go index 89209955..192101f3 100644 --- a/debug/service/client.go +++ b/debug/service/client.go @@ -5,10 +5,10 @@ import ( "context" "time" - "github.com/micro/go-micro/client" + "github.com/micro/go-micro/v2/client" - "github.com/micro/go-micro/debug/log" - pb "github.com/micro/go-micro/debug/service/proto" + "github.com/micro/go-micro/v2/debug/log" + pb "github.com/micro/go-micro/v2/debug/service/proto" ) // Debug provides debug service client diff --git a/debug/service/handler/debug.go b/debug/service/handler/debug.go index e66c8fb2..967a3218 100644 --- a/debug/service/handler/debug.go +++ b/debug/service/handler/debug.go @@ -5,11 +5,11 @@ import ( "context" "time" - "github.com/micro/go-micro/debug/log" - proto "github.com/micro/go-micro/debug/service/proto" - "github.com/micro/go-micro/debug/stats" - "github.com/micro/go-micro/debug/trace" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/debug/log" + proto "github.com/micro/go-micro/v2/debug/service/proto" + "github.com/micro/go-micro/v2/debug/stats" + "github.com/micro/go-micro/v2/debug/trace" + "github.com/micro/go-micro/v2/server" ) // NewHandler returns an instance of the Debug Handler diff --git a/debug/service/proto/debug.pb.micro.go b/debug/service/proto/debug.pb.micro.go index 2144f1b4..a5f773e1 100644 --- a/debug/service/proto/debug.pb.micro.go +++ b/debug/service/proto/debug.pb.micro.go @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/debug/service/service.go b/debug/service/service.go index 95ad0f3c..cadbe4b8 100644 --- a/debug/service/service.go +++ b/debug/service/service.go @@ -3,8 +3,8 @@ package service import ( "time" - "github.com/micro/go-micro/debug" - "github.com/micro/go-micro/debug/log" + "github.com/micro/go-micro/v2/debug" + "github.com/micro/go-micro/v2/debug/log" ) type serviceLog struct { diff --git a/debug/service/stream.go b/debug/service/stream.go index d7bd9765..f6662ad7 100644 --- a/debug/service/stream.go +++ b/debug/service/stream.go @@ -1,7 +1,7 @@ package service import ( - "github.com/micro/go-micro/debug/log" + "github.com/micro/go-micro/v2/debug/log" ) type logStream struct { diff --git a/debug/stats/default.go b/debug/stats/default.go index d4ffc23e..d36dfd0f 100644 --- a/debug/stats/default.go +++ b/debug/stats/default.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/micro/go-micro/util/ring" + "github.com/micro/go-micro/v2/util/ring" ) type stats struct { diff --git a/debug/trace/memory/memory.go b/debug/trace/memory/memory.go index 20420fa7..11413adc 100644 --- a/debug/trace/memory/memory.go +++ b/debug/trace/memory/memory.go @@ -5,8 +5,8 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/debug/trace" - "github.com/micro/go-micro/util/ring" + "github.com/micro/go-micro/v2/debug/trace" + "github.com/micro/go-micro/v2/util/ring" ) type Tracer struct { diff --git a/defaults.go b/defaults.go index 01854ff3..ca5b1e57 100644 --- a/defaults.go +++ b/defaults.go @@ -1,16 +1,16 @@ package micro import ( - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/debug/trace" - "github.com/micro/go-micro/server" - "github.com/micro/go-micro/store" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/debug/trace" + "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/store" // set defaults - gcli "github.com/micro/go-micro/client/grpc" - memTrace "github.com/micro/go-micro/debug/trace/memory" - gsrv "github.com/micro/go-micro/server/grpc" - memStore "github.com/micro/go-micro/store/memory" + gcli "github.com/micro/go-micro/v2/client/grpc" + memTrace "github.com/micro/go-micro/v2/debug/trace/memory" + gsrv "github.com/micro/go-micro/v2/server/grpc" + memStore "github.com/micro/go-micro/v2/store/memory" ) func init() { diff --git a/event.go b/event.go index 5301c747..c55e37bb 100644 --- a/event.go +++ b/event.go @@ -3,7 +3,7 @@ package micro import ( "context" - "github.com/micro/go-micro/client" + "github.com/micro/go-micro/v2/client" ) type event struct { diff --git a/function.go b/function.go index a9cc0d89..06037066 100644 --- a/function.go +++ b/function.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/server" ) type function struct { diff --git a/function_test.go b/function_test.go index 51d80fc9..8b26516e 100644 --- a/function_test.go +++ b/function_test.go @@ -5,9 +5,9 @@ import ( "sync" "testing" - proto "github.com/micro/go-micro/debug/service/proto" - "github.com/micro/go-micro/registry/memory" - "github.com/micro/go-micro/util/test" + proto "github.com/micro/go-micro/v2/debug/service/proto" + "github.com/micro/go-micro/v2/registry/memory" + "github.com/micro/go-micro/v2/util/test" ) func TestFunction(t *testing.T) { diff --git a/go.mod b/go.mod index 8dfa1e41..eb869453 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/micro/go-micro +module github.com/micro/go-micro/v2 go 1.13 @@ -6,37 +6,29 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/beevik/ntp v0.2.0 github.com/bitly/go-simplejson v0.5.0 - github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect github.com/bwmarrin/discordgo v0.20.2 - github.com/coreos/bbolt v1.3.3 // indirect github.com/coreos/etcd v3.3.18+incompatible - github.com/coreos/go-semver v0.3.0 // indirect - github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c github.com/fsnotify/fsnotify v1.4.7 github.com/fsouza/go-dockerclient v1.6.0 github.com/ghodss/yaml v1.0.0 github.com/go-acme/lego/v3 v3.3.0 github.com/go-playground/universal-translator v0.17.0 // indirect - github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/websocket v1.4.1 - github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect - github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/hashicorp/hcl v1.0.0 github.com/imdario/mergo v0.3.8 - github.com/jonboulle/clockwork v0.1.0 // indirect github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 github.com/json-iterator/go v1.1.9 github.com/kr/pretty v0.1.0 - github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 github.com/mholt/certmagic v0.9.1 github.com/micro/cli/v2 v2.1.1 + github.com/micro/go-micro v1.18.0 github.com/micro/mdns v0.3.0 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 @@ -45,19 +37,13 @@ require ( github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/pkg/errors v0.9.1 - github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 - github.com/technoweenie/multipartstreamer v1.0.1 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect - github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect - go.etcd.io/bbolt v1.3.3 // indirect go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200117160349-530e935923ad golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa google.golang.org/grpc v1.26.0 - gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 - sigs.k8s.io/yaml v1.1.0 // indirect ) diff --git a/go.sum b/go.sum index 05236368..ef80de45 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,10 @@ github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvd github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 h1:ygIc8M6trr62pF5DucadTWGdEB4mEyvzi0e2nbcmcyA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= +github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= @@ -64,6 +66,8 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= +github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= +github.com/bwmarrin/discordgo v0.20.1/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= @@ -80,6 +84,7 @@ github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0 h1:xjvXQWABwS2uiv3TWgQt5Uth60Gu86LTGZXMJkjc7rY= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= +github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVlf61smEIq1nwLLAjQVEK2EADoW3CX9AuT+8= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= @@ -88,12 +93,15 @@ github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDG github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c= +github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpu/goacmedns v0.0.1/go.mod h1:sesf/pNnCYwUevQEQfEwY0Y3DydlQWSGZbaMElOWxok= @@ -103,6 +111,7 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decker502/dnspod-go v0.2.0/go.mod h1:qsurYu1FgxcDwfSwXJdLt4kRsBLZeosEb9uq4Sy+08g= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= @@ -110,6 +119,7 @@ github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s9 github.com/dnsimple/dnsimple-go v0.30.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v1.4.2-0.20190710153559-aa8249ae1b8b/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23 h1:oqgGT9O61YAYvI41EBsLePOr+LE6roB0xY4gpkZuFSE= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= @@ -121,6 +131,7 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1 github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= @@ -131,12 +142,14 @@ github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXj github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsouza/go-dockerclient v1.4.4/go.mod h1:PrwszSL5fbmsESocROrOGq/NULMXRw+bajY0ltzD6MA= github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4GGn3Hig= github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= +github.com/go-acme/lego/v3 v3.1.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= github.com/go-acme/lego/v3 v3.3.0 h1:6BePZsOiYA4/w+M7QDytxQtMfCipMPGnWAHs9pWks98= github.com/go-acme/lego/v3 v3.3.0/go.mod h1:iGSY2vQrvQs3WezicSB/oVbO2eCrD88dpWPwb1qLqu0= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= @@ -144,10 +157,14 @@ github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-log/log v0.1.0 h1:wudGTNsiGzrD5ZjgIkVZ517ugi2XRe9Q/xRCzwEO4/U= +github.com/go-log/log v0.1.0/go.mod h1:4mBwpdRMFLiuXZDCwU2lKQFsoSCo72j3HqBK9d81N2M= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -162,6 +179,7 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -222,6 +240,7 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= +github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd/go.mod h1:3LVOLeyx9XVvwPgrt2be44XgSqndprz1G18rSk8KD84= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= @@ -235,6 +254,7 @@ github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1/go.mod h1:DFXrEwSR github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= @@ -259,17 +279,22 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= +github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ= +github.com/lucas-clemente/quic-go v0.12.1/go.mod h1:UXJJPE4RfFef/xPO5wQm0tITK8gNfqwTxjbE7s3Vb8s= +github.com/lucas-clemente/quic-go v0.13.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= github.com/lucas-clemente/quic-go v0.14.1 h1:c1aKoBZKOPA+49q96B1wGkibyPP0AxYh45WuAoq+87E= github.com/lucas-clemente/quic-go v0.14.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ= github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE= github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= +github.com/marten-seemann/qtls v0.3.2/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -278,14 +303,23 @@ github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mholt/certmagic v0.7.5/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= +github.com/mholt/certmagic v0.8.3/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= github.com/mholt/certmagic v0.9.1 h1:wPzyouOyE+30NIQETJuhTB5ZQWz+0Hy038vaR5WWQDE= github.com/mholt/certmagic v0.9.1/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= +github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= +github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= github.com/micro/cli/v2 v2.1.1 h1:uFw0SMIKmGuyHIm8lXns/NOn7V62bM5y7DnlxUM+BEQ= github.com/micro/cli/v2 v2.1.1/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= +github.com/micro/go-micro v1.16.0/go.mod h1:A0F58bHLh2m0LAI9QyhvmbN8c1cxhAZo3cM6s+iDsrM= +github.com/micro/go-micro v1.18.0 h1:gP70EZVHpJuUIT0YWth192JmlIci+qMOEByHm83XE9E= +github.com/micro/go-micro v1.18.0/go.mod h1:klwUJL1gkdY1MHFyz+fFJXn52dKcty4hoe95Mp571AA= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= +github.com/micro/protoc-gen-micro v1.0.0/go.mod h1:C8ij4DJhapBmypcT00AXdb0cZ675/3PqUO02buWWqbE= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -307,16 +341,20 @@ github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= +github.com/nats-io/nats-server/v2 v2.1.0/go.mod h1:r5y0WgCag0dTj/qiHkHrXAcKQ/f5GMOZaEGdoxxnJ4I= github.com/nats-io/nats-server/v2 v2.1.2 h1:i2Ly0B+1+rzNZHHWtD4ZwKi+OU5l+uQo1iDHZ2PmiIc= github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= +github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= +github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= +github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= @@ -407,6 +445,7 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc h1:yUaosFVTJwnltaHbSNC3i82I92quFs+OFPRl8kNMVwo= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= @@ -433,28 +472,35 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.2.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.12.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg= golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -499,7 +545,9 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -523,6 +571,7 @@ golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -532,12 +581,16 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 h1:Hynbrlo6LbYI3H1IqXpkVDOcX/3HiPdhVEuyj5a59RM= +golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= @@ -563,6 +616,7 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -593,6 +647,7 @@ google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1 h1:aQktFqmDE2yjveXJlVIfslDFmFnUXSqG0i6KRcJAeMc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= @@ -602,6 +657,8 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= @@ -613,6 +670,7 @@ gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= diff --git a/micro.go b/micro.go index 6dc43848..77be00d0 100644 --- a/micro.go +++ b/micro.go @@ -4,8 +4,8 @@ package micro import ( "context" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/server" ) type serviceKey struct{} diff --git a/monitor/default.go b/monitor/default.go index b37b5658..380c036b 100644 --- a/monitor/default.go +++ b/monitor/default.go @@ -6,10 +6,10 @@ import ( "sync" "time" - "github.com/micro/go-micro/client" - pb "github.com/micro/go-micro/debug/service/proto" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/registry/cache" + "github.com/micro/go-micro/v2/client" + pb "github.com/micro/go-micro/v2/debug/service/proto" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/registry/cache" ) type monitor struct { diff --git a/monitor/options.go b/monitor/options.go index 445d39d9..6bb74a02 100644 --- a/monitor/options.go +++ b/monitor/options.go @@ -1,8 +1,8 @@ package monitor import ( - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/registry" ) type Options struct { diff --git a/network/default.go b/network/default.go index 48e6f9ee..a5613827 100644 --- a/network/default.go +++ b/network/default.go @@ -12,23 +12,23 @@ import ( "time" "github.com/golang/protobuf/proto" - "github.com/micro/go-micro/client" - cmucp "github.com/micro/go-micro/client/mucp" - rtr "github.com/micro/go-micro/client/selector/router" - "github.com/micro/go-micro/network/resolver/dns" - pbNet "github.com/micro/go-micro/network/service/proto" - "github.com/micro/go-micro/proxy" - "github.com/micro/go-micro/router" - pbRtr "github.com/micro/go-micro/router/service/proto" - "github.com/micro/go-micro/server" - smucp "github.com/micro/go-micro/server/mucp" - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/tunnel" - bun "github.com/micro/go-micro/tunnel/broker" - tun "github.com/micro/go-micro/tunnel/transport" - "github.com/micro/go-micro/util/backoff" - "github.com/micro/go-micro/util/log" - pbUtil "github.com/micro/go-micro/util/proto" + "github.com/micro/go-micro/v2/client" + cmucp "github.com/micro/go-micro/v2/client/mucp" + rtr "github.com/micro/go-micro/v2/client/selector/router" + "github.com/micro/go-micro/v2/network/resolver/dns" + pbNet "github.com/micro/go-micro/v2/network/service/proto" + "github.com/micro/go-micro/v2/proxy" + "github.com/micro/go-micro/v2/router" + pbRtr "github.com/micro/go-micro/v2/router/service/proto" + "github.com/micro/go-micro/v2/server" + smucp "github.com/micro/go-micro/v2/server/mucp" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/tunnel" + bun "github.com/micro/go-micro/v2/tunnel/broker" + tun "github.com/micro/go-micro/v2/tunnel/transport" + "github.com/micro/go-micro/v2/util/backoff" + "github.com/micro/go-micro/v2/util/log" + pbUtil "github.com/micro/go-micro/v2/util/proto" ) var ( diff --git a/network/network.go b/network/network.go index 535870f0..e71c6ab2 100644 --- a/network/network.go +++ b/network/network.go @@ -4,8 +4,8 @@ package network import ( "time" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/server" ) var ( diff --git a/network/node.go b/network/node.go index 4ff181f6..b952f0ce 100644 --- a/network/node.go +++ b/network/node.go @@ -6,7 +6,7 @@ import ( "sync" "time" - pb "github.com/micro/go-micro/network/service/proto" + pb "github.com/micro/go-micro/v2/network/service/proto" ) var ( diff --git a/network/node_test.go b/network/node_test.go index 99975415..d256e3f8 100644 --- a/network/node_test.go +++ b/network/node_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - pb "github.com/micro/go-micro/network/service/proto" + pb "github.com/micro/go-micro/v2/network/service/proto" ) var ( diff --git a/network/options.go b/network/options.go index 63ff6fe7..084dce63 100644 --- a/network/options.go +++ b/network/options.go @@ -2,12 +2,12 @@ package network import ( "github.com/google/uuid" - "github.com/micro/go-micro/network/resolver" - "github.com/micro/go-micro/network/resolver/registry" - "github.com/micro/go-micro/proxy" - "github.com/micro/go-micro/proxy/mucp" - "github.com/micro/go-micro/router" - "github.com/micro/go-micro/tunnel" + "github.com/micro/go-micro/v2/network/resolver" + "github.com/micro/go-micro/v2/network/resolver/registry" + "github.com/micro/go-micro/v2/proxy" + "github.com/micro/go-micro/v2/proxy/mucp" + "github.com/micro/go-micro/v2/router" + "github.com/micro/go-micro/v2/tunnel" ) type Option func(*Options) diff --git a/network/resolver/dns/dns.go b/network/resolver/dns/dns.go index a8d27b06..2b1670f1 100644 --- a/network/resolver/dns/dns.go +++ b/network/resolver/dns/dns.go @@ -5,7 +5,7 @@ import ( "context" "net" - "github.com/micro/go-micro/network/resolver" + "github.com/micro/go-micro/v2/network/resolver" "github.com/miekg/dns" ) diff --git a/network/resolver/dnssrv/dnssrv.go b/network/resolver/dnssrv/dnssrv.go index 63a92eda..80259eec 100644 --- a/network/resolver/dnssrv/dnssrv.go +++ b/network/resolver/dnssrv/dnssrv.go @@ -5,7 +5,7 @@ import ( "fmt" "net" - "github.com/micro/go-micro/network/resolver" + "github.com/micro/go-micro/v2/network/resolver" ) // Resolver is a DNS network resolve diff --git a/network/resolver/http/http.go b/network/resolver/http/http.go index 889ad687..ad3d1654 100644 --- a/network/resolver/http/http.go +++ b/network/resolver/http/http.go @@ -8,7 +8,7 @@ import ( "net/http" "net/url" - "github.com/micro/go-micro/network/resolver" + "github.com/micro/go-micro/v2/network/resolver" ) // Resolver is a HTTP network resolver diff --git a/network/resolver/registry/registry.go b/network/resolver/registry/registry.go index 20fffc18..0852d9c8 100644 --- a/network/resolver/registry/registry.go +++ b/network/resolver/registry/registry.go @@ -2,8 +2,8 @@ package registry import ( - "github.com/micro/go-micro/network/resolver" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/network/resolver" + "github.com/micro/go-micro/v2/registry" ) // Resolver is a registry network resolver diff --git a/network/resolver/static/static.go b/network/resolver/static/static.go index 485332c5..49f64003 100644 --- a/network/resolver/static/static.go +++ b/network/resolver/static/static.go @@ -2,7 +2,7 @@ package registry import ( - "github.com/micro/go-micro/network/resolver" + "github.com/micro/go-micro/v2/network/resolver" ) // Resolver returns a static list of nodes. In the event the node list diff --git a/network/service/proto/network.pb.go b/network/service/proto/network.pb.go index 54902c65..6dded795 100644 --- a/network/service/proto/network.pb.go +++ b/network/service/proto/network.pb.go @@ -6,7 +6,7 @@ package go_micro_network import ( fmt "fmt" proto "github.com/golang/protobuf/proto" - proto1 "github.com/micro/go-micro/router/service/proto" + proto1 "github.com/micro/go-micro/v2/router/service/proto" math "math" ) diff --git a/network/service/proto/network.pb.micro.go b/network/service/proto/network.pb.micro.go index a6df00c6..4fbda43d 100644 --- a/network/service/proto/network.pb.micro.go +++ b/network/service/proto/network.pb.micro.go @@ -6,14 +6,14 @@ package go_micro_network import ( fmt "fmt" proto "github.com/golang/protobuf/proto" - _ "github.com/micro/go-micro/router/service/proto" + _ "github.com/micro/go-micro/v2/router/service/proto" math "math" ) import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/options.go b/options.go index 1642704d..d616115e 100644 --- a/options.go +++ b/options.go @@ -5,14 +5,14 @@ import ( "time" "github.com/micro/cli/v2" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/config/cmd" - "github.com/micro/go-micro/debug/trace" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/server" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/config/cmd" + "github.com/micro/go-micro/v2/debug/trace" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/transport" ) type Options struct { diff --git a/plugin/default.go b/plugin/default.go index 8fde651a..794f8622 100644 --- a/plugin/default.go +++ b/plugin/default.go @@ -11,13 +11,13 @@ import ( "strings" "text/template" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/config/cmd" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/server" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/config/cmd" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/transport" ) type plugin struct{} diff --git a/plugin/template.go b/plugin/template.go index dd559bfa..38e6f7e4 100644 --- a/plugin/template.go +++ b/plugin/template.go @@ -5,7 +5,7 @@ var ( package main import ( - "github.com/micro/go-micro/plugin" + "github.com/micro/go-micro/v2/plugin" "{{.Path}}" ) diff --git a/proxy/grpc/grpc.go b/proxy/grpc/grpc.go index e8a28877..0df9bbe0 100644 --- a/proxy/grpc/grpc.go +++ b/proxy/grpc/grpc.go @@ -6,11 +6,11 @@ import ( "io" "strings" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/client/grpc" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/proxy" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/grpc" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/proxy" + "github.com/micro/go-micro/v2/server" ) // Proxy will transparently proxy requests to the backend. diff --git a/proxy/http/http.go b/proxy/http/http.go index dd666763..06332da5 100644 --- a/proxy/http/http.go +++ b/proxy/http/http.go @@ -10,9 +10,9 @@ import ( "net/url" "path" - "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/proxy" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/proxy" + "github.com/micro/go-micro/v2/server" ) // Proxy will proxy rpc requests as http POST requests. It is a server.Proxy diff --git a/proxy/http/http_test.go b/proxy/http/http_test.go index acdcde95..fd3a1c11 100644 --- a/proxy/http/http_test.go +++ b/proxy/http/http_test.go @@ -8,10 +8,10 @@ import ( "sync" "testing" - "github.com/micro/go-micro" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/registry/memory" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/registry/memory" + "github.com/micro/go-micro/v2/server" ) type testHandler struct{} diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index e42a13fd..68fa35f6 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -10,16 +10,16 @@ import ( "sync" "time" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/codec/bytes" - "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/metadata" - "github.com/micro/go-micro/proxy" - "github.com/micro/go-micro/router" - "github.com/micro/go-micro/server" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/codec/bytes" + "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/metadata" + "github.com/micro/go-micro/v2/proxy" + "github.com/micro/go-micro/v2/router" + "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/util/log" ) // Proxy will transparently proxy requests to an endpoint. diff --git a/proxy/options.go b/proxy/options.go index 20ca9c4d..877d66d5 100644 --- a/proxy/options.go +++ b/proxy/options.go @@ -2,8 +2,8 @@ package proxy import ( - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/router" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/router" ) type Options struct { diff --git a/proxy/proxy.go b/proxy/proxy.go index 982ad3c6..6b7b3a8d 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -4,7 +4,7 @@ package proxy import ( "context" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/server" ) // Proxy can be used as a proxy server for go-micro services diff --git a/registry/cache/cache.go b/registry/cache/cache.go index 75fcac32..51c3aac0 100644 --- a/registry/cache/cache.go +++ b/registry/cache/cache.go @@ -7,8 +7,8 @@ import ( "sync" "time" - "github.com/micro/go-micro/registry" - log "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/registry" + log "github.com/micro/go-micro/v2/util/log" ) // Cache is the registry cache interface diff --git a/registry/etcd/etcd.go b/registry/etcd/etcd.go index c93a2801..b51a4010 100644 --- a/registry/etcd/etcd.go +++ b/registry/etcd/etcd.go @@ -15,8 +15,8 @@ import ( "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/util/log" hash "github.com/mitchellh/hashstructure" "go.uber.org/zap" ) diff --git a/registry/etcd/options.go b/registry/etcd/options.go index 611e119f..b3ea19f1 100644 --- a/registry/etcd/options.go +++ b/registry/etcd/options.go @@ -3,7 +3,7 @@ package etcd import ( "context" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" "go.uber.org/zap" ) diff --git a/registry/etcd/watcher.go b/registry/etcd/watcher.go index 4eef76ba..fdf2ea58 100644 --- a/registry/etcd/watcher.go +++ b/registry/etcd/watcher.go @@ -6,7 +6,7 @@ import ( "time" "github.com/coreos/etcd/clientv3" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) type etcdWatcher struct { diff --git a/registry/kubernetes/kubernetes.go b/registry/kubernetes/kubernetes.go index 47fa7090..81719376 100644 --- a/registry/kubernetes/kubernetes.go +++ b/registry/kubernetes/kubernetes.go @@ -10,8 +10,8 @@ import ( "strings" "time" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/util/kubernetes/client" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/util/kubernetes/client" ) type kregistry struct { diff --git a/registry/kubernetes/watcher.go b/registry/kubernetes/watcher.go index c51d4fc8..0d848c4a 100644 --- a/registry/kubernetes/watcher.go +++ b/registry/kubernetes/watcher.go @@ -6,9 +6,9 @@ import ( "strings" "sync" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/util/kubernetes/client" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/util/kubernetes/client" + "github.com/micro/go-micro/v2/util/log" ) type k8sWatcher struct { diff --git a/registry/mdns/mdns.go b/registry/mdns/mdns.go index f84e8961..498b2429 100644 --- a/registry/mdns/mdns.go +++ b/registry/mdns/mdns.go @@ -4,7 +4,7 @@ package mdns import ( "context" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) // NewRegistry returns a new mdns registry diff --git a/registry/memory/memory.go b/registry/memory/memory.go index 3d7b782e..2586d5e4 100644 --- a/registry/memory/memory.go +++ b/registry/memory/memory.go @@ -7,8 +7,8 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/util/log" ) var ( diff --git a/registry/memory/memory_test.go b/registry/memory/memory_test.go index cab6a6f4..9609b20c 100644 --- a/registry/memory/memory_test.go +++ b/registry/memory/memory_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) var ( diff --git a/registry/memory/memory_watcher.go b/registry/memory/memory_watcher.go index 8eb3cfd1..79346ec3 100644 --- a/registry/memory/memory_watcher.go +++ b/registry/memory/memory_watcher.go @@ -3,7 +3,7 @@ package memory import ( "errors" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) type memoryWatcher struct { diff --git a/registry/memory/options.go b/registry/memory/options.go index 7922dcaa..57e430ef 100644 --- a/registry/memory/options.go +++ b/registry/memory/options.go @@ -3,7 +3,7 @@ package memory import ( "context" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) type servicesKey struct{} diff --git a/registry/memory/util.go b/registry/memory/util.go index d78e3324..32a3852d 100644 --- a/registry/memory/util.go +++ b/registry/memory/util.go @@ -3,7 +3,7 @@ package memory import ( "time" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) func serviceToRecord(s *registry.Service, ttl time.Duration) *record { diff --git a/registry/memory/watcher.go b/registry/memory/watcher.go index c1a7067c..76ae6440 100644 --- a/registry/memory/watcher.go +++ b/registry/memory/watcher.go @@ -3,7 +3,7 @@ package memory import ( "errors" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) type Watcher struct { diff --git a/registry/memory/watcher_test.go b/registry/memory/watcher_test.go index 1df468fd..37b4a4ae 100644 --- a/registry/memory/watcher_test.go +++ b/registry/memory/watcher_test.go @@ -3,7 +3,7 @@ package memory import ( "testing" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) func TestWatcher(t *testing.T) { diff --git a/registry/service/proto/registry.pb.micro.go b/registry/service/proto/registry.pb.micro.go index 254935ed..7317a4eb 100644 --- a/registry/service/proto/registry.pb.micro.go +++ b/registry/service/proto/registry.pb.micro.go @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/registry/service/service.go b/registry/service/service.go index 42aa89d8..e266347f 100644 --- a/registry/service/service.go +++ b/registry/service/service.go @@ -5,10 +5,10 @@ import ( "context" "time" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/client/grpc" - "github.com/micro/go-micro/registry" - pb "github.com/micro/go-micro/registry/service/proto" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/grpc" + "github.com/micro/go-micro/v2/registry" + pb "github.com/micro/go-micro/v2/registry/service/proto" ) var ( diff --git a/registry/service/util.go b/registry/service/util.go index 76d8ea9d..4ba5f4da 100644 --- a/registry/service/util.go +++ b/registry/service/util.go @@ -1,8 +1,8 @@ package service import ( - "github.com/micro/go-micro/registry" - pb "github.com/micro/go-micro/registry/service/proto" + "github.com/micro/go-micro/v2/registry" + pb "github.com/micro/go-micro/v2/registry/service/proto" ) func values(v []*registry.Value) []*pb.Value { diff --git a/registry/service/watcher.go b/registry/service/watcher.go index 973f9547..bf998a2f 100644 --- a/registry/service/watcher.go +++ b/registry/service/watcher.go @@ -1,8 +1,8 @@ package service import ( - "github.com/micro/go-micro/registry" - pb "github.com/micro/go-micro/registry/service/proto" + "github.com/micro/go-micro/v2/registry" + pb "github.com/micro/go-micro/v2/registry/service/proto" ) type serviceWatcher struct { diff --git a/router/default.go b/router/default.go index f699651c..7056f1a0 100644 --- a/router/default.go +++ b/router/default.go @@ -10,8 +10,8 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/util/log" ) var ( diff --git a/router/default_test.go b/router/default_test.go index 581ef7ae..c94ac9b4 100644 --- a/router/default_test.go +++ b/router/default_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" - "github.com/micro/go-micro/registry/memory" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/registry/memory" + "github.com/micro/go-micro/v2/util/log" ) func routerTestSetup() Router { diff --git a/router/options.go b/router/options.go index 0fa67b4f..a5f44b46 100644 --- a/router/options.go +++ b/router/options.go @@ -2,8 +2,8 @@ package router import ( "github.com/google/uuid" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/registry" ) // Options are router options diff --git a/router/service/proto/router.pb.micro.go b/router/service/proto/router.pb.micro.go index ae8143bc..5bc8c690 100644 --- a/router/service/proto/router.pb.micro.go +++ b/router/service/proto/router.pb.micro.go @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/router/service/service.go b/router/service/service.go index 1de462a7..97b329e7 100644 --- a/router/service/service.go +++ b/router/service/service.go @@ -7,9 +7,9 @@ import ( "sync" "time" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/router" - pb "github.com/micro/go-micro/router/service/proto" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/router" + pb "github.com/micro/go-micro/v2/router/service/proto" ) type svc struct { diff --git a/router/service/table.go b/router/service/table.go index bcfc8ef3..8590d323 100644 --- a/router/service/table.go +++ b/router/service/table.go @@ -3,9 +3,9 @@ package service import ( "context" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/router" - pb "github.com/micro/go-micro/router/service/proto" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/router" + pb "github.com/micro/go-micro/v2/router/service/proto" ) type table struct { diff --git a/router/service/watcher.go b/router/service/watcher.go index 2ffc7ada..3f641e8b 100644 --- a/router/service/watcher.go +++ b/router/service/watcher.go @@ -5,8 +5,8 @@ import ( "sync" "time" - "github.com/micro/go-micro/router" - pb "github.com/micro/go-micro/router/service/proto" + "github.com/micro/go-micro/v2/router" + pb "github.com/micro/go-micro/v2/router/service/proto" ) type watcher struct { diff --git a/router/table.go b/router/table.go index 8ee853ec..df17ee3e 100644 --- a/router/table.go +++ b/router/table.go @@ -6,7 +6,7 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/util/log" ) var ( diff --git a/runtime/default.go b/runtime/default.go index 453510a3..eed3ff3f 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/util/log" ) type runtime struct { diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index fe9b5af8..3545967b 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -6,9 +6,9 @@ import ( "sync" "time" - "github.com/micro/go-micro/runtime" - "github.com/micro/go-micro/util/kubernetes/client" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/runtime" + "github.com/micro/go-micro/v2/util/kubernetes/client" + "github.com/micro/go-micro/v2/util/log" ) // action to take on runtime service diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 3b6963be..6c3024cb 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -5,10 +5,10 @@ import ( "strings" "time" - "github.com/micro/go-micro/runtime" - "github.com/micro/go-micro/util/kubernetes/api" - "github.com/micro/go-micro/util/kubernetes/client" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/runtime" + "github.com/micro/go-micro/v2/util/kubernetes/api" + "github.com/micro/go-micro/v2/util/kubernetes/client" + "github.com/micro/go-micro/v2/util/log" ) type service struct { diff --git a/runtime/local/build/build.go b/runtime/local/build/build.go index a179ec0e..568ddc3f 100644 --- a/runtime/local/build/build.go +++ b/runtime/local/build/build.go @@ -2,7 +2,7 @@ package build import ( - "github.com/micro/go-micro/runtime/local/source" + "github.com/micro/go-micro/v2/runtime/local/source" ) // Builder builds binaries diff --git a/runtime/local/build/docker/docker.go b/runtime/local/build/docker/docker.go index 84b163d4..bb953a71 100644 --- a/runtime/local/build/docker/docker.go +++ b/runtime/local/build/docker/docker.go @@ -9,8 +9,8 @@ import ( "path/filepath" docker "github.com/fsouza/go-dockerclient" - "github.com/micro/go-micro/runtime/local/build" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/runtime/local/build" + "github.com/micro/go-micro/v2/util/log" ) type Builder struct { diff --git a/runtime/local/build/go/golang.go b/runtime/local/build/go/golang.go index c11430c0..ce12124d 100644 --- a/runtime/local/build/go/golang.go +++ b/runtime/local/build/go/golang.go @@ -6,7 +6,7 @@ import ( "os/exec" "path/filepath" - "github.com/micro/go-micro/runtime/local/build" + "github.com/micro/go-micro/v2/runtime/local/build" ) type Builder struct { diff --git a/runtime/local/process/os/os.go b/runtime/local/process/os/os.go index 1fb9f231..f1825e97 100644 --- a/runtime/local/process/os/os.go +++ b/runtime/local/process/os/os.go @@ -10,7 +10,7 @@ import ( "strconv" "syscall" - "github.com/micro/go-micro/runtime/local/process" + "github.com/micro/go-micro/v2/runtime/local/process" ) func (p *Process) Exec(exe *process.Executable) error { diff --git a/runtime/local/process/os/os_windows.go b/runtime/local/process/os/os_windows.go index 38ff70a5..d5c7869d 100644 --- a/runtime/local/process/os/os_windows.go +++ b/runtime/local/process/os/os_windows.go @@ -7,7 +7,7 @@ import ( "os/exec" "strconv" - "github.com/micro/go-micro/runtime/local/process" + "github.com/micro/go-micro/v2/runtime/local/process" ) func (p *Process) Exec(exe *process.Executable) error { diff --git a/runtime/local/process/os/process.go b/runtime/local/process/os/process.go index 71f85a2c..8a939177 100644 --- a/runtime/local/process/os/process.go +++ b/runtime/local/process/os/process.go @@ -2,7 +2,7 @@ package os import ( - "github.com/micro/go-micro/runtime/local/process" + "github.com/micro/go-micro/v2/runtime/local/process" ) type Process struct{} diff --git a/runtime/local/process/process.go b/runtime/local/process/process.go index 8d2bdf7e..4449d294 100644 --- a/runtime/local/process/process.go +++ b/runtime/local/process/process.go @@ -4,7 +4,7 @@ package process import ( "io" - "github.com/micro/go-micro/runtime/local/build" + "github.com/micro/go-micro/v2/runtime/local/build" ) // Process manages a running process diff --git a/runtime/local/source/git/git.go b/runtime/local/source/git/git.go index 516e8857..7581040f 100644 --- a/runtime/local/source/git/git.go +++ b/runtime/local/source/git/git.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "github.com/micro/go-micro/runtime/local/source" + "github.com/micro/go-micro/v2/runtime/local/source" git "gopkg.in/src-d/go-git.v4" ) diff --git a/runtime/local/source/go/golang.go b/runtime/local/source/go/golang.go index 95abdc60..82df5920 100644 --- a/runtime/local/source/go/golang.go +++ b/runtime/local/source/go/golang.go @@ -7,7 +7,7 @@ import ( "path/filepath" "strings" - "github.com/micro/go-micro/runtime/local/source" + "github.com/micro/go-micro/v2/runtime/local/source" ) type Source struct { diff --git a/runtime/service.go b/runtime/service.go index efd499a3..ea42dc9e 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -5,10 +5,10 @@ import ( "sync" "time" - "github.com/micro/go-micro/runtime/local/build" - "github.com/micro/go-micro/runtime/local/process" - proc "github.com/micro/go-micro/runtime/local/process/os" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/runtime/local/build" + "github.com/micro/go-micro/v2/runtime/local/process" + proc "github.com/micro/go-micro/v2/runtime/local/process/os" + "github.com/micro/go-micro/v2/util/log" ) type service struct { diff --git a/runtime/service/proto/runtime.pb.micro.go b/runtime/service/proto/runtime.pb.micro.go index 38f340d4..a357362d 100644 --- a/runtime/service/proto/runtime.pb.micro.go +++ b/runtime/service/proto/runtime.pb.micro.go @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/runtime/service/service.go b/runtime/service/service.go index 5ecfb9ec..c46c5ba4 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -4,9 +4,9 @@ import ( "context" "sync" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/runtime" - pb "github.com/micro/go-micro/runtime/service/proto" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/runtime" + pb "github.com/micro/go-micro/v2/runtime/service/proto" ) type svc struct { diff --git a/server/extractor.go b/server/extractor.go index 2a9d4e01..49655605 100644 --- a/server/extractor.go +++ b/server/extractor.go @@ -5,7 +5,7 @@ import ( "reflect" "strings" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) func extractValue(v reflect.Type, d int) *registry.Value { diff --git a/server/extractor_test.go b/server/extractor_test.go index 8cae373c..8512f241 100644 --- a/server/extractor_test.go +++ b/server/extractor_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) type testHandler struct{} diff --git a/server/grpc/codec.go b/server/grpc/codec.go index dff9f600..cb27ec6e 100644 --- a/server/grpc/codec.go +++ b/server/grpc/codec.go @@ -9,10 +9,10 @@ import ( "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/codec/bytes" - "github.com/micro/go-micro/codec/jsonrpc" - "github.com/micro/go-micro/codec/protorpc" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/codec/bytes" + "github.com/micro/go-micro/v2/codec/jsonrpc" + "github.com/micro/go-micro/v2/codec/protorpc" "google.golang.org/grpc" "google.golang.org/grpc/encoding" "google.golang.org/grpc/metadata" diff --git a/server/grpc/error.go b/server/grpc/error.go index 4001622d..45564152 100644 --- a/server/grpc/error.go +++ b/server/grpc/error.go @@ -3,7 +3,7 @@ package grpc import ( "net/http" - "github.com/micro/go-micro/errors" + "github.com/micro/go-micro/v2/errors" "google.golang.org/grpc/codes" ) diff --git a/server/grpc/extractor.go b/server/grpc/extractor.go index 875bb1c9..5576182b 100644 --- a/server/grpc/extractor.go +++ b/server/grpc/extractor.go @@ -5,7 +5,7 @@ import ( "reflect" "strings" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) func extractValue(v reflect.Type, d int) *registry.Value { diff --git a/server/grpc/extractor_test.go b/server/grpc/extractor_test.go index ebbd0e2b..ccf99424 100644 --- a/server/grpc/extractor_test.go +++ b/server/grpc/extractor_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) type testHandler struct{} diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 53674aa7..7a098e86 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -14,16 +14,16 @@ import ( "sync" "time" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/errors" - meta "github.com/micro/go-micro/metadata" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/server" - "github.com/micro/go-micro/util/addr" - mgrpc "github.com/micro/go-micro/util/grpc" - "github.com/micro/go-micro/util/log" - mnet "github.com/micro/go-micro/util/net" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/errors" + meta "github.com/micro/go-micro/v2/metadata" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/util/addr" + mgrpc "github.com/micro/go-micro/v2/util/grpc" + "github.com/micro/go-micro/v2/util/log" + mnet "github.com/micro/go-micro/v2/util/net" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/server/grpc/grpc_test.go b/server/grpc/grpc_test.go index dcf7350b..5d218ccf 100644 --- a/server/grpc/grpc_test.go +++ b/server/grpc/grpc_test.go @@ -4,11 +4,11 @@ import ( "context" "testing" - "github.com/micro/go-micro/registry/memory" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/registry/memory" + "github.com/micro/go-micro/v2/server" "google.golang.org/grpc" - pb "github.com/micro/go-micro/server/grpc/proto" + pb "github.com/micro/go-micro/v2/server/grpc/proto" ) // server is used to implement helloworld.GreeterServer. diff --git a/server/grpc/handler.go b/server/grpc/handler.go index f41a1fe9..fb4e2bbe 100644 --- a/server/grpc/handler.go +++ b/server/grpc/handler.go @@ -3,8 +3,8 @@ package grpc import ( "reflect" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/server" ) type rpcHandler struct { diff --git a/server/grpc/options.go b/server/grpc/options.go index c57c022e..b411b88e 100644 --- a/server/grpc/options.go +++ b/server/grpc/options.go @@ -4,11 +4,11 @@ import ( "context" "crypto/tls" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/server" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/transport" "google.golang.org/grpc" "google.golang.org/grpc/encoding" ) diff --git a/server/grpc/proto/test.micro.go b/server/grpc/proto/test.micro.go index b00e7ea3..5cc8a4e0 100644 --- a/server/grpc/proto/test.micro.go +++ b/server/grpc/proto/test.micro.go @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/server/grpc/request.go b/server/grpc/request.go index adfed48e..1261bbc8 100644 --- a/server/grpc/request.go +++ b/server/grpc/request.go @@ -1,8 +1,8 @@ package grpc import ( - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/codec/bytes" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/codec/bytes" ) type rpcRequest struct { diff --git a/server/grpc/response.go b/server/grpc/response.go index f13ad89c..e5c74fc2 100644 --- a/server/grpc/response.go +++ b/server/grpc/response.go @@ -1,7 +1,7 @@ package grpc import ( - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) type rpcResponse struct { diff --git a/server/grpc/server.go b/server/grpc/server.go index 140d7e5b..6d43ba17 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -14,8 +14,8 @@ import ( "unicode" "unicode/utf8" - "github.com/micro/go-micro/server" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/util/log" ) var ( diff --git a/server/grpc/stream.go b/server/grpc/stream.go index ae31a0bb..92165864 100644 --- a/server/grpc/stream.go +++ b/server/grpc/stream.go @@ -3,7 +3,7 @@ package grpc import ( "context" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/server" "google.golang.org/grpc" ) diff --git a/server/grpc/subscriber.go b/server/grpc/subscriber.go index 9dd071c1..c628a6e0 100644 --- a/server/grpc/subscriber.go +++ b/server/grpc/subscriber.go @@ -7,12 +7,12 @@ import ( "runtime/debug" "strings" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/metadata" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/server" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/metadata" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/util/log" ) const ( diff --git a/server/mock/mock.go b/server/mock/mock.go index ce2a4671..0725cbfc 100644 --- a/server/mock/mock.go +++ b/server/mock/mock.go @@ -5,7 +5,7 @@ import ( "sync" "github.com/google/uuid" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/server" ) type MockServer struct { diff --git a/server/mock/mock_handler.go b/server/mock/mock_handler.go index e08efc06..de46fe52 100644 --- a/server/mock/mock_handler.go +++ b/server/mock/mock_handler.go @@ -1,8 +1,8 @@ package mock import ( - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/server" ) type MockHandler struct { diff --git a/server/mock/mock_subscriber.go b/server/mock/mock_subscriber.go index e5de5396..fb2bb7da 100644 --- a/server/mock/mock_subscriber.go +++ b/server/mock/mock_subscriber.go @@ -1,8 +1,8 @@ package mock import ( - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/server" ) type MockSubscriber struct { diff --git a/server/mock/mock_test.go b/server/mock/mock_test.go index d910af1a..6c76af91 100644 --- a/server/mock/mock_test.go +++ b/server/mock/mock_test.go @@ -3,7 +3,7 @@ package mock import ( "testing" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/server" ) func TestMockServer(t *testing.T) { diff --git a/server/mucp/mucp.go b/server/mucp/mucp.go index c4133dc0..25e0c734 100644 --- a/server/mucp/mucp.go +++ b/server/mucp/mucp.go @@ -2,7 +2,7 @@ package mucp import ( - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/server" ) // NewServer returns a micro server interface diff --git a/server/options.go b/server/options.go index 42eeccc6..d7b03d4b 100644 --- a/server/options.go +++ b/server/options.go @@ -5,11 +5,11 @@ import ( "sync" "time" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/debug/trace" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/debug/trace" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/transport" ) type Options struct { diff --git a/server/proto/server.pb.go b/server/proto/server.pb.go index bcd86b46..d9fd74aa 100644 --- a/server/proto/server.pb.go +++ b/server/proto/server.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/server/proto/server.proto +// source: github.com/micro/go-micro/v2/server/proto/server.proto package go_micro_server @@ -184,7 +184,7 @@ func init() { } func init() { - proto.RegisterFile("github.com/micro/go-micro/server/proto/server.proto", fileDescriptor_4cb0c66620400ff8) + proto.RegisterFile("github.com/micro/go-micro/v2/server/proto/server.proto", fileDescriptor_4cb0c66620400ff8) } var fileDescriptor_4cb0c66620400ff8 = []byte{ diff --git a/server/proto/server.pb.micro.go b/server/proto/server.pb.micro.go index 77194020..1c7ebd3d 100644 --- a/server/proto/server.pb.micro.go +++ b/server/proto/server.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/server/proto/server.proto +// source: github.com/micro/go-micro/v2/server/proto/server.proto package go_micro_server @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/server/rpc_codec.go b/server/rpc_codec.go index 53d552f4..0d902c3d 100644 --- a/server/rpc_codec.go +++ b/server/rpc_codec.go @@ -4,14 +4,14 @@ import ( "bytes" "sync" - "github.com/micro/go-micro/codec" - raw "github.com/micro/go-micro/codec/bytes" - "github.com/micro/go-micro/codec/grpc" - "github.com/micro/go-micro/codec/json" - "github.com/micro/go-micro/codec/jsonrpc" - "github.com/micro/go-micro/codec/proto" - "github.com/micro/go-micro/codec/protorpc" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/codec" + raw "github.com/micro/go-micro/v2/codec/bytes" + "github.com/micro/go-micro/v2/codec/grpc" + "github.com/micro/go-micro/v2/codec/json" + "github.com/micro/go-micro/v2/codec/jsonrpc" + "github.com/micro/go-micro/v2/codec/proto" + "github.com/micro/go-micro/v2/codec/protorpc" + "github.com/micro/go-micro/v2/transport" "github.com/oxtoacart/bpool" "github.com/pkg/errors" ) diff --git a/server/rpc_codec_test.go b/server/rpc_codec_test.go index 1088af01..47289c6d 100644 --- a/server/rpc_codec_test.go +++ b/server/rpc_codec_test.go @@ -5,8 +5,8 @@ import ( "errors" "testing" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/transport" ) // testCodec is a dummy codec that only knows how to encode nil bodies diff --git a/server/rpc_event.go b/server/rpc_event.go index 4bd39d4d..fe2a946a 100644 --- a/server/rpc_event.go +++ b/server/rpc_event.go @@ -1,8 +1,8 @@ package server import ( - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/transport" ) // event is a broker event we handle on the server transport diff --git a/server/rpc_handler.go b/server/rpc_handler.go index 42ec7f0f..7d2923ca 100644 --- a/server/rpc_handler.go +++ b/server/rpc_handler.go @@ -3,7 +3,7 @@ package server import ( "reflect" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) type rpcHandler struct { diff --git a/server/rpc_request.go b/server/rpc_request.go index 065d57e4..767f1ac8 100644 --- a/server/rpc_request.go +++ b/server/rpc_request.go @@ -3,9 +3,9 @@ package server import ( "bytes" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/util/buf" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/util/buf" ) type rpcRequest struct { diff --git a/server/rpc_response.go b/server/rpc_response.go index d89fa0b6..d42a2ac8 100644 --- a/server/rpc_response.go +++ b/server/rpc_response.go @@ -3,8 +3,8 @@ package server import ( "net/http" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/transport" ) type rpcResponse struct { diff --git a/server/rpc_router.go b/server/rpc_router.go index 70fe1104..8d36f1f0 100644 --- a/server/rpc_router.go +++ b/server/rpc_router.go @@ -18,9 +18,9 @@ import ( "unicode" "unicode/utf8" - "github.com/micro/go-micro/codec" - merrors "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/codec" + merrors "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/util/log" ) var ( diff --git a/server/rpc_server.go b/server/rpc_server.go index a6ccd6a5..7eba3806 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -12,16 +12,16 @@ import ( "sync" "time" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/codec" - raw "github.com/micro/go-micro/codec/bytes" - "github.com/micro/go-micro/metadata" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/util/addr" - log "github.com/micro/go-micro/util/log" - mnet "github.com/micro/go-micro/util/net" - "github.com/micro/go-micro/util/socket" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/codec" + raw "github.com/micro/go-micro/v2/codec/bytes" + "github.com/micro/go-micro/v2/metadata" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/util/addr" + log "github.com/micro/go-micro/v2/util/log" + mnet "github.com/micro/go-micro/v2/util/net" + "github.com/micro/go-micro/v2/util/socket" ) type rpcServer struct { diff --git a/server/rpc_stream.go b/server/rpc_stream.go index 7421fd45..dbee673e 100644 --- a/server/rpc_stream.go +++ b/server/rpc_stream.go @@ -6,7 +6,7 @@ import ( "io" "sync" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) // Implements the Streamer interface diff --git a/server/rpc_stream_test.go b/server/rpc_stream_test.go index 18a0f0a3..f4b0b7bd 100644 --- a/server/rpc_stream_test.go +++ b/server/rpc_stream_test.go @@ -10,8 +10,8 @@ import ( "time" "github.com/golang/protobuf/proto" - "github.com/micro/go-micro/codec/json" - protoCodec "github.com/micro/go-micro/codec/proto" + "github.com/micro/go-micro/v2/codec/json" + protoCodec "github.com/micro/go-micro/v2/codec/proto" ) // protoStruct implements proto.Message diff --git a/server/server.go b/server/server.go index f494ef0b..a45dd8d0 100644 --- a/server/server.go +++ b/server/server.go @@ -9,9 +9,9 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/registry" - log "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/registry" + log "github.com/micro/go-micro/v2/util/log" ) // Server is a simple micro server abstraction diff --git a/server/subscriber.go b/server/subscriber.go index 62de0ed8..6278175a 100644 --- a/server/subscriber.go +++ b/server/subscriber.go @@ -4,7 +4,7 @@ import ( "fmt" "reflect" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) const ( diff --git a/service.go b/service.go index de5697f7..b1bf7e2c 100644 --- a/service.go +++ b/service.go @@ -8,18 +8,18 @@ import ( "sync" "syscall" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/config/cmd" - "github.com/micro/go-micro/debug/profile" - "github.com/micro/go-micro/debug/profile/http" - "github.com/micro/go-micro/debug/profile/pprof" - "github.com/micro/go-micro/debug/service/handler" - "github.com/micro/go-micro/debug/stats" - "github.com/micro/go-micro/debug/trace" - "github.com/micro/go-micro/plugin" - "github.com/micro/go-micro/server" - "github.com/micro/go-micro/util/log" - "github.com/micro/go-micro/util/wrapper" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/config/cmd" + "github.com/micro/go-micro/v2/debug/profile" + "github.com/micro/go-micro/v2/debug/profile/http" + "github.com/micro/go-micro/v2/debug/profile/pprof" + "github.com/micro/go-micro/v2/debug/service/handler" + "github.com/micro/go-micro/v2/debug/stats" + "github.com/micro/go-micro/v2/debug/trace" + "github.com/micro/go-micro/v2/plugin" + "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/util/log" + "github.com/micro/go-micro/v2/util/wrapper" ) type service struct { diff --git a/service/grpc/grpc.go b/service/grpc/grpc.go index f6c0effa..e5d46bb5 100644 --- a/service/grpc/grpc.go +++ b/service/grpc/grpc.go @@ -1,11 +1,11 @@ package grpc import ( - "github.com/micro/go-micro/client" - gclient "github.com/micro/go-micro/client/grpc" - "github.com/micro/go-micro/server" - gserver "github.com/micro/go-micro/server/grpc" - "github.com/micro/go-micro/service" + "github.com/micro/go-micro/v2/client" + gclient "github.com/micro/go-micro/v2/client/grpc" + "github.com/micro/go-micro/v2/server" + gserver "github.com/micro/go-micro/v2/server/grpc" + "github.com/micro/go-micro/v2/service" ) type grpcService struct { diff --git a/service/grpc/grpc_test.go b/service/grpc/grpc_test.go index 4ea738dd..1f213008 100644 --- a/service/grpc/grpc_test.go +++ b/service/grpc/grpc_test.go @@ -7,10 +7,10 @@ import ( "testing" "time" - "github.com/micro/go-micro/registry/memory" - "github.com/micro/go-micro/service" - hello "github.com/micro/go-micro/service/grpc/proto" - mls "github.com/micro/go-micro/util/tls" + "github.com/micro/go-micro/v2/registry/memory" + "github.com/micro/go-micro/v2/service" + hello "github.com/micro/go-micro/v2/service/grpc/proto" + mls "github.com/micro/go-micro/v2/util/tls" ) type testHandler struct{} diff --git a/service/grpc/options.go b/service/grpc/options.go index 82dbb19f..302f960b 100644 --- a/service/grpc/options.go +++ b/service/grpc/options.go @@ -3,9 +3,9 @@ package grpc import ( "crypto/tls" - gc "github.com/micro/go-micro/client/grpc" - gs "github.com/micro/go-micro/server/grpc" - "github.com/micro/go-micro/service" + gc "github.com/micro/go-micro/v2/client/grpc" + gs "github.com/micro/go-micro/v2/server/grpc" + "github.com/micro/go-micro/v2/service" ) // WithTLS sets the TLS config for the service diff --git a/service/grpc/proto/test.micro.go b/service/grpc/proto/test.micro.go index b00e7ea3..5cc8a4e0 100644 --- a/service/grpc/proto/test.micro.go +++ b/service/grpc/proto/test.micro.go @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/service/mucp/mucp.go b/service/mucp/mucp.go index 64f70d51..d8238014 100644 --- a/service/mucp/mucp.go +++ b/service/mucp/mucp.go @@ -2,11 +2,11 @@ package mucp import ( - "github.com/micro/go-micro/client" - cmucp "github.com/micro/go-micro/client/mucp" - "github.com/micro/go-micro/server" - smucp "github.com/micro/go-micro/server/mucp" - "github.com/micro/go-micro/service" + "github.com/micro/go-micro/v2/client" + cmucp "github.com/micro/go-micro/v2/client/mucp" + "github.com/micro/go-micro/v2/server" + smucp "github.com/micro/go-micro/v2/server/mucp" + "github.com/micro/go-micro/v2/service" ) type mucpService struct { diff --git a/service/options.go b/service/options.go index b3268786..52e2a424 100644 --- a/service/options.go +++ b/service/options.go @@ -4,11 +4,11 @@ import ( "context" "time" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/server" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/transport" ) type Options struct { diff --git a/service/service.go b/service/service.go index aca8acd6..31d943b8 100644 --- a/service/service.go +++ b/service/service.go @@ -2,8 +2,8 @@ package service import ( - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/server" ) // Service is an interface for a micro service diff --git a/service_test.go b/service_test.go index c2a7c33b..3c97c6a0 100644 --- a/service_test.go +++ b/service_test.go @@ -6,12 +6,12 @@ import ( "sync" "testing" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/debug/log/noop" - proto "github.com/micro/go-micro/debug/service/proto" - "github.com/micro/go-micro/registry/memory" - "github.com/micro/go-micro/util/log" - "github.com/micro/go-micro/util/test" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/debug/log/noop" + proto "github.com/micro/go-micro/v2/debug/service/proto" + "github.com/micro/go-micro/v2/registry/memory" + "github.com/micro/go-micro/v2/util/log" + "github.com/micro/go-micro/v2/util/test" ) func testShutdown(wg *sync.WaitGroup, cancel func()) { diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index ff1a6d8e..7feac885 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -17,7 +17,7 @@ import ( "strconv" "time" - "github.com/micro/go-micro/store" + "github.com/micro/go-micro/v2/store" "github.com/pkg/errors" ) diff --git a/store/cloudflare/cloudflare_test.go b/store/cloudflare/cloudflare_test.go index b1586a36..ee5deee1 100644 --- a/store/cloudflare/cloudflare_test.go +++ b/store/cloudflare/cloudflare_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/micro/go-micro/store" + "github.com/micro/go-micro/v2/store" ) func TestCloudflare(t *testing.T) { diff --git a/store/cloudflare/options.go b/store/cloudflare/options.go index be6bf6f6..8b307024 100644 --- a/store/cloudflare/options.go +++ b/store/cloudflare/options.go @@ -3,7 +3,7 @@ package cloudflare import ( "context" - "github.com/micro/go-micro/store" + "github.com/micro/go-micro/v2/store" ) func getOption(ctx context.Context, key string) string { diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index d60a60f5..faaf9e2a 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -10,8 +10,8 @@ import ( "unicode" "github.com/lib/pq" - "github.com/micro/go-micro/store" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/store" + "github.com/micro/go-micro/v2/util/log" "github.com/pkg/errors" ) diff --git a/store/cockroach/cockroach_test.go b/store/cockroach/cockroach_test.go index cb0b53a8..02354eac 100644 --- a/store/cockroach/cockroach_test.go +++ b/store/cockroach/cockroach_test.go @@ -7,7 +7,7 @@ import ( "time" "github.com/kr/pretty" - "github.com/micro/go-micro/store" + "github.com/micro/go-micro/v2/store" ) func TestSQL(t *testing.T) { diff --git a/store/etcd/etcd.go b/store/etcd/etcd.go index c1d8850e..fd896c7a 100644 --- a/store/etcd/etcd.go +++ b/store/etcd/etcd.go @@ -6,7 +6,7 @@ import ( "log" client "github.com/coreos/etcd/clientv3" - "github.com/micro/go-micro/store" + "github.com/micro/go-micro/v2/store" ) type ekv struct { diff --git a/store/memory/memory.go b/store/memory/memory.go index 224c0f97..97e6bd84 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/micro/go-micro/store" + "github.com/micro/go-micro/v2/store" ) type memoryStore struct { diff --git a/store/memory/memory_test.go b/store/memory/memory_test.go index de889856..27837e2f 100644 --- a/store/memory/memory_test.go +++ b/store/memory/memory_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/micro/go-micro/store" + "github.com/micro/go-micro/v2/store" ) func TestReadRecordExpire(t *testing.T) { diff --git a/store/service/proto/store.pb.micro.go b/store/service/proto/store.pb.micro.go index 422387b9..448ea6bc 100644 --- a/store/service/proto/store.pb.micro.go +++ b/store/service/proto/store.pb.micro.go @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/store/service/service.go b/store/service/service.go index 6a34bdfe..713cda15 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -6,10 +6,10 @@ import ( "io" "time" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/metadata" - "github.com/micro/go-micro/store" - pb "github.com/micro/go-micro/store/service/proto" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/metadata" + "github.com/micro/go-micro/v2/store" + pb "github.com/micro/go-micro/v2/store/service/proto" ) type serviceStore struct { diff --git a/sync/cron.go b/sync/cron.go index 0fd479a1..bc3133b6 100644 --- a/sync/cron.go +++ b/sync/cron.go @@ -5,10 +5,10 @@ import ( "math" "time" - "github.com/micro/go-micro/sync/leader/etcd" - "github.com/micro/go-micro/sync/task" - "github.com/micro/go-micro/sync/task/local" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/sync/leader/etcd" + "github.com/micro/go-micro/v2/sync/task" + "github.com/micro/go-micro/v2/sync/task/local" + "github.com/micro/go-micro/v2/util/log" ) type syncCron struct { diff --git a/sync/leader/etcd/etcd.go b/sync/leader/etcd/etcd.go index f8e5baa5..8e23370b 100644 --- a/sync/leader/etcd/etcd.go +++ b/sync/leader/etcd/etcd.go @@ -8,7 +8,7 @@ import ( client "github.com/coreos/etcd/clientv3" cc "github.com/coreos/etcd/clientv3/concurrency" - "github.com/micro/go-micro/sync/leader" + "github.com/micro/go-micro/v2/sync/leader" ) type etcdLeader struct { diff --git a/sync/lock/etcd/etcd.go b/sync/lock/etcd/etcd.go index 9c55ddde..1d2a7e70 100644 --- a/sync/lock/etcd/etcd.go +++ b/sync/lock/etcd/etcd.go @@ -11,7 +11,7 @@ import ( client "github.com/coreos/etcd/clientv3" cc "github.com/coreos/etcd/clientv3/concurrency" - "github.com/micro/go-micro/sync/lock" + "github.com/micro/go-micro/v2/sync/lock" ) type etcdLock struct { diff --git a/sync/lock/http/http.go b/sync/lock/http/http.go index 497774d5..3118c189 100644 --- a/sync/lock/http/http.go +++ b/sync/lock/http/http.go @@ -11,7 +11,7 @@ import ( "path/filepath" "strings" - "github.com/micro/go-micro/sync/lock" + "github.com/micro/go-micro/v2/sync/lock" ) var ( diff --git a/sync/lock/http/server/server.go b/sync/lock/http/server/server.go index 49298547..df38fd69 100644 --- a/sync/lock/http/server/server.go +++ b/sync/lock/http/server/server.go @@ -4,8 +4,8 @@ package server import ( "net/http" - "github.com/micro/go-micro/sync/lock" - lkhttp "github.com/micro/go-micro/sync/lock/http" + "github.com/micro/go-micro/v2/sync/lock" + lkhttp "github.com/micro/go-micro/v2/sync/lock/http" ) func Handler(lk lock.Lock) http.Handler { diff --git a/sync/lock/memory/memory.go b/sync/lock/memory/memory.go index f8e46c7f..99ad1532 100644 --- a/sync/lock/memory/memory.go +++ b/sync/lock/memory/memory.go @@ -5,7 +5,7 @@ import ( "sync" "time" - lock "github.com/micro/go-micro/sync/lock" + lock "github.com/micro/go-micro/v2/sync/lock" ) type memoryLock struct { diff --git a/sync/map.go b/sync/map.go index 2515d57c..83736cff 100644 --- a/sync/map.go +++ b/sync/map.go @@ -7,9 +7,9 @@ import ( "fmt" "sort" - "github.com/micro/go-micro/store" - ckv "github.com/micro/go-micro/store/etcd" - lock "github.com/micro/go-micro/sync/lock/etcd" + "github.com/micro/go-micro/v2/store" + ckv "github.com/micro/go-micro/v2/store/etcd" + lock "github.com/micro/go-micro/v2/sync/lock/etcd" ) type syncMap struct { diff --git a/sync/options.go b/sync/options.go index 0e5cf3d0..a179479d 100644 --- a/sync/options.go +++ b/sync/options.go @@ -1,10 +1,10 @@ package sync import ( - "github.com/micro/go-micro/store" - "github.com/micro/go-micro/sync/leader" - "github.com/micro/go-micro/sync/lock" - "github.com/micro/go-micro/sync/time" + "github.com/micro/go-micro/v2/store" + "github.com/micro/go-micro/v2/sync/leader" + "github.com/micro/go-micro/v2/sync/lock" + "github.com/micro/go-micro/v2/sync/time" ) // WithLeader sets the leader election implementation opton diff --git a/sync/sync.go b/sync/sync.go index 7b080b1d..69d0c410 100644 --- a/sync/sync.go +++ b/sync/sync.go @@ -2,11 +2,11 @@ package sync import ( - "github.com/micro/go-micro/store" - "github.com/micro/go-micro/sync/leader" - "github.com/micro/go-micro/sync/lock" - "github.com/micro/go-micro/sync/task" - "github.com/micro/go-micro/sync/time" + "github.com/micro/go-micro/v2/store" + "github.com/micro/go-micro/v2/sync/leader" + "github.com/micro/go-micro/v2/sync/lock" + "github.com/micro/go-micro/v2/sync/task" + "github.com/micro/go-micro/v2/sync/time" ) // Map provides synchronized access to key-value storage. diff --git a/sync/task/broker/broker.go b/sync/task/broker/broker.go index 45c20b3e..feedb0ec 100644 --- a/sync/task/broker/broker.go +++ b/sync/task/broker/broker.go @@ -11,8 +11,8 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/sync/task" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/sync/task" ) type brokerKey struct{} diff --git a/sync/task/local/local.go b/sync/task/local/local.go index 94aa7707..5ce2631d 100644 --- a/sync/task/local/local.go +++ b/sync/task/local/local.go @@ -5,7 +5,7 @@ import ( "fmt" "sync" - "github.com/micro/go-micro/sync/task" + "github.com/micro/go-micro/v2/sync/task" ) type localTask struct { diff --git a/sync/time/local/local.go b/sync/time/local/local.go index a3d899c1..6be36de7 100644 --- a/sync/time/local/local.go +++ b/sync/time/local/local.go @@ -4,7 +4,7 @@ package local import ( gotime "time" - "github.com/micro/go-micro/sync/time" + "github.com/micro/go-micro/v2/sync/time" ) type Time struct{} diff --git a/sync/time/ntp/ntp.go b/sync/time/ntp/ntp.go index 2de6a852..91cf5862 100644 --- a/sync/time/ntp/ntp.go +++ b/sync/time/ntp/ntp.go @@ -6,7 +6,7 @@ import ( gotime "time" "github.com/beevik/ntp" - "github.com/micro/go-micro/sync/time" + "github.com/micro/go-micro/v2/sync/time" ) type ntpTime struct { diff --git a/transport/grpc/grpc.go b/transport/grpc/grpc.go index a60ec70e..58f5cfd7 100644 --- a/transport/grpc/grpc.go +++ b/transport/grpc/grpc.go @@ -6,15 +6,15 @@ import ( "crypto/tls" "net" - "github.com/micro/go-micro/transport" - maddr "github.com/micro/go-micro/util/addr" - mnet "github.com/micro/go-micro/util/net" - mls "github.com/micro/go-micro/util/tls" + "github.com/micro/go-micro/v2/transport" + maddr "github.com/micro/go-micro/v2/util/addr" + mnet "github.com/micro/go-micro/v2/util/net" + mls "github.com/micro/go-micro/v2/util/tls" "google.golang.org/grpc" "google.golang.org/grpc/credentials" - pb "github.com/micro/go-micro/transport/grpc/proto" + pb "github.com/micro/go-micro/v2/transport/grpc/proto" ) type grpcTransport struct { diff --git a/transport/grpc/grpc_test.go b/transport/grpc/grpc_test.go index b1e46ba5..5fbca5b8 100644 --- a/transport/grpc/grpc_test.go +++ b/transport/grpc/grpc_test.go @@ -4,7 +4,7 @@ import ( "net" "testing" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) func expectedPort(t *testing.T, expected string, lsn transport.Listener) { diff --git a/transport/grpc/handler.go b/transport/grpc/handler.go index ce58a227..ce3690f3 100644 --- a/transport/grpc/handler.go +++ b/transport/grpc/handler.go @@ -3,10 +3,10 @@ package grpc import ( "runtime/debug" - "github.com/micro/go-micro/errors" - "github.com/micro/go-micro/transport" - pb "github.com/micro/go-micro/transport/grpc/proto" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/transport" + pb "github.com/micro/go-micro/v2/transport/grpc/proto" + "github.com/micro/go-micro/v2/util/log" "google.golang.org/grpc/peer" ) diff --git a/transport/grpc/proto/transport.micro.go b/transport/grpc/proto/transport.micro.go index 81cf981c..6cb11d4e 100644 --- a/transport/grpc/proto/transport.micro.go +++ b/transport/grpc/proto/transport.micro.go @@ -11,8 +11,8 @@ import ( import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/transport/grpc/socket.go b/transport/grpc/socket.go index 2567559d..866ee7ae 100644 --- a/transport/grpc/socket.go +++ b/transport/grpc/socket.go @@ -1,8 +1,8 @@ package grpc import ( - "github.com/micro/go-micro/transport" - pb "github.com/micro/go-micro/transport/grpc/proto" + "github.com/micro/go-micro/v2/transport" + pb "github.com/micro/go-micro/v2/transport/grpc/proto" "google.golang.org/grpc" ) diff --git a/transport/http/http.go b/transport/http/http.go index 672db54c..b9fd0b11 100644 --- a/transport/http/http.go +++ b/transport/http/http.go @@ -2,7 +2,7 @@ package http import ( - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) // NewTransport returns a new http transport using net/http and supporting http2 diff --git a/transport/http/http_test.go b/transport/http/http_test.go index faaf5215..fd519063 100644 --- a/transport/http/http_test.go +++ b/transport/http/http_test.go @@ -4,7 +4,7 @@ import ( "sync" "testing" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) func call(b *testing.B, c int) { diff --git a/transport/http/options.go b/transport/http/options.go index 2a6e56c5..c5210f09 100644 --- a/transport/http/options.go +++ b/transport/http/options.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) // Handle registers the handler for the given pattern. diff --git a/transport/http_transport.go b/transport/http_transport.go index 1ce109aa..ced00c13 100644 --- a/transport/http_transport.go +++ b/transport/http_transport.go @@ -13,10 +13,10 @@ import ( "sync" "time" - maddr "github.com/micro/go-micro/util/addr" - "github.com/micro/go-micro/util/buf" - mnet "github.com/micro/go-micro/util/net" - mls "github.com/micro/go-micro/util/tls" + maddr "github.com/micro/go-micro/v2/util/addr" + "github.com/micro/go-micro/v2/util/buf" + mnet "github.com/micro/go-micro/v2/util/net" + mls "github.com/micro/go-micro/v2/util/tls" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" ) diff --git a/transport/memory/memory.go b/transport/memory/memory.go index ed269367..ae831cc6 100644 --- a/transport/memory/memory.go +++ b/transport/memory/memory.go @@ -10,9 +10,9 @@ import ( "sync" "time" - "github.com/micro/go-micro/transport" - maddr "github.com/micro/go-micro/util/addr" - mnet "github.com/micro/go-micro/util/net" + "github.com/micro/go-micro/v2/transport" + maddr "github.com/micro/go-micro/v2/util/addr" + mnet "github.com/micro/go-micro/v2/util/net" ) type memorySocket struct { diff --git a/transport/memory/memory_test.go b/transport/memory/memory_test.go index d779f53e..50e64aaf 100644 --- a/transport/memory/memory_test.go +++ b/transport/memory/memory_test.go @@ -3,7 +3,7 @@ package memory import ( "testing" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) func TestMemoryTransport(t *testing.T) { diff --git a/transport/options.go b/transport/options.go index bea0d227..d30e4c28 100644 --- a/transport/options.go +++ b/transport/options.go @@ -5,7 +5,7 @@ import ( "crypto/tls" "time" - "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/v2/codec" ) type Options struct { diff --git a/transport/quic/quic.go b/transport/quic/quic.go index a39e9519..4bb65202 100644 --- a/transport/quic/quic.go +++ b/transport/quic/quic.go @@ -8,8 +8,8 @@ import ( "time" quic "github.com/lucas-clemente/quic-go" - "github.com/micro/go-micro/transport" - utls "github.com/micro/go-micro/util/tls" + "github.com/micro/go-micro/v2/transport" + utls "github.com/micro/go-micro/v2/util/tls" ) type quicSocket struct { diff --git a/tunnel/broker/broker.go b/tunnel/broker/broker.go index d11e160c..1b904e95 100644 --- a/tunnel/broker/broker.go +++ b/tunnel/broker/broker.go @@ -4,9 +4,9 @@ package broker import ( "context" - "github.com/micro/go-micro/broker" - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/tunnel" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/tunnel" ) type tunBroker struct { diff --git a/tunnel/default.go b/tunnel/default.go index d146cb34..0bde3bde 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -8,8 +8,8 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/util/log" ) var ( diff --git a/tunnel/link.go b/tunnel/link.go index 0f5b3980..b05a25b2 100644 --- a/tunnel/link.go +++ b/tunnel/link.go @@ -8,8 +8,8 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/util/log" ) type link struct { diff --git a/tunnel/listener.go b/tunnel/listener.go index 052955cb..ac5ba3dc 100644 --- a/tunnel/listener.go +++ b/tunnel/listener.go @@ -4,7 +4,7 @@ import ( "io" "sync" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/util/log" ) type tunListener struct { diff --git a/tunnel/options.go b/tunnel/options.go index 262df797..166680d9 100644 --- a/tunnel/options.go +++ b/tunnel/options.go @@ -4,8 +4,8 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/transport/quic" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/transport/quic" ) var ( diff --git a/tunnel/session.go b/tunnel/session.go index ebf01ded..f662b1df 100644 --- a/tunnel/session.go +++ b/tunnel/session.go @@ -5,8 +5,8 @@ import ( "io" "time" - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/util/log" ) // session is our pseudo session for transport.Socket diff --git a/tunnel/transport/listener.go b/tunnel/transport/listener.go index 075f12cf..337ab72a 100644 --- a/tunnel/transport/listener.go +++ b/tunnel/transport/listener.go @@ -1,8 +1,8 @@ package transport import ( - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/tunnel" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/tunnel" ) type tunListener struct { diff --git a/tunnel/transport/transport.go b/tunnel/transport/transport.go index d37468d2..0448d969 100644 --- a/tunnel/transport/transport.go +++ b/tunnel/transport/transport.go @@ -4,8 +4,8 @@ package transport import ( "context" - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/tunnel" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/tunnel" ) type tunTransport struct { diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 516ce6c0..4075029b 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -5,7 +5,7 @@ import ( "errors" "time" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) const ( diff --git a/tunnel/tunnel_test.go b/tunnel/tunnel_test.go index 9633e53d..2e86baf0 100644 --- a/tunnel/tunnel_test.go +++ b/tunnel/tunnel_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) func testBrokenTunAccept(t *testing.T, tun Tunnel, wait chan bool, wg *sync.WaitGroup) { diff --git a/util/ctx/ctx.go b/util/ctx/ctx.go index 2fb69a43..939a6587 100644 --- a/util/ctx/ctx.go +++ b/util/ctx/ctx.go @@ -5,7 +5,7 @@ import ( "net/http" "strings" - "github.com/micro/go-micro/metadata" + "github.com/micro/go-micro/v2/metadata" ) func FromRequest(r *http.Request) context.Context { diff --git a/util/ctx/ctx_test.go b/util/ctx/ctx_test.go index 3df4acc7..03effcf3 100644 --- a/util/ctx/ctx_test.go +++ b/util/ctx/ctx_test.go @@ -4,7 +4,7 @@ import ( "net/http" "testing" - "github.com/micro/go-micro/metadata" + "github.com/micro/go-micro/v2/metadata" ) func TestRequestToContext(t *testing.T) { diff --git a/util/http/http.go b/util/http/http.go index 47fc33f4..055374ed 100644 --- a/util/http/http.go +++ b/util/http/http.go @@ -3,8 +3,8 @@ package http import ( "net/http" - "github.com/micro/go-micro/client/selector" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/registry" ) func NewRoundTripper(opts ...Option) http.RoundTripper { diff --git a/util/http/http_test.go b/util/http/http_test.go index 60196038..34585c9f 100644 --- a/util/http/http_test.go +++ b/util/http/http_test.go @@ -6,8 +6,8 @@ import ( "net/http" "testing" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/registry/memory" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/registry/memory" ) func TestRoundTripper(t *testing.T) { diff --git a/util/http/options.go b/util/http/options.go index a248e422..319b5157 100644 --- a/util/http/options.go +++ b/util/http/options.go @@ -1,7 +1,7 @@ package http import ( - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) type Options struct { diff --git a/util/http/roundtripper.go b/util/http/roundtripper.go index 36c26b5c..349418ee 100644 --- a/util/http/roundtripper.go +++ b/util/http/roundtripper.go @@ -4,7 +4,7 @@ import ( "errors" "net/http" - "github.com/micro/go-micro/client/selector" + "github.com/micro/go-micro/v2/client/selector" ) type roundTripper struct { diff --git a/util/io/io.go b/util/io/io.go index 133ba6b8..257d9b93 100644 --- a/util/io/io.go +++ b/util/io/io.go @@ -4,7 +4,7 @@ package io import ( "io" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) type rwc struct { diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index a71d8bab..01bf48cc 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -12,8 +12,8 @@ import ( "path" "strings" - "github.com/micro/go-micro/util/kubernetes/api" - "github.com/micro/go-micro/util/log" + "github.com/micro/go-micro/v2/util/kubernetes/api" + "github.com/micro/go-micro/v2/util/log" ) var ( diff --git a/util/kubernetes/client/watch.go b/util/kubernetes/client/watch.go index a734db93..c55a406a 100644 --- a/util/kubernetes/client/watch.go +++ b/util/kubernetes/client/watch.go @@ -7,7 +7,7 @@ import ( "errors" "net/http" - "github.com/micro/go-micro/util/kubernetes/api" + "github.com/micro/go-micro/v2/util/kubernetes/api" ) const ( diff --git a/util/log/log.go b/util/log/log.go index 360f8039..ddd6e929 100644 --- a/util/log/log.go +++ b/util/log/log.go @@ -6,7 +6,7 @@ import ( "os" "time" - "github.com/micro/go-micro/debug/log" + "github.com/micro/go-micro/v2/debug/log" ) // level is a log level diff --git a/util/mux/mux.go b/util/mux/mux.go index 7655f802..0f03298f 100644 --- a/util/mux/mux.go +++ b/util/mux/mux.go @@ -5,9 +5,9 @@ import ( "context" "sync" - "github.com/micro/go-micro/debug/service/handler" - "github.com/micro/go-micro/proxy" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/debug/service/handler" + "github.com/micro/go-micro/v2/proxy" + "github.com/micro/go-micro/v2/server" ) // Server is a proxy muxer that incudes the use of the DefaultHandler diff --git a/util/pool/default.go b/util/pool/default.go index d625289c..7175b2bb 100644 --- a/util/pool/default.go +++ b/util/pool/default.go @@ -5,7 +5,7 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) type pool struct { diff --git a/util/pool/default_test.go b/util/pool/default_test.go index 4823e228..74c84bb7 100644 --- a/util/pool/default_test.go +++ b/util/pool/default_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" - "github.com/micro/go-micro/transport" - "github.com/micro/go-micro/transport/memory" + "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/transport/memory" ) func testPool(t *testing.T, size int, ttl time.Duration) { diff --git a/util/pool/options.go b/util/pool/options.go index ed3feda7..5b6632ac 100644 --- a/util/pool/options.go +++ b/util/pool/options.go @@ -3,7 +3,7 @@ package pool import ( "time" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) type Options struct { diff --git a/util/pool/pool.go b/util/pool/pool.go index 79dd1a64..68e43395 100644 --- a/util/pool/pool.go +++ b/util/pool/pool.go @@ -4,7 +4,7 @@ package pool import ( "time" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) // Pool is an interface for connection pooling diff --git a/util/proto/proto.go b/util/proto/proto.go index 1e41c61c..ef49f123 100644 --- a/util/proto/proto.go +++ b/util/proto/proto.go @@ -2,8 +2,8 @@ package proto import ( - "github.com/micro/go-micro/router" - pbRtr "github.com/micro/go-micro/router/service/proto" + "github.com/micro/go-micro/v2/router" + pbRtr "github.com/micro/go-micro/v2/router/service/proto" ) // RouteToProto encodes route into protobuf and returns it diff --git a/util/socket/socket.go b/util/socket/socket.go index e68df694..d1338ab5 100644 --- a/util/socket/socket.go +++ b/util/socket/socket.go @@ -4,7 +4,7 @@ package socket import ( "io" - "github.com/micro/go-micro/transport" + "github.com/micro/go-micro/v2/transport" ) // Socket is our pseudo socket for transport.Socket diff --git a/util/test/test.go b/util/test/test.go index 100c8e79..f95b1f68 100644 --- a/util/test/test.go +++ b/util/test/test.go @@ -1,7 +1,7 @@ package test import ( - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2/registry" ) var ( diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index d6d2814a..c91368b6 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -3,11 +3,11 @@ package wrapper import ( "context" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/debug/stats" - "github.com/micro/go-micro/debug/trace" - "github.com/micro/go-micro/metadata" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/debug/stats" + "github.com/micro/go-micro/v2/debug/trace" + "github.com/micro/go-micro/v2/metadata" + "github.com/micro/go-micro/v2/server" ) type clientWrapper struct { diff --git a/util/wrapper/wrapper_test.go b/util/wrapper/wrapper_test.go index 915eb668..b45fb86b 100644 --- a/util/wrapper/wrapper_test.go +++ b/util/wrapper/wrapper_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/micro/go-micro/metadata" + "github.com/micro/go-micro/v2/metadata" ) func TestWrapper(t *testing.T) { diff --git a/web/options.go b/web/options.go index ec4e1a6b..c675f4ea 100644 --- a/web/options.go +++ b/web/options.go @@ -7,8 +7,8 @@ import ( "time" "github.com/micro/cli/v2" - "github.com/micro/go-micro" - "github.com/micro/go-micro/registry" + "github.com/micro/go-micro/v2" + "github.com/micro/go-micro/v2/registry" ) type Options struct { diff --git a/web/service.go b/web/service.go index c717e9e0..aa351236 100644 --- a/web/service.go +++ b/web/service.go @@ -15,13 +15,13 @@ import ( "time" "github.com/micro/cli/v2" - "github.com/micro/go-micro" - "github.com/micro/go-micro/registry" - maddr "github.com/micro/go-micro/util/addr" - mhttp "github.com/micro/go-micro/util/http" - "github.com/micro/go-micro/util/log" - mnet "github.com/micro/go-micro/util/net" - mls "github.com/micro/go-micro/util/tls" + "github.com/micro/go-micro/v2" + "github.com/micro/go-micro/v2/registry" + maddr "github.com/micro/go-micro/v2/util/addr" + mhttp "github.com/micro/go-micro/v2/util/http" + "github.com/micro/go-micro/v2/util/log" + mnet "github.com/micro/go-micro/v2/util/net" + mls "github.com/micro/go-micro/v2/util/tls" ) type service struct { diff --git a/web/service_test.go b/web/service_test.go index 33365535..99b36ae5 100644 --- a/web/service_test.go +++ b/web/service_test.go @@ -11,8 +11,8 @@ import ( "testing" "time" - "github.com/micro/go-micro/registry" - "github.com/micro/go-micro/registry/memory" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/registry/memory" ) func TestService(t *testing.T) { From f6fcfcb8fc18d2533328c095025a355b8add8121 Mon Sep 17 00:00:00 2001 From: Evgeniy Date: Thu, 30 Jan 2020 17:25:07 +0300 Subject: [PATCH 221/788] exponentialBackoff was changed from power function to exponential function --- client/backoff.go | 7 ++----- client/backoff_test.go | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/client/backoff.go b/client/backoff.go index 57407a06..4a7e3746 100644 --- a/client/backoff.go +++ b/client/backoff.go @@ -8,10 +8,7 @@ import ( type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error) -// exponential backoff +// exponential backoff multiplied by a factor of 0.1 second. func exponentialBackoff(ctx context.Context, req Request, attempts int) (time.Duration, error) { - if attempts == 0 { - return time.Duration(0), nil - } - return time.Duration(math.Pow(10, float64(attempts))) * time.Millisecond, nil + return time.Duration(math.Pow(float64(attempts), math.E)) * time.Millisecond * 100, nil } diff --git a/client/backoff_test.go b/client/backoff_test.go index 60ae19aa..a6d39dee 100644 --- a/client/backoff_test.go +++ b/client/backoff_test.go @@ -22,6 +22,6 @@ func TestBackoff(t *testing.T) { t.Fatalf("Expected greater than %v, got %v", delta, d) } - delta = time.Millisecond * time.Duration(math.Pow(10, float64(i+1))) + delta = time.Millisecond * 100 * time.Duration(math.Pow(math.E, float64(i))) } } From ffb9da0230d3d1df677504466126570c39ef2bec Mon Sep 17 00:00:00 2001 From: Evgeniy Date: Thu, 30 Jan 2020 19:43:03 +0300 Subject: [PATCH 222/788] fix test and description --- client/backoff.go | 2 +- client/backoff_test.go | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/client/backoff.go b/client/backoff.go index 4a7e3746..70070da2 100644 --- a/client/backoff.go +++ b/client/backoff.go @@ -8,7 +8,7 @@ import ( type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error) -// exponential backoff multiplied by a factor of 0.1 second. +// exponential backoff is a function x^e multiplied by a factor of 0.1 second. func exponentialBackoff(ctx context.Context, req Request, attempts int) (time.Duration, error) { return time.Duration(math.Pow(float64(attempts), math.E)) * time.Millisecond * 100, nil } diff --git a/client/backoff_test.go b/client/backoff_test.go index a6d39dee..75963cbf 100644 --- a/client/backoff_test.go +++ b/client/backoff_test.go @@ -2,13 +2,12 @@ package client import ( "context" - "math" "testing" "time" ) func TestBackoff(t *testing.T) { - delta := time.Duration(0) + results := []time.Duration{0 * time.Second, 100 * time.Millisecond, 600 * time.Millisecond, 1900 * time.Millisecond, 4300 * time.Millisecond, 7900 * time.Millisecond} c := NewClient() @@ -18,10 +17,8 @@ func TestBackoff(t *testing.T) { t.Fatal(err) } - if d < delta { - t.Fatalf("Expected greater than %v, got %v", delta, d) + if d != results[i] { + t.Fatalf("Expected equal than %v, got %v", results[i], d) } - - delta = time.Millisecond * 100 * time.Duration(math.Pow(math.E, float64(i))) } } From 87753ad28953cc1635f734edaf61006f18442fe2 Mon Sep 17 00:00:00 2001 From: Evgeniy Date: Thu, 30 Jan 2020 20:08:03 +0300 Subject: [PATCH 223/788] format results in TestBacloff --- client/backoff_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/backoff_test.go b/client/backoff_test.go index 75963cbf..7e1e1990 100644 --- a/client/backoff_test.go +++ b/client/backoff_test.go @@ -7,7 +7,14 @@ import ( ) func TestBackoff(t *testing.T) { - results := []time.Duration{0 * time.Second, 100 * time.Millisecond, 600 * time.Millisecond, 1900 * time.Millisecond, 4300 * time.Millisecond, 7900 * time.Millisecond} + results := []time.Duration{ + 0 * time.Second, + 100 * time.Millisecond, + 600 * time.Millisecond, + 1900 * time.Millisecond, + 4300 * time.Millisecond, + 7900 * time.Millisecond, + } c := NewClient() From 98d55545fd31e78b8633a0248a0e7cb6c159f7b2 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Thu, 30 Jan 2020 09:25:50 -0800 Subject: [PATCH 224/788] runtime/kubernetes: remove unused name variable --- runtime/kubernetes/kubernetes.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 3545967b..f24843b0 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -271,12 +271,6 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er options.Type = k.options.Type } - // quickly prevalidate the name and version - name := s.Name - if len(s.Version) > 0 { - name = name + "-" + s.Version - } - // create new kubernetes micro service service := newService(s, options) From 0be22c98c6691562aa16bfbe4159807b3918ca11 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 30 Jan 2020 23:24:46 +0000 Subject: [PATCH 225/788] add tracing --- config/cmd/cmd.go | 1 - debug/service/client.go | 9 +- debug/service/proto/debug.pb.go | 46 +++++----- debug/service/proto/debug.pb.micro.go | 126 +++++++++++++------------- debug/service/proto/debug.proto | 2 +- 5 files changed, 97 insertions(+), 87 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index c576df2d..6bbaacd4 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -217,7 +217,6 @@ var ( Name: "tracer", EnvVars: []string{"MICRO_TRACER"}, Usage: "Tracer for distributed tracing, e.g. memory, jaeger", - Value: "memory", }, &cli.StringFlag{ Name: "tracer_address", diff --git a/debug/service/client.go b/debug/service/client.go index 192101f3..6b6affd1 100644 --- a/debug/service/client.go +++ b/debug/service/client.go @@ -6,7 +6,6 @@ import ( "time" "github.com/micro/go-micro/v2/client" - "github.com/micro/go-micro/v2/debug/log" pb "github.com/micro/go-micro/v2/debug/service/proto" ) @@ -16,6 +15,14 @@ type debugClient struct { Client pb.DebugService } +func (d *debugClient) Trace() ([]*pb.Span, error) { + rsp, err := d.Client.Trace(context.Background(), &pb.TraceRequest{}) + if err != nil { + return nil, err + } + return rsp.Spans, nil +} + // Logs queries the services logs and returns a channel to read the logs from func (d *debugClient) Log(since time.Time, count int, stream bool) (log.Stream, error) { req := &pb.LogRequest{} diff --git a/debug/service/proto/debug.pb.go b/debug/service/proto/debug.pb.go index 6e513462..a2378b30 100644 --- a/debug/service/proto/debug.pb.go +++ b/debug/service/proto/debug.pb.go @@ -564,40 +564,40 @@ func init() { } var fileDescriptor_dea322649cde1ef2 = []byte{ - // 554 bytes of a gzipped FileDescriptorProto + // 553 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcd, 0x6e, 0xd4, 0x30, 0x10, 0xde, 0x24, 0x9b, 0xdd, 0xcd, 0xb4, 0x09, 0xc8, 0xfc, 0x28, 0x0a, 0x08, 0x2a, 0x9f, 0x16, 0x01, 0x5e, 0x28, 0x17, 0x04, 0x57, 0x90, 0x38, 0x94, 0x8b, 0xcb, 0x0b, 0xb8, 0x89, 0x95, 0x06, 0x9a, 0x38, 0xd8, 0x4e, 0xa5, 0x7d, 0x24, 0x6e, 0xbc, 0x0c, 0x6f, 0xc3, 0x01, 0xf9, 0x27, 0xdb, - 0x44, 0x08, 0xf5, 0xc0, 0xcd, 0xdf, 0xe7, 0x99, 0x2f, 0x33, 0x9f, 0x67, 0x02, 0xa4, 0x6d, 0x4a, + 0x44, 0x08, 0xf5, 0xc0, 0xcd, 0xdf, 0xe7, 0xf1, 0x97, 0x99, 0x6f, 0x66, 0x02, 0xa4, 0x6d, 0x4a, 0x29, 0x76, 0xb5, 0x78, 0xe9, 0x0e, 0x15, 0xbf, 0x18, 0xea, 0x9d, 0xe2, 0xf2, 0xba, 0x29, 0xf9, 0xae, 0x97, 0x42, 0x7b, 0x8e, 0xd8, 0x33, 0x7e, 0x06, 0xe9, 0x27, 0xce, 0xae, 0xf4, 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+ 0x32, 0xdd, 0xe6, 0x22, 0x23, 0xb3, 0x8d, 0x75, 0x91, 0xb6, 0x5d, 0x28, 0x25, 0xd3, 0xb6, 0x16, + 0x19, 0x99, 0x75, 0x11, 0x2f, 0x2e, 0x56, 0xf6, 0xaf, 0xf3, 0xe6, 0x4f, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xc7, 0x3f, 0xbe, 0xe3, 0xa7, 0x04, 0x00, 0x00, } diff --git a/debug/service/proto/debug.pb.micro.go b/debug/service/proto/debug.pb.micro.go index a5f773e1..0692209c 100644 --- a/debug/service/proto/debug.pb.micro.go +++ b/debug/service/proto/debug.pb.micro.go @@ -34,9 +34,9 @@ var _ server.Option // Client API for Debug service type DebugService interface { + Log(ctx context.Context, in *LogRequest, opts ...client.CallOption) (Debug_LogService, error) Health(ctx context.Context, in *HealthRequest, opts ...client.CallOption) (*HealthResponse, error) Stats(ctx context.Context, in *StatsRequest, opts ...client.CallOption) (*StatsResponse, error) - Log(ctx context.Context, in *LogRequest, opts ...client.CallOption) (Debug_LogService, error) Trace(ctx context.Context, in *TraceRequest, opts ...client.CallOption) (*TraceResponse, error) } @@ -46,18 +46,61 @@ type debugService struct { } func NewDebugService(name string, c client.Client) DebugService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "debug" - } return &debugService{ c: c, name: name, } } +func (c *debugService) Log(ctx context.Context, in *LogRequest, opts ...client.CallOption) (Debug_LogService, error) { + req := c.c.NewRequest(c.name, "Debug.Log", &LogRequest{}) + stream, err := c.c.Stream(ctx, req, opts...) + if err != nil { + return nil, err + } + if err := stream.Send(in); err != nil { + return nil, err + } + return &debugServiceLog{stream}, nil +} + +type Debug_LogService interface { + Context() context.Context + SendMsg(interface{}) error + RecvMsg(interface{}) error + Close() error + Recv() (*Record, error) +} + +type debugServiceLog struct { + stream client.Stream +} + +func (x *debugServiceLog) Close() error { + return x.stream.Close() +} + +func (x *debugServiceLog) Context() context.Context { + return x.stream.Context() +} + +func (x *debugServiceLog) SendMsg(m interface{}) error { + return x.stream.Send(m) +} + +func (x *debugServiceLog) RecvMsg(m interface{}) error { + return x.stream.Recv(m) +} + +func (x *debugServiceLog) Recv() (*Record, error) { + m := new(Record) + err := x.stream.Recv(m) + if err != nil { + return nil, err + } + return m, nil +} + func (c *debugService) Health(ctx context.Context, in *HealthRequest, opts ...client.CallOption) (*HealthResponse, error) { req := c.c.NewRequest(c.name, "Debug.Health", in) out := new(HealthResponse) @@ -78,50 +121,6 @@ func (c *debugService) Stats(ctx context.Context, in *StatsRequest, opts ...clie return out, nil } -func (c *debugService) Log(ctx context.Context, in *LogRequest, opts ...client.CallOption) (Debug_LogService, error) { - req := c.c.NewRequest(c.name, "Debug.Log", &LogRequest{}) - stream, err := c.c.Stream(ctx, req, opts...) - if err != nil { - return nil, err - } - if err := stream.Send(in); err != nil { - return nil, err - } - return &debugServiceLog{stream}, nil -} - -type Debug_LogService interface { - SendMsg(interface{}) error - RecvMsg(interface{}) error - Close() error - Recv() (*Record, error) -} - -type debugServiceLog struct { - stream client.Stream -} - -func (x *debugServiceLog) Close() error { - return x.stream.Close() -} - -func (x *debugServiceLog) SendMsg(m interface{}) error { - return x.stream.Send(m) -} - -func (x *debugServiceLog) RecvMsg(m interface{}) error { - return x.stream.Recv(m) -} - -func (x *debugServiceLog) Recv() (*Record, error) { - m := new(Record) - err := x.stream.Recv(m) - if err != nil { - return nil, err - } - return m, nil -} - func (c *debugService) Trace(ctx context.Context, in *TraceRequest, opts ...client.CallOption) (*TraceResponse, error) { req := c.c.NewRequest(c.name, "Debug.Trace", in) out := new(TraceResponse) @@ -135,17 +134,17 @@ func (c *debugService) Trace(ctx context.Context, in *TraceRequest, opts ...clie // Server API for Debug service type DebugHandler interface { + Log(context.Context, *LogRequest, Debug_LogStream) error Health(context.Context, *HealthRequest, *HealthResponse) error Stats(context.Context, *StatsRequest, *StatsResponse) error - Log(context.Context, *LogRequest, Debug_LogStream) error Trace(context.Context, *TraceRequest, *TraceResponse) error } func RegisterDebugHandler(s server.Server, hdlr DebugHandler, opts ...server.HandlerOption) error { type debug interface { + Log(ctx context.Context, stream server.Stream) error Health(ctx context.Context, in *HealthRequest, out *HealthResponse) error Stats(ctx context.Context, in *StatsRequest, out *StatsResponse) error - Log(ctx context.Context, stream server.Stream) error Trace(ctx context.Context, in *TraceRequest, out *TraceResponse) error } type Debug struct { @@ -159,14 +158,6 @@ type debugHandler struct { DebugHandler } -func (h *debugHandler) Health(ctx context.Context, in *HealthRequest, out *HealthResponse) error { - return h.DebugHandler.Health(ctx, in, out) -} - -func (h *debugHandler) Stats(ctx context.Context, in *StatsRequest, out *StatsResponse) error { - return h.DebugHandler.Stats(ctx, in, out) -} - func (h *debugHandler) Log(ctx context.Context, stream server.Stream) error { m := new(LogRequest) if err := stream.Recv(m); err != nil { @@ -176,6 +167,7 @@ func (h *debugHandler) Log(ctx context.Context, stream server.Stream) error { } type Debug_LogStream interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -190,6 +182,10 @@ func (x *debugLogStream) Close() error { return x.stream.Close() } +func (x *debugLogStream) Context() context.Context { + return x.stream.Context() +} + func (x *debugLogStream) SendMsg(m interface{}) error { return x.stream.Send(m) } @@ -202,6 +198,14 @@ func (x *debugLogStream) Send(m *Record) error { return x.stream.Send(m) } +func (h *debugHandler) Health(ctx context.Context, in *HealthRequest, out *HealthResponse) error { + return h.DebugHandler.Health(ctx, in, out) +} + +func (h *debugHandler) Stats(ctx context.Context, in *StatsRequest, out *StatsResponse) error { + return h.DebugHandler.Stats(ctx, in, out) +} + func (h *debugHandler) Trace(ctx context.Context, in *TraceRequest, out *TraceResponse) error { return h.DebugHandler.Trace(ctx, in, out) } diff --git a/debug/service/proto/debug.proto b/debug/service/proto/debug.proto index 140b2d91..81eb44b8 100644 --- a/debug/service/proto/debug.proto +++ b/debug/service/proto/debug.proto @@ -1,9 +1,9 @@ syntax = "proto3"; service Debug { + rpc Log(LogRequest) returns (stream Record) {}; rpc Health(HealthRequest) returns (HealthResponse) {}; rpc Stats(StatsRequest) returns (StatsResponse) {}; - rpc Log(LogRequest) returns (stream Record) {}; rpc Trace(TraceRequest) returns (TraceResponse) {}; } From efb59d97095555d114c5d0d05e2514c509f51287 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 1 Feb 2020 02:46:50 +0300 Subject: [PATCH 226/788] fix map race condition in grpc server Signed-off-by: Vasiliy Tolstov --- server/grpc/grpc.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 7a098e86..d014734a 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -562,11 +562,17 @@ func (g *grpcServer) Register() error { return err } + // make copy of metadata + md := make(meta.Metadata) + for k, v := range config.Metadata { + md[k] = v + } + // register service node := ®istry.Node{ Id: config.Name + "-" + config.Id, Address: mnet.HostPort(addr, port), - Metadata: config.Metadata, + Metadata: md, } node.Metadata["broker"] = config.Broker.String() From a9d371e727e7b6b068ad7500754888db8d9973cc Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 2 Feb 2020 19:49:59 +0000 Subject: [PATCH 227/788] fatal on command error --- service.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/service.go b/service.go index b1bf7e2c..f67edd72 100644 --- a/service.go +++ b/service.go @@ -87,13 +87,15 @@ func (s *service) Init(opts ...Option) { } // Initialise the command flags, overriding new service - _ = s.opts.Cmd.Init( + if err := s.opts.Cmd.Init( cmd.Broker(&s.opts.Broker), cmd.Registry(&s.opts.Registry), cmd.Transport(&s.opts.Transport), cmd.Client(&s.opts.Client), cmd.Server(&s.opts.Server), - ) + ); err != nil { + log.Fatal(err) + } }) } From 449bcb46fed6078926e371618b9fc71172bd379d Mon Sep 17 00:00:00 2001 From: tpam28 Date: Sun, 2 Feb 2020 23:32:55 +0300 Subject: [PATCH 228/788] New backoff (#1153) * new backoff function * use backoff from util/backoff * remove reset atemts * change comment * fmt --- client/backoff.go | 6 +++--- network/default.go | 12 ------------ util/backoff/backoff.go | 8 +++++--- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/client/backoff.go b/client/backoff.go index 70070da2..7281f4a8 100644 --- a/client/backoff.go +++ b/client/backoff.go @@ -2,13 +2,13 @@ package client import ( "context" - "math" "time" + + "github.com/micro/go-micro/v2/util/backoff" ) type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error) -// exponential backoff is a function x^e multiplied by a factor of 0.1 second. func exponentialBackoff(ctx context.Context, req Request, attempts int) (time.Duration, error) { - return time.Duration(math.Pow(float64(attempts), math.E)) * time.Millisecond * 100, nil + return backoff.Do(attempts), nil } diff --git a/network/default.go b/network/default.go index a5613827..6fb347ae 100644 --- a/network/default.go +++ b/network/default.go @@ -225,9 +225,6 @@ func (n *network) acceptNetConn(l tunnel.Listener, recv chan *message) { sleep := backoff.Do(i) log.Debugf("Network tunnel [%s] accept error: %v, backing off for %v", ControlChannel, err, sleep) time.Sleep(sleep) - if i > 5 { - i = 0 - } i++ continue } @@ -255,10 +252,6 @@ func (n *network) acceptCtrlConn(l tunnel.Listener, recv chan *message) { sleep := backoff.Do(i) log.Debugf("Network tunnel [%s] accept error: %v, backing off for %v", ControlChannel, err, sleep) time.Sleep(sleep) - if i > 5 { - // reset the counter - i = 0 - } i++ continue } @@ -1572,11 +1565,6 @@ func (n *network) connect() { case <-time.After(time.Second + backoff.Do(attempts)): // we have to try again attempts++ - - // reset attempts 5 == ~2mins - if attempts > 5 { - attempts = 0 - } } } } diff --git a/util/backoff/backoff.go b/util/backoff/backoff.go index 013d5291..cadc2fc1 100644 --- a/util/backoff/backoff.go +++ b/util/backoff/backoff.go @@ -6,9 +6,11 @@ import ( "time" ) +// Do is a function x^e multiplied by a factor of 0.1 second. +// Result is limited to 2 minute. func Do(attempts int) time.Duration { - if attempts == 0 { - return time.Duration(0) + if attempts > 13 { + return 2 * time.Minute } - return time.Duration(math.Pow(10, float64(attempts))) * time.Millisecond + return time.Duration(math.Pow(float64(attempts), math.E)) * time.Millisecond * 100 } From d6215481206f4c6e252794aa374339e08c9e904e Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 3 Feb 2020 08:16:02 +0000 Subject: [PATCH 229/788] Auth (#1147) Implement the Auth interface, with JWT and service implementations. * Update Auth Interface * Define Auth Service Implementation * Support Service Auth * Add Auth Service Proto * Remove erronious files * Implement Auth Service Package * Update Auth Interface * Update Auth Interface. Add Validate, remove Add/Remove roles * Make Revoke interface more explicit * Refactor serializing and deserializing service accounts * Fix srv name & update interface to be more explicit * Require jwt public key for auth * Rename Variables (Resource.ID => Resource.Name & ServiceAccount => Account) * Implement JWT Auth Package * Remove parent, add ID * Update auth imports to v2. Add String() to auth interface --- auth/auth.go | 48 +-- auth/default.go | 34 ++ auth/jwt/jwt.go | 106 +++++++ auth/options.go | 57 ++++ auth/service/proto/auth.pb.go | 466 ++++++++++++++++++++++++++++ auth/service/proto/auth.pb.micro.go | 125 ++++++++ auth/service/proto/auth.proto | 50 +++ auth/service/service.go | 128 ++++++++ config/cmd/cmd.go | 49 +++ config/cmd/options.go | 16 + go.mod | 1 + options.go | 8 + server/options.go | 9 + store/memory/memory.go | 21 +- store/options.go | 9 + store/store.go | 2 + 16 files changed, 1103 insertions(+), 26 deletions(-) create mode 100644 auth/default.go create mode 100644 auth/jwt/jwt.go create mode 100644 auth/options.go create mode 100644 auth/service/proto/auth.pb.go create mode 100644 auth/service/proto/auth.pb.micro.go create mode 100644 auth/service/proto/auth.proto create mode 100644 auth/service/service.go diff --git a/auth/auth.go b/auth/auth.go index a7750745..69f22c91 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -7,34 +7,44 @@ import ( // Auth providers authentication and authorization type Auth interface { - // Generate a new auth token - Generate(string) (*Token, error) - // Revoke an authorization token - Revoke(*Token) error - // Grant access to a resource - Grant(*Token, *Service) error - // Verify a token can access a resource - Verify(*Token, *Service) error + // String to identify the package + String() string + // Init the auth package + Init(opts ...Option) error + // Generate a new auth Account + Generate(id string, opts ...GenerateOption) (*Account, error) + // Revoke an authorization Account + Revoke(token string) error + // Validate an account token + Validate(token string) (*Account, error) } -// Service is some thing to provide access to -type Service struct { +// Resource is an entity such as a user or +type Resource struct { // Name of the resource Name string - // Endpoint is the specific endpoint - Endpoint string + // Type of resource, e.g. + Type string } -// Token providers by an auth provider -type Token struct { - // Unique token id +// Role an account has +type Role struct { + Name string + Resource *Resource +} + +// Account provided by an auth provider +type Account struct { + // ID of the account (UUID or email) Id string `json: "id"` - // Time of token creation + // Token used to authenticate + Token string `json: "token"` + // Time of Account creation Created time.Time `json:"created"` - // Time of token expiry + // Time of Account expiry Expiry time.Time `json:"expiry"` - // Roles associated with the token - Roles []string `json:"roles"` + // Roles associated with the Account + Roles []*Role `json:"roles"` // Any other associated metadata Metadata map[string]string `json:"metadata"` } diff --git a/auth/default.go b/auth/default.go new file mode 100644 index 00000000..f463a003 --- /dev/null +++ b/auth/default.go @@ -0,0 +1,34 @@ +package auth + +var ( + DefaultAuth Auth = new(noop) +) + +type noop struct { + options Options +} + +// String name of implementation +func (a *noop) String() string { + return "noop" +} + +// Init the svc +func (a *noop) Init(...Option) error { + return nil +} + +// Generate a new auth Account +func (a *noop) Generate(id string, ops ...GenerateOption) (*Account, error) { + return nil, nil +} + +// Revoke an authorization Account +func (a *noop) Revoke(token string) error { + return nil +} + +// Validate a account token +func (a *noop) Validate(token string) (*Account, error) { + return nil, nil +} diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go new file mode 100644 index 00000000..47498001 --- /dev/null +++ b/auth/jwt/jwt.go @@ -0,0 +1,106 @@ +package jwt + +import ( + "errors" + "time" + + "github.com/dgrijalva/jwt-go" + "github.com/micro/go-micro/v2/auth" +) + +// ErrInvalidPrivateKey is returned when the service provided an invalid private key +var ErrInvalidPrivateKey = errors.New("An invalid private key was provided") + +// ErrEncodingToken is returned when the service encounters an error during encoding +var ErrEncodingToken = errors.New("An error occured while encoding the JWT") + +// ErrInvalidToken is returned when the token provided is not valid +var ErrInvalidToken = errors.New("An invalid token was provided") + +// NewAuth returns a new instance of the Auth service +func NewAuth(opts ...auth.Option) auth.Auth { + svc := new(svc) + svc.Init(opts...) + return svc +} + +// svc is the JWT implementation of the Auth interface +type svc struct { + options auth.Options +} + +func (s *svc) String() string { + return "jwt" +} + +func (s *svc) Init(opts ...auth.Option) error { + for _, o := range opts { + o(&s.options) + } + + return nil +} + +// AuthClaims to be encoded in the JWT +type AuthClaims struct { + Id string `json:"id"` + Roles []*auth.Role `json:"roles"` + Metadata map[string]string `json:"metadata"` + + jwt.StandardClaims +} + +// Generate a new JWT +func (s *svc) Generate(id string, ops ...auth.GenerateOption) (*auth.Account, error) { + key, err := jwt.ParseRSAPrivateKeyFromPEM(s.options.PrivateKey) + if err != nil { + return nil, ErrEncodingToken + } + + options := auth.NewGenerateOptions(ops...) + account := jwt.NewWithClaims(jwt.SigningMethodRS256, AuthClaims{ + id, options.Roles, options.Metadata, jwt.StandardClaims{ + Subject: "TODO", + ExpiresAt: time.Now().Add(time.Hour * 24).Unix(), + }, + }) + + token, err := account.SignedString(key) + if err != nil { + return nil, err + } + + return &auth.Account{ + Id: id, + Token: token, + Roles: options.Roles, + Metadata: options.Metadata, + }, nil +} + +// Revoke an authorization account +func (s *svc) Revoke(token string) error { + return nil +} + +// Validate a JWT +func (s *svc) Validate(token string) (*auth.Account, error) { + res, err := jwt.ParseWithClaims(token, &AuthClaims{}, func(token *jwt.Token) (interface{}, error) { + return jwt.ParseRSAPublicKeyFromPEM(s.options.PublicKey) + }) + if err != nil { + return nil, err + } + + if !res.Valid { + return nil, ErrInvalidToken + } + + claims := res.Claims.(*AuthClaims) + + return &auth.Account{ + Id: claims.Id, + Metadata: claims.Metadata, + Roles: claims.Roles, + }, nil +} diff --git a/auth/options.go b/auth/options.go new file mode 100644 index 00000000..3488c03c --- /dev/null +++ b/auth/options.go @@ -0,0 +1,57 @@ +package auth + +import ( + b64 "encoding/base64" +) + +type Options struct { + PublicKey []byte + PrivateKey []byte +} + +type Option func(o *Options) + +// PublicKey is the JWT public key +func PublicKey(key string) Option { + return func(o *Options) { + o.PublicKey, _ = b64.StdEncoding.DecodeString(key) + } +} + +// PrivateKey is the JWT private key +func PrivateKey(key string) Option { + return func(o *Options) { + o.PrivateKey, _ = b64.StdEncoding.DecodeString(key) + } +} + +type GenerateOptions struct { + Metadata map[string]string + Roles []*Role +} + +type GenerateOption func(o *GenerateOptions) + +// Metadata for the generated account +func Metadata(md map[string]string) func(o *GenerateOptions) { + return func(o *GenerateOptions) { + o.Metadata = md + } +} + +// Roles for the generated account +func Roles(rs []*Role) func(o *GenerateOptions) { + return func(o *GenerateOptions) { + o.Roles = rs + } +} + +// NewGenerateOptions from a slice of options +func NewGenerateOptions(opts ...GenerateOption) GenerateOptions { + var options GenerateOptions + for _, o := range opts { + o(&options) + } + + return options +} diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go new file mode 100644 index 00000000..de3d6b28 --- /dev/null +++ b/auth/service/proto/auth.pb.go @@ -0,0 +1,466 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: auth/service/proto/auth.proto + +package go_micro_auth + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type Account struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Token string `protobuf:"bytes,2,opt,name=token,proto3" json:"token,omitempty"` + Created int64 `protobuf:"varint,3,opt,name=created,proto3" json:"created,omitempty"` + Expiry int64 `protobuf:"varint,4,opt,name=expiry,proto3" json:"expiry,omitempty"` + Roles []*Role `protobuf:"bytes,5,rep,name=roles,proto3" json:"roles,omitempty"` + Metadata map[string]string `protobuf:"bytes,6,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Account) Reset() { *m = Account{} } +func (m *Account) String() string { return proto.CompactTextString(m) } +func (*Account) ProtoMessage() {} +func (*Account) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{0} +} + +func (m *Account) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Account.Unmarshal(m, b) +} +func (m *Account) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Account.Marshal(b, m, deterministic) +} +func (m *Account) XXX_Merge(src proto.Message) { + xxx_messageInfo_Account.Merge(m, src) +} +func (m *Account) XXX_Size() int { + return xxx_messageInfo_Account.Size(m) +} +func (m *Account) XXX_DiscardUnknown() { + xxx_messageInfo_Account.DiscardUnknown(m) +} + +var xxx_messageInfo_Account proto.InternalMessageInfo + +func (m *Account) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *Account) GetToken() string { + if m != nil { + return m.Token + } + return "" +} + +func (m *Account) GetCreated() int64 { + if m != nil { + return m.Created + } + return 0 +} + +func (m *Account) GetExpiry() int64 { + if m != nil { + return m.Expiry + } + return 0 +} + +func (m *Account) GetRoles() []*Role { + if m != nil { + return m.Roles + } + return nil +} + +func (m *Account) GetMetadata() map[string]string { + if m != nil { + return m.Metadata + } + return nil +} + +type Role struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Role) Reset() { *m = Role{} } +func (m *Role) String() string { return proto.CompactTextString(m) } +func (*Role) ProtoMessage() {} +func (*Role) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{1} +} + +func (m *Role) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Role.Unmarshal(m, b) +} +func (m *Role) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Role.Marshal(b, m, deterministic) +} +func (m *Role) XXX_Merge(src proto.Message) { + xxx_messageInfo_Role.Merge(m, src) +} +func (m *Role) XXX_Size() int { + return xxx_messageInfo_Role.Size(m) +} +func (m *Role) XXX_DiscardUnknown() { + xxx_messageInfo_Role.DiscardUnknown(m) +} + +var xxx_messageInfo_Role proto.InternalMessageInfo + +func (m *Role) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *Role) GetResource() *Resource { + if m != nil { + return m.Resource + } + return nil +} + +type Resource struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Resource) Reset() { *m = Resource{} } +func (m *Resource) String() string { return proto.CompactTextString(m) } +func (*Resource) ProtoMessage() {} +func (*Resource) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{2} +} + +func (m *Resource) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Resource.Unmarshal(m, b) +} +func (m *Resource) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Resource.Marshal(b, m, deterministic) +} +func (m *Resource) XXX_Merge(src proto.Message) { + xxx_messageInfo_Resource.Merge(m, src) +} +func (m *Resource) XXX_Size() int { + return xxx_messageInfo_Resource.Size(m) +} +func (m *Resource) XXX_DiscardUnknown() { + xxx_messageInfo_Resource.DiscardUnknown(m) +} + +var xxx_messageInfo_Resource proto.InternalMessageInfo + +func (m *Resource) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *Resource) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +type GenerateRequest struct { + Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GenerateRequest) Reset() { *m = GenerateRequest{} } +func (m *GenerateRequest) String() string { return proto.CompactTextString(m) } +func (*GenerateRequest) ProtoMessage() {} +func (*GenerateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{3} +} + +func (m *GenerateRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GenerateRequest.Unmarshal(m, b) +} +func (m *GenerateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GenerateRequest.Marshal(b, m, deterministic) +} +func (m *GenerateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenerateRequest.Merge(m, src) +} +func (m *GenerateRequest) XXX_Size() int { + return xxx_messageInfo_GenerateRequest.Size(m) +} +func (m *GenerateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GenerateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GenerateRequest proto.InternalMessageInfo + +func (m *GenerateRequest) GetAccount() *Account { + if m != nil { + return m.Account + } + return nil +} + +type GenerateResponse struct { + Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GenerateResponse) Reset() { *m = GenerateResponse{} } +func (m *GenerateResponse) String() string { return proto.CompactTextString(m) } +func (*GenerateResponse) ProtoMessage() {} +func (*GenerateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{4} +} + +func (m *GenerateResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GenerateResponse.Unmarshal(m, b) +} +func (m *GenerateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GenerateResponse.Marshal(b, m, deterministic) +} +func (m *GenerateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenerateResponse.Merge(m, src) +} +func (m *GenerateResponse) XXX_Size() int { + return xxx_messageInfo_GenerateResponse.Size(m) +} +func (m *GenerateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GenerateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GenerateResponse proto.InternalMessageInfo + +func (m *GenerateResponse) GetAccount() *Account { + if m != nil { + return m.Account + } + return nil +} + +type ValidateRequest struct { + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ValidateRequest) Reset() { *m = ValidateRequest{} } +func (m *ValidateRequest) String() string { return proto.CompactTextString(m) } +func (*ValidateRequest) ProtoMessage() {} +func (*ValidateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{5} +} + +func (m *ValidateRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ValidateRequest.Unmarshal(m, b) +} +func (m *ValidateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ValidateRequest.Marshal(b, m, deterministic) +} +func (m *ValidateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidateRequest.Merge(m, src) +} +func (m *ValidateRequest) XXX_Size() int { + return xxx_messageInfo_ValidateRequest.Size(m) +} +func (m *ValidateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ValidateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidateRequest proto.InternalMessageInfo + +func (m *ValidateRequest) GetToken() string { + if m != nil { + return m.Token + } + return "" +} + +type ValidateResponse struct { + Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ValidateResponse) Reset() { *m = ValidateResponse{} } +func (m *ValidateResponse) String() string { return proto.CompactTextString(m) } +func (*ValidateResponse) ProtoMessage() {} +func (*ValidateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{6} +} + +func (m *ValidateResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ValidateResponse.Unmarshal(m, b) +} +func (m *ValidateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ValidateResponse.Marshal(b, m, deterministic) +} +func (m *ValidateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidateResponse.Merge(m, src) +} +func (m *ValidateResponse) XXX_Size() int { + return xxx_messageInfo_ValidateResponse.Size(m) +} +func (m *ValidateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ValidateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidateResponse proto.InternalMessageInfo + +func (m *ValidateResponse) GetAccount() *Account { + if m != nil { + return m.Account + } + return nil +} + +type RevokeRequest struct { + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RevokeRequest) Reset() { *m = RevokeRequest{} } +func (m *RevokeRequest) String() string { return proto.CompactTextString(m) } +func (*RevokeRequest) ProtoMessage() {} +func (*RevokeRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{7} +} + +func (m *RevokeRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RevokeRequest.Unmarshal(m, b) +} +func (m *RevokeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RevokeRequest.Marshal(b, m, deterministic) +} +func (m *RevokeRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_RevokeRequest.Merge(m, src) +} +func (m *RevokeRequest) XXX_Size() int { + return xxx_messageInfo_RevokeRequest.Size(m) +} +func (m *RevokeRequest) XXX_DiscardUnknown() { + xxx_messageInfo_RevokeRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_RevokeRequest proto.InternalMessageInfo + +func (m *RevokeRequest) GetToken() string { + if m != nil { + return m.Token + } + return "" +} + +type RevokeResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RevokeResponse) Reset() { *m = RevokeResponse{} } +func (m *RevokeResponse) String() string { return proto.CompactTextString(m) } +func (*RevokeResponse) ProtoMessage() {} +func (*RevokeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{8} +} + +func (m *RevokeResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RevokeResponse.Unmarshal(m, b) +} +func (m *RevokeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RevokeResponse.Marshal(b, m, deterministic) +} +func (m *RevokeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_RevokeResponse.Merge(m, src) +} +func (m *RevokeResponse) XXX_Size() int { + return xxx_messageInfo_RevokeResponse.Size(m) +} +func (m *RevokeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_RevokeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_RevokeResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Account)(nil), "go.micro.auth.Account") + proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.Account.MetadataEntry") + proto.RegisterType((*Role)(nil), "go.micro.auth.Role") + proto.RegisterType((*Resource)(nil), "go.micro.auth.Resource") + proto.RegisterType((*GenerateRequest)(nil), "go.micro.auth.GenerateRequest") + proto.RegisterType((*GenerateResponse)(nil), "go.micro.auth.GenerateResponse") + proto.RegisterType((*ValidateRequest)(nil), "go.micro.auth.ValidateRequest") + proto.RegisterType((*ValidateResponse)(nil), "go.micro.auth.ValidateResponse") + proto.RegisterType((*RevokeRequest)(nil), "go.micro.auth.RevokeRequest") + proto.RegisterType((*RevokeResponse)(nil), "go.micro.auth.RevokeResponse") +} + +func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } + +var fileDescriptor_21300bfacc51fc2a = []byte{ + // 429 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0xad, 0x3f, 0xe2, 0x98, 0x89, 0xd2, 0x46, 0x03, 0x2a, 0x56, 0x44, 0x21, 0xb2, 0x40, 0x84, + 0x8b, 0x83, 0xdc, 0x0b, 0x82, 0x0b, 0x15, 0xa0, 0x9e, 0x2a, 0xa4, 0x3d, 0x70, 0x5f, 0xec, 0x11, + 0xb5, 0xe2, 0x78, 0xcd, 0x7a, 0x1d, 0xe1, 0xdf, 0xc0, 0x6f, 0xe5, 0x3f, 0x20, 0xaf, 0xbd, 0x69, + 0xea, 0xb4, 0xaa, 0xd4, 0xdb, 0x7c, 0xbc, 0x79, 0xf3, 0xde, 0x68, 0x17, 0xce, 0x78, 0xad, 0xae, + 0x57, 0x15, 0xc9, 0x6d, 0x96, 0xd0, 0xaa, 0x94, 0x42, 0x89, 0x55, 0x5b, 0x8a, 0x74, 0x88, 0xd3, + 0x5f, 0x22, 0xda, 0x64, 0x89, 0x14, 0x51, 0x5b, 0x0c, 0xff, 0xda, 0x30, 0xbe, 0x48, 0x12, 0x51, + 0x17, 0x0a, 0x8f, 0xc1, 0xce, 0xd2, 0xc0, 0x5a, 0x58, 0xcb, 0x27, 0xcc, 0xce, 0x52, 0x7c, 0x06, + 0x23, 0x25, 0xd6, 0x54, 0x04, 0xb6, 0x2e, 0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, 0x8f, 0x60, 0x79, + 0x0b, 0x27, 0x3f, 0x78, 0x9e, 0xa5, 0x7b, 0x52, 0x76, 0x8f, 0xc2, 0xda, 0x7b, 0x14, 0xed, 0xba, + 0x1b, 0xe0, 0xa3, 0xd7, 0xbd, 0x81, 0x29, 0xa3, 0xad, 0x58, 0x3f, 0xb0, 0x6c, 0x06, 0xc7, 0x06, + 0xd6, 0xad, 0x8a, 0xff, 0x59, 0xe0, 0x5e, 0xd4, 0xea, 0x1a, 0xaf, 0xc0, 0x37, 0xb6, 0xf1, 0xe5, + 0x60, 0xdd, 0xe0, 0xa8, 0xf3, 0x57, 0xf7, 0xf6, 0x3b, 0xd6, 0xf0, 0xa8, 0xa5, 0x33, 0xb6, 0x0e, + 0xe8, 0x06, 0x87, 0x39, 0xa0, 0x1b, 0xde, 0x23, 0x3c, 0xc2, 0x4b, 0xf0, 0x3a, 0xe1, 0xf8, 0xe2, + 0xe0, 0xe9, 0xec, 0xd9, 0x9e, 0x9f, 0xdd, 0xd3, 0x35, 0x44, 0x3f, 0x3d, 0xfd, 0x97, 0xcf, 0xff, + 0x07, 0x00, 0x00, 0xff, 0xff, 0x79, 0x35, 0xb2, 0x7e, 0xec, 0x03, 0x00, 0x00, +} diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go new file mode 100644 index 00000000..86ccd75d --- /dev/null +++ b/auth/service/proto/auth.pb.micro.go @@ -0,0 +1,125 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: auth/service/proto/auth.proto + +package go_micro_auth + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +import ( + context "context" + client "github.com/micro/go-micro/client" + server "github.com/micro/go-micro/server" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ client.Option +var _ server.Option + +// Client API for Auth service + +type AuthService interface { + Generate(ctx context.Context, in *GenerateRequest, opts ...client.CallOption) (*GenerateResponse, error) + Validate(ctx context.Context, in *ValidateRequest, opts ...client.CallOption) (*ValidateResponse, error) + Revoke(ctx context.Context, in *RevokeRequest, opts ...client.CallOption) (*RevokeResponse, error) +} + +type authService struct { + c client.Client + name string +} + +func NewAuthService(name string, c client.Client) AuthService { + if c == nil { + c = client.NewClient() + } + if len(name) == 0 { + name = "go.micro.auth" + } + return &authService{ + c: c, + name: name, + } +} + +func (c *authService) Generate(ctx context.Context, in *GenerateRequest, opts ...client.CallOption) (*GenerateResponse, error) { + req := c.c.NewRequest(c.name, "Auth.Generate", in) + out := new(GenerateResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authService) Validate(ctx context.Context, in *ValidateRequest, opts ...client.CallOption) (*ValidateResponse, error) { + req := c.c.NewRequest(c.name, "Auth.Validate", in) + out := new(ValidateResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authService) Revoke(ctx context.Context, in *RevokeRequest, opts ...client.CallOption) (*RevokeResponse, error) { + req := c.c.NewRequest(c.name, "Auth.Revoke", in) + out := new(RevokeResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Auth service + +type AuthHandler interface { + Generate(context.Context, *GenerateRequest, *GenerateResponse) error + Validate(context.Context, *ValidateRequest, *ValidateResponse) error + Revoke(context.Context, *RevokeRequest, *RevokeResponse) error +} + +func RegisterAuthHandler(s server.Server, hdlr AuthHandler, opts ...server.HandlerOption) error { + type auth interface { + Generate(ctx context.Context, in *GenerateRequest, out *GenerateResponse) error + Validate(ctx context.Context, in *ValidateRequest, out *ValidateResponse) error + Revoke(ctx context.Context, in *RevokeRequest, out *RevokeResponse) error + } + type Auth struct { + auth + } + h := &authHandler{hdlr} + return s.Handle(s.NewHandler(&Auth{h}, opts...)) +} + +type authHandler struct { + AuthHandler +} + +func (h *authHandler) Generate(ctx context.Context, in *GenerateRequest, out *GenerateResponse) error { + return h.AuthHandler.Generate(ctx, in, out) +} + +func (h *authHandler) Validate(ctx context.Context, in *ValidateRequest, out *ValidateResponse) error { + return h.AuthHandler.Validate(ctx, in, out) +} + +func (h *authHandler) Revoke(ctx context.Context, in *RevokeRequest, out *RevokeResponse) error { + return h.AuthHandler.Revoke(ctx, in, out) +} diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto new file mode 100644 index 00000000..03f8ca76 --- /dev/null +++ b/auth/service/proto/auth.proto @@ -0,0 +1,50 @@ +syntax = "proto3"; + +package go.micro.auth; + +service Auth { + rpc Generate(GenerateRequest) returns (GenerateResponse) {}; + rpc Validate(ValidateRequest) returns (ValidateResponse) {}; + rpc Revoke(RevokeRequest) returns (RevokeResponse) {}; +} + +message Account{ + string id = 1; + string token = 2; + int64 created = 3; + int64 expiry = 4; + repeated Role roles = 5; + map metadata = 6; +} + +message Role { + string name = 1; + Resource resource = 2; +} + +message Resource{ + string name = 1; + string type = 2; +} + +message GenerateRequest { + Account account = 1; +} + +message GenerateResponse { + Account account = 1; +} + +message ValidateRequest { + string token = 1; +} + +message ValidateResponse { + Account account = 1; +} + +message RevokeRequest { + string token = 1; +} + +message RevokeResponse {} diff --git a/auth/service/service.go b/auth/service/service.go new file mode 100644 index 00000000..58fb572f --- /dev/null +++ b/auth/service/service.go @@ -0,0 +1,128 @@ +package service + +import ( + "context" + "time" + + "github.com/micro/go-micro/client" + "github.com/micro/go-micro/v2/auth" + pb "github.com/micro/go-micro/v2/auth/service/proto" +) + +// NewAuth returns a new instance of the Auth service +func NewAuth(opts ...auth.Option) auth.Auth { + svc := new(svc) + svc.Init(opts...) + return svc +} + +// svc is the service implementation of the Auth interface +type svc struct { + options auth.Options + auth pb.AuthService +} + +func (s *svc) String() string { + return "service" +} + +func (s *svc) Init(opts ...auth.Option) error { + for _, o := range opts { + o(&s.options) + } + + dc := client.DefaultClient + s.auth = pb.NewAuthService("go.micro.auth", dc) + + return nil +} + +// Generate a new auth account +func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { + // construct the request + options := auth.NewGenerateOptions(opts...) + sa := &auth.Account{ + Id: id, + Roles: options.Roles, + Metadata: options.Metadata, + } + req := &pb.GenerateRequest{Account: serializeAccount(sa)} + + // execute the request + resp, err := s.auth.Generate(context.Background(), req) + if err != nil { + return nil, err + } + + // format the response + return deserializeAccount(resp.Account), nil +} + +// Revoke an authorization account +func (s *svc) Revoke(token string) error { + // contruct the request + req := &pb.RevokeRequest{Token: token} + + // execute the request + _, err := s.auth.Revoke(context.Background(), req) + return err +} + +// Validate an account token +func (s *svc) Validate(token string) (*auth.Account, error) { + resp, err := s.auth.Validate(context.Background(), &pb.ValidateRequest{Token: token}) + if err != nil { + return nil, err + } + + return deserializeAccount(resp.Account), nil +} + +func serializeAccount(sa *auth.Account) *pb.Account { + roles := make([]*pb.Role, len(sa.Roles)) + for i, r := range sa.Roles { + roles[i] = &pb.Role{ + Name: r.Name, + } + + if r.Resource != nil { + roles[i].Resource = &pb.Resource{ + Name: r.Resource.Name, + Type: r.Resource.Type, + } + } + } + + return &pb.Account{ + Id: sa.Id, + Roles: roles, + Metadata: sa.Metadata, + } +} + +func deserializeAccount(a *pb.Account) *auth.Account { + // format the response + sa := &auth.Account{ + Id: a.Id, + Token: a.Token, + Created: time.Unix(a.Created, 0), + Expiry: time.Unix(a.Expiry, 0), + Metadata: a.Metadata, + } + + sa.Roles = make([]*auth.Role, len(a.Roles)) + for i, r := range a.Roles { + sa.Roles[i] = &auth.Role{ + Name: r.Name, + } + + if r.Resource != nil { + sa.Roles[i].Resource = &auth.Resource{ + Name: r.Resource.Name, + Type: r.Resource.Type, + } + } + } + + return sa +} diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 6bbaacd4..04fa0d23 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" @@ -55,6 +56,10 @@ import ( // tracers // jTracer "github.com/micro/go-micro/v2/debug/trace/jaeger" memTracer "github.com/micro/go-micro/v2/debug/trace/memory" + + // auth + jwtAuth "github.com/micro/go-micro/v2/auth/jwt" + sAuth "github.com/micro/go-micro/v2/auth/service" ) type Cmd interface { @@ -223,6 +228,21 @@ var ( EnvVars: []string{"MICRO_TRACER_ADDRESS"}, Usage: "Comma-separated list of tracer addresses", }, + &cli.StringFlag{ + Name: "auth", + EnvVars: []string{"MICRO_AUTH"}, + Usage: "Auth for role based access control, e.g. service", + }, + &cli.StringFlag{ + Name: "auth_public_key", + EnvVars: []string{"MICRO_AUTH_PUBLIC_KEY"}, + Usage: "Public key for JWT auth (base64 encoded PEM)", + }, + &cli.StringFlag{ + Name: "auth_private_key", + EnvVars: []string{"MICRO_AUTH_PRIVATE_KEY"}, + Usage: "Private key for JWT auth (base64 encoded PEM)", + }, } DefaultBrokers = map[string]func(...broker.Option) broker.Broker{ @@ -274,6 +294,11 @@ var ( // "jaeger": jTracer.NewTracer, } + DefaultAuths = map[string]func(...auth.Option) auth.Auth{ + "service": sAuth.NewAuth, + "jwt": jwtAuth.NewAuth, + } + // used for default selection as the fall back defaultClient = "grpc" defaultServer = "grpc" @@ -300,6 +325,7 @@ func newCmd(opts ...Option) Cmd { Runtime: &runtime.DefaultRuntime, Store: &store.DefaultStore, Tracer: &trace.DefaultTracer, + Auth: &auth.DefaultAuth, Brokers: DefaultBrokers, Clients: DefaultClients, @@ -310,6 +336,7 @@ func newCmd(opts ...Option) Cmd { Runtimes: DefaultRuntimes, Stores: DefaultStores, Tracers: DefaultTracers, + Auths: DefaultAuths, } for _, o := range opts { @@ -382,6 +409,16 @@ func (c *cmd) Before(ctx *cli.Context) error { *c.opts.Tracer = r() } + // Set the auth + if name := ctx.String("auth"); len(name) > 0 { + r, ok := c.opts.Auths[name] + if !ok { + return fmt.Errorf("Unsupported auth: %s", name) + } + + *c.opts.Auth = r() + } + // Set the client if name := ctx.String("client"); len(name) > 0 { // only change if we have the client and type differs @@ -531,6 +568,18 @@ func (c *cmd) Before(ctx *cli.Context) error { serverOpts = append(serverOpts, server.RegisterInterval(val*time.Second)) } + if len(ctx.String("auth_public_key")) > 0 { + if err := (*c.opts.Auth).Init(auth.PublicKey(ctx.String("auth_public_key"))); err != nil { + log.Fatalf("Error configuring auth: %v", err) + } + } + + if len(ctx.String("auth_private_key")) > 0 { + if err := (*c.opts.Auth).Init(auth.PrivateKey(ctx.String("auth_private_key"))); err != nil { + log.Fatalf("Error configuring auth: %v", err) + } + } + // client opts if r := ctx.Int("client_retries"); r >= 0 { clientOpts = append(clientOpts, client.Retries(r)) diff --git a/config/cmd/options.go b/config/cmd/options.go index 695e8ccf..cf387228 100644 --- a/config/cmd/options.go +++ b/config/cmd/options.go @@ -3,6 +3,7 @@ package cmd import ( "context" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" @@ -30,6 +31,7 @@ type Options struct { Runtime *runtime.Runtime Store *store.Store Tracer *trace.Tracer + Auth *auth.Auth Brokers map[string]func(...broker.Option) broker.Broker Clients map[string]func(...client.Option) client.Client @@ -40,6 +42,7 @@ type Options struct { Runtimes map[string]func(...runtime.Option) runtime.Runtime Stores map[string]func(...store.Option) store.Store Tracers map[string]func(...trace.Option) trace.Tracer + Auths map[string]func(...auth.Option) auth.Auth // Other options for implementations of the interface // can be stored in a context @@ -109,6 +112,12 @@ func Tracer(t *trace.Tracer) Option { } } +func Auth(a *auth.Auth) Option { + return func(o *Options) { + o.Auth = a + } +} + // New broker func func NewBroker(name string, b func(...broker.Option) broker.Broker) Option { return func(o *Options) { @@ -164,3 +173,10 @@ func NewTracer(name string, t func(...trace.Option) trace.Tracer) Option { o.Tracers[name] = t } } + +// New auth func +func NewAuth(name string, t func(...auth.Option) auth.Auth) Option { + return func(o *Options) { + o.Auths[name] = t + } +} diff --git a/go.mod b/go.mod index eb869453..0b8d74dd 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/bitly/go-simplejson v0.5.0 github.com/bwmarrin/discordgo v0.20.2 github.com/coreos/etcd v3.3.18+incompatible + github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c github.com/fsnotify/fsnotify v1.4.7 github.com/fsouza/go-dockerclient v1.6.0 diff --git a/options.go b/options.go index d616115e..22207223 100644 --- a/options.go +++ b/options.go @@ -5,6 +5,7 @@ import ( "time" "github.com/micro/cli/v2" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" @@ -120,6 +121,13 @@ func Tracer(t trace.Tracer) Option { } } +// Auth sets the auth for the service +func Auth(a auth.Auth) Option { + return func(o *Options) { + o.Server.Init(server.Auth(a)) + } +} + // Selector sets the selector for the service client func Selector(s selector.Selector) Option { return func(o *Options) { diff --git a/server/options.go b/server/options.go index d7b03d4b..53424548 100644 --- a/server/options.go +++ b/server/options.go @@ -5,6 +5,7 @@ import ( "sync" "time" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/debug/trace" @@ -17,6 +18,7 @@ type Options struct { Broker broker.Broker Registry registry.Registry Tracer trace.Tracer + Auth auth.Auth Transport transport.Transport Metadata map[string]string Name string @@ -161,6 +163,13 @@ func Tracer(t trace.Tracer) Option { } } +// Auth mechanism for role based access control +func Auth(a auth.Auth) Option { + return func(o *Options) { + o.Auth = a + } +} + // Transport mechanism for communication e.g http, rabbitmq, etc func Transport(t transport.Transport) Option { return func(o *Options) { diff --git a/store/memory/memory.go b/store/memory/memory.go index 97e6bd84..00ce68b4 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -68,19 +68,26 @@ func (m *memoryStore) Read(key string, opts ...store.ReadOption) ([]*store.Recor var vals []*memoryRecord - if !options.Prefix { - v, ok := m.values[key] - if !ok { - return nil, store.ErrNotFound - } - vals = []*memoryRecord{v} - } else { + if options.Prefix { for _, v := range m.values { if !strings.HasPrefix(v.r.Key, key) { continue } vals = append(vals, v) } + } else if options.Suffix { + for _, v := range m.values { + if !strings.HasSuffix(v.r.Key, key) { + continue + } + vals = append(vals, v) + } + } else { + v, ok := m.values[key] + if !ok { + return nil, store.ErrNotFound + } + vals = []*memoryRecord{v} } //nolint:prealloc diff --git a/store/options.go b/store/options.go index a319cf58..f1ed4f52 100644 --- a/store/options.go +++ b/store/options.go @@ -11,6 +11,8 @@ type Options struct { Namespace string // Prefix of the keys used Prefix string + // Suffix of the keys used + Suffix string // Alternative options Context context.Context } @@ -45,3 +47,10 @@ func ReadPrefix() ReadOption { o.Prefix = true } } + +// ReadSuffix uses the key as a suffix +func ReadSuffix() ReadOption { + return func(o *ReadOptions) { + o.Suffix = true + } +} diff --git a/store/store.go b/store/store.go index 2e7d73ca..cf21ddee 100644 --- a/store/store.go +++ b/store/store.go @@ -39,6 +39,8 @@ type Record struct { type ReadOptions struct { // Read key as a prefix Prefix bool + // Read key as a suffix + Suffix bool } type ReadOption func(o *ReadOptions) From 1b9cabd654bf2a9cb2ab3a0e0c745622d4d0ec21 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 3 Feb 2020 08:26:57 +0000 Subject: [PATCH 230/788] Update Micro Auth Protocol Buffer to use V2 (#1155) --- auth/service/proto/auth.pb.micro.go | 10 +++++----- auth/service/service.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index 86ccd75d..6f2e0741 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -5,14 +5,14 @@ package go_micro_auth import ( fmt "fmt" - proto "github.com/golang/protobuf/proto" math "math" -) -import ( context "context" - client "github.com/micro/go-micro/client" - server "github.com/micro/go-micro/server" + + proto "github.com/golang/protobuf/proto" + + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/auth/service/service.go b/auth/service/service.go index 58fb572f..fdac98ca 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -4,9 +4,9 @@ import ( "context" "time" - "github.com/micro/go-micro/client" "github.com/micro/go-micro/v2/auth" pb "github.com/micro/go-micro/v2/auth/service/proto" + "github.com/micro/go-micro/v2/client" ) // NewAuth returns a new instance of the Auth service From a1d5d6831f0a862cbcfd3c62900457ddc1a3332e Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Mon, 3 Feb 2020 15:56:16 +0000 Subject: [PATCH 231/788] Add String to Runtime interface --- runtime/runtime.go | 2 ++ runtime/service.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/runtime/runtime.go b/runtime/runtime.go index 4dfe5d27..ce1b03f3 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -17,6 +17,8 @@ var ( // Runtime is a service runtime manager type Runtime interface { + // String describes runtime + String() string // Init initializes runtime Init(...Option) error // Create registers a service diff --git a/runtime/service.go b/runtime/service.go index ea42dc9e..45f70470 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -170,6 +170,8 @@ func (s *service) Wait() { s.Metadata["status"] = "error" s.Metadata["error"] = err.Error() s.err = err + } else { + s.Metadata["status"] = "done" } // no longer running From 7ab3a31ac4fefde8c7d8149d664e2f3a88443b6e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 4 Feb 2020 02:29:44 +0300 Subject: [PATCH 232/788] update micro/cli, tidy mod (#1156) Signed-off-by: Vasiliy Tolstov --- go.mod | 20 ++++++++++++++++++-- go.sum | 58 ++-------------------------------------------------------- 2 files changed, 20 insertions(+), 58 deletions(-) diff --git a/go.mod b/go.mod index 0b8d74dd..baceb3ac 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,13 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/beevik/ntp v0.2.0 github.com/bitly/go-simplejson v0.5.0 + github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect github.com/bwmarrin/discordgo v0.20.2 + github.com/coreos/bbolt v1.3.3 // indirect github.com/coreos/etcd v3.3.18+incompatible + github.com/coreos/go-semver v0.3.0 // indirect + github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect + github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c github.com/fsnotify/fsnotify v1.4.7 @@ -15,21 +20,25 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/go-acme/lego/v3 v3.3.0 github.com/go-playground/universal-translator v0.17.0 // indirect + github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/websocket v1.4.1 + github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect + github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/hashicorp/hcl v1.0.0 github.com/imdario/mergo v0.3.8 + github.com/jonboulle/clockwork v0.1.0 // indirect github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 github.com/json-iterator/go v1.1.9 github.com/kr/pretty v0.1.0 + github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 github.com/mholt/certmagic v0.9.1 - github.com/micro/cli/v2 v2.1.1 - github.com/micro/go-micro v1.18.0 + github.com/micro/cli/v2 v2.1.2-0.20200203150404-894195727d9c github.com/micro/mdns v0.3.0 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 @@ -38,13 +47,20 @@ require ( github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/pkg/errors v0.9.1 + github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 + github.com/technoweenie/multipartstreamer v1.0.1 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect + github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect + go.etcd.io/bbolt v1.3.3 // indirect go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200117160349-530e935923ad golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa + golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 // indirect google.golang.org/grpc v1.26.0 + gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 + sigs.k8s.io/yaml v1.1.0 // indirect ) diff --git a/go.sum b/go.sum index ef80de45..2bda9337 100644 --- a/go.sum +++ b/go.sum @@ -30,10 +30,8 @@ github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvd github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 h1:ygIc8M6trr62pF5DucadTWGdEB4mEyvzi0e2nbcmcyA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= -github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= @@ -66,8 +64,6 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= -github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= -github.com/bwmarrin/discordgo v0.20.1/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= @@ -84,7 +80,6 @@ github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0 h1:xjvXQWABwS2uiv3TWgQt5Uth60Gu86LTGZXMJkjc7rY= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= -github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVlf61smEIq1nwLLAjQVEK2EADoW3CX9AuT+8= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= @@ -93,7 +88,6 @@ github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDG github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= @@ -111,7 +105,6 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/decker502/dnspod-go v0.2.0/go.mod h1:qsurYu1FgxcDwfSwXJdLt4kRsBLZeosEb9uq4Sy+08g= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= @@ -119,7 +112,6 @@ github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s9 github.com/dnsimple/dnsimple-go v0.30.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v1.4.2-0.20190710153559-aa8249ae1b8b/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23 h1:oqgGT9O61YAYvI41EBsLePOr+LE6roB0xY4gpkZuFSE= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= @@ -131,7 +123,6 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1 github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= @@ -142,14 +133,12 @@ github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXj github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsouza/go-dockerclient v1.4.4/go.mod h1:PrwszSL5fbmsESocROrOGq/NULMXRw+bajY0ltzD6MA= github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4GGn3Hig= github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= -github.com/go-acme/lego/v3 v3.1.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= github.com/go-acme/lego/v3 v3.3.0 h1:6BePZsOiYA4/w+M7QDytxQtMfCipMPGnWAHs9pWks98= github.com/go-acme/lego/v3 v3.3.0/go.mod h1:iGSY2vQrvQs3WezicSB/oVbO2eCrD88dpWPwb1qLqu0= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= @@ -157,14 +146,10 @@ github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-log/log v0.1.0 h1:wudGTNsiGzrD5ZjgIkVZ517ugi2XRe9Q/xRCzwEO4/U= -github.com/go-log/log v0.1.0/go.mod h1:4mBwpdRMFLiuXZDCwU2lKQFsoSCo72j3HqBK9d81N2M= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -179,7 +164,6 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -240,7 +224,6 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= -github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd/go.mod h1:3LVOLeyx9XVvwPgrt2be44XgSqndprz1G18rSk8KD84= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= @@ -254,7 +237,6 @@ github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1/go.mod h1:DFXrEwSR github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= @@ -279,22 +261,17 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= -github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ= -github.com/lucas-clemente/quic-go v0.12.1/go.mod h1:UXJJPE4RfFef/xPO5wQm0tITK8gNfqwTxjbE7s3Vb8s= -github.com/lucas-clemente/quic-go v0.13.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= github.com/lucas-clemente/quic-go v0.14.1 h1:c1aKoBZKOPA+49q96B1wGkibyPP0AxYh45WuAoq+87E= github.com/lucas-clemente/quic-go v0.14.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ= github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE= github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= -github.com/marten-seemann/qtls v0.3.2/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -303,23 +280,14 @@ github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mholt/certmagic v0.7.5/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= -github.com/mholt/certmagic v0.8.3/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= github.com/mholt/certmagic v0.9.1 h1:wPzyouOyE+30NIQETJuhTB5ZQWz+0Hy038vaR5WWQDE= github.com/mholt/certmagic v0.9.1/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= -github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= -github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= -github.com/micro/cli/v2 v2.1.1 h1:uFw0SMIKmGuyHIm8lXns/NOn7V62bM5y7DnlxUM+BEQ= -github.com/micro/cli/v2 v2.1.1/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= -github.com/micro/go-micro v1.16.0/go.mod h1:A0F58bHLh2m0LAI9QyhvmbN8c1cxhAZo3cM6s+iDsrM= -github.com/micro/go-micro v1.18.0 h1:gP70EZVHpJuUIT0YWth192JmlIci+qMOEByHm83XE9E= -github.com/micro/go-micro v1.18.0/go.mod h1:klwUJL1gkdY1MHFyz+fFJXn52dKcty4hoe95Mp571AA= +github.com/micro/cli/v2 v2.1.2-0.20200203150404-894195727d9c h1:oohy8v2QQeXfDe9/BaM0b+5wETzoMiemOs3fhPhnFTg= +github.com/micro/cli/v2 v2.1.2-0.20200203150404-894195727d9c/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= -github.com/micro/protoc-gen-micro v1.0.0/go.mod h1:C8ij4DJhapBmypcT00AXdb0cZ675/3PqUO02buWWqbE= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -341,20 +309,16 @@ github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server/v2 v2.1.0/go.mod h1:r5y0WgCag0dTj/qiHkHrXAcKQ/f5GMOZaEGdoxxnJ4I= github.com/nats-io/nats-server/v2 v2.1.2 h1:i2Ly0B+1+rzNZHHWtD4ZwKi+OU5l+uQo1iDHZ2PmiIc= github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= -github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= -github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= -github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= @@ -445,7 +409,6 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc h1:yUaosFVTJwnltaHbSNC3i82I92quFs+OFPRl8kNMVwo= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= @@ -472,35 +435,28 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.2.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.12.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg= golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -545,9 +501,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -571,7 +525,6 @@ golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -581,12 +534,10 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 h1:Hynbrlo6LbYI3H1IqXpkVDOcX/3HiPdhVEuyj5a59RM= @@ -616,7 +567,6 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -647,7 +597,6 @@ google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1 h1:aQktFqmDE2yjveXJlVIfslDFmFnUXSqG0i6KRcJAeMc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= @@ -657,8 +606,6 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= @@ -670,7 +617,6 @@ gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= -gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= From 4333f00a4398fd3f87c72aa5a144d8be949757f9 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Tue, 4 Feb 2020 13:02:05 -0800 Subject: [PATCH 233/788] runtime/kubernetes: remove unused constants (#1159) --- runtime/kubernetes/kubernetes.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index f24843b0..995ea9d9 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -14,12 +14,6 @@ import ( // action to take on runtime service type action int -const ( - start action = iota - update - stop -) - type kubernetes struct { sync.RWMutex // options configure runtime From bf747a86f4e00d3022e67f786a243d6247297429 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 5 Feb 2020 13:59:35 +0000 Subject: [PATCH 234/788] Runtime (#1160) * Add String to Runtime interface * Setup Dynamic Runtime Configuration --- config/cmd/cmd.go | 21 ++++++++++++++++++++- runtime/kubernetes/kubernetes.go | 6 ++++++ runtime/local/local.go | 11 +++++++++++ runtime/{default.go => local_runtime.go} | 0 runtime/options.go | 9 +++++++++ runtime/runtime.go | 2 ++ runtime/service.go | 2 ++ 7 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 runtime/local/local.go rename runtime/{default.go => local_runtime.go} (100%) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 04fa0d23..f2b8b4a0 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -40,6 +40,11 @@ import ( rmem "github.com/micro/go-micro/v2/registry/memory" regSrv "github.com/micro/go-micro/v2/registry/service" + // runtimes + kRuntime "github.com/micro/go-micro/v2/runtime/kubernetes" + lRuntime "github.com/micro/go-micro/v2/runtime/local" + srvRuntime "github.com/micro/go-micro/v2/runtime/service" + // selectors "github.com/micro/go-micro/v2/client/selector/dns" "github.com/micro/go-micro/v2/client/selector/router" @@ -188,6 +193,12 @@ var ( EnvVars: []string{"MICRO_RUNTIME"}, Value: "local", }, + &cli.StringFlag{ + Name: "runtime_source", + Usage: "Runtime source for building and running services e.g github.com/micro/service", + EnvVars: []string{"MICRO_RUNTIME_SOURCE"}, + Value: "github.com/micro/services", + }, &cli.StringFlag{ Name: "selector", EnvVars: []string{"MICRO_SELECTOR"}, @@ -281,7 +292,9 @@ var ( } DefaultRuntimes = map[string]func(...runtime.Option) runtime.Runtime{ - "local": runtime.NewRuntime, + "local": lRuntime.NewRuntime, + "service": srvRuntime.NewRuntime, + "kubernetes": kRuntime.NewRuntime, } DefaultStores = map[string]func(...store.Option) store.Store{ @@ -580,6 +593,12 @@ func (c *cmd) Before(ctx *cli.Context) error { } } + if len(ctx.String("runtime_source")) > 0 { + if err := (*c.opts.Runtime).Init(runtime.WithSource(ctx.String("runtime_source"))); err != nil { + log.Fatalf("Error configuring runtime: %v", err) + } + } + // client opts if r := ctx.Int("client_retries"); r >= 0 { clientOpts = append(clientOpts, client.Retries(r)) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 995ea9d9..520ab78b 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -2,7 +2,9 @@ package kubernetes import ( + "errors" "fmt" + "strings" "sync" "time" @@ -245,6 +247,10 @@ func (k *kubernetes) Init(opts ...runtime.Option) error { o(&k.options) } + if strings.HasPrefix(k.options.Source, "github.com") { + return errors.New("invalid source provided to kubernetes runtime, expected docker image") + } + return nil } diff --git a/runtime/local/local.go b/runtime/local/local.go new file mode 100644 index 00000000..e8ed179e --- /dev/null +++ b/runtime/local/local.go @@ -0,0 +1,11 @@ +// Package local provides a local runtime +package local + +import ( + "github.com/micro/go-micro/v2/runtime" +) + +// NewRuntime returns a new local runtime +func NewRuntime(opts ...runtime.Option) runtime.Runtime { + return runtime.NewRuntime(opts...) +} diff --git a/runtime/default.go b/runtime/local_runtime.go similarity index 100% rename from runtime/default.go rename to runtime/local_runtime.go diff --git a/runtime/options.go b/runtime/options.go index 5c2ce688..1034e7f2 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -12,6 +12,15 @@ type Options struct { Scheduler Scheduler // Service type to manage Type string + // Source of the services repository + Source string +} + +// WithSource sets the host addresses to be used by the broker +func WithSource(src string) Option { + return func(o *Options) { + o.Source = src + } } // WithScheduler specifies a scheduler for updates diff --git a/runtime/runtime.go b/runtime/runtime.go index 4dfe5d27..ce1b03f3 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -17,6 +17,8 @@ var ( // Runtime is a service runtime manager type Runtime interface { + // String describes runtime + String() string // Init initializes runtime Init(...Option) error // Create registers a service diff --git a/runtime/service.go b/runtime/service.go index ea42dc9e..45f70470 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -170,6 +170,8 @@ func (s *service) Wait() { s.Metadata["status"] = "error" s.Metadata["error"] = err.Error() s.err = err + } else { + s.Metadata["status"] = "done" } // no longer running From 12181bd441185edddf704bb44b30fa365535b65d Mon Sep 17 00:00:00 2001 From: Shu xian Date: Thu, 6 Feb 2020 02:16:57 +0800 Subject: [PATCH 235/788] fix LevelInfo > LevelWarn (#1162) --- util/log/log.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/util/log/log.go b/util/log/log.go index ddd6e929..67c3b75c 100644 --- a/util/log/log.go +++ b/util/log/log.go @@ -4,19 +4,20 @@ package log import ( "fmt" "os" + "sync/atomic" "time" "github.com/micro/go-micro/v2/debug/log" ) // level is a log level -type Level int +type Level int32 const ( LevelFatal Level = iota LevelError - LevelInfo LevelWarn + LevelInfo LevelDebug LevelTrace ) @@ -186,7 +187,7 @@ func GetLogger() log.Log { // SetLevel sets the log level func SetLevel(l Level) { - level = l + atomic.StoreInt32((*int32)(&level), int32(l)) } // GetLevel returns the current level From a44dc90d45a978ba721687f348a8d4fc9c4016b5 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 6 Feb 2020 00:13:14 +0300 Subject: [PATCH 236/788] fix ctx.Done issue #720 (#1166) Signed-off-by: Vasiliy Tolstov --- client/grpc/grpc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index dc790760..542c9173 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -147,7 +147,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R case err := <-ch: grr = err case <-ctx.Done(): - grr = ctx.Err() + grr = errors.Timeout("go.micro.client", "%v", ctx.Err()) } return grr From d8110b70a375f342491b9e415dfa70e55164f6ef Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 6 Feb 2020 08:52:25 +0000 Subject: [PATCH 237/788] Runtime custom docker img (#1168) * Add DeploymentOptions to K8s Client * WithBaseImage for Runtime * Revert Change * Fix sequencing --- runtime/kubernetes/kubernetes.go | 3 ++- runtime/options.go | 11 ++++++++++- util/kubernetes/client/client.go | 6 ++++-- util/kubernetes/client/options.go | 26 ++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 520ab78b..e7bd4bd1 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -343,7 +343,8 @@ func (k *kubernetes) Delete(s *runtime.Service) error { // create new kubernetes micro service service := newService(s, runtime.CreateOptions{ - Type: k.options.Type, + Type: k.options.Type, + BaseImage: k.options.Source, }) return service.Stop(k.client) diff --git a/runtime/options.go b/runtime/options.go index 1034e7f2..cd1a6538 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -16,7 +16,7 @@ type Options struct { Source string } -// WithSource sets the host addresses to be used by the broker +// WithSource sets the base image / repository func WithSource(src string) Option { return func(o *Options) { o.Source = src @@ -51,6 +51,8 @@ type CreateOptions struct { Output io.Writer // Type of service to create Type string + // Base image for docker + BaseImage string } // ReadOptions queries runtime services @@ -92,6 +94,13 @@ func WithOutput(out io.Writer) CreateOption { } } +// WithBaseImage sets the docker img +func WithBaseImage(img string) CreateOption { + return func(o *CreateOptions) { + o.BaseImage = img + } +} + // ReadService returns services with the given name func ReadService(service string) ReadOption { return func(o *ReadOptions) { diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 01bf48cc..f67a3970 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -226,9 +226,11 @@ func NewService(name, version, typ string) *Service { } // NewService returns default micro kubernetes deployment definition -func NewDeployment(name, version, typ string) *Deployment { +func NewDeployment(name, version, typ string, opts ...DeploymentOption) *Deployment { log.Tracef("kubernetes default deployment: name: %s, version: %s", name, version) + options := NewDeploymentOptions(opts) + Labels := map[string]string{ "name": name, "version": version, @@ -265,7 +267,7 @@ func NewDeployment(name, version, typ string) *Deployment { PodSpec: &PodSpec{ Containers: []Container{{ Name: name, - Image: DefaultImage, + Image: options.BaseImage, Env: []EnvVar{env}, Command: []string{"go", "run", "main.go"}, Ports: []ContainerPort{{ diff --git a/util/kubernetes/client/options.go b/util/kubernetes/client/options.go index 0e293522..4670ae80 100644 --- a/util/kubernetes/client/options.go +++ b/util/kubernetes/client/options.go @@ -1,5 +1,9 @@ package client +type DeploymentOptions struct { + BaseImage string +} + type LogOptions struct { Params map[string]string } @@ -10,6 +14,7 @@ type WatchOptions struct { type LogOption func(*LogOptions) type WatchOption func(*WatchOptions) +type DeploymentOption func(*DeploymentOptions) // LogParams provides additional params for logs func LogParams(p map[string]string) LogOption { @@ -24,3 +29,24 @@ func WatchParams(p map[string]string) WatchOption { w.Params = p } } + +// WithBaseImage sets the base image for the deployment +func WithBaseImage(img string) DeploymentOption { + return func(d *DeploymentOptions) { + d.BaseImage = img + } +} + +// NewDeploymentOptions returns an initialized DeploymentOptions +func NewDeploymentOptions(opts []DeploymentOption) DeploymentOptions { + var options DeploymentOptions + for _, o := range opts { + o(&options) + } + + if options.BaseImage == "" { + options.BaseImage = DefaultImage + } + + return options +} From aa58a9749bd7a041feaff40a374090e412259115 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 09:17:10 +0000 Subject: [PATCH 238/788] Action Asim's Feedback --- runtime/kubernetes/kubernetes.go | 7 ++++--- runtime/kubernetes/service.go | 7 +++++++ runtime/options.go | 11 ++--------- util/kubernetes/client/client.go | 6 ++---- util/kubernetes/client/options.go | 26 -------------------------- 5 files changed, 15 insertions(+), 42 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index e7bd4bd1..00e7846a 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -327,7 +327,8 @@ func (k *kubernetes) List() ([]*runtime.Service, error) { func (k *kubernetes) Update(s *runtime.Service) error { // create new kubernetes micro service service := newService(s, runtime.CreateOptions{ - Type: k.options.Type, + Type: k.options.Type, + Source: k.options.Source, }) // update build time annotation @@ -343,8 +344,8 @@ func (k *kubernetes) Delete(s *runtime.Service) error { // create new kubernetes micro service service := newService(s, runtime.CreateOptions{ - Type: k.options.Type, - BaseImage: k.options.Source, + Type: k.options.Type, + Source: k.options.Source, }) return service.Stop(k.client) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 6c3024cb..4548e216 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -34,6 +34,13 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kservice := client.NewService(name, version, c.Type) kdeploy := client.NewDeployment(name, version, c.Type) + if len(s.Source) > 0 { + for _, c := range kdeploy.Spec.Template.PodSpec.Containers { + c.Image = s.Source + c.Command = []string{name} + } + } + // attach our values to the deployment; name, version, source kdeploy.Metadata.Annotations["name"] = s.Name kdeploy.Metadata.Annotations["version"] = s.Version diff --git a/runtime/options.go b/runtime/options.go index cd1a6538..8a29cf30 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -51,8 +51,8 @@ type CreateOptions struct { Output io.Writer // Type of service to create Type string - // Base image for docker - BaseImage string + // Source of the code + Source string } // ReadOptions queries runtime services @@ -94,13 +94,6 @@ func WithOutput(out io.Writer) CreateOption { } } -// WithBaseImage sets the docker img -func WithBaseImage(img string) CreateOption { - return func(o *CreateOptions) { - o.BaseImage = img - } -} - // ReadService returns services with the given name func ReadService(service string) ReadOption { return func(o *ReadOptions) { diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index f67a3970..01bf48cc 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -226,11 +226,9 @@ func NewService(name, version, typ string) *Service { } // NewService returns default micro kubernetes deployment definition -func NewDeployment(name, version, typ string, opts ...DeploymentOption) *Deployment { +func NewDeployment(name, version, typ string) *Deployment { log.Tracef("kubernetes default deployment: name: %s, version: %s", name, version) - options := NewDeploymentOptions(opts) - Labels := map[string]string{ "name": name, "version": version, @@ -267,7 +265,7 @@ func NewDeployment(name, version, typ string, opts ...DeploymentOption) *Deploym PodSpec: &PodSpec{ Containers: []Container{{ Name: name, - Image: options.BaseImage, + Image: DefaultImage, Env: []EnvVar{env}, Command: []string{"go", "run", "main.go"}, Ports: []ContainerPort{{ diff --git a/util/kubernetes/client/options.go b/util/kubernetes/client/options.go index 4670ae80..0e293522 100644 --- a/util/kubernetes/client/options.go +++ b/util/kubernetes/client/options.go @@ -1,9 +1,5 @@ package client -type DeploymentOptions struct { - BaseImage string -} - type LogOptions struct { Params map[string]string } @@ -14,7 +10,6 @@ type WatchOptions struct { type LogOption func(*LogOptions) type WatchOption func(*WatchOptions) -type DeploymentOption func(*DeploymentOptions) // LogParams provides additional params for logs func LogParams(p map[string]string) LogOption { @@ -29,24 +24,3 @@ func WatchParams(p map[string]string) WatchOption { w.Params = p } } - -// WithBaseImage sets the base image for the deployment -func WithBaseImage(img string) DeploymentOption { - return func(d *DeploymentOptions) { - d.BaseImage = img - } -} - -// NewDeploymentOptions returns an initialized DeploymentOptions -func NewDeploymentOptions(opts []DeploymentOption) DeploymentOptions { - var options DeploymentOptions - for _, o := range opts { - o(&options) - } - - if options.BaseImage == "" { - options.BaseImage = DefaultImage - } - - return options -} From 9983aea9287e2236524b409b5d6ae886d8c8a6ff Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 09:29:27 +0000 Subject: [PATCH 239/788] Tidying Up --- runtime/kubernetes/kubernetes.go | 6 ++---- runtime/kubernetes/service.go | 3 --- runtime/options.go | 2 -- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 00e7846a..520ab78b 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -327,8 +327,7 @@ func (k *kubernetes) List() ([]*runtime.Service, error) { func (k *kubernetes) Update(s *runtime.Service) error { // create new kubernetes micro service service := newService(s, runtime.CreateOptions{ - Type: k.options.Type, - Source: k.options.Source, + Type: k.options.Type, }) // update build time annotation @@ -344,8 +343,7 @@ func (k *kubernetes) Delete(s *runtime.Service) error { // create new kubernetes micro service service := newService(s, runtime.CreateOptions{ - Type: k.options.Type, - Source: k.options.Source, + Type: k.options.Type, }) return service.Stop(k.client) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 4548e216..2b0287e7 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -71,9 +71,6 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { // specify the command to exec if len(c.Command) > 0 { kdeploy.Spec.Template.PodSpec.Containers[0].Command = c.Command - } else if len(s.Source) > 0 { - // default command for our k8s service should be source - kdeploy.Spec.Template.PodSpec.Containers[0].Command = []string{"go", "run", s.Source} } return &service{ diff --git a/runtime/options.go b/runtime/options.go index 8a29cf30..d8011aa2 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -51,8 +51,6 @@ type CreateOptions struct { Output io.Writer // Type of service to create Type string - // Source of the code - Source string } // ReadOptions queries runtime services From 243c6a4246b9a01e01aa69d7fc360ce85a30b275 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 10:08:56 +0000 Subject: [PATCH 240/788] Debug --- runtime/kubernetes/service.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 2b0287e7..e110919f 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -2,6 +2,7 @@ package kubernetes import ( "encoding/json" + "fmt" "strings" "time" @@ -34,6 +35,7 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kservice := client.NewService(name, version, c.Type) kdeploy := client.NewDeployment(name, version, c.Type) + fmt.Printf("Source is %v", s.Source) if len(s.Source) > 0 { for _, c := range kdeploy.Spec.Template.PodSpec.Containers { c.Image = s.Source From f0762bbb6b5c9c473a6af7a7e8db8292b75359d8 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 10:16:32 +0000 Subject: [PATCH 241/788] Improve Logging --- runtime/kubernetes/service.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index e110919f..c572d077 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -2,7 +2,6 @@ package kubernetes import ( "encoding/json" - "fmt" "strings" "time" @@ -35,7 +34,7 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kservice := client.NewService(name, version, c.Type) kdeploy := client.NewDeployment(name, version, c.Type) - fmt.Printf("Source is %v", s.Source) + log.Debugf("newService Source: %v", s.Source) if len(s.Source) > 0 { for _, c := range kdeploy.Spec.Template.PodSpec.Containers { c.Image = s.Source From 7105e4099c8dbce93539d1e98462e03f914ed12f Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 6 Feb 2020 13:18:33 +0300 Subject: [PATCH 242/788] pass micro errors from grpc server to grpc client (#1167) * pass micro errors from grpc server to grpc client Signed-off-by: Vasiliy Tolstov * wrap micro errors.Error to grpc status Signed-off-by: Vasiliy Tolstov --- client/grpc/error.go | 16 +++--- client/grpc/grpc_test.go | 25 ++++++++++ errors/errors.go | 8 +-- errors/errors.pb.go | 102 +++++++++++++++++++++++++++++++++++++++ errors/errors.proto | 10 ++++ server/grpc/grpc.go | 72 +++++++++++++++++++++------ server/grpc/grpc_test.go | 23 +++++++++ 7 files changed, 227 insertions(+), 29 deletions(-) create mode 100644 errors/errors.pb.go create mode 100644 errors/errors.proto diff --git a/client/grpc/error.go b/client/grpc/error.go index 07a31c77..b625d1d8 100644 --- a/client/grpc/error.go +++ b/client/grpc/error.go @@ -12,17 +12,21 @@ func microError(err error) error { return nil } - // micro error - if v, ok := err.(*errors.Error); ok { - return v + if verr, ok := err.(*errors.Error); ok { + return verr } // grpc error if s, ok := status.FromError(err); ok { - if e := errors.Parse(s.Message()); e.Code > 0 { - return e // actually a micro error + details := s.Details() + if len(details) == 0 { + if e := errors.Parse(s.Message()); e.Code > 0 { + return e // actually a micro error + } + return errors.InternalServerError("go.micro.client", s.Message()) } - return errors.InternalServerError("go.micro.client", s.Message()) + // return first error from details + return details[0].(error) } // do nothing diff --git a/client/grpc/grpc_test.go b/client/grpc/grpc_test.go index 16d34e79..1b37dadb 100644 --- a/client/grpc/grpc_test.go +++ b/client/grpc/grpc_test.go @@ -7,6 +7,7 @@ import ( "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/registry/memory" pgrpc "google.golang.org/grpc" @@ -18,6 +19,9 @@ type greeterServer struct{} // SayHello implements helloworld.GreeterServer func (g *greeterServer) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { + if in.Name == "Error" { + return nil, &errors.Error{Id: "1", Code: 99, Detail: "detail"} + } return &pb.HelloReply{Message: "Hello " + in.Name}, nil } @@ -84,4 +88,25 @@ func TestGRPCClient(t *testing.T) { t.Fatalf("Got unexpected response %v", rsp.Message) } } + + req := c.NewRequest("helloworld", "/helloworld.Greeter/SayHello", &pb.HelloRequest{ + Name: "Error", + }) + + rsp := pb.HelloReply{} + + err = c.Call(context.TODO(), req, &rsp) + if err == nil { + t.Fatal("nil error received") + } + + verr, ok := err.(*errors.Error) + if !ok { + t.Fatalf("invalid error received %#+v\n", err) + } + + if verr.Code != 99 && verr.Id != "1" && verr.Detail != "detail" { + t.Fatalf("invalid error received %#+v\n", verr) + } + } diff --git a/errors/errors.go b/errors/errors.go index 61d340e4..df6e6c9f 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -8,13 +8,7 @@ import ( "net/http" ) -// Error implements the error interface. -type Error struct { - Id string `json:"id"` - Code int32 `json:"code"` - Detail string `json:"detail"` - Status string `json:"status"` -} +//go:generate protoc -I. --go_out=paths=source_relative:. errors.proto func (e *Error) Error() string { b, _ := json.Marshal(e) diff --git a/errors/errors.pb.go b/errors/errors.pb.go new file mode 100644 index 00000000..f749993d --- /dev/null +++ b/errors/errors.pb.go @@ -0,0 +1,102 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: errors.proto + +package errors + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type Error struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"` + Detail string `protobuf:"bytes,3,opt,name=detail,proto3" json:"detail,omitempty"` + Status string `protobuf:"bytes,4,opt,name=status,proto3" json:"status,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Error) Reset() { *m = Error{} } +func (m *Error) String() string { return proto.CompactTextString(m) } +func (*Error) ProtoMessage() {} +func (*Error) Descriptor() ([]byte, []int) { + return fileDescriptor_24fe73c7f0ddb19c, []int{0} +} + +func (m *Error) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Error.Unmarshal(m, b) +} +func (m *Error) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Error.Marshal(b, m, deterministic) +} +func (m *Error) XXX_Merge(src proto.Message) { + xxx_messageInfo_Error.Merge(m, src) +} +func (m *Error) XXX_Size() int { + return xxx_messageInfo_Error.Size(m) +} +func (m *Error) XXX_DiscardUnknown() { + xxx_messageInfo_Error.DiscardUnknown(m) +} + +var xxx_messageInfo_Error proto.InternalMessageInfo + +func (m *Error) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *Error) GetCode() int32 { + if m != nil { + return m.Code + } + return 0 +} + +func (m *Error) GetDetail() string { + if m != nil { + return m.Detail + } + return "" +} + +func (m *Error) GetStatus() string { + if m != nil { + return m.Status + } + return "" +} + +func init() { + proto.RegisterType((*Error)(nil), "errors.Error") +} + +func init() { proto.RegisterFile("errors.proto", fileDescriptor_24fe73c7f0ddb19c) } + +var fileDescriptor_24fe73c7f0ddb19c = []byte{ + // 116 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0x2d, 0x2a, 0xca, + 0x2f, 0x2a, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0x94, 0xa2, 0xb9, 0x58, + 0x5d, 0x41, 0x2c, 0x21, 0x3e, 0x2e, 0xa6, 0xcc, 0x14, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20, + 0xa6, 0xcc, 0x14, 0x21, 0x21, 0x2e, 0x96, 0xe4, 0xfc, 0x94, 0x54, 0x09, 0x26, 0x05, 0x46, 0x0d, + 0xd6, 0x20, 0x30, 0x5b, 0x48, 0x8c, 0x8b, 0x2d, 0x25, 0xb5, 0x24, 0x31, 0x33, 0x47, 0x82, 0x19, + 0xac, 0x0e, 0xca, 0x03, 0x89, 0x17, 0x97, 0x24, 0x96, 0x94, 0x16, 0x4b, 0xb0, 0x40, 0xc4, 0x21, + 0xbc, 0x24, 0x36, 0xb0, 0x5d, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xef, 0xe7, 0x5d, 0xd3, + 0x7b, 0x00, 0x00, 0x00, +} diff --git a/errors/errors.proto b/errors/errors.proto new file mode 100644 index 00000000..e9d51ff3 --- /dev/null +++ b/errors/errors.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package errors; + +message Error { + string id = 1; + int32 code = 2; + string detail = 3; + string status = 4; +}; diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index d014734a..dd2daeff 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -14,6 +14,7 @@ import ( "sync" "time" + "github.com/golang/protobuf/proto" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/errors" @@ -375,20 +376,38 @@ func (g *grpcServer) processRequest(stream grpc.ServerStream, service *service, statusCode := codes.OK statusDesc := "" - // execute the handler if appErr := fn(ctx, r, replyv.Interface()); appErr != nil { - if err, ok := appErr.(*rpcError); ok { - statusCode = err.code - statusDesc = err.desc - } else if err, ok := appErr.(*errors.Error); ok { - statusCode = microError(err) - statusDesc = appErr.Error() - } else { + var errStatus *status.Status + switch verr := appErr.(type) { + case *errors.Error: + // micro.Error now proto based and we can attach it to grpc status + statusCode = microError(verr) + statusDesc = verr.Error() + errStatus, err = status.New(statusCode, statusDesc).WithDetails(verr) + if err != nil { + return err + } + case proto.Message: + // user defined error that proto based we can attach it to grpc status statusCode = convertCode(appErr) statusDesc = appErr.Error() + errStatus, err = status.New(statusCode, statusDesc).WithDetails(verr) + if err != nil { + return err + } + case *rpcError: + // rpcError handling may be we have ability to attach it to details? + statusCode = verr.code + statusDesc = verr.desc + errStatus = status.New(statusCode, statusDesc) + default: + // default case user pass own error type that not proto based + statusCode = convertCode(verr) + statusDesc = verr.Error() + errStatus = status.New(statusCode, statusDesc) } - return status.New(statusCode, statusDesc).Err() + return errStatus.Err() } if err := stream.SendMsg(replyv.Interface()); err != nil { @@ -436,16 +455,37 @@ func (g *grpcServer) processStream(stream grpc.ServerStream, service *service, m appErr := fn(ctx, r, ss) if appErr != nil { - if err, ok := appErr.(*rpcError); ok { - statusCode = err.code - statusDesc = err.desc - } else if err, ok := appErr.(*errors.Error); ok { - statusCode = microError(err) - statusDesc = appErr.Error() - } else { + var err error + var errStatus *status.Status + switch verr := appErr.(type) { + case *errors.Error: + // micro.Error now proto based and we can attach it to grpc status + statusCode = microError(verr) + statusDesc = verr.Error() + errStatus, err = status.New(statusCode, statusDesc).WithDetails(verr) + if err != nil { + return err + } + case proto.Message: + // user defined error that proto based we can attach it to grpc status statusCode = convertCode(appErr) statusDesc = appErr.Error() + errStatus, err = status.New(statusCode, statusDesc).WithDetails(verr) + if err != nil { + return err + } + case *rpcError: + // rpcError handling may be we have ability to attach it to details? + statusCode = verr.code + statusDesc = verr.desc + errStatus = status.New(statusCode, statusDesc) + default: + // default case user pass own error type that not proto based + statusCode = convertCode(verr) + statusDesc = verr.Error() + errStatus = status.New(statusCode, statusDesc) } + return errStatus.Err() } return status.New(statusCode, statusDesc).Err() diff --git a/server/grpc/grpc_test.go b/server/grpc/grpc_test.go index 5d218ccf..829a7f1c 100644 --- a/server/grpc/grpc_test.go +++ b/server/grpc/grpc_test.go @@ -4,9 +4,11 @@ import ( "context" "testing" + "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/registry/memory" "github.com/micro/go-micro/v2/server" "google.golang.org/grpc" + "google.golang.org/grpc/status" pb "github.com/micro/go-micro/v2/server/grpc/proto" ) @@ -16,6 +18,10 @@ type testServer struct{} // TestHello implements helloworld.GreeterServer func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error { + if req.Name == "Error" { + return &errors.Error{Id: "1", Code: 99, Detail: "detail"} + } + rsp.Msg = "Hello " + req.Name return nil } @@ -63,4 +69,21 @@ func TestGRPCServer(t *testing.T) { t.Fatalf("Got unexpected response %v", rsp.Msg) } } + + // Test grpc error + rsp := pb.Response{} + + if err := cc.Invoke(context.Background(), "/test.Test/Call", &pb.Request{Name: "Error"}, &rsp); err != nil { + st, ok := status.FromError(err) + if !ok { + t.Fatalf("invalid error received %#+v\n", err) + } + verr, ok := st.Details()[0].(*errors.Error) + if !ok { + t.Fatalf("invalid error received %#+v\n", st.Details()[0]) + } + if verr.Code != 99 && verr.Id != "1" && verr.Detail != "detail" { + t.Fatalf("invalid error received %#+v\n", verr) + } + } } From 6aef28dad2036bbb596a653e6e8a724b61bd4d15 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 10:33:23 +0000 Subject: [PATCH 243/788] Runtime set service source --- runtime/kubernetes/kubernetes.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 520ab78b..479ae967 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -270,8 +270,10 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er if len(options.Type) == 0 { options.Type = k.options.Type } + if len(k.options.Source) > 0 { + s.Source = k.options.Source + } - // create new kubernetes micro service service := newService(s, options) // start the service From f8e696bd306188dee8cc0afd9f1a15f02734e903 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 10:44:12 +0000 Subject: [PATCH 244/788] Debugging --- runtime/kubernetes/service.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index c572d077..5a12bdd5 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -41,6 +41,8 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { c.Command = []string{name} } } + log.Debugf("kdeploy: %v", kdeploy) + log.Debugf("options: %v", c) // attach our values to the deployment; name, version, source kdeploy.Metadata.Annotations["name"] = s.Name From c7d922fac2dbd2e3f439094383f3e7b0cf1d4a31 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 10:49:01 +0000 Subject: [PATCH 245/788] Debugging --- runtime/kubernetes/service.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 5a12bdd5..298a62e8 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -34,15 +34,13 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kservice := client.NewService(name, version, c.Type) kdeploy := client.NewDeployment(name, version, c.Type) - log.Debugf("newService Source: %v", s.Source) if len(s.Source) > 0 { for _, c := range kdeploy.Spec.Template.PodSpec.Containers { c.Image = s.Source c.Command = []string{name} + log.Debugf("Setting name to %v", c.Command) } } - log.Debugf("kdeploy: %v", kdeploy) - log.Debugf("options: %v", c) // attach our values to the deployment; name, version, source kdeploy.Metadata.Annotations["name"] = s.Name @@ -72,6 +70,7 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { } // specify the command to exec + log.Debug("c.Command: ", c.Command) if len(c.Command) > 0 { kdeploy.Spec.Template.PodSpec.Containers[0].Command = c.Command } From c28737e88e1e40cbde8df64ad7082e4c8d0c0c68 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 10:54:11 +0000 Subject: [PATCH 246/788] Debugging --- runtime/kubernetes/kubernetes.go | 4 ++++ runtime/kubernetes/service.go | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 479ae967..dfe91808 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -2,6 +2,7 @@ package kubernetes import ( + "encoding/json" "errors" "fmt" "strings" @@ -276,6 +277,9 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er service := newService(s, options) + bytes, _ := json.Marshal(service) + log.Debug(string(bytes)) + // start the service return service.Start(k.client) } diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 298a62e8..2b0287e7 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -38,7 +38,6 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { for _, c := range kdeploy.Spec.Template.PodSpec.Containers { c.Image = s.Source c.Command = []string{name} - log.Debugf("Setting name to %v", c.Command) } } @@ -70,7 +69,6 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { } // specify the command to exec - log.Debug("c.Command: ", c.Command) if len(c.Command) > 0 { kdeploy.Spec.Template.PodSpec.Containers[0].Command = c.Command } From 54371bba6afcb4e7f4a9a2e42ea25ce6a2b684c9 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 10:55:41 +0000 Subject: [PATCH 247/788] Debugging --- util/kubernetes/client/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 01bf48cc..478889d2 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -267,7 +267,7 @@ func NewDeployment(name, version, typ string) *Deployment { Name: name, Image: DefaultImage, Env: []EnvVar{env}, - Command: []string{"go", "run", "main.go"}, + Command: []string{"go", "run", "mainx.go"}, Ports: []ContainerPort{{ Name: "service-port", ContainerPort: 8080, From 111126c780113449a20a99889169b541857b1b51 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 11:00:14 +0000 Subject: [PATCH 248/788] Debugging --- runtime/kubernetes/kubernetes.go | 4 ---- runtime/kubernetes/service.go | 3 +++ util/kubernetes/client/client.go | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index dfe91808..479ae967 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -2,7 +2,6 @@ package kubernetes import ( - "encoding/json" "errors" "fmt" "strings" @@ -277,9 +276,6 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er service := newService(s, options) - bytes, _ := json.Marshal(service) - log.Debug(string(bytes)) - // start the service return service.Start(k.client) } diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 2b0287e7..aa84585a 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -98,6 +98,9 @@ func serviceResource(s *client.Service) *client.Resource { // Start starts the Kubernetes service. It creates new kubernetes deployment and service API objects func (s *service) Start(k client.Client) error { + bytes, _ := json.Marshal(s.kdeploy) + log.Debug("kdeploy", string(bytes)) + // create deployment first; if we fail, we dont create service if err := k.Create(deploymentResource(s.kdeploy)); err != nil { log.Debugf("Runtime failed to create deployment: %v", err) diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 478889d2..82df204a 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -267,8 +267,8 @@ func NewDeployment(name, version, typ string) *Deployment { Name: name, Image: DefaultImage, Env: []EnvVar{env}, - Command: []string{"go", "run", "mainx.go"}, - Ports: []ContainerPort{{ + Command: []string{"go", "run", "main.go"}, + Ports: []ContainerPort{ Name: "service-port", ContainerPort: 8080, }}, From fc4191c647fbdce1cc04fb9a5bee7c10c219a4dc Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 11:12:40 +0000 Subject: [PATCH 249/788] Fix --- runtime/kubernetes/service.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index aa84585a..aeebb42b 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -35,9 +35,9 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kdeploy := client.NewDeployment(name, version, c.Type) if len(s.Source) > 0 { - for _, c := range kdeploy.Spec.Template.PodSpec.Containers { - c.Image = s.Source - c.Command = []string{name} + for i := range kdeploy.Spec.Template.PodSpec.Containers { + kdeploy.Spec.Template.PodSpec.Containers[i].Image = s.Source + kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{name} } } @@ -98,9 +98,6 @@ func serviceResource(s *client.Service) *client.Resource { // Start starts the Kubernetes service. It creates new kubernetes deployment and service API objects func (s *service) Start(k client.Client) error { - bytes, _ := json.Marshal(s.kdeploy) - log.Debug("kdeploy", string(bytes)) - // create deployment first; if we fail, we dont create service if err := k.Create(deploymentResource(s.kdeploy)); err != nil { log.Debugf("Runtime failed to create deployment: %v", err) From 2925b1615c4acf64dc1a6ffa4fe58a4bf40c037b Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 11:15:30 +0000 Subject: [PATCH 250/788] Fix --- util/kubernetes/client/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 82df204a..01bf48cc 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -268,7 +268,7 @@ func NewDeployment(name, version, typ string) *Deployment { Image: DefaultImage, Env: []EnvVar{env}, Command: []string{"go", "run", "main.go"}, - Ports: []ContainerPort{ + Ports: []ContainerPort{{ Name: "service-port", ContainerPort: 8080, }}, From e46278a76639c69bf30cf101f2567584ccd662c5 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 11:24:56 +0000 Subject: [PATCH 251/788] Test --- runtime/kubernetes/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index aeebb42b..c7083573 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -37,7 +37,7 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { if len(s.Source) > 0 { for i := range kdeploy.Spec.Template.PodSpec.Containers { kdeploy.Spec.Template.PodSpec.Containers[i].Image = s.Source - kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{name} + kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{"./entrypoint.sh", name} } } From 48b9f3f5e9d402ecedeac6f521281dd7d39dacb8 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 11:28:34 +0000 Subject: [PATCH 252/788] Fix --- runtime/kubernetes/service.go | 3 ++- util/kubernetes/client/types.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index c7083573..d4df59fd 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -37,7 +37,8 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { if len(s.Source) > 0 { for i := range kdeploy.Spec.Template.PodSpec.Containers { kdeploy.Spec.Template.PodSpec.Containers[i].Image = s.Source - kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{"./entrypoint.sh", name} + kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{} + kdeploy.Spec.Template.PodSpec.Containers[i].Arg = []string{name} } } diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index b3ce9a72..7a006273 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -20,6 +20,7 @@ type Container struct { Image string `json:"image"` Env []EnvVar `json:"env,omitempty"` Command []string `json:"command,omitempty"` + Arg []string `json:"arg,omitempty"` Ports []ContainerPort `json:"ports,omitempty"` } From 0591760932175319f427a0ede5f8497a9fbd90cb Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 12:17:16 +0000 Subject: [PATCH 253/788] Arg => Args --- runtime/kubernetes/service.go | 2 +- util/kubernetes/client/types.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index d4df59fd..0fafd962 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -38,7 +38,7 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { for i := range kdeploy.Spec.Template.PodSpec.Containers { kdeploy.Spec.Template.PodSpec.Containers[i].Image = s.Source kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{} - kdeploy.Spec.Template.PodSpec.Containers[i].Arg = []string{name} + kdeploy.Spec.Template.PodSpec.Containers[i].Args = []string{name} } } diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index 7a006273..f437bccb 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -20,7 +20,7 @@ type Container struct { Image string `json:"image"` Env []EnvVar `json:"env,omitempty"` Command []string `json:"command,omitempty"` - Arg []string `json:"arg,omitempty"` + Args []string `json:"args,omitempty"` Ports []ContainerPort `json:"ports,omitempty"` } From 5414195dc331d1eb8d55e58920c275f6baf0129c Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 6 Feb 2020 12:31:54 +0000 Subject: [PATCH 254/788] Add Args --- util/kubernetes/client/templates.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index 12b5be7f..84852cc0 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -60,6 +60,10 @@ spec: value: "{{ .Value }}" {{- end }} {{- end }} + args: + {{- range .Args }} + - {{.}} + {{- end }} command: {{- range .Command }} - {{.}} From 92571db693906ec0b3528ea30a9a4b6032de5420 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Thu, 6 Feb 2020 17:22:16 +0000 Subject: [PATCH 255/788] Tracing: traces now correctly form a tree (#1170) * First cut of trace * Dial it back yo * Defensive programming --- debug/trace/memory/memory.go | 22 +++++++++++----------- debug/trace/trace.go | 30 +++++++++++++++++++++++------- metadata/metadata.go | 3 +++ 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/debug/trace/memory/memory.go b/debug/trace/memory/memory.go index 11413adc..99e67c03 100644 --- a/debug/trace/memory/memory.go +++ b/debug/trace/memory/memory.go @@ -49,27 +49,27 @@ func (t *Tracer) Start(ctx context.Context, name string) (context.Context, *trac // return span if no context if ctx == nil { - return context.Background(), span + return trace.ToContext(context.Background(), span.Trace, span.Id), span } - - s, ok := trace.FromContext(ctx) + traceID, parentSpanID, ok := trace.FromContext(ctx) + // If the trace can not be found in the header, + // that means this is where the trace is created. if !ok { - return ctx, span + return trace.ToContext(ctx, span.Trace, span.Id), span } // set trace id - span.Trace = s.Trace + span.Trace = traceID // set parent - span.Parent = s.Id + span.Parent = parentSpanID - // return the sapn - return ctx, span + // return the span + return trace.ToContext(ctx, span.Trace, span.Id), span } func (t *Tracer) Finish(s *trace.Span) error { // set finished time s.Duration = time.Since(s.Started) - // save the span t.buffer.Put(s) @@ -84,7 +84,7 @@ func NewTracer(opts ...trace.Option) trace.Tracer { return &Tracer{ opts: options, - // the last 64 requests - buffer: ring.New(64), + // the last 256 requests + buffer: ring.New(256), } } diff --git a/debug/trace/trace.go b/debug/trace/trace.go index 1c1f85bc..efb8c432 100644 --- a/debug/trace/trace.go +++ b/debug/trace/trace.go @@ -3,6 +3,7 @@ package trace import ( "context" + "github.com/micro/go-micro/v2/metadata" "time" ) @@ -34,17 +35,32 @@ type Span struct { Metadata map[string]string } -type spanKey struct{} +const ( + traceIDKey = "Micro-Trace-Id" + spanIDKey = "Micro-Span-Id" +) // FromContext returns a span from context -func FromContext(ctx context.Context) (*Span, bool) { - s, ok := ctx.Value(spanKey{}).(*Span) - return s, ok +func FromContext(ctx context.Context) (traceID string, parentSpanID string, isFound bool) { + traceID, traceOk := metadata.Get(ctx, traceIDKey) + microID, microOk := metadata.Get(ctx, "Micro-Id") + if !traceOk && !microOk { + isFound = false + return + } + if !traceOk { + traceID = microID + } + parentSpanID, ok := metadata.Get(ctx, spanIDKey) + return traceID, parentSpanID, ok } -// NewContext creates a new context with the span -func NewContext(ctx context.Context, s *Span) context.Context { - return context.WithValue(ctx, spanKey{}, s) +// ToContext saves the trace and span ids in the context +func ToContext(ctx context.Context, traceID, parentSpanID string) context.Context { + return metadata.MergeContext(ctx, map[string]string{ + traceIDKey: traceID, + spanIDKey: parentSpanID, + }, true) } var ( diff --git a/metadata/metadata.go b/metadata/metadata.go index 3d6357ec..2f1f234b 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -63,6 +63,9 @@ func NewContext(ctx context.Context, md Metadata) context.Context { // MergeContext merges metadata to existing metadata, overwriting if specified func MergeContext(ctx context.Context, patchMd Metadata, overwrite bool) context.Context { + if ctx == nil { + ctx = context.Background() + } md, _ := ctx.Value(metaKey{}).(Metadata) cmd := make(Metadata) for k, v := range md { From 512df2628f24e2afef15159a94f9ea13e73df310 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 6 Feb 2020 18:34:16 +0000 Subject: [PATCH 256/788] trim source url if its set to github.com/ --- runtime/kubernetes/kubernetes.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 479ae967..69afc54e 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -247,8 +247,9 @@ func (k *kubernetes) Init(opts ...runtime.Option) error { o(&k.options) } + // trim the source prefix if its a git url if strings.HasPrefix(k.options.Source, "github.com") { - return errors.New("invalid source provided to kubernetes runtime, expected docker image") + k.options.Source = strings.TrimPrefix(k.options.Source, "github.com/") } return nil From dbeb7cfe9c55a1a14e0c50a545dccaa033983f39 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 6 Feb 2020 18:45:12 +0000 Subject: [PATCH 257/788] remove errors import --- runtime/kubernetes/kubernetes.go | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 69afc54e..aafa2f92 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -2,7 +2,6 @@ package kubernetes import ( - "errors" "fmt" "strings" "sync" From fdfb2bc4c1ec6b7b7de37a6124269e28157d494e Mon Sep 17 00:00:00 2001 From: Shu xian Date: Fri, 7 Feb 2020 05:35:46 +0800 Subject: [PATCH 258/788] [WIP] logger first (#1161) * logger first * log->logger * update comment * add context in Options * add Fields * remove logfi * add field encode * add common Field Types * update logger field --- logger/field.go | 43 ++++++++++++++++++++++++++++++++++++++++++ logger/level.go | 13 +++++++++++++ logger/logger.go | 48 +++++++++++++++++++++++++++++++++++++++++++++++ logger/options.go | 19 +++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 logger/field.go create mode 100644 logger/level.go create mode 100644 logger/logger.go create mode 100644 logger/options.go diff --git a/logger/field.go b/logger/field.go new file mode 100644 index 00000000..a91572ac --- /dev/null +++ b/logger/field.go @@ -0,0 +1,43 @@ +package logger + +type FieldType uint8 + +type Encode func(*Field) string + +type Field struct { + Key string + Type FieldType + Value interface{} + Encode Encode +} + +func (f *Field) GetValue() interface{} { + if f.Encode != nil { + return f.Encode(f) + } + + return f.Value +} + +// preset common types for choosing encoder faster +const ( + UnknownType FieldType = iota + BoolType + DurationType + Float64Type + Float32Type + Int64Type + Int32Type + Int16Type + Int8Type + Uint64Type + Uint32Type + Uint16Type + Uint8Type + StringType + TimeType +) + +func Bool(key string, val bool) Field { + return Field{Key: key, Type: BoolType, Value: val} +} diff --git a/logger/level.go b/logger/level.go new file mode 100644 index 00000000..d7a345be --- /dev/null +++ b/logger/level.go @@ -0,0 +1,13 @@ +package logger + +type Level int8 + +const ( + TraceLevel Level = iota - 1 + DebugLevel + InfoLevel + WarnLevel + ErrorLevel + PanicLevel + FatalLevel +) diff --git a/logger/logger.go b/logger/logger.go new file mode 100644 index 00000000..001bb2b1 --- /dev/null +++ b/logger/logger.go @@ -0,0 +1,48 @@ +// Package log provides a log interface +package logger + +import ( + "fmt" + "sync" +) + +// Logger is a generic logging interface +type Logger interface { + Init(options ...Option) error + // String returns the name of logger + String() string + // SetLevel updates the logging level. + SetLevel(Level) + // Level returns the logging level + Level() Level + // Log inserts a log entry. Arguments may be handled in the manner + // of fmt.Print, but the underlying logger may also decide to handle + // them differently. + Log(level Level, v ...interface{}) + // Logf insets a log entry. Arguments are handled in the manner of + // fmt.Printf. + Logf(level Level, format string, v ...interface{}) + // Fields set fields to always be logged + Fields(fields ...Field) Logger +} + +var ( + mux sync.Mutex + loggerMap = map[string]Logger{} +) + +func Register(logger Logger) { + mux.Lock() + defer mux.Unlock() + + loggerMap[logger.String()] = logger +} + +func GetLogger(name string) (Logger, error) { + l := loggerMap[name] + if l == nil { + return nil, fmt.Errorf("no such name logger found %s", name) + } + + return l, nil +} diff --git a/logger/options.go b/logger/options.go new file mode 100644 index 00000000..ca502f7c --- /dev/null +++ b/logger/options.go @@ -0,0 +1,19 @@ +package logger + +import "context" + +// Option for load profiles maybe +// eg. yml +// micro: +// logger: +// name: +// dialect: zap/default/logrus +// zap: +// xxx: +// logrus: +// xxx: +type Option func(*Options) + +type Options struct { + Context context.Context +} From 4079b22c1ea8ab929e0db922a863553ea709d8ad Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 6 Feb 2020 21:36:33 +0000 Subject: [PATCH 259/788] reorder logger methods --- logger/logger.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/logger/logger.go b/logger/logger.go index 001bb2b1..40c87d8e 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -8,11 +8,8 @@ import ( // Logger is a generic logging interface type Logger interface { + // Init initialises options Init(options ...Option) error - // String returns the name of logger - String() string - // SetLevel updates the logging level. - SetLevel(Level) // Level returns the logging level Level() Level // Log inserts a log entry. Arguments may be handled in the manner @@ -24,6 +21,10 @@ type Logger interface { Logf(level Level, format string, v ...interface{}) // Fields set fields to always be logged Fields(fields ...Field) Logger + // SetLevel updates the logging level. + SetLevel(Level) + // String returns the name of logger + String() string } var ( From d40b13a04568e7d71bbd132cb7ef987019c0f6a4 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 6 Feb 2020 21:37:17 +0000 Subject: [PATCH 260/788] mux to mtx --- logger/logger.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/logger/logger.go b/logger/logger.go index 40c87d8e..8d7a4ece 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -28,13 +28,13 @@ type Logger interface { } var ( - mux sync.Mutex + mtx sync.Mutex loggerMap = map[string]Logger{} ) func Register(logger Logger) { - mux.Lock() - defer mux.Unlock() + mtx.Lock() + defer mtx.Unlock() loggerMap[logger.String()] = logger } From 0e9b4c26a4c715ca60159f883ecc8d2989d05c05 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 6 Feb 2020 21:39:08 +0000 Subject: [PATCH 261/788] import with braces --- logger/options.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/logger/options.go b/logger/options.go index ca502f7c..e5ca063d 100644 --- a/logger/options.go +++ b/logger/options.go @@ -1,6 +1,8 @@ package logger -import "context" +import ( + "context" +) // Option for load profiles maybe // eg. yml From 19c454ec4bc6c16c201c0b0c8c80cc48c90e4c26 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Fri, 7 Feb 2020 11:39:26 +0000 Subject: [PATCH 262/788] Fix Local Runtime Default Command (#1173) * Auth API Proto * Fix local runtime bug * Add Platform Proto * Restructuring --- runtime/local_runtime.go | 2 +- runtime/service.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/local_runtime.go b/runtime/local_runtime.go index eed3ff3f..b72a80cc 100644 --- a/runtime/local_runtime.go +++ b/runtime/local_runtime.go @@ -164,7 +164,7 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error { } if len(options.Command) == 0 { - return errors.New("missing exec command") + options.Command = []string{"go", "run", "."} } // create new service diff --git a/runtime/service.go b/runtime/service.go index 45f70470..37fe38f2 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -167,6 +167,7 @@ func (s *service) Wait() { // save the error if err != nil { + log.Debugf("Error running service (%v): %v", s.Name, err) s.Metadata["status"] = "error" s.Metadata["error"] = err.Error() s.err = err From fe7f5a4134c7ace5d302e97c73231fef438866fc Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Fri, 7 Feb 2020 12:02:41 +0000 Subject: [PATCH 263/788] Runtime Retries Limit (#1163) * Implement Runtime Retries * Remove Debug * Action Feedback * Refactor Retries * Fix WithRetires Typo --- runtime/local_runtime.go | 6 +- runtime/options.go | 11 ++- runtime/service.go | 29 ++++-- runtime/service/proto/runtime.pb.go | 102 +++++++++++----------- runtime/service/proto/runtime.pb.micro.go | 8 +- runtime/service/proto/runtime.proto | 4 +- 6 files changed, 90 insertions(+), 70 deletions(-) diff --git a/runtime/local_runtime.go b/runtime/local_runtime.go index b72a80cc..18247d89 100644 --- a/runtime/local_runtime.go +++ b/runtime/local_runtime.go @@ -92,7 +92,7 @@ func (r *runtime) run(events <-chan Event) { // check running services r.RLock() for _, service := range r.services { - if service.Running() { + if !service.ShouldStart() { continue } @@ -104,7 +104,7 @@ func (r *runtime) run(events <-chan Event) { } r.RUnlock() case service := <-r.start: - if service.Running() { + if !service.ShouldStart() { continue } // TODO: check service error @@ -245,7 +245,7 @@ func (r *runtime) Delete(s *Service) error { log.Debugf("Runtime deleting service %s", s.Name) if s, ok := r.services[s.Name]; ok { // check if running - if !s.Running() { + if s.Running() { delete(r.services, s.Name) return nil } diff --git a/runtime/options.go b/runtime/options.go index d8011aa2..197f3d7f 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -51,6 +51,8 @@ type CreateOptions struct { Output io.Writer // Type of service to create Type string + // Retries before failing deploy + Retries int } // ReadOptions queries runtime services @@ -78,6 +80,13 @@ func WithCommand(args ...string) CreateOption { } } +// WithRetries sets the max retries attemps +func WithRetries(retries int) CreateOption { + return func(o *CreateOptions) { + o.Retries = retries + } +} + // WithEnv sets the created service environment func WithEnv(env []string) CreateOption { return func(o *CreateOptions) { @@ -99,7 +108,7 @@ func ReadService(service string) ReadOption { } } -// WithVersion confifgures service version +// ReadVersion confifgures service version func ReadVersion(version string) ReadOption { return func(o *ReadOptions) { o.Version = version diff --git a/runtime/service.go b/runtime/service.go index 37fe38f2..0a40f2f7 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -2,6 +2,7 @@ package runtime import ( "io" + "strconv" "sync" "time" @@ -19,6 +20,9 @@ type service struct { err error updated time.Time + retries int + maxRetries int + // output for logs output io.Writer @@ -54,9 +58,10 @@ func newService(s *Service, c CreateOptions) *service { Env: c.Env, Args: args, }, - closed: make(chan bool), - output: c.Output, - updated: time.Now(), + closed: make(chan bool), + output: c.Output, + updated: time.Now(), + maxRetries: c.Retries, } } @@ -65,7 +70,17 @@ func (s *service) streamOutput() { go io.Copy(s.output, s.PID.Error) } -// Running returns true is the service is running +func (s *service) ShouldStart() bool { + s.RLock() + defer s.RUnlock() + + if s.running { + return false + } + + return s.maxRetries < s.retries +} + func (s *service) Running() bool { s.RLock() defer s.RUnlock() @@ -77,7 +92,7 @@ func (s *service) Start() error { s.Lock() defer s.Unlock() - if s.running { + if !s.ShouldStart() { return nil } @@ -167,9 +182,11 @@ func (s *service) Wait() { // save the error if err != nil { - log.Debugf("Error running service (%v): %v", s.Name, err) + s.retries++ s.Metadata["status"] = "error" s.Metadata["error"] = err.Error() + s.Metadata["retries"] = strconv.Itoa(s.retries) + s.err = err } else { s.Metadata["status"] = "done" diff --git a/runtime/service/proto/runtime.pb.go b/runtime/service/proto/runtime.pb.go index 0e389f5c..82161fff 100644 --- a/runtime/service/proto/runtime.pb.go +++ b/runtime/service/proto/runtime.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: micro/go-micro/runtime/service/proto/runtime.proto +// source: runtime/service/proto/runtime.proto package go_micro_runtime @@ -38,7 +38,7 @@ func (m *Service) Reset() { *m = Service{} } func (m *Service) String() string { return proto.CompactTextString(m) } func (*Service) ProtoMessage() {} func (*Service) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{0} + return fileDescriptor_2434d8152598889b, []int{0} } func (m *Service) XXX_Unmarshal(b []byte) error { @@ -101,7 +101,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{1} + return fileDescriptor_2434d8152598889b, []int{1} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -166,7 +166,7 @@ func (m *CreateOptions) Reset() { *m = CreateOptions{} } func (m *CreateOptions) String() string { return proto.CompactTextString(m) } func (*CreateOptions) ProtoMessage() {} func (*CreateOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{2} + return fileDescriptor_2434d8152598889b, []int{2} } func (m *CreateOptions) XXX_Unmarshal(b []byte) error { @@ -220,7 +220,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{3} + return fileDescriptor_2434d8152598889b, []int{3} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -265,7 +265,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{4} + return fileDescriptor_2434d8152598889b, []int{4} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -302,7 +302,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{5} + return fileDescriptor_2434d8152598889b, []int{5} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -355,7 +355,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{6} + return fileDescriptor_2434d8152598889b, []int{6} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -394,7 +394,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{7} + return fileDescriptor_2434d8152598889b, []int{7} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -433,7 +433,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{8} + return fileDescriptor_2434d8152598889b, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -471,7 +471,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{9} + return fileDescriptor_2434d8152598889b, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -503,7 +503,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{10} + return fileDescriptor_2434d8152598889b, []int{10} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -541,7 +541,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{11} + return fileDescriptor_2434d8152598889b, []int{11} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -572,7 +572,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{12} + return fileDescriptor_2434d8152598889b, []int{12} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -604,7 +604,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{13} + return fileDescriptor_2434d8152598889b, []int{13} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -651,42 +651,42 @@ func init() { } func init() { - proto.RegisterFile("micro/go-micro/runtime/service/proto/runtime.proto", fileDescriptor_4bc91a8efec81434) + proto.RegisterFile("runtime/service/proto/runtime.proto", fileDescriptor_2434d8152598889b) } -var fileDescriptor_4bc91a8efec81434 = []byte{ - // 526 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x4b, 0x6b, 0xdb, 0x40, - 0x10, 0x8e, 0x2d, 0xc7, 0x4e, 0x46, 0x55, 0x31, 0x4b, 0x29, 0x6a, 0xe8, 0xc3, 0xe8, 0xd2, 0x5c, - 0x2a, 0x83, 0x42, 0xe9, 0xeb, 0x18, 0xbb, 0xbd, 0xd4, 0x14, 0x14, 0xf2, 0x03, 0xb6, 0xf6, 0x10, - 0x44, 0x23, 0xad, 0xaa, 0x5d, 0x09, 0x7c, 0xea, 0xb5, 0x7f, 0xaf, 0xff, 0xa8, 0xec, 0x4b, 0x0f, - 0x47, 0xca, 0xc5, 0xb7, 0x99, 0xd9, 0xd9, 0x4f, 0xdf, 0x63, 0x11, 0x44, 0x69, 0xb2, 0x2d, 0xd8, - 0xf2, 0x8e, 0xbd, 0xd3, 0x45, 0x51, 0x66, 0x22, 0x49, 0x71, 0xc9, 0xb1, 0xa8, 0x92, 0x2d, 0x2e, - 0xf3, 0x82, 0x89, 0x7a, 0x1a, 0xaa, 0x8e, 0xcc, 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x98, 0x6a, 0x8f, 0xfb, 0x78, 0x75, 0x32, 0xec, 0xe3, 0x75, 0x10, - 0x8f, 0x82, 0xd3, 0xd6, 0xf6, 0xc1, 0x75, 0xa2, 0xeb, 0x83, 0x3b, 0x48, 0x45, 0xc9, 0x94, 0x41, - 0xf4, 0xc9, 0x6c, 0xe5, 0xd5, 0x27, 0xb3, 0x9d, 0x5f, 0x70, 0xf2, 0x73, 0xaa, 0x7e, 0xdd, 0x57, - 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0xcd, 0x8e, 0xbb, 0xe1, 0xf0, 0x05, 0x00, 0x00, +var fileDescriptor_2434d8152598889b = []byte{ + // 521 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x4b, 0x6f, 0xd3, 0x40, + 0x10, 0xae, 0xeb, 0x34, 0x69, 0xc7, 0x18, 0x45, 0x2b, 0x84, 0x4c, 0xc5, 0x23, 0x32, 0x07, 0x7a, + 0x72, 0xa4, 0x54, 0x88, 0xd7, 0xb1, 0x09, 0x5c, 0x88, 0x90, 0x5c, 0xf5, 0x07, 0x2c, 0xc9, 0x08, + 0x59, 0xd4, 0xbb, 0xc6, 0xbb, 0xb6, 0x94, 0x13, 0x57, 0xfe, 0x1e, 0xff, 0x08, 0xed, 0x2b, 0xb6, + 0x53, 0x9b, 0x4b, 0x6e, 0x3b, 0xb3, 0x33, 0x9f, 0xbf, 0xc7, 0xca, 0xf0, 0xba, 0xac, 0x98, 0xcc, + 0x72, 0x9c, 0x0b, 0x2c, 0xeb, 0x6c, 0x83, 0xf3, 0xa2, 0xe4, 0x92, 0xcf, 0x6d, 0x37, 0xd1, 0x15, + 0x99, 0xfe, 0xe0, 0x49, 0x9e, 0x6d, 0x4a, 0x9e, 0xd8, 0x7e, 0xfc, 0xd7, 0x83, 0xc9, 0xad, 0xd9, + 0x20, 0x04, 0x46, 0x8c, 0xe6, 0x18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89, 0xae, 0x0f, 0xee, 0x20, 0x15, 0x2d, 0x53, 0x05, 0xd1, 0x27, 0xb3, 0x95, 0x57, + 0x9f, 0xcc, 0x76, 0x7e, 0xf1, 0xc9, 0xf7, 0xb1, 0xfe, 0x75, 0x5f, 0xff, 0x0b, 0x00, 0x00, 0xff, + 0xff, 0x43, 0x9c, 0x97, 0x62, 0xe1, 0x05, 0x00, 0x00, } diff --git a/runtime/service/proto/runtime.pb.micro.go b/runtime/service/proto/runtime.pb.micro.go index a357362d..12b6691b 100644 --- a/runtime/service/proto/runtime.pb.micro.go +++ b/runtime/service/proto/runtime.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: micro/go-micro/runtime/service/proto/runtime.proto +// source: runtime/service/proto/runtime.proto package go_micro_runtime @@ -47,12 +47,6 @@ type runtimeService struct { } func NewRuntimeService(name string, c client.Client) RuntimeService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "go.micro.runtime" - } return &runtimeService{ c: c, name: name, diff --git a/runtime/service/proto/runtime.proto b/runtime/service/proto/runtime.proto index a292c88b..9e0d7722 100644 --- a/runtime/service/proto/runtime.proto +++ b/runtime/service/proto/runtime.proto @@ -17,8 +17,8 @@ message Service { string version = 2; // git url of the source string source = 3; - // service metadata - map metadata = 4; + // service metadata + map metadata = 4; } message Event { From 0755084a598bdca5a4caa3980d21e21ec894896d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 7 Feb 2020 13:55:55 +0000 Subject: [PATCH 264/788] fix deadlock --- runtime/service.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/runtime/service.go b/runtime/service.go index 0a40f2f7..8c8fffba 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -70,17 +70,19 @@ func (s *service) streamOutput() { go io.Copy(s.output, s.PID.Error) } -func (s *service) ShouldStart() bool { - s.RLock() - defer s.RUnlock() - +func (s *service) shouldStart() bool { if s.running { return false } - return s.maxRetries < s.retries } +func (s *service) ShouldStart() bool { + s.RLock() + defer s.RUnlock() + return s.shouldStart() +} + func (s *service) Running() bool { s.RLock() defer s.RUnlock() @@ -92,7 +94,7 @@ func (s *service) Start() error { s.Lock() defer s.Unlock() - if !s.ShouldStart() { + if !s.shouldStart() { return nil } From 812ea786042dd15bcfbd17c4450650653f90a39a Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 7 Feb 2020 14:00:09 +0000 Subject: [PATCH 265/788] Fix runtime deadlock --- runtime/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/service.go b/runtime/service.go index 8c8fffba..8ddd1bcc 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -74,7 +74,7 @@ func (s *service) shouldStart() bool { if s.running { return false } - return s.maxRetries < s.retries + return s.maxRetries <= s.retries } func (s *service) ShouldStart() bool { From c7f075d157d38b18c973512c5c4f50edeaf5cfa7 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 7 Feb 2020 14:00:27 +0000 Subject: [PATCH 266/788] rename file --- runtime/{local_runtime.go => default.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename runtime/{local_runtime.go => default.go} (100%) diff --git a/runtime/local_runtime.go b/runtime/default.go similarity index 100% rename from runtime/local_runtime.go rename to runtime/default.go From ef537270add34716bd25bb872ffbdd71829bb31b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 7 Feb 2020 20:58:03 +0000 Subject: [PATCH 267/788] Don't store traces for Debug endpoints --- util/wrapper/wrapper.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index c91368b6..3004abd4 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -2,6 +2,7 @@ package wrapper import ( "context" + "strings" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/debug/stats" @@ -111,6 +112,11 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper { return func(h server.HandlerFunc) server.HandlerFunc { // return a function that returns a function return func(ctx context.Context, req server.Request, rsp interface{}) error { + // don't store traces for debug + if strings.HasPrefix(req.Endpoint(), "Debug.") { + return h(ctx, req, rsp) + } + // get the span newCtx, s := t.Start(ctx, req.Service()+"."+req.Endpoint()) From f0f7f860d68a08c506624c897a9e1e4e3c2c3ee2 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 8 Feb 2020 00:48:24 +0300 Subject: [PATCH 268/788] add some docs (#1176) Signed-off-by: Vasiliy Tolstov --- options.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/options.go b/options.go index 22207223..380d9511 100644 --- a/options.go +++ b/options.go @@ -16,6 +16,7 @@ import ( "github.com/micro/go-micro/v2/transport" ) +// Options for micro service type Options struct { Broker broker.Broker Cmd cmd.Cmd @@ -56,6 +57,7 @@ func newOptions(opts ...Option) Options { return opt } +// Broker to be used for service func Broker(b broker.Broker) Option { return func(o *Options) { o.Broker = b @@ -71,6 +73,7 @@ func Cmd(c cmd.Cmd) Option { } } +// Client to be used for service func Client(c client.Client) Option { return func(o *Options) { o.Client = c @@ -78,8 +81,7 @@ func Client(c client.Client) Option { } // Context specifies a context for the service. -// Can be used to signal shutdown of the service. -// Can be used for extra option values. +// Can be used to signal shutdown of the service and for extra option values. func Context(ctx context.Context) Option { return func(o *Options) { o.Context = ctx @@ -95,6 +97,7 @@ func HandleSignal(b bool) Option { } } +// Server to be used for service func Server(s server.Server) Option { return func(o *Options) { o.Server = s @@ -176,12 +179,14 @@ func Metadata(md map[string]string) Option { } } +// Flags that can be passed to service func Flags(flags ...cli.Flag) Option { return func(o *Options) { o.Cmd.App().Flags = append(o.Cmd.App().Flags, flags...) } } +// Action can be used to parse user provided cli options func Action(a func(*cli.Context) error) Option { return func(o *Options) { o.Cmd.App().Action = a @@ -251,24 +256,28 @@ func WrapSubscriber(w ...server.SubscriberWrapper) Option { // Before and Afters +// BeforeStart run funcs before service starts func BeforeStart(fn func() error) Option { return func(o *Options) { o.BeforeStart = append(o.BeforeStart, fn) } } +// BeforeStop run funcs before service stops func BeforeStop(fn func() error) Option { return func(o *Options) { o.BeforeStop = append(o.BeforeStop, fn) } } +// AfterStart run funcs after service starts func AfterStart(fn func() error) Option { return func(o *Options) { o.AfterStart = append(o.AfterStart, fn) } } +// AfterStop run funcs after service stops func AfterStop(fn func() error) Option { return func(o *Options) { o.AfterStop = append(o.AfterStop, fn) From 99807a680c2bacf777c5abd674bfb85fc3964de5 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 8 Feb 2020 01:09:52 +0300 Subject: [PATCH 269/788] strip Micro-Topic header from incoming context in client.Call (#1177) Signed-off-by: Vasiliy Tolstov --- client/rpc_client.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/rpc_client.go b/client/rpc_client.go index 61c3fabb..9f55cd7d 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -74,6 +74,11 @@ func (r *rpcClient) call(ctx context.Context, node *registry.Node, req Request, md, ok := metadata.FromContext(ctx) if ok { for k, v := range md { + // don't copy Micro-Topic header, that used for pub/sub + // this fix case then client uses the same context that received in subscriber + if k == "Micro-Topic" { + continue + } msg.Header[k] = v } } From 0bf6c9fc0817db96c864c7279c8fe3435f9697d8 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 8 Feb 2020 02:14:34 +0300 Subject: [PATCH 270/788] config/source/cli: fix default flag value loading (#1178) Signed-off-by: Vasiliy Tolstov --- config/source/cli/cli.go | 13 +++++----- config/source/cli/cli_test.go | 48 ++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/config/source/cli/cli.go b/config/source/cli/cli.go index 6ca71709..30e1adaf 100644 --- a/config/source/cli/cli.go +++ b/config/source/cli/cli.go @@ -21,7 +21,9 @@ type cliSource struct { func (c *cliSource) Read() (*source.ChangeSet, error) { var changes map[string]interface{} - for _, name := range c.ctx.FlagNames() { + // directly using app cli flags, to access default values of not specified options + for _, f := range c.ctx.App.Flags { + name := f.Names()[0] tmp := toEntry(name, c.ctx.Generic(name)) mergo.Map(&changes, tmp) // need to sort error handling } @@ -100,13 +102,10 @@ func NewSource(opts ...source.Option) source.Source { var ctx *cli.Context - c, ok := options.Context.Value(contextKey{}).(*cli.Context) - if ok { + if c, ok := options.Context.Value(contextKey{}).(*cli.Context); ok { ctx = c - } - - // no context - if ctx == nil { + } else { + // no context // get the default app/flags app := cmd.App() flags := app.Flags diff --git a/config/source/cli/cli_test.go b/config/source/cli/cli_test.go index 45022a95..1a752a2e 100644 --- a/config/source/cli/cli_test.go +++ b/config/source/cli/cli_test.go @@ -6,10 +6,52 @@ import ( "testing" "github.com/micro/cli/v2" + "github.com/micro/go-micro/v2" + "github.com/micro/go-micro/v2/config" "github.com/micro/go-micro/v2/config/cmd" "github.com/micro/go-micro/v2/config/source" ) +func TestCliSourceDefault(t *testing.T) { + const expVal string = "flagvalue" + + service := micro.NewService( + micro.Flags( + // to be able to run insude go test + &cli.StringFlag{ + Name: "test.timeout", + }, + &cli.BoolFlag{ + Name: "test.v", + }, + &cli.StringFlag{ + Name: "test.run", + }, + &cli.StringFlag{ + Name: "flag", + Usage: "It changes something", + EnvVars: []string{"flag"}, + Value: expVal, + }, + ), + ) + var cliSrc source.Source + service.Init( + // Loads CLI configuration + micro.Action(func(c *cli.Context) error { + cliSrc = NewSource( + Context(c), + ) + return nil + }), + ) + + config.Load(cliSrc) + if fval := config.Get("flag").String("default"); fval != expVal { + t.Fatalf("default flag value not loaded %v != %v", fval, expVal) + } +} + func test(t *testing.T, withContext bool) { var src source.Source @@ -17,7 +59,11 @@ func test(t *testing.T, withContext bool) { app := cmd.App() app.Name = "testapp" app.Flags = []cli.Flag{ - &cli.StringFlag{Name: "db-host"}, + &cli.StringFlag{ + Name: "db-host", + EnvVars: []string{"db-host"}, + Value: "myval", + }, } // with context From 67acd9288b490edc5aca3b3622ad13f3cc1c2ad7 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 8 Feb 2020 02:45:32 +0300 Subject: [PATCH 271/788] config/source/cli: fix tests (#1179) * config/source/cli: fix tests * skip mdns test in travis Signed-off-by: Vasiliy Tolstov --- config/source/cli/cli_test.go | 5 ++++- registry/mdns_test.go | 5 +++++ registry/watcher_test.go | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config/source/cli/cli_test.go b/config/source/cli/cli_test.go index 1a752a2e..70b1d4dd 100644 --- a/config/source/cli/cli_test.go +++ b/config/source/cli/cli_test.go @@ -17,7 +17,7 @@ func TestCliSourceDefault(t *testing.T) { service := micro.NewService( micro.Flags( - // to be able to run insude go test + // to be able to run inside go test &cli.StringFlag{ Name: "test.timeout", }, @@ -27,6 +27,9 @@ func TestCliSourceDefault(t *testing.T) { &cli.StringFlag{ Name: "test.run", }, + &cli.StringFlag{ + Name: "test.testlogfile", + }, &cli.StringFlag{ Name: "flag", Usage: "It changes something", diff --git a/registry/mdns_test.go b/registry/mdns_test.go index 9656d2dc..a5630c67 100644 --- a/registry/mdns_test.go +++ b/registry/mdns_test.go @@ -7,6 +7,11 @@ import ( ) func TestMDNS(t *testing.T) { + // skip test in travis because of sendto: operation not permitted error + if travis := os.Getenv("TRAVIS"); travis == "true" { + t.Skip() + } + testData := []*Service{ { Name: "test1", diff --git a/registry/watcher_test.go b/registry/watcher_test.go index 717dbde3..bd837c58 100644 --- a/registry/watcher_test.go +++ b/registry/watcher_test.go @@ -7,6 +7,10 @@ import ( ) func TestWatcher(t *testing.T) { + if travis := os.Getenv("TRAVIS"); travis == "true" { + t.Skip() + } + testData := []*Service{ { Name: "test1", From ca1d0b94c367783698d5cadcd6b76db62893f8d5 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Sat, 8 Feb 2020 03:19:10 -0800 Subject: [PATCH 272/788] config/cmd: remove 8 unused variables (#1175) --- config/cmd/cmd.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index f2b8b4a0..962b6761 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -311,16 +311,6 @@ var ( "service": sAuth.NewAuth, "jwt": jwtAuth.NewAuth, } - - // used for default selection as the fall back - defaultClient = "grpc" - defaultServer = "grpc" - defaultBroker = "eats" - defaultRegistry = "mdns" - defaultSelector = "registry" - defaultTransport = "http" - defaultRuntime = "local" - defaultStore = "memory" ) func init() { From c706afcf04793f3f1e58934314d86b8cb396d51d Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 10 Feb 2020 00:26:46 +0300 Subject: [PATCH 273/788] logger helper to pass down it via context (#1180) Signed-off-by: Vasiliy Tolstov --- logger/context.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 logger/context.go diff --git a/logger/context.go b/logger/context.go new file mode 100644 index 00000000..6940122d --- /dev/null +++ b/logger/context.go @@ -0,0 +1,14 @@ +package logger + +import "context" + +type loggerKey struct{} + +func FromContext(ctx context.Context) (Logger, bool) { + l, ok := ctx.Value(loggerKey{}).(Logger) + return l, ok +} + +func NewContext(ctx context.Context, l Logger) context.Context { + return context.WithValue(ctx, loggerKey{}, l) +} From 4401c12e6c9c7e95470e0f26d840c1b639f36d62 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 10 Feb 2020 08:26:28 +0000 Subject: [PATCH 274/788] Auth Wrapper (#1174) * Auth Wrapper * Tweak cmd flag * auth_excludes => auth_exclude * Make Auth.Excludes variadic * Use metadata.Get (passes through http and http2 it will go through various case formats) * fix auth wrapper auth.Auth interface initialisation Co-authored-by: Asim Aslam --- auth/auth.go | 2 ++ auth/default.go | 5 +++++ auth/jwt/jwt.go | 4 ++++ auth/options.go | 8 +++++++ auth/service/service.go | 4 ++++ config/cmd/cmd.go | 42 +++++++++++++++++++++++------------- options.go | 3 +++ service.go | 14 +++++++++--- util/wrapper/wrapper.go | 47 +++++++++++++++++++++++++++++++++++++++++ 9 files changed, 111 insertions(+), 18 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 69f22c91..0aabfec8 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -11,6 +11,8 @@ type Auth interface { String() string // Init the auth package Init(opts ...Option) error + // Options returns the options set + Options() Options // Generate a new auth Account Generate(id string, opts ...GenerateOption) (*Account, error) // Revoke an authorization Account diff --git a/auth/default.go b/auth/default.go index f463a003..8213fc05 100644 --- a/auth/default.go +++ b/auth/default.go @@ -18,6 +18,11 @@ func (a *noop) Init(...Option) error { return nil } +// Options set in init +func (a *noop) Options() Options { + return a.options +} + // Generate a new auth Account func (a *noop) Generate(id string, ops ...GenerateOption) (*Account, error) { return nil, nil diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go index 47498001..540bec43 100644 --- a/auth/jwt/jwt.go +++ b/auth/jwt/jwt.go @@ -33,6 +33,10 @@ func (s *svc) String() string { return "jwt" } +func (s *svc) Options() auth.Options { + return s.options +} + func (s *svc) Init(opts ...auth.Option) error { for _, o := range opts { o(&s.options) diff --git a/auth/options.go b/auth/options.go index 3488c03c..586f7b5f 100644 --- a/auth/options.go +++ b/auth/options.go @@ -7,10 +7,18 @@ import ( type Options struct { PublicKey []byte PrivateKey []byte + Excludes []string } type Option func(o *Options) +// Excludes endpoints from auth +func Excludes(excludes ...string) Option { + return func(o *Options) { + o.Excludes = excludes + } +} + // PublicKey is the JWT public key func PublicKey(key string) Option { return func(o *Options) { diff --git a/auth/service/service.go b/auth/service/service.go index fdac98ca..91949c51 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -37,6 +37,10 @@ func (s *svc) Init(opts ...auth.Option) error { return nil } +func (s *svc) Options() auth.Options { + return s.options +} + // Generate a new auth account func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { // construct the request diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 962b6761..437d5f71 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -254,6 +254,11 @@ var ( EnvVars: []string{"MICRO_AUTH_PRIVATE_KEY"}, Usage: "Private key for JWT auth (base64 encoded PEM)", }, + &cli.StringSliceFlag{ + Name: "auth_exclude", + EnvVars: []string{"MICRO_AUTH_EXCLUDE"}, + Usage: "Comma-separated list of endpoints excluded from authentication", + }, } DefaultBrokers = map[string]func(...broker.Option) broker.Broker{ @@ -319,6 +324,7 @@ func init() { func newCmd(opts ...Option) Cmd { options := Options{ + Auth: &auth.DefaultAuth, Broker: &broker.DefaultBroker, Client: &client.DefaultClient, Registry: ®istry.DefaultRegistry, @@ -328,7 +334,6 @@ func newCmd(opts ...Option) Cmd { Runtime: &runtime.DefaultRuntime, Store: &store.DefaultStore, Tracer: &trace.DefaultTracer, - Auth: &auth.DefaultAuth, Brokers: DefaultBrokers, Clients: DefaultClients, @@ -379,6 +384,7 @@ func (c *cmd) Options() Options { func (c *cmd) Before(ctx *cli.Context) error { // If flags are set then use them otherwise do nothing + var authOpts []auth.Option var serverOpts []server.Option var clientOpts []client.Option @@ -414,12 +420,12 @@ func (c *cmd) Before(ctx *cli.Context) error { // Set the auth if name := ctx.String("auth"); len(name) > 0 { - r, ok := c.opts.Auths[name] + a, ok := c.opts.Auths[name] if !ok { return fmt.Errorf("Unsupported auth: %s", name) } - *c.opts.Auth = r() + *c.opts.Auth = a() } // Set the client @@ -571,24 +577,30 @@ func (c *cmd) Before(ctx *cli.Context) error { serverOpts = append(serverOpts, server.RegisterInterval(val*time.Second)) } - if len(ctx.String("auth_public_key")) > 0 { - if err := (*c.opts.Auth).Init(auth.PublicKey(ctx.String("auth_public_key"))); err != nil { - log.Fatalf("Error configuring auth: %v", err) - } - } - - if len(ctx.String("auth_private_key")) > 0 { - if err := (*c.opts.Auth).Init(auth.PrivateKey(ctx.String("auth_private_key"))); err != nil { - log.Fatalf("Error configuring auth: %v", err) - } - } - if len(ctx.String("runtime_source")) > 0 { if err := (*c.opts.Runtime).Init(runtime.WithSource(ctx.String("runtime_source"))); err != nil { log.Fatalf("Error configuring runtime: %v", err) } } + if len(ctx.String("auth_public_key")) > 0 { + authOpts = append(authOpts, auth.PublicKey(ctx.String("auth_public_key"))) + } + + if len(ctx.String("auth_private_key")) > 0 { + authOpts = append(authOpts, auth.PrivateKey(ctx.String("auth_private_key"))) + } + + if len(ctx.StringSlice("auth_exclude")) > 0 { + authOpts = append(authOpts, auth.Excludes(ctx.StringSlice("auth_exclude")...)) + } + + if len(authOpts) > 0 { + if err := (*c.opts.Auth).Init(authOpts...); err != nil { + log.Fatalf("Error configuring auth: %v", err) + } + } + // client opts if r := ctx.Int("client_retries"); r >= 0 { clientOpts = append(clientOpts, client.Retries(r)) diff --git a/options.go b/options.go index 380d9511..a2c32e3d 100644 --- a/options.go +++ b/options.go @@ -18,6 +18,7 @@ import ( // Options for micro service type Options struct { + Auth auth.Auth Broker broker.Broker Cmd cmd.Cmd Client client.Client @@ -40,6 +41,7 @@ type Options struct { func newOptions(opts ...Option) Options { opt := Options{ + Auth: auth.DefaultAuth, Broker: broker.DefaultBroker, Cmd: cmd.DefaultCmd, Client: client.DefaultClient, @@ -127,6 +129,7 @@ func Tracer(t trace.Tracer) Option { // Auth sets the auth for the service func Auth(a auth.Auth) Option { return func(o *Options) { + o.Auth = a o.Server.Init(server.Auth(a)) } } diff --git a/service.go b/service.go index f67edd72..678925d9 100644 --- a/service.go +++ b/service.go @@ -8,6 +8,7 @@ import ( "sync" "syscall" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/config/cmd" "github.com/micro/go-micro/v2/debug/profile" @@ -29,11 +30,15 @@ type service struct { } func newService(opts ...Option) Service { + service := new(service) options := newOptions(opts...) // service name serviceName := options.Server.Options().Name + // TODO: better accessors + authFn := func() auth.Auth { return service.opts.Auth } + // wrap client to inject From-Service header on any calls options.Client = wrapper.FromService(serviceName, options.Client) options.Client = wrapper.TraceCall(serviceName, trace.DefaultTracer, options.Client) @@ -42,11 +47,13 @@ func newService(opts ...Option) Service { options.Server.Init( server.WrapHandler(wrapper.HandlerStats(stats.DefaultStats)), server.WrapHandler(wrapper.TraceHandler(trace.DefaultTracer)), + server.WrapHandler(wrapper.AuthHandler(authFn)), ) - return &service{ - opts: options, - } + // set opts + service.opts = options + + return service } func (s *service) Name() string { @@ -88,6 +95,7 @@ func (s *service) Init(opts ...Option) { // Initialise the command flags, overriding new service if err := s.opts.Cmd.Init( + cmd.Auth(&s.opts.Auth), cmd.Broker(&s.opts.Broker), cmd.Registry(&s.opts.Registry), cmd.Transport(&s.opts.Transport), diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 3004abd4..87af8f13 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -4,9 +4,11 @@ import ( "context" "strings" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/debug/stats" "github.com/micro/go-micro/v2/debug/trace" + "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/server" ) @@ -25,6 +27,7 @@ type traceWrapper struct { var ( HeaderPrefix = "Micro-" + BearerSchema = "Bearer " ) func (c *clientWrapper) setHeaders(ctx context.Context) context.Context { @@ -132,3 +135,47 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper { } } } + +// AuthHandler wraps a server handler to perform auth +func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { + return func(h server.HandlerFunc) server.HandlerFunc { + return func(ctx context.Context, req server.Request, rsp interface{}) error { + // get the auth.Auth interface + a := fn() + + // Extract endpoint and remove service name prefix + // (e.g. Platform.ListServices => ListServices) + var endpoint string + if ec := strings.Split(req.Endpoint(), "."); len(ec) == 2 { + endpoint = ec[1] + } + + // Check for endpoints excluded from auth. If the endpoint + // matches, execute the handler and return + for _, e := range a.Options().Excludes { + if e == endpoint { + return h(ctx, req, rsp) + } + } + + // Extract the token if present. Note: if noop is being used + // then the token can be blank without erroring + var token string + if header, ok := metadata.Get(ctx, "Authorization"); ok { + // Ensure the correct scheme is being used + if !strings.HasPrefix(header, BearerSchema) { + return errors.Unauthorized("go.micro.auth", "invalid authorization header. expected Bearer schema") + } + + token = header[len(BearerSchema):] + } + + // Validate the token + if _, err := a.Validate(token); err != nil { + return err + } + + return h(ctx, req, rsp) + } + } +} From 8ea84ac3ebcaeeb8ea0aacd8465d729729fddbc5 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 10 Feb 2020 15:38:41 +0000 Subject: [PATCH 275/788] Fix router panic for nil watcher --- router/default.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/router/default.go b/router/default.go index 7056f1a0..2187609a 100644 --- a/router/default.go +++ b/router/default.go @@ -530,7 +530,9 @@ func (r *router) Start() error { for { select { case <-r.exit: - w.Stop() + if w != nil { + w.Stop() + } return default: if w == nil { @@ -547,8 +549,10 @@ func (r *router) Start() error { time.Sleep(time.Second) } - w.Stop() - w = nil + if w != nil { + w.Stop() + w = nil + } } } }() From 4a0318348137436216f5b06ec833eb2da4a89755 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 11 Feb 2020 11:22:22 +0000 Subject: [PATCH 276/788] Return a 401 error on invalid auth tokens (#1184) --- util/wrapper/wrapper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 87af8f13..28510443 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -172,7 +172,7 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { // Validate the token if _, err := a.Validate(token); err != nil { - return err + return errors.Unauthorized("go.micro.auth", err.Error()) } return h(ctx, req, rsp) From d1d6eada981024b1d2d7641987dfa443cb50d9fc Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 11 Feb 2020 11:27:16 +0000 Subject: [PATCH 277/788] parse url encoded form in rpc handler (#1183) * parse url encoded form in rpc handler * Remove comment --- api/handler/rpc/rpc.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 76e60dc2..daf601a1 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -202,8 +202,9 @@ func hasCodec(ct string, codecs []string) bool { func requestPayload(r *http.Request) ([]byte, error) { // we have to decode json-rpc and proto-rpc because we suck // well actually because there's no proxy codec right now - switch r.Header.Get("Content-Type") { - case "application/json-rpc": + ct := r.Header.Get("Content-Type") + switch { + case strings.Contains(ct, "application/json-rpc"): msg := codec.Message{ Type: codec.Request, Header: make(map[string]string), @@ -217,7 +218,7 @@ func requestPayload(r *http.Request) ([]byte, error) { return nil, err } return ([]byte)(raw), nil - case "application/proto-rpc", "application/octet-stream": + case strings.Contains(ct, "application/proto-rpc"), strings.Contains(ct, "application/octet-stream"): msg := codec.Message{ Type: codec.Request, Header: make(map[string]string), @@ -232,6 +233,19 @@ func requestPayload(r *http.Request) ([]byte, error) { } b, _ := raw.Marshal() return b, nil + case strings.Contains(ct, "application/www-x-form-urlencoded"): + r.ParseForm() + + // generate a new set of values from the form + vals := make(map[string]string) + for k, v := range r.Form { + vals[k] = strings.Join(v, ",") + } + + // marshal + b, _ := json.Marshal(vals) + return b, nil + // TODO: application/grpc } // otherwise as per usual From 2764de9a1a1f9703d8058385d984bc1e16b48cfe Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 11 Feb 2020 18:46:50 +0300 Subject: [PATCH 278/788] broker/eats: broker disconnect fix (#1186) Signed-off-by: Vasiliy Tolstov --- broker/default.go | 10 +++++++++- broker/nats/nats.go | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/broker/default.go b/broker/default.go index dd4a95ab..9228daad 100644 --- a/broker/default.go +++ b/broker/default.go @@ -295,6 +295,10 @@ func (n *natsBroker) Connect() error { return nil default: // DISCONNECTED or CLOSED or DRAINING opts := n.nopts + opts.DrainTimeout = 1 * time.Second + opts.AsyncErrorCB = n.onAsyncError + opts.DisconnectedErrCB = n.onDisconnectedError + opts.ClosedCB = n.onClose opts.Servers = n.servers opts.Secure = n.opts.Secure opts.TLSConfig = n.opts.TLSConfig @@ -324,7 +328,7 @@ func (n *natsBroker) Disconnect() error { // drain the connection if specified if n.drain { n.conn.Drain() - return <-n.closeCh + n.closeCh <- nil } // close the client connection @@ -434,6 +438,10 @@ func (n *natsBroker) onClose(conn *nats.Conn) { n.closeCh <- nil } +func (n *natsBroker) onDisconnectedError(conn *nats.Conn, err error) { + n.closeCh <- nil +} + func (n *natsBroker) onAsyncError(conn *nats.Conn, sub *nats.Subscription, err error) { // There are kinds of different async error nats might callback, but we are interested // in ErrDrainTimeout only here. diff --git a/broker/nats/nats.go b/broker/nats/nats.go index f4e00fce..680657d9 100644 --- a/broker/nats/nats.go +++ b/broker/nats/nats.go @@ -318,7 +318,7 @@ func (n *natsBroker) Disconnect() error { // drain the connection if specified if n.drain { n.conn.Drain() - return <-n.closeCh + n.closeCh <- nil } // close the client connection @@ -440,6 +440,7 @@ func (n *natsBroker) setOption(opts ...broker.Option) { n.closeCh = make(chan error) n.nopts.ClosedCB = n.onClose n.nopts.AsyncErrorCB = n.onAsyncError + n.nopts.DisconnectedErrCB = n.onDisconnectedError } } @@ -455,6 +456,10 @@ func (n *natsBroker) onAsyncError(conn *nats.Conn, sub *nats.Subscription, err e } } +func (n *natsBroker) onDisconnectedError(conn *nats.Conn, err error) { + n.closeCh <- nil +} + func NewBroker(opts ...broker.Option) broker.Broker { options := broker.Options{ // Default codec From 79ad1e6fe3998e65b26e8afbb0e35ae3fdb74b76 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 11 Feb 2020 21:41:23 +0300 Subject: [PATCH 279/788] various fixes for broker and messaging in server (#1187) * provide broker disconnect messages in server Signed-off-by: Vasiliy Tolstov * broker/eats: another fix Signed-off-by: Vasiliy Tolstov --- broker/default.go | 24 ++++++++++++++++-------- broker/nats/nats.go | 2 +- server/grpc/grpc.go | 6 ++---- server/rpc_server.go | 1 + 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/broker/default.go b/broker/default.go index 9228daad..a71a5d17 100644 --- a/broker/default.go +++ b/broker/default.go @@ -240,6 +240,10 @@ func (n *natsBroker) serve(exit chan bool) error { // register the cluster address for { select { + case err := <-n.closeCh: + if err != nil { + log.Log(err) + } case <-exit: // deregister on exit n.opts.Registry.Deregister(®istry.Service{ @@ -282,7 +286,6 @@ func (n *natsBroker) Connect() error { } // set to connected - n.connected = true } status := nats.CLOSED @@ -313,6 +316,9 @@ func (n *natsBroker) Connect() error { return err } n.conn = c + + n.connected = true + return nil } } @@ -328,7 +334,6 @@ func (n *natsBroker) Disconnect() error { // drain the connection if specified if n.drain { n.conn.Drain() - n.closeCh <- nil } // close the client connection @@ -336,10 +341,12 @@ func (n *natsBroker) Disconnect() error { // shutdown the local server // and deregister - select { - case <-n.exit: - default: - close(n.exit) + if n.server != nil { + select { + case <-n.exit: + default: + close(n.exit) + } } // set not connected @@ -439,7 +446,7 @@ func (n *natsBroker) onClose(conn *nats.Conn) { } func (n *natsBroker) onDisconnectedError(conn *nats.Conn, err error) { - n.closeCh <- nil + n.closeCh <- err } func (n *natsBroker) onAsyncError(conn *nats.Conn, sub *nats.Subscription, err error) { @@ -459,7 +466,8 @@ func NewBroker(opts ...Option) Broker { } n := &natsBroker{ - opts: options, + opts: options, + closeCh: make(chan error), } n.setOption(opts...) diff --git a/broker/nats/nats.go b/broker/nats/nats.go index 680657d9..2cce84e4 100644 --- a/broker/nats/nats.go +++ b/broker/nats/nats.go @@ -457,7 +457,7 @@ func (n *natsBroker) onAsyncError(conn *nats.Conn, sub *nats.Subscription, err e } func (n *natsBroker) onDisconnectedError(conn *nats.Conn, err error) { - n.closeCh <- nil + n.closeCh <- err } func NewBroker(opts ...broker.Option) broker.Broker { diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index dd2daeff..5aed508e 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -805,10 +805,7 @@ func (g *grpcServer) Start() error { return err } - baddr := config.Broker.Address() - bname := config.Broker.String() - - log.Logf("Broker [%s] Connected to %s", bname, baddr) + log.Logf("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address()) } // announce self to the world @@ -876,6 +873,7 @@ func (g *grpcServer) Start() error { // close transport ch <- nil + log.Logf("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address()) // disconnect broker config.Broker.Disconnect() }() diff --git a/server/rpc_server.go b/server/rpc_server.go index 7eba3806..6c0c793d 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -879,6 +879,7 @@ func (s *rpcServer) Start() error { // close transport listener ch <- ts.Close() + log.Logf("Broker [%s] Disconnected from %s", bname, config.Broker.Address()) // disconnect the broker config.Broker.Disconnect() From d76baf59de2e09eb1b3370116f8049a90ed74692 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Wed, 12 Feb 2020 11:57:17 +0100 Subject: [PATCH 280/788] Trace type is now being recorded (#1188) --- debug/service/handler/debug.go | 24 ++++--- debug/service/proto/debug.pb.go | 109 +++++++++++++++++++++----------- debug/service/proto/debug.proto | 18 ++++-- debug/trace/trace.go | 15 ++++- util/wrapper/wrapper.go | 2 + 5 files changed, 117 insertions(+), 51 deletions(-) diff --git a/debug/service/handler/debug.go b/debug/service/handler/debug.go index 967a3218..ffe1a922 100644 --- a/debug/service/handler/debug.go +++ b/debug/service/handler/debug.go @@ -66,15 +66,23 @@ func (d *Debug) Trace(ctx context.Context, req *proto.TraceRequest, rsp *proto.T return err } - for _, trace := range traces { + for _, t := range traces { + var typ proto.SpanType + switch t.Type { + case trace.SpanTypeRequestInbound: + typ = proto.SpanType_INBOUND + case trace.SpanTypeRequestOutbound: + typ = proto.SpanType_OUTBOUND + } rsp.Spans = append(rsp.Spans, &proto.Span{ - Trace: trace.Trace, - Id: trace.Id, - Parent: trace.Parent, - Name: trace.Name, - Started: uint64(trace.Started.UnixNano()), - Duration: uint64(trace.Duration.Nanoseconds()), - Metadata: trace.Metadata, + Trace: t.Trace, + Id: t.Id, + Parent: t.Parent, + Name: t.Name, + Started: uint64(t.Started.UnixNano()), + Duration: uint64(t.Duration.Nanoseconds()), + Type: typ, + Metadata: t.Metadata, }) } diff --git a/debug/service/proto/debug.pb.go b/debug/service/proto/debug.pb.go index a2378b30..83e43aaa 100644 --- a/debug/service/proto/debug.pb.go +++ b/debug/service/proto/debug.pb.go @@ -20,6 +20,31 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +type SpanType int32 + +const ( + SpanType_INBOUND SpanType = 0 + SpanType_OUTBOUND SpanType = 1 +) + +var SpanType_name = map[int32]string{ + 0: "INBOUND", + 1: "OUTBOUND", +} + +var SpanType_value = map[string]int32{ + "INBOUND": 0, + "OUTBOUND": 1, +} + +func (x SpanType) String() string { + return proto.EnumName(SpanType_name, int32(x)) +} + +func (SpanType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_dea322649cde1ef2, []int{0} +} + type HealthRequest struct { // optional service name Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` @@ -466,6 +491,7 @@ type Span struct { Duration uint64 `protobuf:"varint,6,opt,name=duration,proto3" json:"duration,omitempty"` // associated metadata Metadata map[string]string `protobuf:"bytes,7,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Type SpanType `protobuf:"varint,8,opt,name=type,proto3,enum=SpanType" json:"type,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -545,7 +571,15 @@ func (m *Span) GetMetadata() map[string]string { return nil } +func (m *Span) GetType() SpanType { + if m != nil { + return m.Type + } + return SpanType_INBOUND +} + func init() { + proto.RegisterEnum("SpanType", SpanType_name, SpanType_value) proto.RegisterType((*HealthRequest)(nil), "HealthRequest") proto.RegisterType((*HealthResponse)(nil), "HealthResponse") proto.RegisterType((*StatsRequest)(nil), "StatsRequest") @@ -564,40 +598,43 @@ func init() { } var fileDescriptor_dea322649cde1ef2 = []byte{ - // 553 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcd, 0x6e, 0xd4, 0x30, - 0x10, 0xde, 0x24, 0x9b, 0xdd, 0xcd, 0xb4, 0x09, 0xc8, 0xfc, 0x28, 0x0a, 0x08, 0x2a, 0x9f, 0x16, - 0x01, 0x5e, 0x28, 0x17, 0x04, 0x57, 0x90, 0x38, 0x94, 0x8b, 0xcb, 0x0b, 0xb8, 0x89, 0x95, 0x06, - 0x9a, 0x38, 0xd8, 0x4e, 0xa5, 0x7d, 0x24, 0x6e, 0xbc, 0x0c, 0x6f, 0xc3, 0x01, 0xf9, 0x27, 0xdb, - 0x44, 0x08, 0xf5, 0xc0, 0xcd, 0xdf, 0xe7, 0xf1, 0x97, 0x99, 0x6f, 0x66, 0x02, 0xa4, 0x6d, 0x4a, - 0x29, 0x76, 0xb5, 0x78, 0xe9, 0x0e, 0x15, 0xbf, 0x18, 0xea, 0x9d, 0xe2, 0xf2, 0xba, 0x29, 0xf9, - 0xae, 0x97, 0x42, 0x7b, 0x8e, 0xd8, 0x33, 0x7e, 0x06, 0xe9, 0x27, 0xce, 0xae, 0xf4, 0x25, 0xe5, - 0xdf, 0x07, 0xae, 0x34, 0xca, 0x61, 0xed, 0xa3, 0xf3, 0xe0, 0x24, 0xd8, 0x26, 0x74, 0x84, 0x78, - 0x0b, 0xd9, 0x18, 0xaa, 0x7a, 0xd1, 0x29, 0x8e, 0x1e, 0xc2, 0x4a, 0x69, 0xa6, 0x07, 0xe5, 0x43, - 0x3d, 0xc2, 0x5b, 0x38, 0x3e, 0xd7, 0x4c, 0xab, 0xdb, 0x35, 0x7f, 0x05, 0x90, 0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0x5d, 0x28, 0x25, 0xd3, 0xb6, 0x16, - 0x19, 0x99, 0x75, 0x11, 0x2f, 0x2e, 0x56, 0xf6, 0xaf, 0xf3, 0xe6, 0x4f, 0x00, 0x00, 0x00, 0xff, - 0xff, 0xc7, 0x3f, 0xbe, 0xe3, 0xa7, 0x04, 0x00, 0x00, + // 595 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xa4, 0x54, 0x5b, 0x6e, 0xd3, 0x40, + 0x14, 0x8d, 0x63, 0x3b, 0x71, 0x6e, 0x1e, 0x54, 0xc3, 0x43, 0x56, 0x78, 0xca, 0x12, 0x52, 0x78, + 0x39, 0x10, 0x7e, 0x10, 0xfc, 0xa1, 0x22, 0x81, 0x04, 0xad, 0x34, 0x4d, 0x17, 0x30, 0xb5, 0x47, + 0xa9, 0xa1, 0xf6, 0x98, 0x99, 0x71, 0xa5, 0xac, 0x85, 0x15, 0xf0, 0xc7, 0x66, 0xd8, 0x0f, 0xf3, + 0x72, 0x1a, 0x0b, 0xa1, 0x7e, 0xf0, 0x77, 0xcf, 0xf5, 0x99, 0x33, 0xf7, 0x9e, 0x9c, 0x0c, 0xa4, + 0x65, 0x91, 0x71, 0xb6, 0xdc, 0xb0, 0x17, 0xb6, 0xc8, 0xe9, 0x59, 0xb3, 0x59, 0x0a, 0xca, 0x2f, + 0x8b, 0x8c, 0x2e, 0x6b, 0xce, 0xa4, 0xeb, 0xa5, 0xa6, 0x4e, 0x9e, 0xc0, 0xf4, 0x23, 0x25, 0x17, + 0xf2, 0x1c, 0xd3, 0xef, 0x0d, 0x15, 0x12, 0xc5, 0x30, 0x74, 0xec, 0xd8, 0x7b, 0xe4, 0x2d, 0x46, + 0xb8, 0x85, 0xc9, 0x02, 0x66, 0x2d, 0x55, 0xd4, 0xac, 0x12, 0x14, 0xdd, 0x81, 0x81, 0x90, 0x44, + 0x36, 0xc2, 0x51, 0x1d, 0x52,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 0x30, 0xa0, 0x87, 0xe0, 0xab, 0xec, 0xa2, 0x71, 0x7a, 0x95, 0xe0, 0xf9, 0xd0, 0x05, 0x25, 0xe9, + 0xbd, 0xf4, 0xd0, 0x33, 0x18, 0xd8, 0x87, 0x00, 0xcd, 0xd2, 0xce, 0xe3, 0x31, 0xbf, 0x91, 0x76, + 0x5f, 0x88, 0xa4, 0x87, 0x16, 0x10, 0x9a, 0x3f, 0x38, 0x9a, 0xa6, 0xfb, 0x6f, 0xc2, 0x7c, 0x96, + 0x76, 0xfe, 0xf7, 0x96, 0x69, 0x7e, 0x74, 0xc5, 0xdc, 0x0f, 0x87, 0x62, 0x76, 0xb2, 0x90, 0xf4, + 0xce, 0x06, 0xe6, 0xed, 0x7a, 0xfd, 0x27, 0x00, 0x00, 0xff, 0xff, 0xbc, 0xab, 0x72, 0x03, 0xed, + 0x04, 0x00, 0x00, } diff --git a/debug/service/proto/debug.proto b/debug/service/proto/debug.proto index 81eb44b8..7516651e 100644 --- a/debug/service/proto/debug.proto +++ b/debug/service/proto/debug.proto @@ -57,12 +57,12 @@ message LogRequest { // Record is service log record message Record { - // timestamp of log record - int64 timestamp = 1; - // record metadata - map metadata = 2; - // message - string message = 3; + // timestamp of log record + int64 timestamp = 1; + // record metadata + map metadata = 2; + // message + string message = 3; } message TraceRequest { @@ -75,6 +75,11 @@ message TraceResponse { } +enum SpanType { + INBOUND = 0; + OUTBOUND = 1; +} + message Span { // the trace id string trace = 1; @@ -90,4 +95,5 @@ message Span { uint64 duration = 6; // associated metadata map metadata = 7; + SpanType type = 8; } diff --git a/debug/trace/trace.go b/debug/trace/trace.go index efb8c432..12a6ccbf 100644 --- a/debug/trace/trace.go +++ b/debug/trace/trace.go @@ -3,8 +3,9 @@ package trace import ( "context" - "github.com/micro/go-micro/v2/metadata" "time" + + "github.com/micro/go-micro/v2/metadata" ) // Tracer is an interface for distributed tracing @@ -17,6 +18,16 @@ type Tracer interface { Read(...ReadOption) ([]*Span, error) } +// SpanType describe the nature of the trace span +type SpanType int + +const ( + // SpanTypeRequestInbound is a span created when serving a request + SpanTypeRequestInbound SpanType = iota + // SpanTypeRequestOutbound is a span created when making a service call + SpanTypeRequestOutbound +) + // Span is used to record an entry type Span struct { // Id of the trace @@ -33,6 +44,8 @@ type Span struct { Duration time.Duration // associated data Metadata map[string]string + // Type + Type SpanType } const ( diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 28510443..9f211a92 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -63,6 +63,7 @@ func (c *clientWrapper) Publish(ctx context.Context, p client.Message, opts ...c func (c *traceWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { newCtx, s := c.trace.Start(ctx, req.Service()+"."+req.Endpoint()) + s.Type = trace.SpanTypeRequestOutbound err := c.Client.Call(newCtx, req, rsp, opts...) if err != nil { s.Metadata["error"] = err.Error() @@ -122,6 +123,7 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper { // get the span newCtx, s := t.Start(ctx, req.Service()+"."+req.Endpoint()) + s.Type = trace.SpanTypeRequestInbound err := h(newCtx, req, rsp) if err != nil { From 6dc942bc197038fd809e259ab2d8f1c0397d9823 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 13 Feb 2020 14:57:21 +0300 Subject: [PATCH 281/788] client/grpc: fix panic on invalid message (#1191) * client/grpc: fix panic on invalid message * travis: disable lint and race for now Signed-off-by: Vasiliy Tolstov --- .travis.yml | 4 ++-- client/grpc/codec.go | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index d26a9c52..8f880e90 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,8 @@ env: before_script: - go install github.com/golangci/golangci-lint/cmd/golangci-lint script: - - golangci-lint run || true - - go test -v -race ./... || true + # - golangci-lint run || true + # - go test -v -race ./... || true - go test -v ./... notifications: slack: diff --git a/client/grpc/codec.go b/client/grpc/codec.go index 4b224a71..ff377690 100644 --- a/client/grpc/codec.go +++ b/client/grpc/codec.go @@ -69,15 +69,21 @@ func (w wrapCodec) Unmarshal(data []byte, v interface{}) error { } func (protoCodec) Marshal(v interface{}) ([]byte, error) { - b, ok := v.(*bytes.Frame) - if ok { - return b.Data, nil + switch m := v.(type) { + case *bytes.Frame: + return m.Data, nil + case proto.Message: + return proto.Marshal(m) } - return proto.Marshal(v.(proto.Message)) + return nil, fmt.Errorf("failed to marshal: %v is not type of *bytes.Frame or proto.Message", v) } func (protoCodec) Unmarshal(data []byte, v interface{}) error { - return proto.Unmarshal(data, v.(proto.Message)) + m, ok := v.(proto.Message) + if !ok { + return fmt.Errorf("failed to unmarshal: %v is not type of proto.Message", v) + } + return proto.Unmarshal(data, m) } func (protoCodec) Name() string { From ea70711dd34c239f79ed1c4630ad047c69ff4fc2 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 13 Feb 2020 12:02:29 +0000 Subject: [PATCH 282/788] Exclude Stats & Trace from Auth (#1192) --- util/wrapper/wrapper.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 9f211a92..01767b04 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -154,7 +154,8 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { // Check for endpoints excluded from auth. If the endpoint // matches, execute the handler and return - for _, e := range a.Options().Excludes { + excludes := append(a.Options().Excludes, "Stats", "Trace") + for _, e := range excludes { if e == endpoint { return h(ctx, req, rsp) } From e080ecb43a8f48749ddd0a89957ee2aa55553792 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 13 Feb 2020 14:07:14 +0000 Subject: [PATCH 283/788] Auth Improvements (#1195) * Exclude Stats & Trace from Auth * Update Excluded Endpoints Format * Tweak Implementation --- config/cmd/cmd.go | 2 +- util/wrapper/wrapper.go | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 437d5f71..8aea177b 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -257,7 +257,7 @@ var ( &cli.StringSliceFlag{ Name: "auth_exclude", EnvVars: []string{"MICRO_AUTH_EXCLUDE"}, - Usage: "Comma-separated list of endpoints excluded from authentication", + Usage: "Comma-separated list of endpoints excluded from authentication, e.g. Users.ListUsers", }, } diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 01767b04..b9c4275f 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -145,18 +145,14 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { // get the auth.Auth interface a := fn() - // Extract endpoint and remove service name prefix - // (e.g. Platform.ListServices => ListServices) - var endpoint string - if ec := strings.Split(req.Endpoint(), "."); len(ec) == 2 { - endpoint = ec[1] + // Check for debug endpoints which should be excluded from auth + if strings.HasPrefix(req.Endpoint(), "Debug.") { + return h(ctx, req, rsp) } - // Check for endpoints excluded from auth. If the endpoint - // matches, execute the handler and return - excludes := append(a.Options().Excludes, "Stats", "Trace") - for _, e := range excludes { - if e == endpoint { + // Exclude any user excluded endpoints + for _, e := range a.Options().Excludes { + if e == req.Endpoint() { return h(ctx, req, rsp) } } From d9b3b1758235fb0ed58743880f7ba1162a4fd126 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 13 Feb 2020 18:51:32 +0000 Subject: [PATCH 284/788] set dial timeout in stream --- client/grpc/grpc.go | 1 + 1 file changed, 1 insertion(+) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 542c9173..e3ada840 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -189,6 +189,7 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client grpcDialOptions := []grpc.DialOption{ grpc.WithDefaultCallOptions(grpc.ForceCodec(wc)), + grpc.WithTimeout(opts.DialTimeout), g.secure(), } From 203486fd31dad93b67f68d425a3959a6544556b0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 13 Feb 2020 22:34:56 +0000 Subject: [PATCH 285/788] check for etcd watcher canceled value --- registry/etcd/watcher.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/registry/etcd/watcher.go b/registry/etcd/watcher.go index fdf2ea58..b8ce443d 100644 --- a/registry/etcd/watcher.go +++ b/registry/etcd/watcher.go @@ -48,6 +48,9 @@ func (ew *etcdWatcher) Next() (*registry.Result, error) { if wresp.Err() != nil { return nil, wresp.Err() } + if wresp.Canceled { + return nil, errors.New("could not get next") + } for _, ev := range wresp.Events { service := decode(ev.Kv.Value) var action string From cbe8b7dd09fe309a914a406b7020230a1d063ca3 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 14 Feb 2020 15:32:02 +0800 Subject: [PATCH 286/788] Removed redundant spaces (#1196) --- auth/auth.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 0aabfec8..92010501 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -38,9 +38,9 @@ type Role struct { // Account provided by an auth provider type Account struct { // ID of the account (UUID or email) - Id string `json: "id"` + Id string `json:"id"` // Token used to authenticate - Token string `json: "token"` + Token string `json:"token"` // Time of Account creation Created time.Time `json:"created"` // Time of Account expiry From c691d116ab150a3af8404ffaa5ee5d140c3c6a5e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 15 Feb 2020 11:35:08 +0000 Subject: [PATCH 287/788] when the stream errors cleanup the connection (#1199) --- client/grpc/grpc.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index e3ada840..272719c4 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -218,6 +218,12 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client st, err := cc.NewStream(newCtx, desc, methodToGRPC(req.Service(), req.Endpoint()), grpcCallOptions...) if err != nil { + // we need to cleanup as we dialled and created a context + // cancel the context + cancel() + // close the connection + cc.Close() + // now return the error return nil, errors.InternalServerError("go.micro.client", fmt.Sprintf("Error creating stream: %v", err)) } From eed8a0bf5069f0a82175bb91e478515968bd699f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 15 Feb 2020 12:05:22 +0000 Subject: [PATCH 288/788] delete proxy cached route before updating (#1200) --- proxy/mucp/mucp.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index 68fa35f6..4cba3270 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -203,22 +203,33 @@ func (p *Proxy) cacheRoutes(service string) ([]router.Route, error) { // lookup the routes in the router results, err := p.Router.Lookup(router.QueryService(service)) if err != nil { + // assumption that we're ok with stale routes + // otherwise return the error return nil, err } // update the proxy cache p.Lock() + + // delete the existing reference to the service + delete(p.Routes, service) + for _, route := range results { // create if does not exist if _, ok := p.Routes[service]; !ok { p.Routes[service] = make(map[uint64]router.Route) } + // cache the route based on its unique hash p.Routes[service][route.Hash()] = route } + + // make a copy of the service routes routes := p.Routes[service] + p.Unlock() + // return routes to the caller return toSlice(routes), nil } From 158949d0d01cfefd5f12a0cc40e2f59dc800ac54 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 15 Feb 2020 14:09:24 +0000 Subject: [PATCH 289/788] accept Listen option in grpc server (#1201) --- server/grpc/grpc.go | 24 +++++++++++++++++++++--- server/grpc/options.go | 16 ++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 5aed508e..67be638b 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -171,6 +171,17 @@ func (g *grpcServer) getGrpcOptions() []grpc.ServerOption { return opts } +func (g *grpcServer) getListener() net.Listener { + if g.opts.Context != nil { + if v := g.opts.Context.Value(netListener{}); v != nil { + if l, ok := v.(net.Listener); ok { + return l + } + } + } + return nil +} + func (g *grpcServer) handler(srv interface{}, stream grpc.ServerStream) error { if g.wg != nil { g.wg.Add(1) @@ -788,9 +799,16 @@ func (g *grpcServer) Start() error { config := g.Options() // micro: config.Transport.Listen(config.Address) - ts, err := net.Listen("tcp", config.Address) - if err != nil { - return err + var ts net.Listener + + if l := g.getListener(); l != nil { + ts = l + } else { + var err error + ts, err = net.Listen("tcp", config.Address) + if err != nil { + return err + } } log.Logf("Server [grpc] Listening on %s", ts.Addr().String()) diff --git a/server/grpc/options.go b/server/grpc/options.go index b411b88e..a46b9147 100644 --- a/server/grpc/options.go +++ b/server/grpc/options.go @@ -3,6 +3,7 @@ package grpc import ( "context" "crypto/tls" + "net" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/codec" @@ -14,9 +15,10 @@ import ( ) type codecsKey struct{} -type tlsAuth struct{} -type maxMsgSizeKey struct{} type grpcOptions struct{} +type netListener struct{} +type maxMsgSizeKey struct{} +type tlsAuth struct{} // gRPC Codec to be used to encode/decode requests for a given content type func Codec(contentType string, c encoding.Codec) server.Option { @@ -43,6 +45,16 @@ func AuthTLS(t *tls.Config) server.Option { } } +// Listener specifies the net.Listener to use instead of the default +func Listener(l net.Listener) server.Option { + return func(o *server.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, netListener{}, l) + } +} + // Options to be used to configure gRPC options func Options(opts ...grpc.ServerOption) server.Option { return func(o *server.Options) { From 964b7dee3f095db6c1cf550c06cd041fe98111a4 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 15 Feb 2020 15:10:26 +0000 Subject: [PATCH 290/788] add tls config to server (#1202) * add tls config * add TLSConfig to acme provider --- api/server/acme/acme.go | 6 +++- api/server/acme/autocert/autocert.go | 29 +++++++++++++--- api/server/acme/autocert/autocert_test.go | 4 +-- api/server/acme/autocert/cache.go | 37 +++++++++++++++++++++ api/server/acme/certmagic/certmagic.go | 16 +++++++-- api/server/acme/certmagic/certmagic_test.go | 12 +++---- api/server/http/http.go | 2 +- server/grpc/grpc.go | 9 ++++- server/options.go | 17 ++++++++++ 9 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 api/server/acme/autocert/cache.go diff --git a/api/server/acme/acme.go b/api/server/acme/acme.go index f9df8962..c962d038 100644 --- a/api/server/acme/acme.go +++ b/api/server/acme/acme.go @@ -2,6 +2,7 @@ package acme import ( + "crypto/tls" "errors" "net" ) @@ -14,7 +15,10 @@ var ( // Provider is a ACME provider interface type Provider interface { - NewListener(...string) (net.Listener, error) + // Listen returns a new listener + Listen(...string) (net.Listener, error) + // TLSConfig returns a tls config + TLSConfig(...string) (*tls.Config, error) } // The Let's Encrypt ACME endpoints diff --git a/api/server/acme/autocert/autocert.go b/api/server/acme/autocert/autocert.go index 48152517..3b190f05 100644 --- a/api/server/acme/autocert/autocert.go +++ b/api/server/acme/autocert/autocert.go @@ -3,7 +3,10 @@ package autocert import ( + "crypto/tls" + "log" "net" + "os" "github.com/micro/go-micro/v2/api/server/acme" "golang.org/x/crypto/acme/autocert" @@ -12,12 +15,30 @@ import ( // autoCertACME is the ACME provider from golang.org/x/crypto/acme/autocert type autocertProvider struct{} -// NewListener implements acme.Provider -func (a *autocertProvider) NewListener(ACMEHosts ...string) (net.Listener, error) { - return autocert.NewListener(ACMEHosts...), nil +// Listen implements acme.Provider +func (a *autocertProvider) Listen(hosts ...string) (net.Listener, error) { + return autocert.NewListener(hosts...), nil +} + +// TLSConfig returns a new tls config +func (a *autocertProvider) TLSConfig(hosts ...string) (*tls.Config, error) { + // create a new manager + m := &autocert.Manager{ + Prompt: autocert.AcceptTOS, + } + if len(hosts) > 0 { + m.HostPolicy = autocert.HostWhitelist(hosts...) + } + dir := cacheDir() + if err := os.MkdirAll(dir, 0700); err != nil { + log.Printf("warning: autocert not using a cache: %v", err) + } else { + m.Cache = autocert.DirCache(dir) + } + return m.TLSConfig(), nil } // New returns an autocert acme.Provider -func New() acme.Provider { +func NewProvider() acme.Provider { return &autocertProvider{} } diff --git a/api/server/acme/autocert/autocert_test.go b/api/server/acme/autocert/autocert_test.go index 570769df..8a4aed20 100644 --- a/api/server/acme/autocert/autocert_test.go +++ b/api/server/acme/autocert/autocert_test.go @@ -5,9 +5,9 @@ import ( ) func TestAutocert(t *testing.T) { - l := New() + l := NewProvider() if _, ok := l.(*autocertProvider); !ok { - t.Error("New() didn't return an autocertProvider") + t.Error("NewProvider() didn't return an autocertProvider") } // TODO: Travis CI doesn't let us bind :443 // if _, err := l.NewListener(); err != nil { diff --git a/api/server/acme/autocert/cache.go b/api/server/acme/autocert/cache.go new file mode 100644 index 00000000..c898c449 --- /dev/null +++ b/api/server/acme/autocert/cache.go @@ -0,0 +1,37 @@ +package autocert + +import ( + "os" + "path/filepath" + "runtime" +) + +func homeDir() string { + if runtime.GOOS == "windows" { + return os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH") + } + if h := os.Getenv("HOME"); h != "" { + return h + } + return "/" +} + +func cacheDir() string { + const base = "golang-autocert" + switch runtime.GOOS { + case "darwin": + return filepath.Join(homeDir(), "Library", "Caches", base) + case "windows": + for _, ev := range []string{"APPDATA", "CSIDL_APPDATA", "TEMP", "TMP"} { + if v := os.Getenv(ev); v != "" { + return filepath.Join(v, base) + } + } + // Worst case: + return filepath.Join(homeDir(), base) + } + if xdg := os.Getenv("XDG_CACHE_HOME"); xdg != "" { + return filepath.Join(xdg, base) + } + return filepath.Join(homeDir(), ".cache", base) +} diff --git a/api/server/acme/certmagic/certmagic.go b/api/server/acme/certmagic/certmagic.go index febe56a7..81e485fc 100644 --- a/api/server/acme/certmagic/certmagic.go +++ b/api/server/acme/certmagic/certmagic.go @@ -2,6 +2,7 @@ package certmagic import ( + "crypto/tls" "log" "math/rand" "net" @@ -16,7 +17,8 @@ type certmagicProvider struct { opts acme.Options } -func (c *certmagicProvider) NewListener(ACMEHosts ...string) (net.Listener, error) { +// TODO: set self-contained options +func (c *certmagicProvider) setup() { certmagic.Default.CA = c.opts.CA if c.opts.ChallengeProvider != nil { // Enabling DNS Challenge disables the other challenges @@ -34,12 +36,20 @@ func (c *certmagicProvider) NewListener(ACMEHosts ...string) (net.Listener, erro rand.Seed(time.Now().UnixNano()) randomDuration := (7 * 24 * time.Hour) + (time.Duration(rand.Intn(504)) * time.Hour) certmagic.Default.RenewDurationBefore = randomDuration +} - return certmagic.Listen(ACMEHosts) +func (c *certmagicProvider) Listen(hosts ...string) (net.Listener, error) { + c.setup() + return certmagic.Listen(hosts) +} + +func (c *certmagicProvider) TLSConfig(hosts ...string) (*tls.Config, error) { + c.setup() + return certmagic.TLS(hosts) } // New returns a certmagic provider -func New(options ...acme.Option) acme.Provider { +func NewProvider(options ...acme.Option) acme.Provider { opts := acme.DefaultOptions() for _, o := range options { diff --git a/api/server/acme/certmagic/certmagic_test.go b/api/server/acme/certmagic/certmagic_test.go index cf3c515a..f91566b9 100644 --- a/api/server/acme/certmagic/certmagic_test.go +++ b/api/server/acme/certmagic/certmagic_test.go @@ -19,7 +19,7 @@ func TestCertMagic(t *testing.T) { if len(os.Getenv("IN_TRAVIS_CI")) != 0 { t.Skip("Travis doesn't let us bind :443") } - l, err := New().NewListener() + l, err := NewProvider().Listen() if err != nil { t.Fatal(err.Error()) } @@ -36,10 +36,10 @@ func TestCertMagic(t *testing.T) { t.Fatal(err.Error()) } - l, err = New(acme.AcceptToS(true), + l, err = NewProvider(acme.AcceptToS(true), acme.CA(acme.LetsEncryptStagingCA), acme.ChallengeProvider(p), - ).NewListener() + ).Listen() if err != nil { t.Fatal(err.Error()) @@ -180,7 +180,7 @@ func TestStorageImplementation(t *testing.T) { // New interface doesn't return an error, so call it in case any log.Fatal // happens - New(acme.Cache(s)) + NewProvider(acme.Cache(s)) } // Full test with a real zone, with against LE staging @@ -207,7 +207,7 @@ func TestE2e(t *testing.T) { t.Fatal(err.Error()) } - testProvider := New( + testProvider := NewProvider( acme.AcceptToS(true), acme.Cache(testStorage), acme.CA(acme.LetsEncryptStagingCA), @@ -215,7 +215,7 @@ func TestE2e(t *testing.T) { acme.OnDemand(false), ) - listener, err := testProvider.NewListener("*.micro.mu", "micro.mu") + listener, err := testProvider.Listen("*.micro.mu", "micro.mu") if err != nil { t.Fatal(err.Error()) } diff --git a/api/server/http/http.go b/api/server/http/http.go index ecf3d499..f5240cda 100644 --- a/api/server/http/http.go +++ b/api/server/http/http.go @@ -54,7 +54,7 @@ func (s *httpServer) Start() error { if s.opts.EnableACME && s.opts.ACMEProvider != nil { // should we check the address to make sure its using :443? - l, err = s.opts.ACMEProvider.NewListener(s.opts.ACMEHosts...) + l, err = s.opts.ACMEProvider.Listen(s.opts.ACMEHosts...) } else if s.opts.EnableTLS && s.opts.TLSConfig != nil { l, err = tls.Listen("tcp", s.address, s.opts.TLSConfig) } else { diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 67be638b..b21c58e0 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -805,7 +805,14 @@ func (g *grpcServer) Start() error { ts = l } else { var err error - ts, err = net.Listen("tcp", config.Address) + + // check the tls config for secure connect + if tc := config.TLSConfig; tc != nil { + ts, err = tls.Listen("tcp", config.Address, tc) + // otherwise just plain tcp listener + } else { + ts, err = net.Listen("tcp", config.Address) + } if err != nil { return err } diff --git a/server/options.go b/server/options.go index 53424548..6a54620c 100644 --- a/server/options.go +++ b/server/options.go @@ -2,6 +2,7 @@ package server import ( "context" + "crypto/tls" "sync" "time" @@ -39,6 +40,9 @@ type Options struct { // The router for requests Router Router + // TLSConfig specifies tls.Config for secure serving + TLSConfig *tls.Config + // Other options for implementations of the interface // can be stored in a context Context context.Context @@ -205,6 +209,19 @@ func RegisterInterval(t time.Duration) Option { } } +// TLSConfig specifies a *tls.Config +func TLSConfig(t *tls.Config) Option { + return func(o *Options) { + // set the internal tls + o.TLSConfig = t + // set the transport tls + o.Transport.Init( + transport.Secure(true), + transport.TLSConfig(t), + ) + } +} + // WithRouter sets the request router func WithRouter(r Router) Option { return func(o *Options) { From fc5339a368ea090fac3815b23421fb7d190fdc9e Mon Sep 17 00:00:00 2001 From: Sumanth Chinthagunta Date: Sat, 15 Feb 2020 10:19:28 -0800 Subject: [PATCH 291/788] [W.I.P] refactor(logger): logger fields changed to map[string]interface{} (#1198) * support unix daemon socket * refactor(logger): logger fields changed to map[string]interface{} * improvement(logger): adding string to Level Parser * improvement(logger): rename ParseLevel to GetLevel --- logger/field.go | 43 ------------------------------------------- logger/level.go | 20 ++++++++++++++++++++ logger/logger.go | 26 +++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 44 deletions(-) delete mode 100644 logger/field.go diff --git a/logger/field.go b/logger/field.go deleted file mode 100644 index a91572ac..00000000 --- a/logger/field.go +++ /dev/null @@ -1,43 +0,0 @@ -package logger - -type FieldType uint8 - -type Encode func(*Field) string - -type Field struct { - Key string - Type FieldType - Value interface{} - Encode Encode -} - -func (f *Field) GetValue() interface{} { - if f.Encode != nil { - return f.Encode(f) - } - - return f.Value -} - -// preset common types for choosing encoder faster -const ( - UnknownType FieldType = iota - BoolType - DurationType - Float64Type - Float32Type - Int64Type - Int32Type - Int16Type - Int8Type - Uint64Type - Uint32Type - Uint16Type - Uint8Type - StringType - TimeType -) - -func Bool(key string, val bool) Field { - return Field{Key: key, Type: BoolType, Value: val} -} diff --git a/logger/level.go b/logger/level.go index d7a345be..b49ab52d 100644 --- a/logger/level.go +++ b/logger/level.go @@ -11,3 +11,23 @@ const ( PanicLevel FatalLevel ) + +func (l Level) String() string { + switch l { + case TraceLevel: + return "trace" + case DebugLevel: + return "debug" + case InfoLevel: + return "info" + case WarnLevel: + return "warn" + case ErrorLevel: + return "error" + case FatalLevel: + return "fatal" + case PanicLevel: + return "panic" + } + return "" +} diff --git a/logger/logger.go b/logger/logger.go index 8d7a4ece..f4e451a4 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -20,7 +20,9 @@ type Logger interface { // fmt.Printf. Logf(level Level, format string, v ...interface{}) // Fields set fields to always be logged - Fields(fields ...Field) Logger + Fields(fields map[string]interface{}) Logger + // Error set `error` field to be logged + Error(err error) Logger // SetLevel updates the logging level. SetLevel(Level) // String returns the name of logger @@ -47,3 +49,25 @@ func GetLogger(name string) (Logger, error) { return l, nil } + +// GetLevel converts a level string into a logger Level value. +// returns an error if the input string does not match known values. +func GetLevel(levelStr string) (Level, error) { + switch levelStr { + case TraceLevel.String(): + return TraceLevel, nil + case DebugLevel.String(): + return DebugLevel, nil + case InfoLevel.String(): + return InfoLevel, nil + case WarnLevel.String(): + return WarnLevel, nil + case ErrorLevel.String(): + return ErrorLevel, nil + case FatalLevel.String(): + return FatalLevel, nil + case PanicLevel.String(): + return PanicLevel, nil + } + return InfoLevel, fmt.Errorf("Unknown Level String: '%s', defaulting to NoLevel", levelStr) +} From b3fc8be24e262d843bfb855cc5deb34f398d4caa Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 15 Feb 2020 21:57:31 +0000 Subject: [PATCH 292/788] normalise proxy name (#1203) --- client/grpc/grpc.go | 4 ++++ client/rpc_client.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 272719c4..e90386ac 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -52,6 +52,10 @@ func (g *grpcClient) next(request client.Request, opts client.CallOptions) (sele // get proxy if prx := os.Getenv("MICRO_PROXY"); len(prx) > 0 { + // default name + if prx == "service" { + prx = "go.micro.proxy" + } service = prx } diff --git a/client/rpc_client.go b/client/rpc_client.go index 9f55cd7d..0eda7232 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -342,6 +342,10 @@ func (r *rpcClient) next(request Request, opts CallOptions) (selector.Next, erro // get proxy if prx := os.Getenv("MICRO_PROXY"); len(prx) > 0 { + // default name + if prx == "service" { + prx = "go.micro.proxy" + } service = prx } From 9696efde02e6bf920fbca28d476fd63fa33cffd1 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 16 Feb 2020 19:36:45 +0000 Subject: [PATCH 293/788] reorder auth interface (#1204) --- auth/auth.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 92010501..61567079 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -7,8 +7,6 @@ import ( // Auth providers authentication and authorization type Auth interface { - // String to identify the package - String() string // Init the auth package Init(opts ...Option) error // Options returns the options set @@ -19,6 +17,8 @@ type Auth interface { Revoke(token string) error // Validate an account token Validate(token string) (*Account, error) + // String returns the implementation + String() string } // Resource is an entity such as a user or From 1e40c86dfe16db38146a9647f4dcc3cb001da9bc Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 17 Feb 2020 08:14:45 +0000 Subject: [PATCH 294/788] Ignore gRPC Proxy (#1205) --- client/grpc/grpc.go | 5 ----- client/rpc_client.go | 5 ----- 2 files changed, 10 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index e90386ac..1c7f3512 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -576,11 +576,6 @@ func (g *grpcClient) Publish(ctx context.Context, p client.Message, opts ...clie topic := p.Topic() - // get proxy topic - if prx := os.Getenv("MICRO_PROXY"); len(prx) > 0 { - options.Exchange = prx - } - // get the exchange if len(options.Exchange) > 0 { topic = options.Exchange diff --git a/client/rpc_client.go b/client/rpc_client.go index 0eda7232..b701d1ca 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -610,11 +610,6 @@ func (r *rpcClient) Publish(ctx context.Context, msg Message, opts ...PublishOpt // set the topic topic := msg.Topic() - // get proxy - if prx := os.Getenv("MICRO_PROXY"); len(prx) > 0 { - options.Exchange = prx - } - // get the exchange if len(options.Exchange) > 0 { topic = options.Exchange From aa9a0a8d2332d2d1b85b928e1506dcc05195084b Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 17 Feb 2020 09:28:48 +0000 Subject: [PATCH 295/788] Fix Micro Proxy nil Transport Bug (#1208) --- server/options.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/options.go b/server/options.go index 6a54620c..5caba936 100644 --- a/server/options.go +++ b/server/options.go @@ -214,6 +214,13 @@ func TLSConfig(t *tls.Config) Option { return func(o *Options) { // set the internal tls o.TLSConfig = t + + // set the default transport if one is not + // already set. Required for Init call below. + if o.Transport == nil { + o.Transport = transport.DefaultTransport + } + // set the transport tls o.Transport.Init( transport.Secure(true), From 6248f05f749b75e03117c66ae6fb3f98b577ba03 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 18 Feb 2020 14:18:59 +0300 Subject: [PATCH 296/788] add missing option to client.NewMessage (#1212) Signed-off-by: Vasiliy Tolstov --- client/options.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/options.go b/client/options.go index 6f854d17..2d201510 100644 --- a/client/options.go +++ b/client/options.go @@ -291,6 +291,12 @@ func WithDialTimeout(d time.Duration) CallOption { } } +func WithMessageContentType(ct string) MessageOption { + return func(o *MessageOptions) { + o.ContentType = ct + } +} + // Request Options func WithContentType(ct string) RequestOption { From 58598d0fe02f3a5bb4b384970d52bfb798d22c24 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 19 Feb 2020 02:05:38 +0300 Subject: [PATCH 297/788] fixes for safe conversation and avoid panics (#1213) * fixes for safe convertation Signed-off-by: Vasiliy Tolstov * fix client publish panic If broker connect returns error we dont check it status and use it later to publish message, mostly this is unexpected because broker connection failed and we cant use it. Also proposed solution have benefit - we flag connection status only when we have succeseful broker connection Signed-off-by: Vasiliy Tolstov * api/handler/broker: fix possible broker publish panic Signed-off-by: Vasiliy Tolstov --- api/handler/broker/broker.go | 20 +++++++--- auth/jwt/jwt.go | 5 ++- client/grpc/grpc.go | 15 +++++--- client/rpc_client.go | 14 ++++--- codec/codec.go | 5 +++ codec/proto/proto.go | 8 +++- codec/protorpc/protorpc.go | 14 +++++-- server/grpc/codec.go | 18 ++++++--- server/grpc/context.go | 16 ++++++++ server/grpc/grpc.go | 24 ++++-------- server/grpc/options.go | 71 ++++++++---------------------------- 11 files changed, 108 insertions(+), 102 deletions(-) create mode 100644 server/grpc/context.go diff --git a/api/handler/broker/broker.go b/api/handler/broker/broker.go index bf4ccf60..29d78a02 100644 --- a/api/handler/broker/broker.go +++ b/api/handler/broker/broker.go @@ -8,6 +8,7 @@ import ( "net/url" "strings" "sync" + "sync/atomic" "time" "github.com/gorilla/websocket" @@ -26,6 +27,7 @@ const ( ) type brokerHandler struct { + once atomic.Value opts handler.Options u websocket.Upgrader } @@ -42,7 +44,6 @@ type conn struct { } var ( - once sync.Once contentType = "text/plain" ) @@ -155,10 +156,15 @@ func (b *brokerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { br := b.opts.Service.Client().Options().Broker // Setup the broker - once.Do(func() { - br.Init() - br.Connect() - }) + if !b.once.Load().(bool) { + if err := br.Init(); err != nil { + http.Error(w, err.Error(), 500) + } + if err := br.Connect(); err != nil { + http.Error(w, err.Error(), 500) + } + b.once.Store(true) + } // Parse r.ParseForm() @@ -235,7 +241,7 @@ func (b *brokerHandler) String() string { } func NewHandler(opts ...handler.Option) handler.Handler { - return &brokerHandler{ + h := &brokerHandler{ u: websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true @@ -245,6 +251,8 @@ func NewHandler(opts ...handler.Option) handler.Handler { }, opts: handler.NewOptions(opts...), } + h.once.Store(true) + return h } func WithCors(cors map[string]bool, opts ...handler.Option) handler.Handler { diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go index 540bec43..e0719682 100644 --- a/auth/jwt/jwt.go +++ b/auth/jwt/jwt.go @@ -100,7 +100,10 @@ func (s *svc) Validate(token string) (*auth.Account, error) { return nil, ErrInvalidToken } - claims := res.Claims.(*AuthClaims) + claims, ok := res.Claims.(*AuthClaims) + if !ok { + return nil, ErrInvalidToken + } return &auth.Account{ Id: claims.Id, diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 1c7f3512..7c5a0084 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -6,7 +6,7 @@ import ( "crypto/tls" "fmt" "os" - "sync" + "sync/atomic" "time" "github.com/micro/go-micro/v2/broker" @@ -24,9 +24,9 @@ import ( ) type grpcClient struct { - once sync.Once opts client.Options pool *pool + once atomic.Value } func init() { @@ -570,9 +570,12 @@ func (g *grpcClient) Publish(ctx context.Context, p client.Message, opts ...clie body = b } - g.once.Do(func() { - g.opts.Broker.Connect() - }) + if !g.once.Load().(bool) { + if err = g.opts.Broker.Connect(); err != nil { + return errors.InternalServerError("go.micro.client", err.Error()) + } + g.once.Store(true) + } topic := p.Topic() @@ -641,9 +644,9 @@ func newClient(opts ...client.Option) client.Client { } rc := &grpcClient{ - once: sync.Once{}, opts: options, } + rc.once.Store(false) rc.pool = newPool(options.PoolSize, options.PoolTTL, rc.poolMaxIdle(), rc.poolMaxStreams()) diff --git a/client/rpc_client.go b/client/rpc_client.go index b701d1ca..8b4b806b 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "os" - "sync" "sync/atomic" "time" @@ -22,7 +21,7 @@ import ( ) type rpcClient struct { - once sync.Once + once atomic.Value opts Options pool pool.Pool seq uint64 @@ -38,11 +37,11 @@ func newRpcClient(opt ...Option) Client { ) rc := &rpcClient{ - once: sync.Once{}, opts: opts, pool: p, seq: 0, } + rc.once.Store(false) c := Client(rc) @@ -645,9 +644,12 @@ func (r *rpcClient) Publish(ctx context.Context, msg Message, opts ...PublishOpt body = b.Bytes() } - r.once.Do(func() { - r.opts.Broker.Connect() - }) + if !r.once.Load().(bool) { + if err = r.opts.Broker.Connect(); err != nil { + return errors.InternalServerError("go.micro.client", err.Error()) + } + r.once.Store(true) + } return r.opts.Broker.Publish(topic, &broker.Message{ Header: md, diff --git a/codec/codec.go b/codec/codec.go index b4feb0a4..107bdb35 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -2,6 +2,7 @@ package codec import ( + "errors" "io" ) @@ -12,6 +13,10 @@ const ( Event ) +var ( + ErrInvalidMessage = errors.New("invalid message") +) + type MessageType int // Takes in a connection/buffer and returns a new Codec diff --git a/codec/proto/proto.go b/codec/proto/proto.go index c2c4f382..87073619 100644 --- a/codec/proto/proto.go +++ b/codec/proto/proto.go @@ -25,13 +25,17 @@ func (c *Codec) ReadBody(b interface{}) error { if err != nil { return err } - return proto.Unmarshal(buf, b.(proto.Message)) + m, ok := b.(proto.Message) + if !ok { + return codec.ErrInvalidMessage + } + return proto.Unmarshal(buf, m) } func (c *Codec) Write(m *codec.Message, b interface{}) error { p, ok := b.(proto.Message) if !ok { - return nil + return codec.ErrInvalidMessage } buf, err := proto.Marshal(p) if err != nil { diff --git a/codec/protorpc/protorpc.go b/codec/protorpc/protorpc.go index 4e4b2ee8..41f52fff 100644 --- a/codec/protorpc/protorpc.go +++ b/codec/protorpc/protorpc.go @@ -56,8 +56,12 @@ func (c *protoCodec) Write(m *codec.Message, b interface{}) error { if err != nil { return err } - // Of course this is a protobuf! Trust me or detonate the program. - data, err = proto.Marshal(b.(proto.Message)) + // dont trust or incoming message + m, ok := b.(proto.Message) + if !ok { + return codec.ErrInvalidMessage + } + data, err = proto.Marshal(m) if err != nil { return err } @@ -100,7 +104,11 @@ func (c *protoCodec) Write(m *codec.Message, b interface{}) error { } } case codec.Event: - data, err := proto.Marshal(b.(proto.Message)) + m, ok := b.(proto.Message) + if !ok { + return codec.ErrInvalidMessage + } + data, err := proto.Marshal(m) if err != nil { return err } diff --git a/server/grpc/codec.go b/server/grpc/codec.go index cb27ec6e..b92b63b4 100644 --- a/server/grpc/codec.go +++ b/server/grpc/codec.go @@ -2,7 +2,6 @@ package grpc import ( "encoding/json" - "fmt" "strings" b "bytes" @@ -71,11 +70,19 @@ func (w wrapCodec) Unmarshal(data []byte, v interface{}) error { } func (protoCodec) Marshal(v interface{}) ([]byte, error) { - return proto.Marshal(v.(proto.Message)) + m, ok := v.(proto.Message) + if !ok { + return nil, codec.ErrInvalidMessage + } + return proto.Marshal(m) } func (protoCodec) Unmarshal(data []byte, v interface{}) error { - return proto.Unmarshal(data, v.(proto.Message)) + m, ok := v.(proto.Message) + if !ok { + return codec.ErrInvalidMessage + } + return proto.Unmarshal(data, m) } func (protoCodec) Name() string { @@ -85,7 +92,6 @@ func (protoCodec) Name() string { func (jsonCodec) Marshal(v interface{}) ([]byte, error) { if pb, ok := v.(proto.Message); ok { s, err := jsonpbMarshaler.MarshalToString(pb) - return []byte(s), err } @@ -109,7 +115,7 @@ func (jsonCodec) Name() string { func (bytesCodec) Marshal(v interface{}) ([]byte, error) { b, ok := v.(*[]byte) if !ok { - return nil, fmt.Errorf("failed to marshal: %v is not type of *[]byte", v) + return nil, codec.ErrInvalidMessage } return *b, nil } @@ -117,7 +123,7 @@ func (bytesCodec) Marshal(v interface{}) ([]byte, error) { func (bytesCodec) Unmarshal(data []byte, v interface{}) error { b, ok := v.(*[]byte) if !ok { - return fmt.Errorf("failed to unmarshal: %v is not type of *[]byte", v) + return codec.ErrInvalidMessage } *b = data return nil diff --git a/server/grpc/context.go b/server/grpc/context.go new file mode 100644 index 00000000..0b246d7e --- /dev/null +++ b/server/grpc/context.go @@ -0,0 +1,16 @@ +package grpc + +import ( + "context" + + "github.com/micro/go-micro/v2/server" +) + +func setServerOption(k, v interface{}) server.Option { + return func(o *server.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, k, v) + } +} diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index b21c58e0..001ea1b5 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -143,9 +143,8 @@ func (g *grpcServer) getMaxMsgSize() int { func (g *grpcServer) getCredentials() credentials.TransportCredentials { if g.opts.Context != nil { - if v := g.opts.Context.Value(tlsAuth{}); v != nil { - tls := v.(*tls.Config) - return credentials.NewTLS(tls) + if v, ok := g.opts.Context.Value(tlsAuth{}).(*tls.Config); ok && v != nil { + return credentials.NewTLS(v) } } return nil @@ -156,15 +155,8 @@ func (g *grpcServer) getGrpcOptions() []grpc.ServerOption { return nil } - v := g.opts.Context.Value(grpcOptions{}) - - if v == nil { - return nil - } - - opts, ok := v.([]grpc.ServerOption) - - if !ok { + opts, ok := g.opts.Context.Value(grpcOptions{}).([]grpc.ServerOption) + if !ok || opts == nil { return nil } @@ -505,8 +497,8 @@ func (g *grpcServer) processStream(stream grpc.ServerStream, service *service, m func (g *grpcServer) newGRPCCodec(contentType string) (encoding.Codec, error) { codecs := make(map[string]encoding.Codec) if g.opts.Context != nil { - if v := g.opts.Context.Value(codecsKey{}); v != nil { - codecs = v.(map[string]encoding.Codec) + if v, ok := g.opts.Context.Value(codecsKey{}).(map[string]encoding.Codec); ok && v != nil { + codecs = v } } if c, ok := codecs[contentType]; ok { @@ -573,10 +565,10 @@ func (g *grpcServer) Subscribe(sb server.Subscriber) error { g.Lock() - _, ok = g.subscribers[sub] - if ok { + if _, ok = g.subscribers[sub]; ok { return fmt.Errorf("subscriber %v already exists", sub) } + g.subscribers[sub] = nil g.Unlock() return nil diff --git a/server/grpc/options.go b/server/grpc/options.go index a46b9147..64a8173d 100644 --- a/server/grpc/options.go +++ b/server/grpc/options.go @@ -27,8 +27,8 @@ func Codec(contentType string, c encoding.Codec) server.Option { if o.Context == nil { o.Context = context.Background() } - if v := o.Context.Value(codecsKey{}); v != nil { - codecs = v.(map[string]encoding.Codec) + if v, ok := o.Context.Value(codecsKey{}).(map[string]encoding.Codec); ok && v != nil { + codecs = v } codecs[contentType] = c o.Context = context.WithValue(o.Context, codecsKey{}, codecs) @@ -37,32 +37,17 @@ func Codec(contentType string, c encoding.Codec) server.Option { // AuthTLS should be used to setup a secure authentication using TLS func AuthTLS(t *tls.Config) server.Option { - return func(o *server.Options) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, tlsAuth{}, t) - } + return setServerOption(tlsAuth{}, t) } // Listener specifies the net.Listener to use instead of the default func Listener(l net.Listener) server.Option { - return func(o *server.Options) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, netListener{}, l) - } + return setServerOption(netListener{}, l) } // Options to be used to configure gRPC options func Options(opts ...grpc.ServerOption) server.Option { - return func(o *server.Options) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, grpcOptions{}, opts) - } + return setServerOption(grpcOptions{}, opts) } // @@ -70,51 +55,25 @@ func Options(opts ...grpc.ServerOption) server.Option { // send. Default maximum message size is 4 MB. // func MaxMsgSize(s int) server.Option { - return func(o *server.Options) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, maxMsgSizeKey{}, s) - } + return setServerOption(maxMsgSizeKey{}, s) } func newOptions(opt ...server.Option) server.Options { opts := server.Options{ - Codecs: make(map[string]codec.NewCodec), - Metadata: map[string]string{}, + Codecs: make(map[string]codec.NewCodec), + Metadata: map[string]string{}, + Broker: broker.DefaultBroker, + Registry: registry.DefaultRegistry, + Transport: transport.DefaultTransport, + Address: server.DefaultAddress, + Name: server.DefaultName, + Id: server.DefaultId, + Version: server.DefaultVersion, } for _, o := range opt { o(&opts) } - if opts.Broker == nil { - opts.Broker = broker.DefaultBroker - } - - if opts.Registry == nil { - opts.Registry = registry.DefaultRegistry - } - - if opts.Transport == nil { - opts.Transport = transport.DefaultTransport - } - - if len(opts.Address) == 0 { - opts.Address = server.DefaultAddress - } - - if len(opts.Name) == 0 { - opts.Name = server.DefaultName - } - - if len(opts.Id) == 0 { - opts.Id = server.DefaultId - } - - if len(opts.Version) == 0 { - opts.Version = server.DefaultVersion - } - return opts } From f4118dc357ea4e59dcb65f7c1979ea4b4763df9e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 19 Feb 2020 08:44:35 +0000 Subject: [PATCH 298/788] secure the grpc client (#1215) * secure the grpc client * make compile * Add system cert pool * Revert manually adding ca certs * Tweak comment Co-authored-by: ben-toogood --- client/grpc/grpc.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 7c5a0084..519b4450 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -5,7 +5,9 @@ import ( "context" "crypto/tls" "fmt" + "net" "os" + "strings" "sync/atomic" "time" @@ -36,14 +38,36 @@ func init() { } // secure returns the dial option for whether its a secure or insecure connection -func (g *grpcClient) secure() grpc.DialOption { +func (g *grpcClient) secure(addr string) grpc.DialOption { + // first we check if theres'a tls config if g.opts.Context != nil { if v := g.opts.Context.Value(tlsAuth{}); v != nil { tls := v.(*tls.Config) creds := credentials.NewTLS(tls) + // return tls config if it exists return grpc.WithTransportCredentials(creds) } } + + // default config + tlsConfig := &tls.Config{} + defaultCreds := grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)) + + // check if the address is prepended with https + if strings.HasPrefix(addr, "https://") { + return defaultCreds + } + + // if no port is specified or port is 443 default to tls + _, port, err := net.SplitHostPort(addr) + // assuming with no port its going to be secured + if port == "443" { + return defaultCreds + } else if err != nil && strings.Contains(err.Error(), "missing port in address") { + return defaultCreds + } + + // other fallback to insecure return grpc.WithInsecure() } @@ -116,7 +140,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R grpcDialOptions := []grpc.DialOption{ grpc.WithDefaultCallOptions(grpc.ForceCodec(cf)), grpc.WithTimeout(opts.DialTimeout), - g.secure(), + g.secure(address), grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(maxRecvMsgSize), grpc.MaxCallSendMsgSize(maxSendMsgSize), @@ -194,7 +218,7 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client grpcDialOptions := []grpc.DialOption{ grpc.WithDefaultCallOptions(grpc.ForceCodec(wc)), grpc.WithTimeout(opts.DialTimeout), - g.secure(), + g.secure(address), } if opts := g.getGrpcDialOptions(); opts != nil { From 36bcd3bd82240c4621b0900cfebeb16f727fe67b Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 19 Feb 2020 08:51:43 +0000 Subject: [PATCH 299/788] Improve JWT Package Errors (#1206) Co-authored-by: Asim Aslam --- auth/jwt/jwt.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go index e0719682..d60c9361 100644 --- a/auth/jwt/jwt.go +++ b/auth/jwt/jwt.go @@ -17,6 +17,9 @@ var ErrEncodingToken = errors.New("An error occured while encoding the JWT") // ErrInvalidToken is returned when the token provided is not valid var ErrInvalidToken = errors.New("An invalid token was provided") +// ErrMissingToken is returned when no token is provided +var ErrMissingToken = errors.New("A valid JWT is required") + // NewAuth returns a new instance of the Auth service func NewAuth(opts ...auth.Option) auth.Auth { svc := new(svc) @@ -64,7 +67,7 @@ func (s *svc) Generate(id string, ops ...auth.GenerateOption) (*auth.Account, er options := auth.NewGenerateOptions(ops...) account := jwt.NewWithClaims(jwt.SigningMethodRS256, AuthClaims{ id, options.Roles, options.Metadata, jwt.StandardClaims{ - Subject: "TODO", + Subject: id, ExpiresAt: time.Now().Add(time.Hour * 24).Unix(), }, }) @@ -89,6 +92,10 @@ func (s *svc) Revoke(token string) error { // Validate a JWT func (s *svc) Validate(token string) (*auth.Account, error) { + if token == "" { + return nil, ErrMissingToken + } + res, err := jwt.ParseWithClaims(token, &AuthClaims{}, func(token *jwt.Token) (interface{}, error) { return jwt.ParseRSAPublicKeyFromPEM(s.options.PublicKey) }) From c7eed618c2a11f79104954bd6a2edf37be91613c Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Wed, 19 Feb 2020 12:58:22 -0800 Subject: [PATCH 300/788] server/grpc: Prune Unused Code (#1220) * server/grpc: remove unused grpcServer.newCodec() * server/grpc: remove unused defaultRPCCodecs --- server/grpc/codec.go | 10 ---------- server/grpc/grpc.go | 11 ----------- 2 files changed, 21 deletions(-) diff --git a/server/grpc/codec.go b/server/grpc/codec.go index b92b63b4..eb1b09c5 100644 --- a/server/grpc/codec.go +++ b/server/grpc/codec.go @@ -10,8 +10,6 @@ import ( "github.com/golang/protobuf/proto" "github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/codec/bytes" - "github.com/micro/go-micro/v2/codec/jsonrpc" - "github.com/micro/go-micro/v2/codec/protorpc" "google.golang.org/grpc" "google.golang.org/grpc/encoding" "google.golang.org/grpc/metadata" @@ -35,14 +33,6 @@ var ( "application/grpc+proto": protoCodec{}, "application/grpc+bytes": bytesCodec{}, } - - defaultRPCCodecs = map[string]codec.NewCodec{ - "application/json": jsonrpc.NewCodec, - "application/json-rpc": jsonrpc.NewCodec, - "application/protobuf": protorpc.NewCodec, - "application/proto-rpc": protorpc.NewCodec, - "application/octet-stream": protorpc.NewCodec, - } ) func (w wrapCodec) String() string { diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 001ea1b5..735b69ff 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -16,7 +16,6 @@ import ( "github.com/golang/protobuf/proto" "github.com/micro/go-micro/v2/broker" - "github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/errors" meta "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" @@ -510,16 +509,6 @@ func (g *grpcServer) newGRPCCodec(contentType string) (encoding.Codec, error) { return nil, fmt.Errorf("Unsupported Content-Type: %s", contentType) } -func (g *grpcServer) newCodec(contentType string) (codec.NewCodec, error) { - if cf, ok := g.opts.Codecs[contentType]; ok { - return cf, nil - } - if cf, ok := defaultRPCCodecs[contentType]; ok { - return cf, nil - } - return nil, fmt.Errorf("Unsupported Content-Type: %s", contentType) -} - func (g *grpcServer) Options() server.Options { g.RLock() opts := g.opts From 78df154a4d9eddc9111f11839965c714230689a1 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 20 Feb 2020 08:26:12 +0000 Subject: [PATCH 301/788] move log level setting to option (#1222) --- logger/logger.go | 21 ++++++++------------- logger/options.go | 10 ++++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/logger/logger.go b/logger/logger.go index f4e451a4..fa50662f 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -10,21 +10,16 @@ import ( type Logger interface { // Init initialises options Init(options ...Option) error - // Level returns the logging level - Level() Level - // Log inserts a log entry. Arguments may be handled in the manner - // of fmt.Print, but the underlying logger may also decide to handle - // them differently. - Log(level Level, v ...interface{}) - // Logf insets a log entry. Arguments are handled in the manner of - // fmt.Printf. - Logf(level Level, format string, v ...interface{}) - // Fields set fields to always be logged - Fields(fields map[string]interface{}) Logger + // The Logger options + Options() Options // Error set `error` field to be logged Error(err error) Logger - // SetLevel updates the logging level. - SetLevel(Level) + // Fields set fields to always be logged + Fields(fields map[string]interface{}) Logger + // Log writes a log entry + Log(level Level, v ...interface{}) + // Logf writes a formatted log entry + Logf(level Level, format string, v ...interface{}) // String returns the name of logger String() string } diff --git a/logger/options.go b/logger/options.go index e5ca063d..2b4e6aef 100644 --- a/logger/options.go +++ b/logger/options.go @@ -17,5 +17,15 @@ import ( type Option func(*Options) type Options struct { + // The Log Level + Level Level + // Other opts Context context.Context } + +// WithLevel sets the log level +func WithLevel(l Level) Option { + return func(o *Options) { + o.Level = l + } +} From 88457b812e7e69901dfef5e1fe55a4c0500ac654 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Thu, 20 Feb 2020 09:05:49 -0800 Subject: [PATCH 302/788] tunnel: Prune Unused Functions (#1224) * tunnel: remove unused link.setLoopback() * tunnel: remove unused link.accept() * tunnel: remove unused link.connect() --- tunnel/link.go | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/tunnel/link.go b/tunnel/link.go index b05a25b2..3df54cc5 100644 --- a/tunnel/link.go +++ b/tunnel/link.go @@ -107,32 +107,6 @@ func newLink(s transport.Socket) *link { return l } -func (l *link) connect(addr string) error { - c, err := l.transport.Dial(addr) - if err != nil { - return err - } - - l.Lock() - l.Socket = c - l.Unlock() - - return nil -} - -func (l *link) accept(sock transport.Socket) error { - l.Lock() - l.Socket = sock - l.Unlock() - return nil -} - -func (l *link) setLoopback(v bool) { - l.Lock() - l.loopback = v - l.Unlock() -} - // setRate sets the bits per second rate as a float64 func (l *link) setRate(bits int64, delta time.Duration) { // rate of send in bits per nanosecond From 3fa7c2694657a01287e66cab6b031535313f77af Mon Sep 17 00:00:00 2001 From: Sumanth Chinthagunta Date: Thu, 20 Feb 2020 23:57:59 -0800 Subject: [PATCH 303/788] logger with helper methods (#1216) * support unix daemon socket * refactor(logger): logger fields changed to map[string]interface{} * improvement(logger): adding string to Level Parser * improvement(logger): rename ParseLevel to GetLevel * refactor(logger): adding basic logger adding micro default logger, and refactor logger interface * refactor(logger): moved basic logger to top level package * refactor(logger): adding default logger --- logger/default.go | 96 +++++++++++++++++++++++++++++++++++++++++++++++ logger/level.go | 43 +++++++++++++++++++-- logger/logger.go | 65 +++++++++++++------------------- logger/options.go | 50 ++++++++++++++++-------- 4 files changed, 196 insertions(+), 58 deletions(-) create mode 100644 logger/default.go diff --git a/logger/default.go b/logger/default.go new file mode 100644 index 00000000..ec099c6c --- /dev/null +++ b/logger/default.go @@ -0,0 +1,96 @@ +package logger + +import ( + "context" + "encoding/json" + "fmt" + "log" + "os" +) + +type defaultLogger struct { + opts Options + err error +} + +// Init(opts...) should only overwrite provided options +func (l *defaultLogger) Init(opts ...Option) error { + for _, o := range opts { + o(&l.opts) + } + return nil +} + +func (l *defaultLogger) String() string { + return "default" +} + +func (l *defaultLogger) Fields(fields map[string]interface{}) Logger { + l.opts.Fields = fields + return l +} + +func (l *defaultLogger) Error(err error) Logger { + l.err = err + return l +} + +func (l *defaultLogger) Log(level Level, v ...interface{}) { + if !l.opts.Level.Enabled(level) { + return + } + msg := fmt.Sprint(v...) + + fields := l.opts.Fields + fields["level"] = level.String() + fields["message"] = msg + if l.err != nil { + fields["error"] = l.err.Error() + } + + enc := json.NewEncoder(l.opts.Out) + + if err := enc.Encode(fields); err != nil { + log.Fatal(err) + } +} + +func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) { + if level < l.opts.Level { + return + } + msg := fmt.Sprintf(format, v...) + + fields := l.opts.Fields + fields["level"] = level.String() + fields["message"] = msg + if l.err != nil { + fields["error"] = l.err.Error() + } + + enc := json.NewEncoder(l.opts.Out) + + if err := enc.Encode(fields); err != nil { + log.Fatal(err) + } + +} + +func (n *defaultLogger) Options() Options { + return n.opts +} + +// NewLogger builds a new logger based on options +func NewLogger(opts ...Option) Logger { + // Default options + options := Options{ + Level: InfoLevel, + Fields: make(map[string]interface{}), + Out: os.Stderr, + Context: context.Background(), + } + + l := &defaultLogger{opts: options} + _ = l.Init(opts...) + return l +} diff --git a/logger/level.go b/logger/level.go index b49ab52d..f09f7e8a 100644 --- a/logger/level.go +++ b/logger/level.go @@ -1,14 +1,24 @@ package logger +import "fmt" + type Level int8 const ( - TraceLevel Level = iota - 1 + // TraceLevel level. Designates finer-grained informational events than the Debug. + TraceLevel Level = iota - 2 + // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel + // InfoLevel is the default logging priority. + // General operational entries about what's going on inside the application. InfoLevel + // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel + // ErrorLevel level. Logs. Used for errors that should definitely be noted. ErrorLevel + // PanicLevel level, logs the message and then panics. PanicLevel + // FatalLevel level. Logs and then calls `logger.Exit(1)`. highest level of severity. FatalLevel ) @@ -24,10 +34,37 @@ func (l Level) String() string { return "warn" case ErrorLevel: return "error" - case FatalLevel: - return "fatal" case PanicLevel: return "panic" + case FatalLevel: + return "fatal" } return "" } + +// Enabled returns true if the given level is at or above this level. +func (l Level) Enabled(lvl Level) bool { + return lvl >= l +} + +// GetLevel converts a level string into a logger Level value. +// returns an error if the input string does not match known values. +func GetLevel(levelStr string) (Level, error) { + switch levelStr { + case TraceLevel.String(): + return TraceLevel, nil + case DebugLevel.String(): + return DebugLevel, nil + case InfoLevel.String(): + return InfoLevel, nil + case WarnLevel.String(): + return WarnLevel, nil + case ErrorLevel.String(): + return ErrorLevel, nil + case PanicLevel.String(): + return PanicLevel, nil + case FatalLevel.String(): + return FatalLevel, nil + } + return InfoLevel, fmt.Errorf("Unknown Level String: '%s', defaulting to NoLevel", levelStr) +} diff --git a/logger/logger.go b/logger/logger.go index fa50662f..ffc00ff3 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -1,9 +1,9 @@ // Package log provides a log interface package logger -import ( - "fmt" - "sync" +var ( + // Default logger + DefaultLogger Logger = NewLogger() ) // Logger is a generic logging interface @@ -24,45 +24,32 @@ type Logger interface { String() string } -var ( - mtx sync.Mutex - loggerMap = map[string]Logger{} -) - -func Register(logger Logger) { - mtx.Lock() - defer mtx.Unlock() - - loggerMap[logger.String()] = logger +func Init(opts ...Option) error { + return DefaultLogger.Init(opts...) } -func GetLogger(name string) (Logger, error) { - l := loggerMap[name] - if l == nil { - return nil, fmt.Errorf("no such name logger found %s", name) +func Error(err error) Logger { + return DefaultLogger.Error(err) +} + +func Fields(fields map[string]interface{}) Logger { + return DefaultLogger.Fields(fields) +} + +func Log(level Level, v ...interface{}) { + DefaultLogger.Log(level, v...) +} + +func Logf(level Level, format string, v ...interface{}) { + DefaultLogger.Logf(level, format, v...) +} + +func SetGlobalLevel(lvl Level) { + if err := Init(WithLevel(lvl)); err != nil { + print(err) } - - return l, nil } -// GetLevel converts a level string into a logger Level value. -// returns an error if the input string does not match known values. -func GetLevel(levelStr string) (Level, error) { - switch levelStr { - case TraceLevel.String(): - return TraceLevel, nil - case DebugLevel.String(): - return DebugLevel, nil - case InfoLevel.String(): - return InfoLevel, nil - case WarnLevel.String(): - return WarnLevel, nil - case ErrorLevel.String(): - return ErrorLevel, nil - case FatalLevel.String(): - return FatalLevel, nil - case PanicLevel.String(): - return PanicLevel, nil - } - return InfoLevel, fmt.Errorf("Unknown Level String: '%s', defaulting to NoLevel", levelStr) +func String() string { + return DefaultLogger.String() } diff --git a/logger/options.go b/logger/options.go index 2b4e6aef..ef13d49f 100644 --- a/logger/options.go +++ b/logger/options.go @@ -2,30 +2,48 @@ package logger import ( "context" + "io" ) -// Option for load profiles maybe -// eg. yml -// micro: -// logger: -// name: -// dialect: zap/default/logrus -// zap: -// xxx: -// logrus: -// xxx: type Option func(*Options) type Options struct { - // The Log Level + // The logging level the logger should log at. default is `InfoLevel` Level Level - // Other opts + // fields to always be logged + Fields map[string]interface{} + // It's common to set this to a file, or leave it default which is `os.Stderr` + Out io.Writer + // Alternative options Context context.Context } -// WithLevel sets the log level -func WithLevel(l Level) Option { - return func(o *Options) { - o.Level = l +// WithFields set default fields for the logger +func WithFields(fields map[string]interface{}) Option { + return func(args *Options) { + args.Fields = fields + } +} + +// WithLevel set default level for the logger +func WithLevel(level Level) Option { + return func(args *Options) { + args.Level = level + } +} + +// WithOutput set default output writer for the logger +func WithOutput(out io.Writer) Option { + return func(args *Options) { + args.Out = out + } +} + +func SetOption(k, v interface{}) Option { + return func(o *Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, k, v) } } From ee977acfef87893c9d2503ea41c7c8f4412e3798 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 21 Feb 2020 08:28:21 +0000 Subject: [PATCH 304/788] strip SetGlobalLevel (#1228) --- logger/logger.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/logger/logger.go b/logger/logger.go index ffc00ff3..f98d5936 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -44,12 +44,6 @@ func Logf(level Level, format string, v ...interface{}) { DefaultLogger.Logf(level, format, v...) } -func SetGlobalLevel(lvl Level) { - if err := Init(WithLevel(lvl)); err != nil { - print(err) - } -} - func String() string { return DefaultLogger.String() } From 116855572bf9212d9f402753b18db7c6681476c1 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 21 Feb 2020 08:43:23 +0000 Subject: [PATCH 305/788] Add log level helper funtions (#1229) --- logger/level.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ logger/logger.go | 8 ++++---- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/logger/level.go b/logger/level.go index f09f7e8a..eca14075 100644 --- a/logger/level.go +++ b/logger/level.go @@ -68,3 +68,51 @@ func GetLevel(levelStr string) (Level, error) { } return InfoLevel, fmt.Errorf("Unknown Level String: '%s', defaulting to NoLevel", levelStr) } + +func Info(args ...interface{}) { + DefaultLogger.Log(InfoLevel, args...) +} + +func Infof(template string, args ...interface{}) { + DefaultLogger.Logf(InfoLevel, template, args...) +} + +func Trace(args ...interface{}) { + DefaultLogger.Log(TraceLevel, args...) +} + +func Tracef(template string, args ...interface{}) { + DefaultLogger.Logf(TraceLevel, template, args...) +} + +func Debug(args ...interface{}) { + DefaultLogger.Log(DebugLevel, args...) +} + +func Debugf(template string, args ...interface{}) { + DefaultLogger.Logf(DebugLevel, template, args...) +} + +func Warn(args ...interface{}) { + DefaultLogger.Log(WarnLevel, args...) +} + +func Warnf(template string, args ...interface{}) { + DefaultLogger.Logf(WarnLevel, template, args...) +} + +func Error(args ...interface{}) { + DefaultLogger.Log(ErrorLevel, args...) +} + +func Errorf(template string, args ...interface{}) { + DefaultLogger.Logf(ErrorLevel, template, args...) +} + +func Fatal(args ...interface{}) { + DefaultLogger.Log(FatalLevel, args...) +} + +func Fatalf(template string, args ...interface{}) { + DefaultLogger.Logf(FatalLevel, template, args...) +} diff --git a/logger/logger.go b/logger/logger.go index f98d5936..1c0dc826 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -28,10 +28,6 @@ func Init(opts ...Option) error { return DefaultLogger.Init(opts...) } -func Error(err error) Logger { - return DefaultLogger.Error(err) -} - func Fields(fields map[string]interface{}) Logger { return DefaultLogger.Fields(fields) } @@ -47,3 +43,7 @@ func Logf(level Level, format string, v ...interface{}) { func String() string { return DefaultLogger.String() } + +func WithError(err error) Logger { + return DefaultLogger.Error(err) +} From ca251ba111d430320031768eb2db0abbba89def1 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Fri, 21 Feb 2020 17:43:50 +0000 Subject: [PATCH 306/788] Switch from Travis CI to GitHub Actions (#1231) * Create Github Action to run tests on push * -v * Update tests.yml * TODO: Fix tests * Fix colours * Delete .travis.yml * Update tests.yml * builds -> build --- .github/workflows/tests.yml | 50 +++++++++++++++++++++++++++++++++++++ .travis.yml | 17 ------------- 2 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..0a8ba8ea --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,50 @@ +name: Run tests +on: [push] +jobs: + + test: + name: Test repo + runs-on: ubuntu-latest + steps: + + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Get dependencies + run: | + go get -v -t -d ./... + + - name: Run tests + id: tests + env: + IN_TRAVIS_CI: yes + run: go test -v ./... + + - name: Notify of test failure + if: failure() + uses: rtCamp/action-slack-notify@v2.0.0 + env: + SLACK_CHANNEL: build + SLACK_COLOR: '#BF280A' + SLACK_ICON: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png + SLACK_TITLE: Tests Failed + SLACK_USERNAME: GitHub Actions + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} + + - name: Notify of test success + if: success() + uses: rtCamp/action-slack-notify@v2.0.0 + env: + SLACK_CHANNEL: build + SLACK_COLOR: '#1FAD2B' + SLACK_ICON: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png + SLACK_TITLE: Tests Passed + SLACK_USERNAME: GitHub Actions + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8f880e90..00000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: go -go: -- 1.13.x -env: - - GO111MODULE=on IN_TRAVIS_CI=yes -before_script: - - go install github.com/golangci/golangci-lint/cmd/golangci-lint -script: - # - golangci-lint run || true - # - go test -v -race ./... || true - - go test -v ./... -notifications: - slack: - secure: aEvhLbhujaGaKSrOokiG3//PaVHTIrc3fBpoRbCRqfZpyq6WREoapJJhF+tIpWWOwaC9GmChbD6aHo/jMUgwKXVyPSaNjiEL87YzUUpL8B2zslNp1rgfTg/LrzthOx3Q1TYwpaAl3to0fuHUVFX4yMeC2vuThq7WSXgMMxFCtbc= -cache: - directories: - - $GOPATH/pkg/mod From 7e24c0c1cf8a2c97601dc3d9c145ad0522301169 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Fri, 21 Feb 2020 17:57:07 +0000 Subject: [PATCH 307/788] Also run tests on PR (#1233) --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0a8ba8ea..afe896e9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,5 +1,6 @@ name: Run tests -on: [push] +on: [push, pull_request] + jobs: test: From d1e25e7ead2cb8a6b09cfcdd35e875cd4732c2bc Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 21 Feb 2020 23:04:47 +0300 Subject: [PATCH 308/788] add metadata set method (#1232) Signed-off-by: Vasiliy Tolstov --- metadata/metadata.go | 10 ++++++++++ metadata/metadata_test.go | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/metadata/metadata.go b/metadata/metadata.go index 2f1f234b..c5fddd84 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -22,6 +22,16 @@ func Copy(md Metadata) Metadata { return cmd } +// Set add key with val to metadata +func Set(ctx context.Context, k, v string) context.Context { + md, ok := FromContext(ctx) + if !ok { + md = make(Metadata) + } + md[k] = v + return context.WithValue(ctx, metaKey{}, md) +} + // Get returns a single value from metadata in the context func Get(ctx context.Context, key string) (string, bool) { md, ok := FromContext(ctx) diff --git a/metadata/metadata_test.go b/metadata/metadata_test.go index 764cc680..8dacfa84 100644 --- a/metadata/metadata_test.go +++ b/metadata/metadata_test.go @@ -6,6 +6,18 @@ import ( "testing" ) +func TestMetadataSet(t *testing.T) { + ctx := Set(context.TODO(), "Key", "val") + + val, ok := Get(ctx, "Key") + if !ok { + t.Fatal("key Key not found") + } + if val != "val" { + t.Errorf("key Key with value val != %v", val) + } +} + func TestMetadataCopy(t *testing.T) { md := Metadata{ "Foo": "bar", From ceed8942fc07df08ca004f9560d0cd2d3e0aa8c4 Mon Sep 17 00:00:00 2001 From: "Gao.QiLin" <334136724@qq.com> Date: Sat, 22 Feb 2020 16:56:42 +0800 Subject: [PATCH 309/788] Update README.md change godoc => go.dev (#1236) * Update README.md add go dev * Update README.zh-cn.md add go dev --- README.md | 2 +- README.zh-cn.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8e7d9ad8..73837149 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Go Micro [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![GoDoc](https://godoc.org/github.com/micro/go-micro?status.svg)](https://godoc.org/github.com/micro/go-micro) [![Travis CI](https://api.travis-ci.org/micro/go-micro.svg?branch=master)](https://travis-ci.org/micro/go-micro) [![Go Report Card](https://goreportcard.com/badge/micro/go-micro)](https://goreportcard.com/report/github.com/micro/go-micro) +# Go Micro [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/micro/go-micro?tab=doc) [![Travis CI](https://api.travis-ci.org/micro/go-micro.svg?branch=master)](https://travis-ci.org/micro/go-micro) [![Go Report Card](https://goreportcard.com/badge/micro/go-micro)](https://goreportcard.com/report/github.com/micro/go-micro) Go Micro is a framework for microservice development. diff --git a/README.zh-cn.md b/README.zh-cn.md index b770c8bd..60c009ff 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -1,4 +1,4 @@ -# Go Micro [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![GoDoc](https://godoc.org/github.com/micro/go-micro?status.svg)](https://godoc.org/github.com/micro/go-micro) [![Travis CI](https://api.travis-ci.org/micro/go-micro.svg?branch=master)](https://travis-ci.org/micro/go-micro) [![Go Report Card](https://goreportcard.com/badge/micro/go-micro)](https://goreportcard.com/report/github.com/micro/go-micro) +# Go Micro [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/micro/go-micro?tab=doc) [![Travis CI](https://api.travis-ci.org/micro/go-micro.svg?branch=master)](https://travis-ci.org/micro/go-micro) [![Go Report Card](https://goreportcard.com/badge/micro/go-micro)](https://goreportcard.com/report/github.com/micro/go-micro) Go Micro是基于Golang的微服务开发框架。 From 117f56ebf7fac1ce97d3dba20253ad452c8436f2 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 23 Feb 2020 16:45:20 +0300 Subject: [PATCH 310/788] prune util/log and user logger (#1237) * prune util/log and user logger Signed-off-by: Vasiliy Tolstov * plaintext logger Signed-off-by: Vasiliy Tolstov * add newline Signed-off-by: Vasiliy Tolstov --- agent/input/discord/conn.go | 4 +- agent/input/telegram/conn.go | 4 +- api/handler/broker/broker.go | 6 +- api/server/acme/certmagic/certmagic_test.go | 4 + api/server/http/http.go | 4 +- broker/default.go | 6 +- broker/nats/nats.go | 4 +- broker/service/service.go | 2 +- broker/service/subscriber.go | 2 +- config/cmd/cmd.go | 2 +- config/source/service/service.go | 2 +- debug/log/os.go | 123 +----------- logger/default.go | 42 ++-- network/default.go | 2 +- proxy/mucp/mucp.go | 2 +- registry/cache/cache.go | 6 +- registry/etcd/etcd.go | 2 +- registry/kubernetes/watcher.go | 4 +- registry/memory/memory.go | 2 +- router/default.go | 12 +- router/default_test.go | 2 +- router/table.go | 2 +- runtime/default.go | 2 +- runtime/kubernetes/kubernetes.go | 2 +- runtime/kubernetes/service.go | 2 +- runtime/local/build/docker/docker.go | 2 +- runtime/service.go | 2 +- server/grpc/grpc.go | 28 +-- server/grpc/server.go | 20 +- server/grpc/subscriber.go | 6 +- server/rpc_router.go | 20 +- server/rpc_server.go | 44 ++--- server/server.go | 8 +- service.go | 4 +- service_test.go | 5 - store/cockroach/cockroach.go | 2 +- sync/cron.go | 8 +- transport/grpc/handler.go | 4 +- tunnel/default.go | 4 +- tunnel/link.go | 2 +- tunnel/listener.go | 2 +- tunnel/session.go | 2 +- util/kubernetes/client/client.go | 2 +- util/log/README.md | 15 -- util/log/log.go | 206 -------------------- web/service.go | 14 +- 46 files changed, 159 insertions(+), 486 deletions(-) delete mode 100644 util/log/README.md delete mode 100644 util/log/log.go diff --git a/agent/input/discord/conn.go b/agent/input/discord/conn.go index c7ca09ba..8d5d70d1 100644 --- a/agent/input/discord/conn.go +++ b/agent/input/discord/conn.go @@ -7,7 +7,7 @@ import ( "github.com/bwmarrin/discordgo" "github.com/micro/go-micro/v2/agent/input" - "github.com/micro/go-micro/v2/util/log" + log "github.com/micro/go-micro/v2/logger" ) type discordConn struct { @@ -74,7 +74,7 @@ func (dc *discordConn) Send(e *input.Event) error { fields := strings.Split(e.To, ":") _, err := dc.master.session.ChannelMessageSend(fields[0], string(e.Data)) if err != nil { - log.Log("[bot][loop][send]", err) + log.Error("[bot][loop][send]", err) } return nil } diff --git a/agent/input/telegram/conn.go b/agent/input/telegram/conn.go index 9dd594c8..41ecae72 100644 --- a/agent/input/telegram/conn.go +++ b/agent/input/telegram/conn.go @@ -7,7 +7,7 @@ import ( "github.com/forestgiant/sliceutil" "github.com/micro/go-micro/v2/agent/input" - "github.com/micro/go-micro/v2/util/log" + log "github.com/micro/go-micro/v2/logger" tgbotapi "gopkg.in/telegram-bot-api.v4" ) @@ -104,7 +104,7 @@ func (tc *telegramConn) Send(event *input.Event) error { if err != nil { // probably it could be because of nested HTML tags -- telegram doesn't allow nested tags - log.Log("[telegram][Send] error:", err) + log.Error("[telegram][Send] error:", err) msgConfig.Text = "This bot couldn't send the response (Internal error)" tc.input.api.Send(msgConfig) } diff --git a/api/handler/broker/broker.go b/api/handler/broker/broker.go index 29d78a02..6a503e37 100644 --- a/api/handler/broker/broker.go +++ b/api/handler/broker/broker.go @@ -14,7 +14,7 @@ import ( "github.com/gorilla/websocket" "github.com/micro/go-micro/v2/api/handler" "github.com/micro/go-micro/v2/broker" - "github.com/micro/go-micro/v2/util/log" + log "github.com/micro/go-micro/v2/logger" ) const ( @@ -136,7 +136,7 @@ func (c *conn) writeLoop() { }() if err != nil { - log.Log(err.Error()) + log.Error(err.Error()) return } @@ -214,7 +214,7 @@ func (b *brokerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ws, err := b.u.Upgrade(w, r, nil) if err != nil { - log.Log(err.Error()) + log.Error(err.Error()) return } diff --git a/api/server/acme/certmagic/certmagic_test.go b/api/server/acme/certmagic/certmagic_test.go index f91566b9..30d698c8 100644 --- a/api/server/acme/certmagic/certmagic_test.go +++ b/api/server/acme/certmagic/certmagic_test.go @@ -1,6 +1,7 @@ package certmagic import ( + "net" "net/http" "os" "reflect" @@ -21,6 +22,9 @@ func TestCertMagic(t *testing.T) { } l, err := NewProvider().Listen() if err != nil { + if _, ok := err.(*net.OpError); ok { + t.Skip("Run under non privileged user") + } t.Fatal(err.Error()) } l.Close() diff --git a/api/server/http/http.go b/api/server/http/http.go index f5240cda..f5fe5d24 100644 --- a/api/server/http/http.go +++ b/api/server/http/http.go @@ -10,7 +10,7 @@ import ( "github.com/gorilla/handlers" "github.com/micro/go-micro/v2/api/server" - "github.com/micro/go-micro/v2/util/log" + log "github.com/micro/go-micro/v2/logger" ) type httpServer struct { @@ -65,7 +65,7 @@ func (s *httpServer) Start() error { return err } - log.Logf("HTTP API Listening on %s", l.Addr().String()) + log.Infof("HTTP API Listening on %s", l.Addr().String()) s.mtx.Lock() s.address = l.Addr().String() diff --git a/broker/default.go b/broker/default.go index a71a5d17..b8b8ffe1 100644 --- a/broker/default.go +++ b/broker/default.go @@ -11,9 +11,9 @@ import ( "time" "github.com/micro/go-micro/v2/codec/json" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/addr" - "github.com/micro/go-micro/v2/util/log" "github.com/nats-io/nats-server/v2/server" nats "github.com/nats-io/nats.go" ) @@ -167,7 +167,7 @@ func (n *natsBroker) serve(exit chan bool) error { for _, node := range service.Nodes { u, err := url.Parse("nats://" + node.Address) if err != nil { - log.Log(err) + log.Info(err) continue } // append to the cluster routes @@ -242,7 +242,7 @@ func (n *natsBroker) serve(exit chan bool) error { select { case err := <-n.closeCh: if err != nil { - log.Log(err) + log.Info(err) } case <-exit: // deregister on exit diff --git a/broker/nats/nats.go b/broker/nats/nats.go index 2cce84e4..89bfd1e7 100644 --- a/broker/nats/nats.go +++ b/broker/nats/nats.go @@ -13,9 +13,9 @@ import ( "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/codec/json" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/addr" - "github.com/micro/go-micro/v2/util/log" "github.com/nats-io/nats-server/v2/server" nats "github.com/nats-io/nats.go" ) @@ -164,7 +164,7 @@ func (n *natsBroker) serve(exit chan bool) error { for _, node := range service.Nodes { u, err := url.Parse("nats://" + node.Address) if err != nil { - log.Log(err) + log.Error(err) continue } // append to the cluster routes diff --git a/broker/service/service.go b/broker/service/service.go index 81c1fb28..a52400ba 100644 --- a/broker/service/service.go +++ b/broker/service/service.go @@ -8,7 +8,7 @@ import ( "github.com/micro/go-micro/v2/broker" pb "github.com/micro/go-micro/v2/broker/service/proto" "github.com/micro/go-micro/v2/client" - "github.com/micro/go-micro/v2/util/log" + log "github.com/micro/go-micro/v2/logger" ) type serviceBroker struct { diff --git a/broker/service/subscriber.go b/broker/service/subscriber.go index 36de7275..2e92ad43 100644 --- a/broker/service/subscriber.go +++ b/broker/service/subscriber.go @@ -3,7 +3,7 @@ package service import ( "github.com/micro/go-micro/v2/broker" pb "github.com/micro/go-micro/v2/broker/service/proto" - "github.com/micro/go-micro/v2/util/log" + log "github.com/micro/go-micro/v2/logger" ) type serviceSub struct { diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 8aea177b..3c561146 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -12,12 +12,12 @@ import ( "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" "github.com/micro/go-micro/v2/debug/trace" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/store" "github.com/micro/go-micro/v2/transport" - "github.com/micro/go-micro/v2/util/log" // clients cgrpc "github.com/micro/go-micro/v2/client/grpc" diff --git a/config/source/service/service.go b/config/source/service/service.go index 567db30a..5e71ab17 100644 --- a/config/source/service/service.go +++ b/config/source/service/service.go @@ -6,7 +6,7 @@ import ( "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/config/source" proto "github.com/micro/go-micro/v2/config/source/service/proto" - "github.com/micro/go-micro/v2/util/log" + log "github.com/micro/go-micro/v2/logger" ) var ( diff --git a/debug/log/os.go b/debug/log/os.go index 3073eacf..022481c2 100644 --- a/debug/log/os.go +++ b/debug/log/os.go @@ -1,13 +1,7 @@ package log import ( - "bufio" - "encoding/json" - "io" - "os" - "strings" "sync" - "time" "github.com/google/uuid" "github.com/micro/go-micro/v2/util/ring" @@ -25,106 +19,10 @@ type osLog struct { type osStream struct { stream chan Record - stop chan bool -} - -// watch io stream -func (o *osLog) run() { - // save outputs - stdout := *os.Stdout - stderr := *os.Stderr - - // new os pipe - r, w := io.Pipe() - - // create new iopipes - r1, w1, _ := os.Pipe() - r2, w2, _ := os.Pipe() - - // create tea readers - tee1 := io.TeeReader(r1, &stdout) - tee2 := io.TeeReader(r2, &stderr) - - // start copying - go io.Copy(w, tee1) - go io.Copy(w, tee2) - - // set default go log output - //log.SetOutput(w2) - - // replace os stdout and os stderr - *os.Stdout = *w1 - *os.Stderr = *w2 - - // this should short circuit everything - defer func() { - // reset stdout and stderr - *os.Stdout = stdout - *os.Stderr = stderr - //log.SetOutput(stderr) - - // close all the outputs - r.Close() - r1.Close() - r2.Close() - w.Close() - w1.Close() - w2.Close() - }() - - // read from standard error - scanner := bufio.NewReader(r) - - for { - // read the line - line, err := scanner.ReadString('\n') - if err != nil { - return - } - // check if the line exists - if len(line) == 0 { - continue - } - // parse the record - var r Record - if line[0] == '{' { - json.Unmarshal([]byte(line), &r) - } else { - r = Record{ - Timestamp: time.Now(), - Message: strings.TrimSuffix(line, "\n"), - Metadata: make(map[string]string), - } - } - - o.Lock() - - // write to the buffer - o.buffer.Put(r) - - // check subs and send to stream - for id, sub := range o.subs { - // send to stream - select { - case <-sub.stop: - delete(o.subs, id) - case sub.stream <- r: - // send to stream - default: - // do not block - } - } - - o.Unlock() - } } // Read reads log entries from the logger func (o *osLog) Read(...ReadOption) ([]Record, error) { - o.once.Do(func() { - go o.run() - }) - var records []Record // read the last 100 records @@ -137,29 +35,18 @@ func (o *osLog) Read(...ReadOption) ([]Record, error) { // Write writes records to log func (o *osLog) Write(r Record) error { - o.once.Do(func() { - go o.run() - }) - - // generate output - out := o.format(r) + "\n" - _, err := os.Stderr.Write([]byte(out)) - return err + o.buffer.Put(r) + return nil } // Stream log records func (o *osLog) Stream() (Stream, error) { - o.once.Do(func() { - go o.run() - }) - o.Lock() defer o.Unlock() // create stream st := &osStream{ stream: make(chan Record, 128), - stop: make(chan bool), } // save stream @@ -173,12 +60,6 @@ func (o *osStream) Chan() <-chan Record { } func (o *osStream) Stop() error { - select { - case <-o.stop: - return nil - default: - close(o.stop) - } return nil } diff --git a/logger/default.go b/logger/default.go index ec099c6c..3369f64e 100644 --- a/logger/default.go +++ b/logger/default.go @@ -2,10 +2,11 @@ package logger import ( "context" - "encoding/json" "fmt" - "log" "os" + "time" + + dlog "github.com/micro/go-micro/v2/debug/log" ) type defaultLogger struct { @@ -36,44 +37,57 @@ func (l *defaultLogger) Error(err error) Logger { } func (l *defaultLogger) Log(level Level, v ...interface{}) { + // TODO decide does we need to write message if log level not used? if !l.opts.Level.Enabled(level) { return } - msg := fmt.Sprint(v...) fields := l.opts.Fields fields["level"] = level.String() - fields["message"] = msg if l.err != nil { fields["error"] = l.err.Error() } - enc := json.NewEncoder(l.opts.Out) - - if err := enc.Encode(fields); err != nil { - log.Fatal(err) + rec := dlog.Record{ + Timestamp: time.Now(), + Message: fmt.Sprint(v...), + Metadata: make(map[string]string), } + for k, v := range fields { + rec.Metadata[k] = fmt.Sprintf("%v", v) + } + + dlog.DefaultLog.Write(rec) + + t := rec.Timestamp.Format("2006-01-02 15:04:05") + fmt.Printf("%s %v\n", t, rec.Message) } func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) { + // TODO decide does we need to write message if log level not used? if level < l.opts.Level { return } - msg := fmt.Sprintf(format, v...) fields := l.opts.Fields fields["level"] = level.String() - fields["message"] = msg if l.err != nil { fields["error"] = l.err.Error() } - enc := json.NewEncoder(l.opts.Out) - - if err := enc.Encode(fields); err != nil { - log.Fatal(err) + rec := dlog.Record{ + Timestamp: time.Now(), + Message: fmt.Sprintf(format, v...), + Metadata: make(map[string]string), + } + for k, v := range fields { + rec.Metadata[k] = fmt.Sprintf("%v", v) } + dlog.DefaultLog.Write(rec) + + t := rec.Timestamp.Format("2006-01-02 15:04:05") + fmt.Printf("%s %v\n", t, rec.Message) } func (n *defaultLogger) Options() Options { diff --git a/network/default.go b/network/default.go index 6fb347ae..5e116b85 100644 --- a/network/default.go +++ b/network/default.go @@ -15,6 +15,7 @@ import ( "github.com/micro/go-micro/v2/client" cmucp "github.com/micro/go-micro/v2/client/mucp" rtr "github.com/micro/go-micro/v2/client/selector/router" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/network/resolver/dns" pbNet "github.com/micro/go-micro/v2/network/service/proto" "github.com/micro/go-micro/v2/proxy" @@ -27,7 +28,6 @@ import ( bun "github.com/micro/go-micro/v2/tunnel/broker" tun "github.com/micro/go-micro/v2/tunnel/transport" "github.com/micro/go-micro/v2/util/backoff" - "github.com/micro/go-micro/v2/util/log" pbUtil "github.com/micro/go-micro/v2/util/proto" ) diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index 4cba3270..d9edf14a 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -15,11 +15,11 @@ import ( "github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/codec/bytes" "github.com/micro/go-micro/v2/errors" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/proxy" "github.com/micro/go-micro/v2/router" "github.com/micro/go-micro/v2/server" - "github.com/micro/go-micro/v2/util/log" ) // Proxy will transparently proxy requests to an endpoint. diff --git a/registry/cache/cache.go b/registry/cache/cache.go index 51c3aac0..689c6e35 100644 --- a/registry/cache/cache.go +++ b/registry/cache/cache.go @@ -7,8 +7,8 @@ import ( "sync" "time" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" - log "github.com/micro/go-micro/v2/util/log" ) // Cache is the registry cache interface @@ -339,7 +339,7 @@ func (c *cache) run() { c.setStatus(err) if a > 3 { - log.Log("rcache: ", err, " backing off ", d) + log.Info("rcache: ", err, " backing off ", d) a = 0 } @@ -362,7 +362,7 @@ func (c *cache) run() { c.setStatus(err) if b > 3 { - log.Log("rcache: ", err, " backing off ", d) + log.Info("rcache: ", err, " backing off ", d) b = 0 } diff --git a/registry/etcd/etcd.go b/registry/etcd/etcd.go index b51a4010..40ba3b03 100644 --- a/registry/etcd/etcd.go +++ b/registry/etcd/etcd.go @@ -15,8 +15,8 @@ import ( "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" - "github.com/micro/go-micro/v2/util/log" hash "github.com/mitchellh/hashstructure" "go.uber.org/zap" ) diff --git a/registry/kubernetes/watcher.go b/registry/kubernetes/watcher.go index 0d848c4a..5c54a1b6 100644 --- a/registry/kubernetes/watcher.go +++ b/registry/kubernetes/watcher.go @@ -6,9 +6,9 @@ import ( "strings" "sync" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/kubernetes/client" - "github.com/micro/go-micro/v2/util/log" ) type k8sWatcher struct { @@ -132,7 +132,7 @@ func (k *k8sWatcher) buildPodResults(pod *client.Pod, cache *client.Pod) []*regi func (k *k8sWatcher) handleEvent(event client.Event) { var pod client.Pod if err := json.Unmarshal([]byte(event.Object), &pod); err != nil { - log.Log("K8s Watcher: Couldnt unmarshal event object from pod") + log.Info("K8s Watcher: Couldnt unmarshal event object from pod") return } diff --git a/registry/memory/memory.go b/registry/memory/memory.go index 2586d5e4..3dc96f46 100644 --- a/registry/memory/memory.go +++ b/registry/memory/memory.go @@ -7,8 +7,8 @@ import ( "time" "github.com/google/uuid" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" - "github.com/micro/go-micro/v2/util/log" ) var ( diff --git a/router/default.go b/router/default.go index 2187609a..d89ce13a 100644 --- a/router/default.go +++ b/router/default.go @@ -10,8 +10,8 @@ import ( "time" "github.com/google/uuid" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" - "github.com/micro/go-micro/v2/util/log" ) var ( @@ -357,14 +357,14 @@ func (r *router) advertiseEvents() error { // routing table watcher w, err = r.Watch() if err != nil { - log.Logf("Error creating watcher: %v", err) + log.Errorf("Error creating watcher: %v", err) time.Sleep(time.Second) continue } } if err := r.watchTable(w); err != nil { - log.Logf("Error watching table: %v", err) + log.Errorf("Error watching table: %v", err) time.Sleep(time.Second) } @@ -538,14 +538,14 @@ func (r *router) Start() error { if w == nil { w, err = r.options.Registry.Watch() if err != nil { - log.Logf("failed creating registry watcher: %v", err) + log.Errorf("failed creating registry watcher: %v", err) time.Sleep(time.Second) continue } } if err := r.watchRegistry(w); err != nil { - log.Logf("Error watching the registry: %v", err) + log.Errorf("Error watching the registry: %v", err) time.Sleep(time.Second) } @@ -602,7 +602,7 @@ func (r *router) Advertise() (<-chan *Advert, error) { return default: if err := r.advertiseEvents(); err != nil { - log.Logf("Error adveritising events: %v", err) + log.Errorf("Error adveritising events: %v", err) } } }() diff --git a/router/default_test.go b/router/default_test.go index c94ac9b4..42a79595 100644 --- a/router/default_test.go +++ b/router/default_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry/memory" - "github.com/micro/go-micro/v2/util/log" ) func routerTestSetup() Router { diff --git a/router/table.go b/router/table.go index df17ee3e..649cea65 100644 --- a/router/table.go +++ b/router/table.go @@ -6,7 +6,7 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/v2/util/log" + log "github.com/micro/go-micro/v2/logger" ) var ( diff --git a/runtime/default.go b/runtime/default.go index 18247d89..fdd1ed25 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/micro/go-micro/v2/util/log" + log "github.com/micro/go-micro/v2/logger" ) type runtime struct { diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index aafa2f92..eabdb4b8 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -7,9 +7,9 @@ import ( "sync" "time" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/util/kubernetes/client" - "github.com/micro/go-micro/v2/util/log" ) // action to take on runtime service diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 0fafd962..60fb31a5 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -5,10 +5,10 @@ import ( "strings" "time" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/util/kubernetes/api" "github.com/micro/go-micro/v2/util/kubernetes/client" - "github.com/micro/go-micro/v2/util/log" ) type service struct { diff --git a/runtime/local/build/docker/docker.go b/runtime/local/build/docker/docker.go index bb953a71..01bc18a4 100644 --- a/runtime/local/build/docker/docker.go +++ b/runtime/local/build/docker/docker.go @@ -9,8 +9,8 @@ import ( "path/filepath" docker "github.com/fsouza/go-dockerclient" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/runtime/local/build" - "github.com/micro/go-micro/v2/util/log" ) type Builder struct { diff --git a/runtime/service.go b/runtime/service.go index 8ddd1bcc..c93bec73 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -6,10 +6,10 @@ import ( "sync" "time" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/runtime/local/build" "github.com/micro/go-micro/v2/runtime/local/process" proc "github.com/micro/go-micro/v2/runtime/local/process/os" - "github.com/micro/go-micro/v2/util/log" ) type service struct { diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 735b69ff..5b434200 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -17,12 +17,12 @@ import ( "github.com/golang/protobuf/proto" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/errors" + log "github.com/micro/go-micro/v2/logger" meta "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/util/addr" mgrpc "github.com/micro/go-micro/v2/util/grpc" - "github.com/micro/go-micro/v2/util/log" mnet "github.com/micro/go-micro/v2/util/net" "google.golang.org/grpc" @@ -356,8 +356,8 @@ func (g *grpcServer) processRequest(stream grpc.ServerStream, service *service, fn := func(ctx context.Context, req server.Request, rsp interface{}) (err error) { defer func() { if r := recover(); r != nil { - log.Log("panic recovered: ", r) - log.Logf(string(debug.Stack())) + log.Error("panic recovered: ", r) + log.Error(string(debug.Stack())) err = errors.InternalServerError("go.micro.server", "panic recovered: %v", r) } }() @@ -656,7 +656,7 @@ func (g *grpcServer) Register() error { g.Unlock() if !registered { - log.Logf("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) + log.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) } // create registry options @@ -691,7 +691,7 @@ func (g *grpcServer) Register() error { opts = append(opts, broker.DisableAutoAck()) } - log.Logf("Subscribing to topic: %s", sb.Topic()) + log.Infof("Subscribing to topic: %s", sb.Topic()) sub, err := config.Broker.Subscribe(sb.Topic(), handler, opts...) if err != nil { return err @@ -743,7 +743,7 @@ func (g *grpcServer) Deregister() error { Nodes: []*registry.Node{node}, } - log.Logf("Deregistering node: %s", node.Id) + log.Infof("Deregistering node: %s", node.Id) if err := config.Registry.Deregister(service); err != nil { return err } @@ -759,7 +759,7 @@ func (g *grpcServer) Deregister() error { for sb, subs := range g.subscribers { for _, sub := range subs { - log.Logf("Unsubscribing from topic: %s", sub.Topic()) + log.Infof("Unsubscribing from topic: %s", sub.Topic()) sub.Unsubscribe() } g.subscribers[sb] = nil @@ -799,7 +799,7 @@ func (g *grpcServer) Start() error { } } - log.Logf("Server [grpc] Listening on %s", ts.Addr().String()) + log.Infof("Server [grpc] Listening on %s", ts.Addr().String()) g.Lock() g.opts.Address = ts.Addr().String() g.Unlock() @@ -811,18 +811,18 @@ func (g *grpcServer) Start() error { return err } - log.Logf("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address()) + log.Infof("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address()) } // announce self to the world if err := g.Register(); err != nil { - log.Log("Server register error: ", err) + log.Errorf("Server register error: ", err) } // micro: go ts.Accept(s.accept) go func() { if err := g.srv.Serve(ts); err != nil { - log.Log("gRPC Server start error: ", err) + log.Errorf("gRPC Server start error: ", err) } }() @@ -844,7 +844,7 @@ func (g *grpcServer) Start() error { // register self on interval case <-t.C: if err := g.Register(); err != nil { - log.Log("Server register error: ", err) + log.Error("Server register error: ", err) } // wait for exit case ch = <-g.exit: @@ -854,7 +854,7 @@ func (g *grpcServer) Start() error { // deregister self if err := g.Deregister(); err != nil { - log.Log("Server deregister error: ", err) + log.Error("Server deregister error: ", err) } // wait for waitgroup @@ -879,7 +879,7 @@ func (g *grpcServer) Start() error { // close transport ch <- nil - log.Logf("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address()) + log.Infof("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address()) // disconnect broker config.Broker.Disconnect() }() diff --git a/server/grpc/server.go b/server/grpc/server.go index 6d43ba17..81bf9f7c 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -14,8 +14,8 @@ import ( "unicode" "unicode/utf8" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/server" - "github.com/micro/go-micro/v2/util/log" ) var ( @@ -86,7 +86,7 @@ func prepareEndpoint(method reflect.Method) *methodType { replyType = mtype.In(3) contextType = mtype.In(1) default: - log.Log("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn()) + log.Error("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn()) return nil } @@ -94,7 +94,7 @@ func prepareEndpoint(method reflect.Method) *methodType { // check stream type streamType := reflect.TypeOf((*server.Stream)(nil)).Elem() if !argType.Implements(streamType) { - log.Log(mname, "argument does not implement Streamer interface:", argType) + log.Error(mname, "argument does not implement Streamer interface:", argType) return nil } } else { @@ -102,30 +102,30 @@ func prepareEndpoint(method reflect.Method) *methodType { // First arg need not be a pointer. if !isExportedOrBuiltinType(argType) { - log.Log(mname, "argument type not exported:", argType) + log.Error(mname, "argument type not exported:", argType) return nil } if replyType.Kind() != reflect.Ptr { - log.Log("method", mname, "reply type not a pointer:", replyType) + log.Error("method", mname, "reply type not a pointer:", replyType) return nil } // Reply type must be exported. if !isExportedOrBuiltinType(replyType) { - log.Log("method", mname, "reply type not exported:", replyType) + log.Error("method", mname, "reply type not exported:", replyType) return nil } } // Endpoint() needs one out. if mtype.NumOut() != 1 { - log.Log("method", mname, "has wrong number of outs:", mtype.NumOut()) + log.Error("method", mname, "has wrong number of outs:", mtype.NumOut()) return nil } // The return type of the method must be error. if returnType := mtype.Out(0); returnType != typeOfError { - log.Log("method", mname, "returns", returnType.String(), "not error") + log.Error("method", mname, "returns", returnType.String(), "not error") return nil } return &methodType{method: method, ArgType: argType, ReplyType: replyType, ContextType: contextType, stream: stream} @@ -146,7 +146,7 @@ func (server *rServer) register(rcvr interface{}) error { } if !isExported(sname) { s := "rpc Register: type " + sname + " is not exported" - log.Log(s) + log.Error(s) return errors.New(s) } if _, present := server.serviceMap[sname]; present { @@ -165,7 +165,7 @@ func (server *rServer) register(rcvr interface{}) error { if len(s.method) == 0 { s := "rpc Register: type " + sname + " has no exported methods of suitable type" - log.Log(s) + log.Error(s) return errors.New(s) } server.serviceMap[s.name] = s diff --git a/server/grpc/subscriber.go b/server/grpc/subscriber.go index c628a6e0..7bd39a5f 100644 --- a/server/grpc/subscriber.go +++ b/server/grpc/subscriber.go @@ -9,10 +9,10 @@ import ( "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/errors" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/server" - "github.com/micro/go-micro/v2/util/log" ) const ( @@ -171,8 +171,8 @@ func (g *grpcServer) createSubHandler(sb *subscriber, opts server.Options) broke defer func() { if r := recover(); r != nil { - log.Log("panic recovered: ", r) - log.Logf(string(debug.Stack())) + log.Error("panic recovered: ", r) + log.Error(string(debug.Stack())) err = errors.InternalServerError("go.micro.server", "panic recovered: %v", r) } }() diff --git a/server/rpc_router.go b/server/rpc_router.go index 8d36f1f0..3716617d 100644 --- a/server/rpc_router.go +++ b/server/rpc_router.go @@ -20,7 +20,7 @@ import ( "github.com/micro/go-micro/v2/codec" merrors "github.com/micro/go-micro/v2/errors" - "github.com/micro/go-micro/v2/util/log" + log "github.com/micro/go-micro/v2/logger" ) var ( @@ -141,7 +141,7 @@ func prepareMethod(method reflect.Method) *methodType { replyType = mtype.In(3) contextType = mtype.In(1) default: - log.Log("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn()) + log.Error("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn()) return nil } @@ -149,7 +149,7 @@ func prepareMethod(method reflect.Method) *methodType { // check stream type streamType := reflect.TypeOf((*Stream)(nil)).Elem() if !argType.Implements(streamType) { - log.Log(mname, "argument does not implement Stream interface:", argType) + log.Error(mname, "argument does not implement Stream interface:", argType) return nil } } else { @@ -157,30 +157,30 @@ func prepareMethod(method reflect.Method) *methodType { // First arg need not be a pointer. if !isExportedOrBuiltinType(argType) { - log.Log(mname, "argument type not exported:", argType) + log.Error(mname, "argument type not exported:", argType) return nil } if replyType.Kind() != reflect.Ptr { - log.Log("method", mname, "reply type not a pointer:", replyType) + log.Error("method", mname, "reply type not a pointer:", replyType) return nil } // Reply type must be exported. if !isExportedOrBuiltinType(replyType) { - log.Log("method", mname, "reply type not exported:", replyType) + log.Error("method", mname, "reply type not exported:", replyType) return nil } } // Method needs one out. if mtype.NumOut() != 1 { - log.Log("method", mname, "has wrong number of outs:", mtype.NumOut()) + log.Error("method", mname, "has wrong number of outs:", mtype.NumOut()) return nil } // The return type of the method must be error. if returnType := mtype.Out(0); returnType != typeOfError { - log.Log("method", mname, "returns", returnType.String(), "not error") + log.Error("method", mname, "returns", returnType.String(), "not error") return nil } return &methodType{method: method, ArgType: argType, ReplyType: replyType, ContextType: contextType, stream: stream} @@ -509,8 +509,8 @@ func (router *router) ProcessMessage(ctx context.Context, msg Message) (err erro defer func() { // recover any panics if r := recover(); r != nil { - log.Log("panic recovered: ", r) - log.Log(string(debug.Stack())) + log.Error("panic recovered: ", r) + log.Error(string(debug.Stack())) err = merrors.InternalServerError("go.micro.server", "panic recovered: %v", r) } }() diff --git a/server/rpc_server.go b/server/rpc_server.go index 6c0c793d..a692573a 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -15,11 +15,11 @@ import ( "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/codec" raw "github.com/micro/go-micro/v2/codec/bytes" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/transport" "github.com/micro/go-micro/v2/util/addr" - log "github.com/micro/go-micro/v2/util/log" mnet "github.com/micro/go-micro/v2/util/net" "github.com/micro/go-micro/v2/util/socket" ) @@ -158,8 +158,8 @@ func (s *rpcServer) ServeConn(sock transport.Socket) { // recover any panics if r := recover(); r != nil { - log.Log("panic recovered: ", r) - log.Log(string(debug.Stack())) + log.Error("panic recovered: ", r) + log.Error(string(debug.Stack())) } }() @@ -377,8 +377,8 @@ func (s *rpcServer) ServeConn(sock transport.Socket) { // recover any panics for outbound process if r := recover(); r != nil { - log.Log("panic recovered: ", r) - log.Log(string(debug.Stack())) + log.Error("panic recovered: ", r) + log.Error(string(debug.Stack())) } }() @@ -409,8 +409,8 @@ func (s *rpcServer) ServeConn(sock transport.Socket) { // recover any panics for call handler if r := recover(); r != nil { - log.Log("panic recovered: ", r) - log.Log(string(debug.Stack())) + log.Error("panic recovered: ", r) + log.Error(string(debug.Stack())) } }() @@ -608,7 +608,7 @@ func (s *rpcServer) Register() error { s.RUnlock() if !registered { - log.Logf("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) + log.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) } // create registry options @@ -654,7 +654,7 @@ func (s *rpcServer) Register() error { opts = append(opts, broker.DisableAutoAck()) } - log.Logf("Subscribing to topic: %s", sub.Topic()) + log.Infof("Subscribing to topic: %s", sub.Topic()) sub, err := config.Broker.Subscribe(sb.Topic(), s.HandleEvent, opts...) if err != nil { return err @@ -712,7 +712,7 @@ func (s *rpcServer) Deregister() error { Nodes: []*registry.Node{node}, } - log.Logf("Registry [%s] Deregistering node: %s", config.Registry.String(), node.Id) + log.Infof("Registry [%s] Deregistering node: %s", config.Registry.String(), node.Id) if err := config.Registry.Deregister(service); err != nil { return err } @@ -734,7 +734,7 @@ func (s *rpcServer) Deregister() error { for sb, subs := range s.subscribers { for _, sub := range subs { - log.Logf("Unsubscribing %s from topic: %s", node.Id, sub.Topic()) + log.Infof("Unsubscribing %s from topic: %s", node.Id, sub.Topic()) sub.Unsubscribe() } s.subscribers[sb] = nil @@ -760,7 +760,7 @@ func (s *rpcServer) Start() error { return err } - log.Logf("Transport [%s] Listening on %s", config.Transport.String(), ts.Addr()) + log.Infof("Transport [%s] Listening on %s", config.Transport.String(), ts.Addr()) // swap address s.Lock() @@ -775,15 +775,15 @@ func (s *rpcServer) Start() error { bname := config.Broker.String() - log.Logf("Broker [%s] Connected to %s", bname, config.Broker.Address()) + log.Infof("Broker [%s] Connected to %s", bname, config.Broker.Address()) // use RegisterCheck func before register if err = s.opts.RegisterCheck(s.opts.Context); err != nil { - log.Logf("Server %s-%s register check error: %s", config.Name, config.Id, err) + log.Errorf("Server %s-%s register check error: %s", config.Name, config.Id, err) } else { // announce self to the world if err = s.Register(); err != nil { - log.Logf("Server %s-%s register error: %s", config.Name, config.Id, err) + log.Errorf("Server %s-%s register error: %s", config.Name, config.Id, err) } } @@ -804,7 +804,7 @@ func (s *rpcServer) Start() error { // check the error and backoff default: if err != nil { - log.Logf("Accept error: %v", err) + log.Errorf("Accept error: %v", err) time.Sleep(time.Second) continue } @@ -837,17 +837,17 @@ func (s *rpcServer) Start() error { s.RUnlock() rerr := s.opts.RegisterCheck(s.opts.Context) if rerr != nil && registered { - log.Logf("Server %s-%s register check error: %s, deregister it", config.Name, config.Id, err) + log.Errorf("Server %s-%s register check error: %s, deregister it", config.Name, config.Id, err) // deregister self in case of error if err := s.Deregister(); err != nil { - log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err) + log.Errorf("Server %s-%s deregister error: %s", config.Name, config.Id, err) } } else if rerr != nil && !registered { - log.Logf("Server %s-%s register check error: %s", config.Name, config.Id, err) + log.Errorf("Server %s-%s register check error: %s", config.Name, config.Id, err) continue } if err := s.Register(); err != nil { - log.Logf("Server %s-%s register error: %s", config.Name, config.Id, err) + log.Errorf("Server %s-%s register error: %s", config.Name, config.Id, err) } // wait for exit case ch = <-s.exit: @@ -863,7 +863,7 @@ func (s *rpcServer) Start() error { if registered { // deregister self if err := s.Deregister(); err != nil { - log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err) + log.Errorf("Server %s-%s deregister error: %s", config.Name, config.Id, err) } } @@ -879,7 +879,7 @@ func (s *rpcServer) Start() error { // close transport listener ch <- ts.Close() - log.Logf("Broker [%s] Disconnected from %s", bname, config.Broker.Address()) + log.Infof("Broker [%s] Disconnected from %s", bname, config.Broker.Address()) // disconnect the broker config.Broker.Disconnect() diff --git a/server/server.go b/server/server.go index a45dd8d0..e11bc14d 100644 --- a/server/server.go +++ b/server/server.go @@ -10,8 +10,8 @@ import ( "github.com/google/uuid" "github.com/micro/go-micro/v2/codec" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" - log "github.com/micro/go-micro/v2/util/log" ) // Server is a simple micro server abstraction @@ -200,7 +200,7 @@ func Run() error { ch := make(chan os.Signal, 1) signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT) - log.Logf("Received signal %s", <-ch) + log.Infof("Received signal %s", <-ch) return Stop() } @@ -208,13 +208,13 @@ func Run() error { // Start starts the default server func Start() error { config := DefaultServer.Options() - log.Logf("Starting server %s id %s", config.Name, config.Id) + log.Infof("Starting server %s id %s", config.Name, config.Id) return DefaultServer.Start() } // Stop stops the default server func Stop() error { - log.Logf("Stopping server") + log.Infof("Stopping server") return DefaultServer.Stop() } diff --git a/service.go b/service.go index 678925d9..90fdd8ca 100644 --- a/service.go +++ b/service.go @@ -17,9 +17,9 @@ import ( "github.com/micro/go-micro/v2/debug/service/handler" "github.com/micro/go-micro/v2/debug/stats" "github.com/micro/go-micro/v2/debug/trace" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/plugin" "github.com/micro/go-micro/v2/server" - "github.com/micro/go-micro/v2/util/log" "github.com/micro/go-micro/v2/util/wrapper" ) @@ -202,7 +202,7 @@ func (s *service) Run() error { defer profiler.Stop() } - log.Logf("Starting [service] %s", s.Name()) + log.Infof("Starting [service] %s", s.Name()) if err := s.Start(); err != nil { return err diff --git a/service_test.go b/service_test.go index 3c97c6a0..0c3d1829 100644 --- a/service_test.go +++ b/service_test.go @@ -7,10 +7,8 @@ import ( "testing" "github.com/micro/go-micro/v2/client" - "github.com/micro/go-micro/v2/debug/log/noop" proto "github.com/micro/go-micro/v2/debug/service/proto" "github.com/micro/go-micro/v2/registry/memory" - "github.com/micro/go-micro/v2/util/log" "github.com/micro/go-micro/v2/util/test" ) @@ -24,9 +22,6 @@ func testShutdown(wg *sync.WaitGroup, cancel func()) { } func testService(ctx context.Context, wg *sync.WaitGroup, name string) Service { - // set no op logger - log.SetLogger(noop.NewLog()) - // add self wg.Add(1) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index faaf9e2a..0e0dc38e 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -10,8 +10,8 @@ import ( "unicode" "github.com/lib/pq" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/store" - "github.com/micro/go-micro/v2/util/log" "github.com/pkg/errors" ) diff --git a/sync/cron.go b/sync/cron.go index bc3133b6..caf51e71 100644 --- a/sync/cron.go +++ b/sync/cron.go @@ -5,10 +5,10 @@ import ( "math" "time" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/sync/leader/etcd" "github.com/micro/go-micro/v2/sync/task" "github.com/micro/go-micro/v2/sync/task/local" - "github.com/micro/go-micro/v2/util/log" ) type syncCron struct { @@ -35,7 +35,7 @@ func (c *syncCron) Schedule(s task.Schedule, t task.Command) error { // leader election e, err := c.opts.Leader.Elect(id) if err != nil { - log.Logf("[cron] leader election error: %v", err) + log.Errorf("[cron] leader election error: %v", err) time.Sleep(backoff(i)) i++ continue @@ -55,9 +55,9 @@ func (c *syncCron) Schedule(s task.Schedule, t task.Command) error { break Tick } - log.Logf("[cron] executing command %s", t.Name) + log.Infof("[cron] executing command %s", t.Name) if err := c.opts.Task.Run(t); err != nil { - log.Logf("[cron] error executing command %s: %v", t.Name, err) + log.Errorf("[cron] error executing command %s: %v", t.Name, err) } // leader revoked case <-r: diff --git a/transport/grpc/handler.go b/transport/grpc/handler.go index ce3690f3..d5a626a0 100644 --- a/transport/grpc/handler.go +++ b/transport/grpc/handler.go @@ -4,9 +4,9 @@ import ( "runtime/debug" "github.com/micro/go-micro/v2/errors" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/transport" pb "github.com/micro/go-micro/v2/transport/grpc/proto" - "github.com/micro/go-micro/v2/util/log" "google.golang.org/grpc/peer" ) @@ -30,7 +30,7 @@ func (m *microTransport) Stream(ts pb.Transport_StreamServer) (err error) { defer func() { if r := recover(); r != nil { - log.Log(r, string(debug.Stack())) + log.Error(r, string(debug.Stack())) sock.Close() err = errors.InternalServerError("go.micro.transport", "panic recovered: %v", r) } diff --git a/tunnel/default.go b/tunnel/default.go index 0bde3bde..523d1978 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -8,8 +8,8 @@ import ( "time" "github.com/google/uuid" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/transport" - "github.com/micro/go-micro/v2/util/log" ) var ( @@ -949,7 +949,7 @@ func (t *tun) connect() error { // still connected but the tunnel died if err != nil && t.connected { - log.Logf("Tunnel listener died: %v", err) + log.Errorf("Tunnel listener died: %v", err) } }() diff --git a/tunnel/link.go b/tunnel/link.go index 3df54cc5..e698a280 100644 --- a/tunnel/link.go +++ b/tunnel/link.go @@ -8,8 +8,8 @@ import ( "time" "github.com/google/uuid" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/transport" - "github.com/micro/go-micro/v2/util/log" ) type link struct { diff --git a/tunnel/listener.go b/tunnel/listener.go index ac5ba3dc..3aff7b85 100644 --- a/tunnel/listener.go +++ b/tunnel/listener.go @@ -4,7 +4,7 @@ import ( "io" "sync" - "github.com/micro/go-micro/v2/util/log" + log "github.com/micro/go-micro/v2/logger" ) type tunListener struct { diff --git a/tunnel/session.go b/tunnel/session.go index f662b1df..fc5b9be9 100644 --- a/tunnel/session.go +++ b/tunnel/session.go @@ -5,8 +5,8 @@ import ( "io" "time" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/transport" - "github.com/micro/go-micro/v2/util/log" ) // session is our pseudo session for transport.Socket diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 01bf48cc..1e702a32 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -12,8 +12,8 @@ import ( "path" "strings" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/util/kubernetes/api" - "github.com/micro/go-micro/v2/util/log" ) var ( diff --git a/util/log/README.md b/util/log/README.md deleted file mode 100644 index b5b9c5df..00000000 --- a/util/log/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Log - -This is the global logger for all micro based libraries. - -## Set Logger - -Set the logger for micro libraries - -```go -// import go-micro/util/log -import "github.com/micro/go-micro/util/log" - -// SetLogger expects github.com/micro/go-micro/debug/log.Log interface -log.SetLogger(mylogger) -``` diff --git a/util/log/log.go b/util/log/log.go deleted file mode 100644 index 67c3b75c..00000000 --- a/util/log/log.go +++ /dev/null @@ -1,206 +0,0 @@ -// Package log is a global internal logger -package log - -import ( - "fmt" - "os" - "sync/atomic" - "time" - - "github.com/micro/go-micro/v2/debug/log" -) - -// level is a log level -type Level int32 - -const ( - LevelFatal Level = iota - LevelError - LevelWarn - LevelInfo - LevelDebug - LevelTrace -) - -var ( - // the local logger - logger log.Log = log.DefaultLog - - // default log level is info - level = LevelInfo - - // prefix for all messages - prefix string -) - -func init() { - switch os.Getenv("MICRO_LOG_LEVEL") { - case "trace": - level = LevelTrace - case "debug": - level = LevelDebug - case "warn": - level = LevelWarn - case "info": - level = LevelInfo - case "error": - level = LevelError - case "fatal": - level = LevelFatal - } -} - -func (l Level) String() string { - switch l { - case LevelTrace: - return "trace" - case LevelDebug: - return "debug" - case LevelWarn: - return "warn" - case LevelInfo: - return "info" - case LevelError: - return "error" - case LevelFatal: - return "fatal" - default: - return "unknown" - } -} - -// Log makes use of github.com/micro/debug/log -func Log(v ...interface{}) { - if len(prefix) > 0 { - v = append([]interface{}{prefix, " "}, v...) - } - logger.Write(log.Record{ - Timestamp: time.Now(), - Message: fmt.Sprint(v...), - Metadata: map[string]string{ - "level": level.String(), - }, - }) -} - -// Logf makes use of github.com/micro/debug/log -func Logf(format string, v ...interface{}) { - if len(prefix) > 0 { - format = prefix + " " + format - } - logger.Write(log.Record{ - Timestamp: time.Now(), - Message: fmt.Sprintf(format, v...), - Metadata: map[string]string{ - "level": level.String(), - }, - }) -} - -// WithLevel logs with the level specified -func WithLevel(l Level, v ...interface{}) { - if l > level { - return - } - Log(v...) -} - -// WithLevel logs with the level specified -func WithLevelf(l Level, format string, v ...interface{}) { - if l > level { - return - } - Logf(format, v...) -} - -// Trace provides trace level logging -func Trace(v ...interface{}) { - WithLevel(LevelTrace, v...) -} - -// Tracef provides trace level logging -func Tracef(format string, v ...interface{}) { - WithLevelf(LevelTrace, format, v...) -} - -// Debug provides debug level logging -func Debug(v ...interface{}) { - WithLevel(LevelDebug, v...) -} - -// Debugf provides debug level logging -func Debugf(format string, v ...interface{}) { - WithLevelf(LevelDebug, format, v...) -} - -// Warn provides warn level logging -func Warn(v ...interface{}) { - WithLevel(LevelWarn, v...) -} - -// Warnf provides warn level logging -func Warnf(format string, v ...interface{}) { - WithLevelf(LevelWarn, format, v...) -} - -// Info provides info level logging -func Info(v ...interface{}) { - WithLevel(LevelInfo, v...) -} - -// Infof provides info level logging -func Infof(format string, v ...interface{}) { - WithLevelf(LevelInfo, format, v...) -} - -// Error provides warn level logging -func Error(v ...interface{}) { - WithLevel(LevelError, v...) -} - -// Errorf provides warn level logging -func Errorf(format string, v ...interface{}) { - WithLevelf(LevelError, format, v...) -} - -// Fatal logs with Log and then exits with os.Exit(1) -func Fatal(v ...interface{}) { - WithLevel(LevelFatal, v...) - os.Exit(1) -} - -// Fatalf logs with Logf and then exits with os.Exit(1) -func Fatalf(format string, v ...interface{}) { - WithLevelf(LevelFatal, format, v...) - os.Exit(1) -} - -// SetLogger sets the local logger -func SetLogger(l log.Log) { - logger = l -} - -// GetLogger returns the local logger -func GetLogger() log.Log { - return logger -} - -// SetLevel sets the log level -func SetLevel(l Level) { - atomic.StoreInt32((*int32)(&level), int32(l)) -} - -// GetLevel returns the current level -func GetLevel() Level { - return level -} - -// Set a prefix for the logger -func SetPrefix(p string) { - prefix = p -} - -// Set service name -func Name(name string) { - prefix = fmt.Sprintf("[%s]", name) -} diff --git a/web/service.go b/web/service.go index aa351236..e9837892 100644 --- a/web/service.go +++ b/web/service.go @@ -16,10 +16,10 @@ import ( "github.com/micro/cli/v2" "github.com/micro/go-micro/v2" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" maddr "github.com/micro/go-micro/v2/util/addr" mhttp "github.com/micro/go-micro/v2/util/http" - "github.com/micro/go-micro/v2/util/log" mnet "github.com/micro/go-micro/v2/util/net" mls "github.com/micro/go-micro/v2/util/tls" ) @@ -126,7 +126,7 @@ func (s *service) register() error { // use RegisterCheck func before register if err := s.opts.RegisterCheck(s.opts.Context); err != nil { - log.Logf("Server %s-%s register check error: %s", s.opts.Name, s.opts.Id, err) + log.Errorf("Server %s-%s register check error: %s", s.opts.Name, s.opts.Id, err) return err } @@ -185,7 +185,7 @@ func (s *service) start() error { if s.static { _, err := os.Stat(static) if err == nil { - log.Logf("Enabling static file serving from %s", static) + log.Infof("Enabling static file serving from %s", static) s.mux.Handle("/", http.FileServer(http.Dir(static))) } } @@ -223,7 +223,7 @@ func (s *service) start() error { ch <- l.Close() }() - log.Logf("Listening on %v", l.Addr().String()) + log.Infof("Listening on %v", l.Addr().String()) return nil } @@ -245,7 +245,7 @@ func (s *service) stop() error { s.exit <- ch s.running = false - log.Log("Stopping") + log.Info("Stopping") for _, fn := range s.opts.AfterStop { if err := fn(); err != nil { @@ -392,10 +392,10 @@ func (s *service) Run() error { select { // wait on kill signal case sig := <-ch: - log.Logf("Received signal %s", sig) + log.Infof("Received signal %s", sig) // wait on context cancel case <-s.opts.Context.Done(): - log.Logf("Received context shutdown") + log.Info("Received context shutdown") } // exit reg loop From 915c4242132874704e8a1ccbf1a6cdcbcd4daa7d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 23 Feb 2020 15:57:21 +0000 Subject: [PATCH 311/788] Add docker build (#1239) --- .github/workflows/docker.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..552d23b1 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,19 @@ +name: Docker + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + name: Check out repository + - uses: elgohr/Publish-Docker-Github-Action@2.12 + name: Build and Push Docker Image + with: + name: micro/go-micro + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} From 1f767ba18c3f9a57b19cfd366a79630c05a3e83e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 23 Feb 2020 23:47:44 +0300 Subject: [PATCH 312/788] update go modules (#1240) Signed-off-by: Vasiliy Tolstov --- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index baceb3ac..3e58e15b 100644 --- a/go.mod +++ b/go.mod @@ -37,12 +37,12 @@ require ( github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 - github.com/mholt/certmagic v0.9.1 - github.com/micro/cli/v2 v2.1.2-0.20200203150404-894195727d9c + github.com/mholt/certmagic v0.9.3 + github.com/micro/cli/v2 v2.1.2 github.com/micro/mdns v0.3.0 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 - github.com/nats-io/nats-server/v2 v2.1.2 + github.com/nats-io/nats-server/v2 v2.1.4 github.com/nats-io/nats.go v1.9.1 github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c @@ -54,8 +54,8 @@ require ( github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect go.etcd.io/bbolt v1.3.3 // indirect go.uber.org/zap v1.13.0 - golang.org/x/crypto v0.0.0-20200117160349-530e935923ad - golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa + golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d + golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 // indirect google.golang.org/grpc v1.26.0 gopkg.in/go-playground/assert.v1 v1.2.1 // indirect diff --git a/go.sum b/go.sum index 2bda9337..d18b6af8 100644 --- a/go.sum +++ b/go.sum @@ -280,10 +280,10 @@ github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mholt/certmagic v0.9.1 h1:wPzyouOyE+30NIQETJuhTB5ZQWz+0Hy038vaR5WWQDE= -github.com/mholt/certmagic v0.9.1/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= -github.com/micro/cli/v2 v2.1.2-0.20200203150404-894195727d9c h1:oohy8v2QQeXfDe9/BaM0b+5wETzoMiemOs3fhPhnFTg= -github.com/micro/cli/v2 v2.1.2-0.20200203150404-894195727d9c/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= +github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU= +github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= +github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= +github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= @@ -309,8 +309,8 @@ github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server/v2 v2.1.2 h1:i2Ly0B+1+rzNZHHWtD4ZwKi+OU5l+uQo1iDHZ2PmiIc= -github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= +github.com/nats-io/nats-server/v2 v2.1.4 h1:BILRnsJ2Yb/fefiFbBWADpViGF69uh4sxe8poVDQ06g= +github.com/nats-io/nats-server/v2 v2.1.4/go.mod h1:Jw1Z28soD/QasIA2uWjXyM9El1jly3YwyFOuR8tH1rg= github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= @@ -457,8 +457,8 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg= -golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw= +golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -502,8 +502,8 @@ golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 h1:MsuvTghUPjX762sGLnGsxC3HM0B5r83wEtYcYR8/vRs= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= From cf0b39eaacb8f3323e2e85c9784f9347000746eb Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 24 Feb 2020 16:07:40 +0300 Subject: [PATCH 313/788] logger fixes (#1244) * logger: fix race conditions Signed-off-by: Vasiliy Tolstov * restore util/log for compatibility Signed-off-by: Vasiliy Tolstov --- logger/default.go | 39 ++++++-- util/log/README.md | 17 ++++ util/log/log.go | 227 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 275 insertions(+), 8 deletions(-) create mode 100644 util/log/README.md create mode 100644 util/log/log.go diff --git a/logger/default.go b/logger/default.go index 3369f64e..6fa2b009 100644 --- a/logger/default.go +++ b/logger/default.go @@ -4,12 +4,14 @@ import ( "context" "fmt" "os" + "sync" "time" dlog "github.com/micro/go-micro/v2/debug/log" ) type defaultLogger struct { + sync.RWMutex opts Options err error } @@ -27,31 +29,46 @@ func (l *defaultLogger) String() string { } func (l *defaultLogger) Fields(fields map[string]interface{}) Logger { - l.opts.Fields = fields + l.Lock() + l.opts.Fields = copyFields(fields) + l.Unlock() return l } func (l *defaultLogger) Error(err error) Logger { + l.Lock() l.err = err + l.Unlock() return l } +func copyFields(src map[string]interface{}) map[string]interface{} { + dst := make(map[string]interface{}, len(src)) + for k, v := range src { + dst[k] = v + } + return dst +} + func (l *defaultLogger) Log(level Level, v ...interface{}) { // TODO decide does we need to write message if log level not used? if !l.opts.Level.Enabled(level) { return } - fields := l.opts.Fields - fields["level"] = level.String() + l.RLock() + fields := copyFields(l.opts.Fields) if l.err != nil { fields["error"] = l.err.Error() } + l.RUnlock() + + fields["level"] = level.String() rec := dlog.Record{ Timestamp: time.Now(), Message: fmt.Sprint(v...), - Metadata: make(map[string]string), + Metadata: make(map[string]string, len(fields)), } for k, v := range fields { rec.Metadata[k] = fmt.Sprintf("%v", v) @@ -69,16 +86,19 @@ func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) { return } - fields := l.opts.Fields - fields["level"] = level.String() + l.RLock() + fields := copyFields(l.opts.Fields) if l.err != nil { fields["error"] = l.err.Error() } + l.RUnlock() + + fields["level"] = level.String() rec := dlog.Record{ Timestamp: time.Now(), Message: fmt.Sprintf(format, v...), - Metadata: make(map[string]string), + Metadata: make(map[string]string, len(fields)), } for k, v := range fields { rec.Metadata[k] = fmt.Sprintf("%v", v) @@ -105,6 +125,9 @@ func NewLogger(opts ...Option) Logger { } l := &defaultLogger{opts: options} - _ = l.Init(opts...) + if err := l.Init(opts...); err != nil { + l.Log(FatalLevel, err) + } + return l } diff --git a/util/log/README.md b/util/log/README.md new file mode 100644 index 00000000..97ddacf3 --- /dev/null +++ b/util/log/README.md @@ -0,0 +1,17 @@ +# Log + +DEPRECATED: use github.com/micro/go-micro/v2/logger interface + +This is the global logger for all micro based libraries. + +## Set Logger + +Set the logger for micro libraries + +```go +// import go-micro/util/log +import "github.com/micro/go-micro/util/log" + +// SetLogger expects github.com/micro/go-micro/debug/log.Log interface +log.SetLogger(mylogger) +``` diff --git a/util/log/log.go b/util/log/log.go new file mode 100644 index 00000000..16e5cd83 --- /dev/null +++ b/util/log/log.go @@ -0,0 +1,227 @@ +// Package log is a global internal logger +// DEPRECATED: this is frozen package, use github.com/micro/go-micro/v2/logger +package log + +import ( + "fmt" + "os" + "sync/atomic" + + dlog "github.com/micro/go-micro/v2/debug/log" + nlog "github.com/micro/go-micro/v2/logger" +) + +// level is a log level +type Level int32 + +const ( + LevelFatal Level = iota + LevelError + LevelWarn + LevelInfo + LevelDebug + LevelTrace +) + +type elog struct { + dlog dlog.Log +} + +var ( + // the local logger + logger dlog.Log = &elog{} + + // default log level is info + level = LevelInfo + + // prefix for all messages + prefix string +) + +func levelToLevel(l Level) nlog.Level { + switch l { + case LevelTrace: + return nlog.TraceLevel + case LevelDebug: + return nlog.DebugLevel + case LevelWarn: + return nlog.WarnLevel + case LevelInfo: + return nlog.InfoLevel + case LevelError: + return nlog.ErrorLevel + case LevelFatal: + return nlog.FatalLevel + } + return nlog.InfoLevel +} + +func init() { + switch os.Getenv("MICRO_LOG_LEVEL") { + case "trace": + level = LevelTrace + case "debug": + level = LevelDebug + case "warn": + level = LevelWarn + case "info": + level = LevelInfo + case "error": + level = LevelError + case "fatal": + level = LevelFatal + } +} + +func (l Level) String() string { + switch l { + case LevelTrace: + return "trace" + case LevelDebug: + return "debug" + case LevelWarn: + return "warn" + case LevelInfo: + return "info" + case LevelError: + return "error" + case LevelFatal: + return "fatal" + default: + return "unknown" + } +} + +func (el *elog) Read(opt ...dlog.ReadOption) ([]dlog.Record, error) { + return el.dlog.Read(opt...) +} + +func (el *elog) Write(r dlog.Record) error { + return el.dlog.Write(r) +} + +func (el *elog) Stream() (dlog.Stream, error) { + return el.dlog.Stream() +} + +// Log makes use of github.com/micro/debug/log +func Log(v ...interface{}) { + if len(prefix) > 0 { + v = append([]interface{}{prefix, " "}, v...) + } + nlog.DefaultLogger.Log(levelToLevel(level), v) +} + +// Logf makes use of github.com/micro/debug/log +func Logf(format string, v ...interface{}) { + if len(prefix) > 0 { + format = prefix + " " + format + } + nlog.DefaultLogger.Log(levelToLevel(level), format, v) +} + +// WithLevel logs with the level specified +func WithLevel(l Level, v ...interface{}) { + if l > level { + return + } + Log(v...) +} + +// WithLevel logs with the level specified +func WithLevelf(l Level, format string, v ...interface{}) { + if l > level { + return + } + Logf(format, v...) +} + +// Trace provides trace level logging +func Trace(v ...interface{}) { + WithLevel(LevelTrace, v...) +} + +// Tracef provides trace level logging +func Tracef(format string, v ...interface{}) { + WithLevelf(LevelTrace, format, v...) +} + +// Debug provides debug level logging +func Debug(v ...interface{}) { + WithLevel(LevelDebug, v...) +} + +// Debugf provides debug level logging +func Debugf(format string, v ...interface{}) { + WithLevelf(LevelDebug, format, v...) +} + +// Warn provides warn level logging +func Warn(v ...interface{}) { + WithLevel(LevelWarn, v...) +} + +// Warnf provides warn level logging +func Warnf(format string, v ...interface{}) { + WithLevelf(LevelWarn, format, v...) +} + +// Info provides info level logging +func Info(v ...interface{}) { + WithLevel(LevelInfo, v...) +} + +// Infof provides info level logging +func Infof(format string, v ...interface{}) { + WithLevelf(LevelInfo, format, v...) +} + +// Error provides warn level logging +func Error(v ...interface{}) { + WithLevel(LevelError, v...) +} + +// Errorf provides warn level logging +func Errorf(format string, v ...interface{}) { + WithLevelf(LevelError, format, v...) +} + +// Fatal logs with Log and then exits with os.Exit(1) +func Fatal(v ...interface{}) { + WithLevel(LevelFatal, v...) +} + +// Fatalf logs with Logf and then exits with os.Exit(1) +func Fatalf(format string, v ...interface{}) { + WithLevelf(LevelFatal, format, v...) +} + +// SetLogger sets the local logger +func SetLogger(l dlog.Log) { + logger = l +} + +// GetLogger returns the local logger +func GetLogger() dlog.Log { + return logger +} + +// SetLevel sets the log level +func SetLevel(l Level) { + atomic.StoreInt32((*int32)(&level), int32(l)) +} + +// GetLevel returns the current level +func GetLevel() Level { + return level +} + +// Set a prefix for the logger +func SetPrefix(p string) { + prefix = p +} + +// Set service name +func Name(name string) { + prefix = fmt.Sprintf("[%s]", name) +} From 24d574ae71f694b2a873d78064fee1a08d8a9cba Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 24 Feb 2020 16:48:56 +0300 Subject: [PATCH 314/788] server/grpc: add MaxConn option to limit max inflight requests (#1247) Signed-off-by: Vasiliy Tolstov --- server/grpc/grpc.go | 20 ++++++++++++++------ server/grpc/options.go | 6 ++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 5b434200..2ee03bac 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -24,6 +24,7 @@ import ( "github.com/micro/go-micro/v2/util/addr" mgrpc "github.com/micro/go-micro/v2/util/grpc" mnet "github.com/micro/go-micro/v2/util/net" + "golang.org/x/net/netutil" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -163,13 +164,14 @@ func (g *grpcServer) getGrpcOptions() []grpc.ServerOption { } func (g *grpcServer) getListener() net.Listener { - if g.opts.Context != nil { - if v := g.opts.Context.Value(netListener{}); v != nil { - if l, ok := v.(net.Listener); ok { - return l - } - } + if g.opts.Context == nil { + return nil } + + if l, ok := g.opts.Context.Value(netListener{}).(net.Listener); ok && l != nil { + return l + } + return nil } @@ -799,6 +801,12 @@ func (g *grpcServer) Start() error { } } + if g.opts.Context != nil { + if c, ok := g.opts.Context.Value(maxConnKey{}).(int); ok && c > 0 { + ts = netutil.LimitListener(ts, c) + } + } + log.Infof("Server [grpc] Listening on %s", ts.Addr().String()) g.Lock() g.opts.Address = ts.Addr().String() diff --git a/server/grpc/options.go b/server/grpc/options.go index 64a8173d..5cd52cb0 100644 --- a/server/grpc/options.go +++ b/server/grpc/options.go @@ -18,6 +18,7 @@ type codecsKey struct{} type grpcOptions struct{} type netListener struct{} type maxMsgSizeKey struct{} +type maxConnKey struct{} type tlsAuth struct{} // gRPC Codec to be used to encode/decode requests for a given content type @@ -40,6 +41,11 @@ func AuthTLS(t *tls.Config) server.Option { return setServerOption(tlsAuth{}, t) } +// MaxConn specifies maximum number of max simultaneous connections to server +func MaxConn(n int) server.Option { + return setServerOption(maxConnKey{}, n) +} + // Listener specifies the net.Listener to use instead of the default func Listener(l net.Listener) server.Option { return setServerOption(netListener{}, l) From d467236f8ff719c2111afa4f8cd8d0da55bf8d01 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Mon, 24 Feb 2020 05:49:27 -0800 Subject: [PATCH 315/788] broker/nats: remove unused setPublishOption() (#1234) broker/nats: remove unused setSubscribeOption() --- broker/nats/context.go | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/broker/nats/context.go b/broker/nats/context.go index d4c1a3b0..8284b557 100644 --- a/broker/nats/context.go +++ b/broker/nats/context.go @@ -6,16 +6,6 @@ import ( "github.com/micro/go-micro/v2/broker" ) -// setSubscribeOption returns a function to setup a context with given value -func setSubscribeOption(k, v interface{}) broker.SubscribeOption { - return func(o *broker.SubscribeOptions) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, k, v) - } -} - // setBrokerOption returns a function to setup a context with given value func setBrokerOption(k, v interface{}) broker.Option { return func(o *broker.Options) { @@ -25,13 +15,3 @@ func setBrokerOption(k, v interface{}) broker.Option { o.Context = context.WithValue(o.Context, k, v) } } - -// setPublishOption returns a function to setup a context with given value -func setPublishOption(k, v interface{}) broker.PublishOption { - return func(o *broker.PublishOptions) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, k, v) - } -} From 01d88601c0293c12068c8631e2de34e58931e49d Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Mon, 24 Feb 2020 14:11:17 +0000 Subject: [PATCH 316/788] Split PR and merge tests (#1249) --- .github/workflows/pr.yml | 28 ++++++++++++++++++++++++++++ .github/workflows/tests.yml | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 00000000..6528e523 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,28 @@ +name: PR Sanity Check +on: pull_request + +jobs: + + prtest: + name: Test repo + runs-on: ubuntu-latest + steps: + + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Get dependencies + run: | + go get -v -t -d ./... + + - name: Run tests + id: tests + env: + IN_TRAVIS_CI: yes + run: go test -v ./... diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index afe896e9..8b108ca8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,5 +1,5 @@ name: Run tests -on: [push, pull_request] +on: [push] jobs: From 5b0175c2e5c475bb2500e485ef93e35fd9d1bb5a Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 24 Feb 2020 17:15:20 +0300 Subject: [PATCH 317/788] allocations improvements and tunnel fixes (#1248) * reduce allocations in tunnel code Signed-off-by: Vasiliy Tolstov * another allocation fix Signed-off-by: Vasiliy Tolstov * allocate maps with len if it known Signed-off-by: Vasiliy Tolstov * allocate key for send once Signed-off-by: Vasiliy Tolstov --- client/grpc/codec.go | 2 +- client/grpc/grpc.go | 13 +++++++++++-- client/grpc/response.go | 2 +- metadata/metadata.go | 2 +- registry/memory/util.go | 10 +++++----- server/grpc/codec.go | 2 +- server/grpc/subscriber.go | 2 +- server/rpc_server.go | 4 ++-- transport/http_transport.go | 10 +++++----- tunnel/crypto.go | 23 ++++++++++++++++++----- tunnel/default.go | 1 + tunnel/listener.go | 2 ++ tunnel/session.go | 16 +++++++++------- 13 files changed, 58 insertions(+), 31 deletions(-) diff --git a/client/grpc/codec.go b/client/grpc/codec.go index ff377690..0366675a 100644 --- a/client/grpc/codec.go +++ b/client/grpc/codec.go @@ -155,7 +155,7 @@ func (g *grpcCodec) ReadHeader(m *codec.Message, mt codec.MessageType) error { m = new(codec.Message) } if m.Header == nil { - m.Header = make(map[string]string) + m.Header = make(map[string]string, len(md)) } for k, v := range md { m.Header[k] = strings.Join(v, ",") diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 519b4450..0905eac9 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -110,13 +110,18 @@ func (g *grpcClient) next(request client.Request, opts client.CallOptions) (sele } func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.Request, rsp interface{}, opts client.CallOptions) error { + var header map[string]string + address := node.Address - header := make(map[string]string) + header = make(map[string]string) if md, ok := metadata.FromContext(ctx); ok { + header = make(map[string]string, len(md)) for k, v := range md { header[k] = v } + } else { + header = make(map[string]string) } // set timeout in nanoseconds @@ -182,13 +187,17 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R } func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client.Request, opts client.CallOptions) (client.Stream, error) { + var header map[string]string + address := node.Address - header := make(map[string]string) if md, ok := metadata.FromContext(ctx); ok { + header = make(map[string]string, len(md)) for k, v := range md { header[k] = v } + } else { + header = make(map[string]string) } // set timeout in nanoseconds diff --git a/client/grpc/response.go b/client/grpc/response.go index 5fd40169..cd4d319c 100644 --- a/client/grpc/response.go +++ b/client/grpc/response.go @@ -27,7 +27,7 @@ func (r *response) Header() map[string]string { if err != nil { return map[string]string{} } - hdr := make(map[string]string) + hdr := make(map[string]string, len(md)) for k, v := range md { hdr[k] = strings.Join(v, ",") } diff --git a/metadata/metadata.go b/metadata/metadata.go index c5fddd84..c41aa284 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -58,7 +58,7 @@ func FromContext(ctx context.Context) (Metadata, bool) { } // capitalise all values - newMD := make(map[string]string) + newMD := make(map[string]string, len(md)) for k, v := range md { newMD[strings.Title(k)] = v } diff --git a/registry/memory/util.go b/registry/memory/util.go index 32a3852d..69cfc8de 100644 --- a/registry/memory/util.go +++ b/registry/memory/util.go @@ -7,12 +7,12 @@ import ( ) func serviceToRecord(s *registry.Service, ttl time.Duration) *record { - metadata := make(map[string]string) + metadata := make(map[string]string, len(s.Metadata)) for k, v := range s.Metadata { metadata[k] = v } - nodes := make(map[string]*node) + nodes := make(map[string]*node, len(s.Nodes)) for _, n := range s.Nodes { nodes[n.Id] = &node{ Node: n, @@ -36,7 +36,7 @@ func serviceToRecord(s *registry.Service, ttl time.Duration) *record { } func recordToService(r *record) *registry.Service { - metadata := make(map[string]string) + metadata := make(map[string]string, len(r.Metadata)) for k, v := range r.Metadata { metadata[k] = v } @@ -52,7 +52,7 @@ func recordToService(r *record) *registry.Service { *response = *e.Response } - metadata := make(map[string]string) + metadata := make(map[string]string, len(e.Metadata)) for k, v := range e.Metadata { metadata[k] = v } @@ -68,7 +68,7 @@ func recordToService(r *record) *registry.Service { nodes := make([]*registry.Node, len(r.Nodes)) i := 0 for _, n := range r.Nodes { - metadata := make(map[string]string) + metadata := make(map[string]string, len(n.Metadata)) for k, v := range n.Metadata { metadata[k] = v } diff --git a/server/grpc/codec.go b/server/grpc/codec.go index eb1b09c5..db9706d0 100644 --- a/server/grpc/codec.go +++ b/server/grpc/codec.go @@ -140,7 +140,7 @@ func (g *grpcCodec) ReadHeader(m *codec.Message, mt codec.MessageType) error { m = new(codec.Message) } if m.Header == nil { - m.Header = make(map[string]string) + m.Header = make(map[string]string, len(md)) } for k, v := range md { m.Header[k] = strings.Join(v, ",") diff --git a/server/grpc/subscriber.go b/server/grpc/subscriber.go index 7bd39a5f..a29ebcba 100644 --- a/server/grpc/subscriber.go +++ b/server/grpc/subscriber.go @@ -188,7 +188,7 @@ func (g *grpcServer) createSubHandler(sb *subscriber, opts server.Options) broke return err } - hdr := make(map[string]string) + hdr := make(map[string]string, len(msg.Header)) for k, v := range msg.Header { hdr[k] = v } diff --git a/server/rpc_server.go b/server/rpc_server.go index a692573a..eb079883 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -85,7 +85,7 @@ func (s *rpcServer) HandleEvent(e broker.Event) error { } // copy headers - hdr := make(map[string]string) + hdr := make(map[string]string, len(msg.Header)) for k, v := range msg.Header { hdr[k] = v } @@ -262,7 +262,7 @@ func (s *rpcServer) ServeConn(sock transport.Socket) { ct := msg.Header["Content-Type"] // copy the message headers - hdr := make(map[string]string) + hdr := make(map[string]string, len(msg.Header)) for k, v := range msg.Header { hdr[k] = v } diff --git a/transport/http_transport.go b/transport/http_transport.go index ced00c13..3e8bce8b 100644 --- a/transport/http_transport.go +++ b/transport/http_transport.go @@ -156,7 +156,7 @@ func (h *httpTransportClient) Recv(m *Message) error { m.Body = b if m.Header == nil { - m.Header = make(map[string]string) + m.Header = make(map[string]string, len(rsp.Header)) } for k, v := range rsp.Header { @@ -193,10 +193,6 @@ func (h *httpTransportSocket) Recv(m *Message) error { return errors.New("message passed in is nil") } - if m.Header == nil { - m.Header = make(map[string]string) - } - // process http 1 if h.r.ProtoMajor == 1 { // set timeout if its greater than 0 @@ -228,6 +224,10 @@ func (h *httpTransportSocket) Recv(m *Message) error { r.Body.Close() m.Body = b + if m.Header == nil { + m.Header = make(map[string]string, len(r.Header)) + } + // set headers for k, v := range r.Header { if len(v) > 0 { diff --git a/tunnel/crypto.go b/tunnel/crypto.go index 9f9f45af..e7f5a2f0 100644 --- a/tunnel/crypto.go +++ b/tunnel/crypto.go @@ -5,7 +5,16 @@ import ( "crypto/cipher" "crypto/rand" "crypto/sha256" - "io" + + "github.com/oxtoacart/bpool" +) + +var ( + // the local buffer pool + // gcmStandardNonceSize from crypto/cipher/gcm.go is 12 bytes + // 100 - is max size of pool + noncePool = bpool.NewBytePool(100, 12) + hashPool = bpool.NewBytePool(1024*32, 32) ) // hash hahes the data into 32 bytes key and returns it @@ -13,7 +22,10 @@ import ( func hash(key string) []byte { hasher := sha256.New() hasher.Write([]byte(key)) - return hasher.Sum(nil) + out := hashPool.Get() + defer hashPool.Put(out[:0]) + out = hasher.Sum(out[:0]) + return out } // Encrypt encrypts data and returns the encrypted data @@ -32,12 +44,13 @@ func Encrypt(data []byte, key string) ([]byte, error) { return nil, err } - // create a new byte array the size of the nonce + // get new byte array the size of the nonce from pool // NOTE: we might use smaller nonce size in the future - nonce := make([]byte, gcm.NonceSize()) - if _, err = io.ReadFull(rand.Reader, nonce); err != nil { + nonce := noncePool.Get() + if _, err = rand.Read(nonce); err != nil { return nil, err } + defer noncePool.Put(nonce) // NOTE: we prepend the nonce to the payload // we need to do this as we need the same nonce diff --git a/tunnel/default.go b/tunnel/default.go index 523d1978..398f52ad 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -131,6 +131,7 @@ func (t *tun) newSession(channel, sessionId string) (*session, bool) { recv: make(chan *message, 128), send: t.send, errChan: make(chan error, 1), + key: t.token + channel + sessionId, } // save session diff --git a/tunnel/listener.go b/tunnel/listener.go index 3aff7b85..4e35360b 100644 --- a/tunnel/listener.go +++ b/tunnel/listener.go @@ -77,6 +77,8 @@ func (t *tunListener) process() { // create a new session session sess = &session{ + // the session key + key: t.token + m.channel + sessionId, // the id of the remote side tunnel: m.tunnel, // the channel diff --git a/tunnel/session.go b/tunnel/session.go index fc5b9be9..6dd90a3d 100644 --- a/tunnel/session.go +++ b/tunnel/session.go @@ -47,6 +47,8 @@ type session struct { link string // the error response errChan chan error + // key for session encryption + key string } // message is sent over the send channel @@ -326,22 +328,22 @@ func (s *session) Announce() error { // Send is used to send a message func (s *session) Send(m *transport.Message) error { // encrypt the transport message payload - body, err := Encrypt(m.Body, s.token+s.channel+s.session) + body, err := Encrypt(m.Body, s.key) if err != nil { log.Debugf("failed to encrypt message body: %v", err) return err } - // make copy + // make copy, without rehash and realloc data := &transport.Message{ - Header: make(map[string]string), + Header: make(map[string]string, len(m.Header)), Body: body, } // encrypt all the headers for k, v := range m.Header { // encrypt the transport message payload - val, err := Encrypt([]byte(v), s.token+s.channel+s.session) + val, err := Encrypt([]byte(v), s.key) if err != nil { log.Debugf("failed to encrypt message header %s: %v", k, err) return err @@ -387,14 +389,14 @@ func (s *session) Recv(m *transport.Message) error { default: } - //log.Tracef("Received %+v from recv backlog", msg) log.Tracef("Received %+v from recv backlog", msg) + key := s.token + s.channel + msg.session // decrypt the received payload using the token // we have to used msg.session because multicast has a shared // session id of "multicast" in this session struct on // the listener side - body, err := Decrypt(msg.data.Body, s.token+s.channel+msg.session) + body, err := Decrypt(msg.data.Body, key) if err != nil { log.Debugf("failed to decrypt message body: %v", err) return err @@ -410,7 +412,7 @@ func (s *session) Recv(m *transport.Message) error { return err } // encrypt the transport message payload - val, err := Decrypt([]byte(h), s.token+s.channel+msg.session) + val, err := Decrypt([]byte(h), key) if err != nil { log.Debugf("failed to decrypt message header %s: %v", k, err) return err From 56f8115ea8f203c52af7834f8f1ffb66e64777cb Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Mon, 24 Feb 2020 14:16:51 +0000 Subject: [PATCH 318/788] Rename PR job (#1250) --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 6528e523..59c4c27a 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -4,7 +4,7 @@ on: pull_request jobs: prtest: - name: Test repo + name: PR sanity check runs-on: ubuntu-latest steps: From ffdf986aac4e71233e62fcd736b57da6c785ad85 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 24 Feb 2020 15:07:27 +0000 Subject: [PATCH 319/788] Refactor auth: add token and store implementations (#1230) * Refactor auth: add token and memory implementations * Fix typo * Remove memory auth (implemented already by the store implementation), revert default to noop * Add grpc header * Global Config * config/global => util/config * Rename package to remove confict * Tweak * Improve Error Handling --- auth/default.go | 57 +++++++++---------- auth/store/store.go | 128 ++++++++++++++++++++++++++++++++++++++++++ client/grpc/grpc.go | 5 ++ config/cmd/cmd.go | 2 + go.sum | 1 + util/config/config.go | 88 +++++++++++++++++++++++++++++ 6 files changed, 251 insertions(+), 30 deletions(-) create mode 100644 auth/store/store.go create mode 100644 util/config/config.go diff --git a/auth/default.go b/auth/default.go index 8213fc05..0fe97dfc 100644 --- a/auth/default.go +++ b/auth/default.go @@ -1,39 +1,36 @@ package auth var ( - DefaultAuth Auth = new(noop) + DefaultAuth = NewAuth() ) -type noop struct { - options Options +// NewAuth returns a new default registry which is noop +func NewAuth(opts ...Option) Auth { + return noop{} } -// String name of implementation -func (a *noop) String() string { +type noop struct{} + +func (noop) Init(opts ...Option) error { + return nil +} + +func (noop) Options() Options { + return Options{} +} + +func (noop) Generate(id string, opts ...GenerateOption) (*Account, error) { + return nil, nil +} + +func (noop) Revoke(token string) error { + return nil +} + +func (noop) Validate(token string) (*Account, error) { + return nil, nil +} + +func (noop) String() string { return "noop" } - -// Init the svc -func (a *noop) Init(...Option) error { - return nil -} - -// Options set in init -func (a *noop) Options() Options { - return a.options -} - -// Generate a new auth Account -func (a *noop) Generate(id string, ops ...GenerateOption) (*Account, error) { - return nil, nil -} - -// Revoke an authorization Account -func (a *noop) Revoke(token string) error { - return nil -} - -// Validate a account token -func (a *noop) Validate(token string) (*Account, error) { - return nil, nil -} diff --git a/auth/store/store.go b/auth/store/store.go new file mode 100644 index 00000000..d53e7a14 --- /dev/null +++ b/auth/store/store.go @@ -0,0 +1,128 @@ +package store + +import ( + "bytes" + "encoding/gob" + "time" + + "github.com/google/uuid" + "github.com/micro/go-micro/v2/auth" + + "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/store" +) + +// NewAuth returns an instance of store auth +func NewAuth(opts ...auth.Option) auth.Auth { + options := auth.Options{} + for _, o := range opts { + o(&options) + } + + return &Auth{ + store: store.DefaultStore, + opts: options, + } +} + +type Auth struct { + store store.Store + opts auth.Options +} + +// Init the auth package +func (a *Auth) Init(opts ...auth.Option) error { + for _, o := range opts { + o(&a.opts) + } + return nil +} + +// Options returns the options set +func (a *Auth) Options() auth.Options { + return a.opts +} + +// Generate a new auth Account +func (a *Auth) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { + // generate the token + token, err := uuid.NewUUID() + if err != nil { + return nil, err + } + + // parse the options + options := auth.NewGenerateOptions(opts...) + + // construct the account + sa := auth.Account{ + Id: id, + Token: token.String(), + Created: time.Now(), + Metadata: options.Metadata, + Roles: options.Roles, + } + + // encode the data to bytes + buf := &bytes.Buffer{} + e := gob.NewEncoder(buf) + if err := e.Encode(sa); err != nil { + return nil, err + } + + // write to the store + err = a.store.Write(&store.Record{ + Key: token.String(), + Value: buf.Bytes(), + }) + if err != nil { + return nil, err + } + + // return the result + return &sa, nil +} + +// Revoke an authorization Account +func (a *Auth) Revoke(token string) error { + records, err := a.store.Read(token, store.ReadSuffix()) + if err != nil { + return err + } + if len(records) == 0 { + return errors.BadRequest("go.micro.auth", "token not found") + } + + for _, r := range records { + if err := a.store.Delete(r.Key); err != nil { + return errors.InternalServerError("go.micro.auth", "error deleting from store") + } + } + + return nil +} + +// Validate an account token +func (a *Auth) Validate(token string) (*auth.Account, error) { + // lookup the record by token + records, err := a.store.Read(token, store.ReadSuffix()) + if err == store.ErrNotFound || len(records) == 0 { + return nil, errors.Unauthorized("go.micro.auth", "invalid token") + } else if err != nil { + return nil, errors.InternalServerError("go.micro.auth", "error reading store") + } + + // decode the result + b := bytes.NewBuffer(records[0].Value) + decoder := gob.NewDecoder(b) + var sa auth.Account + err = decoder.Decode(&sa) + + // return the result + return &sa, err +} + +// String returns the implementation +func (a *Auth) String() string { + return "store" +} diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 0905eac9..cefb3150 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -18,6 +18,7 @@ import ( "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/util/config" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -128,6 +129,10 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R header["timeout"] = fmt.Sprintf("%d", opts.RequestTimeout) // set the content type for the request header["x-content-type"] = req.ContentType() + // set the authorization token if one is saved locally + if token, err := config.Get("token"); err == nil && len(token) > 0 { + header["authorization"] = fmt.Sprintf("Bearer %v", token) + } md := gmetadata.New(header) ctx = gmetadata.NewOutgoingContext(ctx, md) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 3c561146..dc16b7e6 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -65,6 +65,7 @@ import ( // auth jwtAuth "github.com/micro/go-micro/v2/auth/jwt" sAuth "github.com/micro/go-micro/v2/auth/service" + storeAuth "github.com/micro/go-micro/v2/auth/store" ) type Cmd interface { @@ -314,6 +315,7 @@ var ( DefaultAuths = map[string]func(...auth.Option) auth.Auth{ "service": sAuth.NewAuth, + "store": storeAuth.NewAuth, "jwt": jwtAuth.NewAuth, } ) diff --git a/go.sum b/go.sum index d18b6af8..3c3fc7aa 100644 --- a/go.sum +++ b/go.sum @@ -284,6 +284,7 @@ github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= +github.com/micro/go-micro v1.18.0 h1:gP70EZVHpJuUIT0YWth192JmlIci+qMOEByHm83XE9E= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= diff --git a/util/config/config.go b/util/config/config.go new file mode 100644 index 00000000..af4eae78 --- /dev/null +++ b/util/config/config.go @@ -0,0 +1,88 @@ +package config + +import ( + "io/ioutil" + "os" + "os/user" + "path/filepath" + + conf "github.com/micro/go-micro/v2/config" + "github.com/micro/go-micro/v2/config/source/file" +) + +// FileName for global micro config +const FileName = ".micro" + +// Get a value from the .micro file +func Get(key string) (string, error) { + // get the filepath + fp, err := filePath() + if err != nil { + return "", err + } + + // create a new config + c, err := conf.NewConfig( + conf.WithSource( + file.NewSource( + file.WithPath(fp), + ), + ), + ) + if err != nil { + return "", err + } + + // load the config + if err := c.Load(); err != nil { + return "", err + } + + // set a value + return c.Get(key).String(""), nil +} + +// Set a value in the .micro file +func Set(key, value string) error { + // get the filepath + fp, err := filePath() + if err != nil { + return err + } + + // write the file if it does not exist + if _, err := os.Stat(fp); os.IsNotExist(err) { + ioutil.WriteFile(fp, []byte{}, 0644) + } + + // create a new config + c, err := conf.NewConfig( + conf.WithSource( + file.NewSource( + file.WithPath(fp), + ), + ), + ) + if err != nil { + return err + } + + // load the config + if err := c.Load(); err != nil { + return err + } + + // set a value + c.Set(value, key) + + // write the file + return ioutil.WriteFile(fp, c.Bytes(), 0644) +} + +func filePath() (string, error) { + usr, err := user.Current() + if err != nil { + return "", err + } + return filepath.Join(usr.HomeDir, FileName), nil +} From 5e8d5834ebf2c3f73c519296296d8073aec928f1 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 24 Feb 2020 17:47:47 +0000 Subject: [PATCH 320/788] Dynamic Runtime source for k8s with github packages (#1252) * Dynamic Runtime source for k8s * Still check for source * Replace / with - for k8s service names * Simplify sourceForName function --- runtime/kubernetes/kubernetes.go | 21 +++++++++++++++++---- runtime/kubernetes/service.go | 4 ++-- runtime/options.go | 9 +++++++++ runtime/service/service.go | 5 +++++ util/kubernetes/client/util.go | 2 ++ 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index eabdb4b8..293597a5 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -270,9 +270,9 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er if len(options.Type) == 0 { options.Type = k.options.Type } - if len(k.options.Source) > 0 { - s.Source = k.options.Source - } + + // determine the full source for this service + options.Source = k.sourceForService(s.Name) service := newService(s, options) @@ -329,7 +329,8 @@ func (k *kubernetes) List() ([]*runtime.Service, error) { func (k *kubernetes) Update(s *runtime.Service) error { // create new kubernetes micro service service := newService(s, runtime.CreateOptions{ - Type: k.options.Type, + Type: k.options.Type, + Source: k.sourceForService(s.Name), }) // update build time annotation @@ -432,3 +433,15 @@ func NewRuntime(opts ...runtime.Option) runtime.Runtime { client: client, } } + +// sourceForService determines the nested package name for github +// e.g src: docker.pkg.github.com/micro/services an srv: users/api +// would become docker.pkg.github.com/micro/services/users-api +func (k *kubernetes) sourceForService(name string) string { + if !strings.HasPrefix(k.options.Source, "docker.pkg.github.com") { + return k.options.Source + } + + formattedName := strings.ReplaceAll(name, "/", "-") + return fmt.Sprintf("%v/%v", k.options.Source, formattedName) +} diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 60fb31a5..72fcc636 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -34,9 +34,9 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kservice := client.NewService(name, version, c.Type) kdeploy := client.NewDeployment(name, version, c.Type) - if len(s.Source) > 0 { + if len(c.Source) > 0 { for i := range kdeploy.Spec.Template.PodSpec.Containers { - kdeploy.Spec.Template.PodSpec.Containers[i].Image = s.Source + kdeploy.Spec.Template.PodSpec.Containers[i].Image = c.Source kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{} kdeploy.Spec.Template.PodSpec.Containers[i].Args = []string{name} } diff --git a/runtime/options.go b/runtime/options.go index 197f3d7f..ab73a02e 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -53,6 +53,8 @@ type CreateOptions struct { Type string // Retries before failing deploy Retries int + // Source of the service + Source string } // ReadOptions queries runtime services @@ -72,6 +74,13 @@ func CreateType(t string) CreateOption { } } +// CreateSource sets the source of service to create +func CreateSource(t string) CreateOption { + return func(o *CreateOptions) { + o.Source = t + } +} + // WithCommand specifies the command to execute func WithCommand(args ...string) CreateOption { return func(o *CreateOptions) { diff --git a/runtime/service/service.go b/runtime/service/service.go index c46c5ba4..f7e3e97a 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -35,6 +35,11 @@ func (s *svc) Create(svc *runtime.Service, opts ...runtime.CreateOption) error { o(&options) } + // set the default source from MICRO_RUNTIME_SOURCE + if len(svc.Source) == 0 { + svc.Source = s.options.Source + } + // runtime service create request req := &pb.CreateRequest{ Service: &pb.Service{ diff --git a/util/kubernetes/client/util.go b/util/kubernetes/client/util.go index 83e17b11..747ac9cb 100644 --- a/util/kubernetes/client/util.go +++ b/util/kubernetes/client/util.go @@ -91,6 +91,8 @@ func CertsFromPEM(pemCerts []byte) ([]*x509.Certificate, error) { func Format(v string) string { // to lower case v = strings.ToLower(v) + // / to dashes + v = strings.ReplaceAll(v, "/", "-") // dots to dashes v = strings.ReplaceAll(v, ".", "-") // limit to 253 chars From f1e7ea30207e8c237d9d7c0111b56caea8f997cf Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 24 Feb 2020 18:07:11 +0000 Subject: [PATCH 321/788] Handle non IsNotExist errors in config (#1251) Co-authored-by: Asim Aslam --- util/config/config.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/config/config.go b/util/config/config.go index af4eae78..20f2bf10 100644 --- a/util/config/config.go +++ b/util/config/config.go @@ -53,6 +53,8 @@ func Set(key, value string) error { // write the file if it does not exist if _, err := os.Stat(fp); os.IsNotExist(err) { ioutil.WriteFile(fp, []byte{}, 0644) + } else if err != nil { + return err } // create a new config From b4a743898ee62b9cc8c56b154327668014162a8e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 25 Feb 2020 02:16:00 +0300 Subject: [PATCH 322/788] fix router panic (#1254) Signed-off-by: Vasiliy Tolstov --- router/default.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/router/default.go b/router/default.go index d89ce13a..47da6ba0 100644 --- a/router/default.go +++ b/router/default.go @@ -368,9 +368,11 @@ func (r *router) advertiseEvents() error { time.Sleep(time.Second) } - // reset - w.Stop() - w = nil + if w != nil { + // reset + w.Stop() + w = nil + } } } }() @@ -467,7 +469,9 @@ func (r *router) advertiseEvents() error { a.penalty += Penalty log.Debugf("Router advert %d for route %s %s event penalty: %f", hash, a.event.Route.Service, a.event.Route.Address, a.penalty) case <-r.exit: - w.Stop() + if w != nil { + w.Stop() + } return nil } } @@ -700,16 +704,15 @@ func (r *router) Stop() error { // extract the events r.drain() + r.sub.Lock() // close advert subscribers for id, sub := range r.subscribers { // close the channel close(sub) - // delete the subscriber - r.sub.Lock() delete(r.subscribers, id) - r.sub.Unlock() } + r.sub.Unlock() } // remove event chan From dcf859098bc12c626d0099e9bf5787e0cf30019f Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 25 Feb 2020 11:39:03 +0000 Subject: [PATCH 323/788] Fix k8s commands for github (#1257) --- runtime/kubernetes/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 72fcc636..7a761437 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -70,7 +70,7 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { } // specify the command to exec - if len(c.Command) > 0 { + if strings.HasPrefix(c.Source, "github.com") && len(c.Command) > 0 { kdeploy.Spec.Template.PodSpec.Containers[0].Command = c.Command } From 53c3bff819e53482f8da249ad99a29ae3ebdc3e8 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 25 Feb 2020 22:44:29 +0800 Subject: [PATCH 324/788] add Panic & Panicf to logger (#1258) * add Panic & Panicf to logger --- logger/level.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/logger/level.go b/logger/level.go index eca14075..3b18e56a 100644 --- a/logger/level.go +++ b/logger/level.go @@ -109,6 +109,14 @@ func Errorf(template string, args ...interface{}) { DefaultLogger.Logf(ErrorLevel, template, args...) } +func Panic(args ...interface{}) { + DefaultLogger.Log(PanicLevel, args...) +} + +func Panicf(template string, args ...interface{}) { + DefaultLogger.Logf(PanicLevel, template, args...) +} + func Fatal(args ...interface{}) { DefaultLogger.Log(FatalLevel, args...) } From 603d37b1351e727e082beb490ba940987ba529ff Mon Sep 17 00:00:00 2001 From: Di Wu Date: Wed, 26 Feb 2020 00:42:43 +0800 Subject: [PATCH 325/788] Set option and cli args to the service profile (#1259) --- config/cmd/cmd.go | 21 +++++++++++++++++++++ config/cmd/options.go | 9 +++++++++ debug/profile/profile.go | 18 ++++++++++++++++++ options.go | 9 +++++++++ service.go | 25 ++++--------------------- 5 files changed, 61 insertions(+), 21 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index dc16b7e6..894cceb9 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -11,6 +11,9 @@ import ( "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/debug/profile" + "github.com/micro/go-micro/v2/debug/profile/http" + "github.com/micro/go-micro/v2/debug/profile/pprof" "github.com/micro/go-micro/v2/debug/trace" log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" @@ -25,6 +28,7 @@ import ( // servers "github.com/micro/cli/v2" + sgrpc "github.com/micro/go-micro/v2/server/grpc" smucp "github.com/micro/go-micro/v2/server/mucp" @@ -318,6 +322,11 @@ var ( "store": storeAuth.NewAuth, "jwt": jwtAuth.NewAuth, } + + DefaultProfiles = map[string]func(...profile.Option) profile.Profile{ + "http": http.NewProfile, + "pprof": pprof.NewProfile, + } ) func init() { @@ -336,6 +345,7 @@ func newCmd(opts ...Option) Cmd { Runtime: &runtime.DefaultRuntime, Store: &store.DefaultStore, Tracer: &trace.DefaultTracer, + Profile: &profile.DefaultProfile, Brokers: DefaultBrokers, Clients: DefaultClients, @@ -347,6 +357,7 @@ func newCmd(opts ...Option) Cmd { Stores: DefaultStores, Tracers: DefaultTracers, Auths: DefaultAuths, + Profiles: DefaultProfiles, } for _, o := range opts { @@ -430,6 +441,16 @@ func (c *cmd) Before(ctx *cli.Context) error { *c.opts.Auth = a() } + // Set the profile + if name := ctx.String("profile"); len(name) > 0 { + p, ok := c.opts.Profiles[name] + if !ok { + return fmt.Errorf("Unsupported profile: %s", name) + } + + *c.opts.Profile = p() + } + // Set the client if name := ctx.String("client"); len(name) > 0 { // only change if we have the client and type differs diff --git a/config/cmd/options.go b/config/cmd/options.go index cf387228..da58938f 100644 --- a/config/cmd/options.go +++ b/config/cmd/options.go @@ -7,6 +7,7 @@ import ( "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/debug/profile" "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/runtime" @@ -32,6 +33,7 @@ type Options struct { Store *store.Store Tracer *trace.Tracer Auth *auth.Auth + Profile *profile.Profile Brokers map[string]func(...broker.Option) broker.Broker Clients map[string]func(...client.Option) client.Client @@ -43,6 +45,7 @@ type Options struct { Stores map[string]func(...store.Option) store.Store Tracers map[string]func(...trace.Option) trace.Tracer Auths map[string]func(...auth.Option) auth.Auth + Profiles map[string]func(...profile.Option) profile.Profile // Other options for implementations of the interface // can be stored in a context @@ -118,6 +121,12 @@ func Auth(a *auth.Auth) Option { } } +func Profile(p *profile.Profile) Option { + return func(o *Options) { + o.Profile = p + } +} + // New broker func func NewBroker(name string, b func(...broker.Option) broker.Broker) Option { return func(o *Options) { diff --git a/debug/profile/profile.go b/debug/profile/profile.go index 3cc075f4..d043e524 100644 --- a/debug/profile/profile.go +++ b/debug/profile/profile.go @@ -10,6 +10,24 @@ type Profile interface { String() string } +var ( + DefaultProfile Profile = new(noop) +) + +type noop struct{} + +func (p *noop) Start() error { + return nil +} + +func (p *noop) Stop() error { + return nil +} + +func (p *noop) String() string { + return "noop" +} + type Options struct { // Name to use for the profile Name string diff --git a/options.go b/options.go index a2c32e3d..289b224b 100644 --- a/options.go +++ b/options.go @@ -10,6 +10,7 @@ import ( "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" "github.com/micro/go-micro/v2/config/cmd" + "github.com/micro/go-micro/v2/debug/profile" "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/server" @@ -25,6 +26,7 @@ type Options struct { Server server.Server Registry registry.Registry Transport transport.Transport + Profile profile.Profile // Before and After funcs BeforeStart []func() error @@ -99,6 +101,13 @@ func HandleSignal(b bool) Option { } } +// Profile to be used for debug profile +func Profile(p profile.Profile) Option { + return func(o *Options) { + o.Profile = p + } +} + // Server to be used for service func Server(s server.Server) Option { return func(o *Options) { diff --git a/service.go b/service.go index 90fdd8ca..d9fe2ca6 100644 --- a/service.go +++ b/service.go @@ -11,9 +11,6 @@ import ( "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/config/cmd" - "github.com/micro/go-micro/v2/debug/profile" - "github.com/micro/go-micro/v2/debug/profile/http" - "github.com/micro/go-micro/v2/debug/profile/pprof" "github.com/micro/go-micro/v2/debug/service/handler" "github.com/micro/go-micro/v2/debug/stats" "github.com/micro/go-micro/v2/debug/trace" @@ -101,6 +98,7 @@ func (s *service) Init(opts ...Option) { cmd.Transport(&s.opts.Transport), cmd.Client(&s.opts.Client), cmd.Server(&s.opts.Server), + cmd.Profile(&s.opts.Profile), ); err != nil { log.Fatal(err) } @@ -175,31 +173,16 @@ func (s *service) Run() error { ) // start the profiler - // TODO: set as an option to the service, don't just use pprof - if prof := os.Getenv("MICRO_DEBUG_PROFILE"); len(prof) > 0 { - var profiler profile.Profile - + if s.opts.Profile != nil { // to view mutex contention runtime.SetMutexProfileFraction(5) // to view blocking profile runtime.SetBlockProfileRate(1) - switch prof { - case "http": - profiler = http.NewProfile() - default: - service := s.opts.Server.Options().Name - version := s.opts.Server.Options().Version - id := s.opts.Server.Options().Id - profiler = pprof.NewProfile( - profile.Name(service + "." + version + "." + id), - ) - } - - if err := profiler.Start(); err != nil { + if err := s.opts.Profile.Start(); err != nil { return err } - defer profiler.Stop() + defer s.opts.Profile.Stop() } log.Infof("Starting [service] %s", s.Name()) From 6aaaf54275e18ff72a15b61cfeda127ae28944bf Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 25 Feb 2020 22:15:44 +0000 Subject: [PATCH 326/788] =?UTF-8?q?add=20MICRO=5FAUTH=5FTOKEN,=20parse=20t?= =?UTF-8?q?oken=20in=20wrapper,=20preload=20config=20and=20othe=E2=80=A6?= =?UTF-8?q?=20(#1261)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add MICRO_AUTH_TOKEN, parse token in wrapper, preload config and other things * fix wrapper panic --- auth/auth.go | 9 +- auth/default.go | 29 ++++-- auth/jwt/jwt.go | 39 ++++--- auth/options.go | 36 ++++--- auth/service/proto/auth.pb.go | 156 ++++++++++++++-------------- auth/service/proto/auth.pb.micro.go | 32 +++--- auth/service/proto/auth.proto | 34 +++--- auth/service/service.go | 6 +- auth/store/store.go | 20 ++-- client/grpc/grpc.go | 5 - config/cmd/cmd.go | 11 +- service.go | 11 +- util/wrapper/wrapper.go | 30 ++++-- util/wrapper/wrapper_test.go | 2 + 14 files changed, 243 insertions(+), 177 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 61567079..f98b2a67 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -15,8 +15,8 @@ type Auth interface { Generate(id string, opts ...GenerateOption) (*Account, error) // Revoke an authorization Account Revoke(token string) error - // Validate an account token - Validate(token string) (*Account, error) + // Verify an account token + Verify(token string) (*Account, error) // String returns the implementation String() string } @@ -31,7 +31,10 @@ type Resource struct { // Role an account has type Role struct { - Name string + // Name of the role + Name string + // The resource it has access + // TODO: potentially remove Resource *Resource } diff --git a/auth/default.go b/auth/default.go index 0fe97dfc..ef5a5ba3 100644 --- a/auth/default.go +++ b/auth/default.go @@ -6,31 +6,42 @@ var ( // NewAuth returns a new default registry which is noop func NewAuth(opts ...Option) Auth { - return noop{} + var options Options + for _, o := range opts { + o(&options) + } + return &noop{ + opts: options, + } } -type noop struct{} +type noop struct { + opts Options +} -func (noop) Init(opts ...Option) error { +func (n *noop) Init(opts ...Option) error { + for _, o := range opts { + o(&n.opts) + } return nil } -func (noop) Options() Options { - return Options{} +func (n *noop) Options() Options { + return n.opts } -func (noop) Generate(id string, opts ...GenerateOption) (*Account, error) { +func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) { return nil, nil } -func (noop) Revoke(token string) error { +func (n *noop) Revoke(token string) error { return nil } -func (noop) Validate(token string) (*Account, error) { +func (n *noop) Verify(token string) (*Account, error) { return nil, nil } -func (noop) String() string { +func (n *noop) String() string { return "noop" } diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go index d60c9361..b2aab0a8 100644 --- a/auth/jwt/jwt.go +++ b/auth/jwt/jwt.go @@ -1,6 +1,7 @@ package jwt import ( + "encoding/base64" "errors" "time" @@ -8,17 +9,19 @@ import ( "github.com/micro/go-micro/v2/auth" ) -// ErrInvalidPrivateKey is returned when the service provided an invalid private key -var ErrInvalidPrivateKey = errors.New("An invalid private key was provided") +var ( + // ErrInvalidPrivateKey is returned when the service provided an invalid private key + ErrInvalidPrivateKey = errors.New("An invalid private key was provided") -// ErrEncodingToken is returned when the service encounters an error during encoding -var ErrEncodingToken = errors.New("An error occured while encoding the JWT") + // ErrEncodingToken is returned when the service encounters an error during encoding + ErrEncodingToken = errors.New("An error occured while encoding the JWT") -// ErrInvalidToken is returned when the token provided is not valid -var ErrInvalidToken = errors.New("An invalid token was provided") + // ErrInvalidToken is returned when the token provided is not valid + ErrInvalidToken = errors.New("An invalid token was provided") -// ErrMissingToken is returned when no token is provided -var ErrMissingToken = errors.New("A valid JWT is required") + // ErrMissingToken is returned when no token is provided + ErrMissingToken = errors.New("A valid JWT is required") +) // NewAuth returns a new instance of the Auth service func NewAuth(opts ...auth.Option) auth.Auth { @@ -59,7 +62,13 @@ type AuthClaims struct { // Generate a new JWT func (s *svc) Generate(id string, ops ...auth.GenerateOption) (*auth.Account, error) { - key, err := jwt.ParseRSAPrivateKeyFromPEM(s.options.PrivateKey) + // decode the private key + priv, err := base64.StdEncoding.DecodeString(s.options.PrivateKey) + if err != nil { + return nil, err + } + + key, err := jwt.ParseRSAPrivateKeyFromPEM(priv) if err != nil { return nil, ErrEncodingToken } @@ -90,14 +99,20 @@ func (s *svc) Revoke(token string) error { return nil } -// Validate a JWT -func (s *svc) Validate(token string) (*auth.Account, error) { +// Verify a JWT +func (s *svc) Verify(token string) (*auth.Account, error) { if token == "" { return nil, ErrMissingToken } + // decode the public key + pub, err := base64.StdEncoding.DecodeString(s.options.PublicKey) + if err != nil { + return nil, err + } + res, err := jwt.ParseWithClaims(token, &AuthClaims{}, func(token *jwt.Token) (interface{}, error) { - return jwt.ParseRSAPublicKeyFromPEM(s.options.PublicKey) + return jwt.ParseRSAPublicKeyFromPEM(pub) }) if err != nil { return nil, err diff --git a/auth/options.go b/auth/options.go index 586f7b5f..059c3931 100644 --- a/auth/options.go +++ b/auth/options.go @@ -1,41 +1,51 @@ package auth -import ( - b64 "encoding/base64" -) - type Options struct { - PublicKey []byte - PrivateKey []byte - Excludes []string + // Token is an auth token + Token string + // Public key base64 encoded + PublicKey string + // Private key base64 encoded + PrivateKey string + // Endpoints to exclude + Exclude []string } type Option func(o *Options) -// Excludes endpoints from auth -func Excludes(excludes ...string) Option { +// Exclude ecludes a set of endpoints from authorization +func Exclude(e ...string) Option { return func(o *Options) { - o.Excludes = excludes + o.Exclude = e } } // PublicKey is the JWT public key func PublicKey(key string) Option { return func(o *Options) { - o.PublicKey, _ = b64.StdEncoding.DecodeString(key) + o.PublicKey = key } } // PrivateKey is the JWT private key func PrivateKey(key string) Option { return func(o *Options) { - o.PrivateKey, _ = b64.StdEncoding.DecodeString(key) + o.PrivateKey = key + } +} + +// Token sets an auth token +func Token(t string) Option { + return func(o *Options) { + o.Token = t } } type GenerateOptions struct { + // Metadata associated with the account Metadata map[string]string - Roles []*Role + // Roles/scopes associated with the account + Roles []*Role } type GenerateOption func(o *GenerateOptions) diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index de3d6b28..b57f3cc5 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: auth/service/proto/auth.proto +// source: micro/go-micro/auth/service/proto/auth.proto package go_micro_auth @@ -36,7 +36,7 @@ func (m *Account) Reset() { *m = Account{} } func (m *Account) String() string { return proto.CompactTextString(m) } func (*Account) ProtoMessage() {} func (*Account) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{0} + return fileDescriptor_de609d4872dacc78, []int{0} } func (m *Account) XXX_Unmarshal(b []byte) error { @@ -111,7 +111,7 @@ func (m *Role) Reset() { *m = Role{} } func (m *Role) String() string { return proto.CompactTextString(m) } func (*Role) ProtoMessage() {} func (*Role) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{1} + return fileDescriptor_de609d4872dacc78, []int{1} } func (m *Role) XXX_Unmarshal(b []byte) error { @@ -158,7 +158,7 @@ func (m *Resource) Reset() { *m = Resource{} } func (m *Resource) String() string { return proto.CompactTextString(m) } func (*Resource) ProtoMessage() {} func (*Resource) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{2} + return fileDescriptor_de609d4872dacc78, []int{2} } func (m *Resource) XXX_Unmarshal(b []byte) error { @@ -204,7 +204,7 @@ func (m *GenerateRequest) Reset() { *m = GenerateRequest{} } func (m *GenerateRequest) String() string { return proto.CompactTextString(m) } func (*GenerateRequest) ProtoMessage() {} func (*GenerateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{3} + return fileDescriptor_de609d4872dacc78, []int{3} } func (m *GenerateRequest) XXX_Unmarshal(b []byte) error { @@ -243,7 +243,7 @@ func (m *GenerateResponse) Reset() { *m = GenerateResponse{} } func (m *GenerateResponse) String() string { return proto.CompactTextString(m) } func (*GenerateResponse) ProtoMessage() {} func (*GenerateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{4} + return fileDescriptor_de609d4872dacc78, []int{4} } func (m *GenerateResponse) XXX_Unmarshal(b []byte) error { @@ -271,78 +271,78 @@ func (m *GenerateResponse) GetAccount() *Account { return nil } -type ValidateRequest struct { +type VerifyRequest struct { Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *ValidateRequest) Reset() { *m = ValidateRequest{} } -func (m *ValidateRequest) String() string { return proto.CompactTextString(m) } -func (*ValidateRequest) ProtoMessage() {} -func (*ValidateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{5} +func (m *VerifyRequest) Reset() { *m = VerifyRequest{} } +func (m *VerifyRequest) String() string { return proto.CompactTextString(m) } +func (*VerifyRequest) ProtoMessage() {} +func (*VerifyRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_de609d4872dacc78, []int{5} } -func (m *ValidateRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ValidateRequest.Unmarshal(m, b) +func (m *VerifyRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_VerifyRequest.Unmarshal(m, b) } -func (m *ValidateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ValidateRequest.Marshal(b, m, deterministic) +func (m *VerifyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_VerifyRequest.Marshal(b, m, deterministic) } -func (m *ValidateRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ValidateRequest.Merge(m, src) +func (m *VerifyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_VerifyRequest.Merge(m, src) } -func (m *ValidateRequest) XXX_Size() int { - return xxx_messageInfo_ValidateRequest.Size(m) +func (m *VerifyRequest) XXX_Size() int { + return xxx_messageInfo_VerifyRequest.Size(m) } -func (m *ValidateRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ValidateRequest.DiscardUnknown(m) +func (m *VerifyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_VerifyRequest.DiscardUnknown(m) } -var xxx_messageInfo_ValidateRequest proto.InternalMessageInfo +var xxx_messageInfo_VerifyRequest proto.InternalMessageInfo -func (m *ValidateRequest) GetToken() string { +func (m *VerifyRequest) GetToken() string { if m != nil { return m.Token } return "" } -type ValidateResponse struct { +type VerifyResponse struct { Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *ValidateResponse) Reset() { *m = ValidateResponse{} } -func (m *ValidateResponse) String() string { return proto.CompactTextString(m) } -func (*ValidateResponse) ProtoMessage() {} -func (*ValidateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{6} +func (m *VerifyResponse) Reset() { *m = VerifyResponse{} } +func (m *VerifyResponse) String() string { return proto.CompactTextString(m) } +func (*VerifyResponse) ProtoMessage() {} +func (*VerifyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_de609d4872dacc78, []int{6} } -func (m *ValidateResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ValidateResponse.Unmarshal(m, b) +func (m *VerifyResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_VerifyResponse.Unmarshal(m, b) } -func (m *ValidateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ValidateResponse.Marshal(b, m, deterministic) +func (m *VerifyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_VerifyResponse.Marshal(b, m, deterministic) } -func (m *ValidateResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_ValidateResponse.Merge(m, src) +func (m *VerifyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_VerifyResponse.Merge(m, src) } -func (m *ValidateResponse) XXX_Size() int { - return xxx_messageInfo_ValidateResponse.Size(m) +func (m *VerifyResponse) XXX_Size() int { + return xxx_messageInfo_VerifyResponse.Size(m) } -func (m *ValidateResponse) XXX_DiscardUnknown() { - xxx_messageInfo_ValidateResponse.DiscardUnknown(m) +func (m *VerifyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_VerifyResponse.DiscardUnknown(m) } -var xxx_messageInfo_ValidateResponse proto.InternalMessageInfo +var xxx_messageInfo_VerifyResponse proto.InternalMessageInfo -func (m *ValidateResponse) GetAccount() *Account { +func (m *VerifyResponse) GetAccount() *Account { if m != nil { return m.Account } @@ -360,7 +360,7 @@ func (m *RevokeRequest) Reset() { *m = RevokeRequest{} } func (m *RevokeRequest) String() string { return proto.CompactTextString(m) } func (*RevokeRequest) ProtoMessage() {} func (*RevokeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{7} + return fileDescriptor_de609d4872dacc78, []int{7} } func (m *RevokeRequest) XXX_Unmarshal(b []byte) error { @@ -398,7 +398,7 @@ func (m *RevokeResponse) Reset() { *m = RevokeResponse{} } func (m *RevokeResponse) String() string { return proto.CompactTextString(m) } func (*RevokeResponse) ProtoMessage() {} func (*RevokeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{8} + return fileDescriptor_de609d4872dacc78, []int{8} } func (m *RevokeResponse) XXX_Unmarshal(b []byte) error { @@ -426,41 +426,43 @@ func init() { proto.RegisterType((*Resource)(nil), "go.micro.auth.Resource") proto.RegisterType((*GenerateRequest)(nil), "go.micro.auth.GenerateRequest") proto.RegisterType((*GenerateResponse)(nil), "go.micro.auth.GenerateResponse") - proto.RegisterType((*ValidateRequest)(nil), "go.micro.auth.ValidateRequest") - proto.RegisterType((*ValidateResponse)(nil), "go.micro.auth.ValidateResponse") + proto.RegisterType((*VerifyRequest)(nil), "go.micro.auth.VerifyRequest") + proto.RegisterType((*VerifyResponse)(nil), "go.micro.auth.VerifyResponse") proto.RegisterType((*RevokeRequest)(nil), "go.micro.auth.RevokeRequest") proto.RegisterType((*RevokeResponse)(nil), "go.micro.auth.RevokeResponse") } -func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } - -var fileDescriptor_21300bfacc51fc2a = []byte{ - // 429 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x4d, 0x6f, 0xd3, 0x40, - 0x10, 0xad, 0x3f, 0xe2, 0x98, 0x89, 0xd2, 0x46, 0x03, 0x2a, 0x56, 0x44, 0x21, 0xb2, 0x40, 0x84, - 0x8b, 0x83, 0xdc, 0x0b, 0x82, 0x0b, 0x15, 0xa0, 0x9e, 0x2a, 0xa4, 0x3d, 0x70, 0x5f, 0xec, 0x11, - 0xb5, 0xe2, 0x78, 0xcd, 0x7a, 0x1d, 0xe1, 0xdf, 0xc0, 0x6f, 0xe5, 0x3f, 0x20, 0xaf, 0xbd, 0x69, - 0xea, 0xb4, 0xaa, 0xd4, 0xdb, 0x7c, 0xbc, 0x79, 0xf3, 0xde, 0x68, 0x17, 0xce, 0x78, 0xad, 0xae, - 0x57, 0x15, 0xc9, 0x6d, 0x96, 0xd0, 0xaa, 0x94, 0x42, 0x89, 0x55, 0x5b, 0x8a, 0x74, 0x88, 0xd3, - 0x5f, 0x22, 0xda, 0x64, 0x89, 0x14, 0x51, 0x5b, 0x0c, 0xff, 0xda, 0x30, 0xbe, 0x48, 0x12, 0x51, - 0x17, 0x0a, 0x8f, 0xc1, 0xce, 0xd2, 0xc0, 0x5a, 0x58, 0xcb, 0x27, 0xcc, 0xce, 0x52, 0x7c, 0x06, - 0x23, 0x25, 0xd6, 0x54, 0x04, 0xb6, 0x2e, 0x75, 0x09, 0x06, 0x30, 0x4e, 0x24, 0x71, 0x45, 0x69, - 0xe0, 0x2c, 0xac, 0xa5, 0xc3, 0x4c, 0x8a, 0xa7, 0xe0, 0xd1, 0x9f, 0x32, 0x93, 0x4d, 0xe0, 0xea, - 0x46, 0x9f, 0xe1, 0x3b, 0x18, 0x49, 0x91, 0x53, 0x15, 0x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c7, 0x06, - 0xd6, 0xad, 0x8a, 0xff, 0x59, 0xe0, 0x5e, 0xd4, 0xea, 0x1a, 0xaf, 0xc0, 0x37, 0xb6, 0xf1, 0xe5, - 0x60, 0xdd, 0xe0, 0xa8, 0xf3, 0x57, 0xf7, 0xf6, 0x3b, 0xd6, 0xf0, 0xa8, 0xa5, 0x33, 0xb6, 0x0e, - 0xe8, 0x06, 0x87, 0x39, 0xa0, 0x1b, 0xde, 0x23, 0x3c, 0xc2, 0x4b, 0xf0, 0x3a, 0xe1, 0xf8, 0xe2, - 0xe0, 0xe9, 0xec, 0xd9, 0x9e, 0x9f, 0xdd, 0xd3, 0x35, 0x44, 0x3f, 0x3d, 0xfd, 0x97, 0xcf, 0xff, - 0x07, 0x00, 0x00, 0xff, 0xff, 0x79, 0x35, 0xb2, 0x7e, 0xec, 0x03, 0x00, 0x00, +func init() { + proto.RegisterFile("micro/go-micro/auth/service/proto/auth.proto", fileDescriptor_de609d4872dacc78) +} + +var fileDescriptor_de609d4872dacc78 = []byte{ + // 432 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x53, 0x4b, 0x6f, 0xd3, 0x40, + 0x10, 0xae, 0x1d, 0xe7, 0xc1, 0x44, 0x09, 0xd1, 0x80, 0x8a, 0x15, 0xf1, 0x88, 0x56, 0x20, 0x05, + 0x09, 0x1c, 0xe4, 0x5e, 0x10, 0x5c, 0x28, 0x0f, 0xf5, 0x54, 0x21, 0xed, 0x81, 0xfb, 0xe2, 0x0c, + 0xad, 0x95, 0xc4, 0x6b, 0xd6, 0xeb, 0x08, 0xff, 0x06, 0x7e, 0x28, 0x7f, 0x03, 0x79, 0xd7, 0x1b, + 0x6a, 0xb7, 0xe5, 0x00, 0xb7, 0x79, 0x7c, 0xf3, 0xcd, 0xf7, 0x8d, 0x76, 0xe1, 0xc5, 0x2e, 0x4d, + 0x94, 0x5c, 0x5d, 0xc8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74, 0x8d, 0x34, 0x6d, 0x7e, 0x00, + 0xb2, 0x18, 0x46, 0xae, 0x7a, 0x23, 0x29, 0x42, 0xa0, 0xab, 0xdc, 0x29, 0x31, 0x31, 0xfb, 0x00, + 0x77, 0xcf, 0x28, 0x23, 0x25, 0x34, 0x71, 0xfa, 0x5e, 0x52, 0xa1, 0xf1, 0x15, 0x0c, 0x85, 0xf5, + 0x6d, 0xa6, 0xc7, 0xf1, 0xf1, 0xcd, 0x57, 0xe1, 0x0e, 0xc6, 0x3e, 0xc2, 0xec, 0x0f, 0x49, 0x91, + 0xcb, 0xac, 0xa0, 0x7f, 0x60, 0x79, 0x06, 0x93, 0x2f, 0xa4, 0xd2, 0x6f, 0x95, 0x13, 0x72, 0x78, + 0x12, 0xde, 0x95, 0x27, 0xc1, 0xde, 0xc3, 0xd4, 0xc1, 0xfe, 0x67, 0x15, 0xa7, 0xbd, 0xdc, 0xd0, + 0xdf, 0x57, 0xcd, 0x60, 0xea, 0x60, 0x76, 0x55, 0xfc, 0xcb, 0x83, 0xe0, 0xb4, 0xd4, 0x97, 0x78, + 0x0e, 0x23, 0x67, 0x19, 0x1f, 0x77, 0xd6, 0x75, 0x0e, 0x3a, 0x7f, 0x72, 0x6b, 0xdf, 0xb2, 0xb2, + 0x23, 0x3c, 0x83, 0x81, 0x35, 0x85, 0x0f, 0x3b, 0xe0, 0xd6, 0x49, 0xe6, 0x8f, 0x6e, 0xe9, 0x5e, + 0x25, 0xb2, 0x92, 0xaf, 0x11, 0xb5, 0x0c, 0x5f, 0x23, 0x6a, 0xfb, 0x64, 0x47, 0x5f, 0x07, 0xe6, + 0x07, 0x9f, 0xfc, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x34, 0xce, 0x17, 0xf1, 0x03, 0x00, 0x00, } diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index 6f2e0741..72b197fa 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -1,16 +1,16 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: auth/service/proto/auth.proto +// source: micro/go-micro/auth/service/proto/auth.proto package go_micro_auth import ( fmt "fmt" - math "math" - - context "context" - proto "github.com/golang/protobuf/proto" + math "math" +) +import ( + context "context" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -35,7 +35,7 @@ var _ server.Option type AuthService interface { Generate(ctx context.Context, in *GenerateRequest, opts ...client.CallOption) (*GenerateResponse, error) - Validate(ctx context.Context, in *ValidateRequest, opts ...client.CallOption) (*ValidateResponse, error) + Verify(ctx context.Context, in *VerifyRequest, opts ...client.CallOption) (*VerifyResponse, error) Revoke(ctx context.Context, in *RevokeRequest, opts ...client.CallOption) (*RevokeResponse, error) } @@ -45,12 +45,6 @@ type authService struct { } func NewAuthService(name string, c client.Client) AuthService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "go.micro.auth" - } return &authService{ c: c, name: name, @@ -67,9 +61,9 @@ func (c *authService) Generate(ctx context.Context, in *GenerateRequest, opts .. return out, nil } -func (c *authService) Validate(ctx context.Context, in *ValidateRequest, opts ...client.CallOption) (*ValidateResponse, error) { - req := c.c.NewRequest(c.name, "Auth.Validate", in) - out := new(ValidateResponse) +func (c *authService) Verify(ctx context.Context, in *VerifyRequest, opts ...client.CallOption) (*VerifyResponse, error) { + req := c.c.NewRequest(c.name, "Auth.Verify", in) + out := new(VerifyResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { return nil, err @@ -91,14 +85,14 @@ func (c *authService) Revoke(ctx context.Context, in *RevokeRequest, opts ...cli type AuthHandler interface { Generate(context.Context, *GenerateRequest, *GenerateResponse) error - Validate(context.Context, *ValidateRequest, *ValidateResponse) error + Verify(context.Context, *VerifyRequest, *VerifyResponse) error Revoke(context.Context, *RevokeRequest, *RevokeResponse) error } func RegisterAuthHandler(s server.Server, hdlr AuthHandler, opts ...server.HandlerOption) error { type auth interface { Generate(ctx context.Context, in *GenerateRequest, out *GenerateResponse) error - Validate(ctx context.Context, in *ValidateRequest, out *ValidateResponse) error + Verify(ctx context.Context, in *VerifyRequest, out *VerifyResponse) error Revoke(ctx context.Context, in *RevokeRequest, out *RevokeResponse) error } type Auth struct { @@ -116,8 +110,8 @@ func (h *authHandler) Generate(ctx context.Context, in *GenerateRequest, out *Ge return h.AuthHandler.Generate(ctx, in, out) } -func (h *authHandler) Validate(ctx context.Context, in *ValidateRequest, out *ValidateResponse) error { - return h.AuthHandler.Validate(ctx, in, out) +func (h *authHandler) Verify(ctx context.Context, in *VerifyRequest, out *VerifyResponse) error { + return h.AuthHandler.Verify(ctx, in, out) } func (h *authHandler) Revoke(ctx context.Context, in *RevokeRequest, out *RevokeResponse) error { diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index 03f8ca76..7f60f8bb 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -4,47 +4,47 @@ package go.micro.auth; service Auth { rpc Generate(GenerateRequest) returns (GenerateResponse) {}; - rpc Validate(ValidateRequest) returns (ValidateResponse) {}; + rpc Verify(VerifyRequest) returns (VerifyResponse) {}; rpc Revoke(RevokeRequest) returns (RevokeResponse) {}; } message Account{ - string id = 1; - string token = 2; - int64 created = 3; - int64 expiry = 4; - repeated Role roles = 5; + string id = 1; + string token = 2; + int64 created = 3; + int64 expiry = 4; + repeated Role roles = 5; map metadata = 6; } message Role { - string name = 1; - Resource resource = 2; + string name = 1; + Resource resource = 2; } message Resource{ - string name = 1; - string type = 2; + string name = 1; + string type = 2; } message GenerateRequest { - Account account = 1; + Account account = 1; } message GenerateResponse { - Account account = 1; + Account account = 1; } -message ValidateRequest { - string token = 1; +message VerifyRequest { + string token = 1; } -message ValidateResponse { - Account account = 1; +message VerifyResponse { + Account account = 1; } message RevokeRequest { - string token = 1; + string token = 1; } message RevokeResponse {} diff --git a/auth/service/service.go b/auth/service/service.go index 91949c51..6131eda2 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -72,9 +72,9 @@ func (s *svc) Revoke(token string) error { return err } -// Validate an account token -func (s *svc) Validate(token string) (*auth.Account, error) { - resp, err := s.auth.Validate(context.Background(), &pb.ValidateRequest{Token: token}) +// Verify an account token +func (s *svc) Verify(token string) (*auth.Account, error) { + resp, err := s.auth.Verify(context.Background(), &pb.VerifyRequest{Token: token}) if err != nil { return nil, err } diff --git a/auth/store/store.go b/auth/store/store.go index d53e7a14..3f3f4d42 100644 --- a/auth/store/store.go +++ b/auth/store/store.go @@ -7,14 +7,19 @@ import ( "github.com/google/uuid" "github.com/micro/go-micro/v2/auth" - "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/store" ) +type Auth struct { + store store.Store + opts auth.Options +} + // NewAuth returns an instance of store auth func NewAuth(opts ...auth.Option) auth.Auth { - options := auth.Options{} + var options auth.Options + for _, o := range opts { o(&options) } @@ -25,11 +30,6 @@ func NewAuth(opts ...auth.Option) auth.Auth { } } -type Auth struct { - store store.Store - opts auth.Options -} - // Init the auth package func (a *Auth) Init(opts ...auth.Option) error { for _, o := range opts { @@ -64,6 +64,7 @@ func (a *Auth) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, } // encode the data to bytes + // TODO: replace with json buf := &bytes.Buffer{} e := gob.NewEncoder(buf) if err := e.Encode(sa); err != nil { @@ -102,8 +103,8 @@ func (a *Auth) Revoke(token string) error { return nil } -// Validate an account token -func (a *Auth) Validate(token string) (*auth.Account, error) { +// Verify an account token +func (a *Auth) Verify(token string) (*auth.Account, error) { // lookup the record by token records, err := a.store.Read(token, store.ReadSuffix()) if err == store.ErrNotFound || len(records) == 0 { @@ -113,6 +114,7 @@ func (a *Auth) Validate(token string) (*auth.Account, error) { } // decode the result + // TODO: replace with json b := bytes.NewBuffer(records[0].Value) decoder := gob.NewDecoder(b) var sa auth.Account diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index cefb3150..0905eac9 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -18,7 +18,6 @@ import ( "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" - "github.com/micro/go-micro/v2/util/config" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -129,10 +128,6 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R header["timeout"] = fmt.Sprintf("%d", opts.RequestTimeout) // set the content type for the request header["x-content-type"] = req.ContentType() - // set the authorization token if one is saved locally - if token, err := config.Get("token"); err == nil && len(token) > 0 { - header["authorization"] = fmt.Sprintf("Bearer %v", token) - } md := gmetadata.New(header) ctx = gmetadata.NewOutgoingContext(ctx, md) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 894cceb9..fbb253dc 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -249,6 +249,11 @@ var ( EnvVars: []string{"MICRO_AUTH"}, Usage: "Auth for role based access control, e.g. service", }, + &cli.StringFlag{ + Name: "auth_token", + EnvVars: []string{"MICRO_AUTH_TOKEN"}, + Usage: "Auth token used for client authentication", + }, &cli.StringFlag{ Name: "auth_public_key", EnvVars: []string{"MICRO_AUTH_PUBLIC_KEY"}, @@ -606,6 +611,10 @@ func (c *cmd) Before(ctx *cli.Context) error { } } + if len(ctx.String("auth_token")) > 0 { + authOpts = append(authOpts, auth.Token(ctx.String("auth_token"))) + } + if len(ctx.String("auth_public_key")) > 0 { authOpts = append(authOpts, auth.PublicKey(ctx.String("auth_public_key"))) } @@ -615,7 +624,7 @@ func (c *cmd) Before(ctx *cli.Context) error { } if len(ctx.StringSlice("auth_exclude")) > 0 { - authOpts = append(authOpts, auth.Excludes(ctx.StringSlice("auth_exclude")...)) + authOpts = append(authOpts, auth.Exclude(ctx.StringSlice("auth_exclude")...)) } if len(authOpts) > 0 { diff --git a/service.go b/service.go index d9fe2ca6..3ce750ae 100644 --- a/service.go +++ b/service.go @@ -17,6 +17,7 @@ import ( log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/plugin" "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/util/config" "github.com/micro/go-micro/v2/util/wrapper" ) @@ -37,7 +38,7 @@ func newService(opts ...Option) Service { authFn := func() auth.Auth { return service.opts.Auth } // wrap client to inject From-Service header on any calls - options.Client = wrapper.FromService(serviceName, options.Client) + options.Client = wrapper.FromService(serviceName, options.Client, authFn) options.Client = wrapper.TraceCall(serviceName, trace.DefaultTracer, options.Client) // wrap the server to provide handler stats @@ -102,6 +103,14 @@ func (s *service) Init(opts ...Option) { ); err != nil { log.Fatal(err) } + + // TODO: replace Cmd.Init with config.Load + // Right now we're just going to load a token + // May need to re-read value on change + // TODO: should be scoped to micro/auth/token + if tk, _ := config.Get("token"); len(tk) > 0 { + s.opts.Auth.Init(auth.Token(tk)) + } }) } diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index b9c4275f..b83aeca0 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -15,6 +15,10 @@ import ( type clientWrapper struct { client.Client + + // Auth interface + auth func() auth.Auth + // headers to inject headers metadata.Metadata } @@ -27,7 +31,7 @@ type traceWrapper struct { var ( HeaderPrefix = "Micro-" - BearerSchema = "Bearer " + BearerScheme = "Bearer " ) func (c *clientWrapper) setHeaders(ctx context.Context) context.Context { @@ -35,6 +39,15 @@ func (c *clientWrapper) setHeaders(ctx context.Context) context.Context { mda, _ := metadata.FromContext(ctx) md := metadata.Copy(mda) + // get auth token + if a := c.auth(); a != nil { + tk := a.Options().Token + // if the token if exists and auth header isn't set then set it + if len(tk) > 0 && len(md["Authorization"]) == 0 { + md["Authorization"] = BearerScheme + tk + } + } + // set headers for k, v := range c.headers { if _, ok := md[k]; !ok { @@ -75,10 +88,11 @@ func (c *traceWrapper) Call(ctx context.Context, req client.Request, rsp interfa return err } -// FromService wraps a client to inject From-Service header into metadata -func FromService(name string, c client.Client) client.Client { +// FromService wraps a client to inject service and auth metadata +func FromService(name string, c client.Client, fn func() auth.Auth) client.Client { return &clientWrapper{ c, + fn, metadata.Metadata{ HeaderPrefix + "From-Service": name, }, @@ -151,7 +165,7 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { } // Exclude any user excluded endpoints - for _, e := range a.Options().Excludes { + for _, e := range a.Options().Exclude { if e == req.Endpoint() { return h(ctx, req, rsp) } @@ -162,15 +176,15 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { var token string if header, ok := metadata.Get(ctx, "Authorization"); ok { // Ensure the correct scheme is being used - if !strings.HasPrefix(header, BearerSchema) { + if !strings.HasPrefix(header, BearerScheme) { return errors.Unauthorized("go.micro.auth", "invalid authorization header. expected Bearer schema") } - token = header[len(BearerSchema):] + token = header[len(BearerScheme):] } - // Validate the token - if _, err := a.Validate(token); err != nil { + // Verify the token + if _, err := a.Verify(token); err != nil { return errors.Unauthorized("go.micro.auth", err.Error()) } diff --git a/util/wrapper/wrapper_test.go b/util/wrapper/wrapper_test.go index b45fb86b..7fb99bf3 100644 --- a/util/wrapper/wrapper_test.go +++ b/util/wrapper/wrapper_test.go @@ -4,6 +4,7 @@ import ( "context" "testing" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/metadata" ) @@ -33,6 +34,7 @@ func TestWrapper(t *testing.T) { for _, d := range testData { c := &clientWrapper{ + auth: func() auth.Auth { return nil }, headers: d.headers, } From 80f2bfd5d0aaa844d2dc15a471d5cd2b0af48cea Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Wed, 26 Feb 2020 00:25:33 -0800 Subject: [PATCH 327/788] config: remove unused sep variable (#1262) --- config/default_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/default_test.go b/config/default_test.go index 0ee8d84a..93048d56 100644 --- a/config/default_test.go +++ b/config/default_test.go @@ -12,10 +12,6 @@ import ( "github.com/micro/go-micro/v2/config/source/file" ) -var ( - sep = string(os.PathSeparator) -) - func createFileForIssue18(t *testing.T, content string) *os.File { data := []byte(content) path := filepath.Join(os.TempDir(), fmt.Sprintf("file.%d", time.Now().UnixNano())) From 1034837f6910479e8ad41ae0375e7c8240586622 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 26 Feb 2020 16:44:10 +0800 Subject: [PATCH 328/788] Adjusting the BeforeStart () position (#1263) Co-authored-by: Asim Aslam --- web/service.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/web/service.go b/web/service.go index e9837892..5d242e8d 100644 --- a/web/service.go +++ b/web/service.go @@ -154,6 +154,12 @@ func (s *service) start() error { return nil } + for _, fn := range s.opts.BeforeStart { + if err := fn(); err != nil { + return err + } + } + l, err := s.listen("tcp", s.opts.Address) if err != nil { return err @@ -192,12 +198,6 @@ func (s *service) start() error { }) } - for _, fn := range s.opts.BeforeStart { - if err := fn(); err != nil { - return err - } - } - var httpSrv *http.Server if s.opts.Server != nil { httpSrv = s.opts.Server From d651b16acd440ecdc8a724fd2321b3e2474f94b7 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 26 Feb 2020 13:42:32 +0000 Subject: [PATCH 329/788] generate pseudo accounts (#1264) * generate pseudo accounts * when you think you're being clever * return garbage pseudo account when no token --- auth/default.go | 101 ++++++++++++++++++++++++++++++++++++------ util/config/config.go | 5 ++- 2 files changed, 92 insertions(+), 14 deletions(-) diff --git a/auth/default.go b/auth/default.go index ef5a5ba3..36e65679 100644 --- a/auth/default.go +++ b/auth/default.go @@ -1,47 +1,122 @@ package auth +import ( + "encoding/base32" + "sync" + "time" +) + var ( DefaultAuth = NewAuth() ) -// NewAuth returns a new default registry which is noop +func genAccount(id string) *Account { + // return a pseudo account + return &Account{ + Id: id, + Token: base32.StdEncoding.EncodeToString([]byte(id)), + Created: time.Now(), + Expiry: time.Now().Add(time.Hour * 24), + Metadata: make(map[string]string), + } +} + +// NewAuth returns a new default registry which is memory func NewAuth(opts ...Option) Auth { var options Options for _, o := range opts { o(&options) } - return &noop{ - opts: options, + + return &memory{ + accounts: make(map[string]*Account), + opts: options, } } -type noop struct { +// TODO: replace with https://github.com/nats-io/nkeys +// We'll then register public key in registry to use +type memory struct { opts Options + // accounts + sync.RWMutex + accounts map[string]*Account } -func (n *noop) Init(opts ...Option) error { +func (n *memory) Init(opts ...Option) error { for _, o := range opts { o(&n.opts) } return nil } -func (n *noop) Options() Options { +func (n *memory) Options() Options { return n.opts } -func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) { - return nil, nil +func (n *memory) Generate(id string, opts ...GenerateOption) (*Account, error) { + var options GenerateOptions + for _, o := range opts { + o(&options) + } + + // return a pseudo account + acc := genAccount(id) + + // set opts + if len(options.Roles) > 0 { + acc.Roles = options.Roles + } + if options.Metadata != nil { + acc.Metadata = options.Metadata + } + + // TODO: don't overwrite + n.Lock() + // maybe save by account id? + n.accounts[acc.Token] = acc + n.Unlock() + + return acc, nil } -func (n *noop) Revoke(token string) error { +func (n *memory) Revoke(token string) error { + n.Lock() + delete(n.accounts, token) + n.Unlock() return nil } -func (n *noop) Verify(token string) (*Account, error) { - return nil, nil +func (n *memory) Verify(token string) (*Account, error) { + n.RLock() + defer n.RUnlock() + + if len(token) == 0 { + // pseudo account? + return genAccount(""), nil + } + + // try get the local account if it exists + if acc, ok := n.accounts[token]; ok { + return acc, nil + } + + // decode the token otherwise + b, err := base32.StdEncoding.DecodeString(token) + if err != nil { + return nil, err + } + + // return a pseudo account based on token/id + return &Account{ + Id: string(b), + Token: token, + Created: time.Now(), + Expiry: time.Now().Add(time.Hour * 24), + Metadata: make(map[string]string), + }, nil } -func (n *noop) String() string { - return "noop" +func (n *memory) String() string { + return "memory" } diff --git a/util/config/config.go b/util/config/config.go index 20f2bf10..7286a04b 100644 --- a/util/config/config.go +++ b/util/config/config.go @@ -5,6 +5,7 @@ import ( "os" "os/user" "path/filepath" + "strings" conf "github.com/micro/go-micro/v2/config" "github.com/micro/go-micro/v2/config/source/file" @@ -39,7 +40,9 @@ func Get(key string) (string, error) { } // set a value - return c.Get(key).String(""), nil + tk := c.Get(key).String("") + + return strings.TrimSpace(tk), nil } // Set a value in the .micro file From 64a5ce96075367975f443c3379b814a05dde9677 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 26 Feb 2020 21:34:40 +0300 Subject: [PATCH 330/788] various fixes (#1267) * logger: remove Panic log level Signed-off-by: Vasiliy Tolstov * server/grpc: add missing Unlock in Subscribe error Signed-off-by: Vasiliy Tolstov * server: minor code change Signed-off-by: Vasiliy Tolstov * server/grpc: extend test suite with pub/sub testing Signed-off-by: Vasiliy Tolstov * server/grpc: fix invalid check and allow subscriber error to be returned Signed-off-by: Vasiliy Tolstov * server/grpc: add pubsub tests Signed-off-by: Vasiliy Tolstov * client/grpc: check for nil req/rsp Signed-off-by: Vasiliy Tolstov --- client/grpc/grpc.go | 5 ++ logger/level.go | 16 +----- server/grpc/grpc.go | 2 +- server/grpc/grpc_test.go | 108 +++++++++++++++++++++++++++++++++++--- server/grpc/subscriber.go | 5 +- server/rpc_router.go | 10 ++-- 6 files changed, 114 insertions(+), 32 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 0905eac9..42e7101b 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -383,6 +383,11 @@ func (g *grpcClient) NewRequest(service, method string, req interface{}, reqOpts } func (g *grpcClient) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { + if req == nil { + return errors.InternalServerError("go.micro.client", "req is nil") + } else if rsp == nil { + return errors.InternalServerError("go.micro.client", "rsp is nil") + } // make a copy of call opts callOpts := g.opts.CallOptions for _, opt := range opts { diff --git a/logger/level.go b/logger/level.go index 3b18e56a..e4f953d9 100644 --- a/logger/level.go +++ b/logger/level.go @@ -16,8 +16,6 @@ const ( WarnLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. ErrorLevel - // PanicLevel level, logs the message and then panics. - PanicLevel // FatalLevel level. Logs and then calls `logger.Exit(1)`. highest level of severity. FatalLevel ) @@ -34,8 +32,6 @@ func (l Level) String() string { return "warn" case ErrorLevel: return "error" - case PanicLevel: - return "panic" case FatalLevel: return "fatal" } @@ -61,12 +57,10 @@ func GetLevel(levelStr string) (Level, error) { return WarnLevel, nil case ErrorLevel.String(): return ErrorLevel, nil - case PanicLevel.String(): - return PanicLevel, nil case FatalLevel.String(): return FatalLevel, nil } - return InfoLevel, fmt.Errorf("Unknown Level String: '%s', defaulting to NoLevel", levelStr) + return InfoLevel, fmt.Errorf("Unknown Level String: '%s', defaulting to InfoLevel", levelStr) } func Info(args ...interface{}) { @@ -109,14 +103,6 @@ func Errorf(template string, args ...interface{}) { DefaultLogger.Logf(ErrorLevel, template, args...) } -func Panic(args ...interface{}) { - DefaultLogger.Log(PanicLevel, args...) -} - -func Panicf(template string, args ...interface{}) { - DefaultLogger.Logf(PanicLevel, template, args...) -} - func Fatal(args ...interface{}) { DefaultLogger.Log(FatalLevel, args...) } diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 2ee03bac..66539132 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -555,8 +555,8 @@ func (g *grpcServer) Subscribe(sb server.Subscriber) error { } g.Lock() - if _, ok = g.subscribers[sub]; ok { + g.Unlock() return fmt.Errorf("subscriber %v already exists", sub) } diff --git a/server/grpc/grpc_test.go b/server/grpc/grpc_test.go index 829a7f1c..50035836 100644 --- a/server/grpc/grpc_test.go +++ b/server/grpc/grpc_test.go @@ -1,12 +1,19 @@ -package grpc +package grpc_test import ( "context" + "fmt" "testing" + "github.com/micro/go-micro/v2" + bmemory "github.com/micro/go-micro/v2/broker/memory" + "github.com/micro/go-micro/v2/client" + gcli "github.com/micro/go-micro/v2/client/grpc" "github.com/micro/go-micro/v2/errors" - "github.com/micro/go-micro/v2/registry/memory" + rmemory "github.com/micro/go-micro/v2/registry/memory" "github.com/micro/go-micro/v2/server" + gsrv "github.com/micro/go-micro/v2/server/grpc" + tgrpc "github.com/micro/go-micro/v2/transport/grpc" "google.golang.org/grpc" "google.golang.org/grpc/status" @@ -14,7 +21,17 @@ import ( ) // server is used to implement helloworld.GreeterServer. -type testServer struct{} +type testServer struct { + msgCount int +} + +func (s *testServer) Handle(ctx context.Context, msg *pb.Request) error { + s.msgCount++ + return nil +} +func (s *testServer) HandleError(ctx context.Context, msg *pb.Request) error { + return fmt.Errorf("fake") +} // TestHello implements helloworld.GreeterServer func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error { @@ -26,14 +43,75 @@ func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response return nil } -func TestGRPCServer(t *testing.T) { - r := memory.NewRegistry() - s := NewServer( +/* +func BenchmarkServer(b *testing.B) { + r := rmemory.NewRegistry() + br := bmemory.NewBroker() + tr := tgrpc.NewTransport() + s := gsrv.NewServer( + server.Broker(br), server.Name("foo"), server.Registry(r), + server.Transport(tr), ) + c := gcli.NewClient( + client.Registry(r), + client.Broker(br), + client.Transport(tr), + ) + ctx := context.TODO() - pb.RegisterTestHandler(s, &testServer{}) + h := &testServer{} + pb.RegisterTestHandler(s, h) + if err := s.Start(); err != nil { + b.Fatalf("failed to start: %v", err) + } + + // check registration + services, err := r.GetService("foo") + if err != nil || len(services) == 0 { + b.Fatalf("failed to get service: %v # %d", err, len(services)) + } + + defer func() { + if err := s.Stop(); err != nil { + b.Fatalf("failed to stop: %v", err) + } + }() + + b.ResetTimer() + for i := 0; i < b.N; i++ { + c.Call() + } + +} +*/ +func TestGRPCServer(t *testing.T) { + r := rmemory.NewRegistry() + b := bmemory.NewBroker() + tr := tgrpc.NewTransport() + s := gsrv.NewServer( + server.Broker(b), + server.Name("foo"), + server.Registry(r), + server.Transport(tr), + ) + c := gcli.NewClient( + client.Registry(r), + client.Broker(b), + client.Transport(tr), + ) + ctx := context.TODO() + + h := &testServer{} + pb.RegisterTestHandler(s, h) + + if err := micro.RegisterSubscriber("test_topic", s, h.Handle); err != nil { + t.Fatal(err) + } + if err := micro.RegisterSubscriber("error_topic", s, h.HandleError); err != nil { + t.Fatal(err) + } if err := s.Start(); err != nil { t.Fatalf("failed to start: %v", err) @@ -51,6 +129,22 @@ func TestGRPCServer(t *testing.T) { } }() + pub := micro.NewEvent("test_topic", c) + pubErr := micro.NewEvent("error_topic", c) + cnt := 4 + for i := 0; i < cnt; i++ { + if err = pub.Publish(ctx, &pb.Request{Name: fmt.Sprintf("msg %d", i)}); err != nil { + t.Fatal(err) + } + } + + if h.msgCount != cnt { + t.Fatalf("pub/sub not work, or invalid message count %d", h.msgCount) + } + if err = pubErr.Publish(ctx, &pb.Request{}); err == nil { + t.Fatal("this must return error, as we return error from handler") + } + cc, err := grpc.Dial(s.Options().Address, grpc.WithInsecure()) if err != nil { t.Fatalf("failed to dial server: %v", err) diff --git a/server/grpc/subscriber.go b/server/grpc/subscriber.go index a29ebcba..bfe54b8f 100644 --- a/server/grpc/subscriber.go +++ b/server/grpc/subscriber.go @@ -246,18 +246,19 @@ func (g *grpcServer) createSubHandler(sb *subscriber, opts server.Options) broke if g.wg != nil { defer g.wg.Done() } - results <- fn(ctx, &rpcMessage{ + err := fn(ctx, &rpcMessage{ topic: sb.topic, contentType: ct, payload: req.Interface(), header: msg.Header, body: msg.Body, }) + results <- err }() } var errors []string for i := 0; i < len(sb.handlers); i++ { - if rerr := <-results; err != nil { + if rerr := <-results; rerr != nil { errors = append(errors, rerr.Error()) } } diff --git a/server/rpc_router.go b/server/rpc_router.go index 3716617d..82b2c6b9 100644 --- a/server/rpc_router.go +++ b/server/rpc_router.go @@ -505,7 +505,6 @@ func (router *router) Subscribe(s Subscriber) error { } func (router *router) ProcessMessage(ctx context.Context, msg Message) (err error) { - defer func() { // recover any panics if r := recover(); r != nil { @@ -516,16 +515,13 @@ func (router *router) ProcessMessage(ctx context.Context, msg Message) (err erro }() router.su.RLock() - // get the subscribers by topic subs, ok := router.subscribers[msg.Topic()] - if !ok { - router.su.RUnlock() - return nil - } - // unlock since we only need to get the subs router.su.RUnlock() + if !ok { + return nil + } var errResults []string From e21ed3a183ea35a6a5f85e47c083fefec790122a Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 27 Feb 2020 16:11:05 +0000 Subject: [PATCH 331/788] gen account on base32 decode failure (#1269) --- auth/default.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/default.go b/auth/default.go index 36e65679..740437f1 100644 --- a/auth/default.go +++ b/auth/default.go @@ -104,7 +104,7 @@ func (n *memory) Verify(token string) (*Account, error) { // decode the token otherwise b, err := base32.StdEncoding.DecodeString(token) if err != nil { - return nil, err + return genAccount(""), nil } // return a pseudo account based on token/id From 962567ef4276739fd47654d7e3a12de99010e56b Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Fri, 28 Feb 2020 12:58:27 +0000 Subject: [PATCH 332/788] Implement config singleton (#1268) * Implement config singleton * Pass token in grpc request headers * Refactor BearerScheme * Fix typo --- client/grpc/grpc.go | 9 +++++ util/config/config.go | 81 +++++++++++++++++++++---------------------- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 42e7101b..e1043afe 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -18,6 +18,7 @@ import ( "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/util/config" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -25,6 +26,10 @@ import ( gmetadata "google.golang.org/grpc/metadata" ) +var ( + BearerScheme = "Bearer " +) + type grpcClient struct { opts client.Options pool *pool @@ -128,6 +133,10 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R header["timeout"] = fmt.Sprintf("%d", opts.RequestTimeout) // set the content type for the request header["x-content-type"] = req.ContentType() + // set the authorization token if one is saved locally + if token, err := config.Get("token"); err == nil && len(token) > 0 { + header["authorization"] = BearerScheme + token + } md := gmetadata.New(header) ctx = gmetadata.NewOutgoingContext(ctx, md) diff --git a/util/config/config.go b/util/config/config.go index 7286a04b..e0e85e37 100644 --- a/util/config/config.go +++ b/util/config/config.go @@ -9,39 +9,20 @@ import ( conf "github.com/micro/go-micro/v2/config" "github.com/micro/go-micro/v2/config/source/file" + "github.com/micro/go-micro/v2/util/log" ) // FileName for global micro config const FileName = ".micro" +// config is a singleton which is required to ensure +// each function call doesn't load the .micro file +// from disk +var config = newConfig() + // Get a value from the .micro file func Get(key string) (string, error) { - // get the filepath - fp, err := filePath() - if err != nil { - return "", err - } - - // create a new config - c, err := conf.NewConfig( - conf.WithSource( - file.NewSource( - file.WithPath(fp), - ), - ), - ) - if err != nil { - return "", err - } - - // load the config - if err := c.Load(); err != nil { - return "", err - } - - // set a value - tk := c.Get(key).String("") - + tk := config.Get(key).String("") return strings.TrimSpace(tk), nil } @@ -53,11 +34,36 @@ func Set(key, value string) error { return err } + // set the value + config.Set(value, key) + + // write to the file + return ioutil.WriteFile(fp, config.Bytes(), 0644) +} + +func filePath() (string, error) { + usr, err := user.Current() + if err != nil { + return "", err + } + return filepath.Join(usr.HomeDir, FileName), nil +} + +// newConfig returns a loaded config +func newConfig() conf.Config { + // get the filepath + fp, err := filePath() + if err != nil { + log.Error(err) + return conf.DefaultConfig + } + // write the file if it does not exist if _, err := os.Stat(fp); os.IsNotExist(err) { ioutil.WriteFile(fp, []byte{}, 0644) } else if err != nil { - return err + log.Error(err) + return conf.DefaultConfig } // create a new config @@ -69,25 +75,16 @@ func Set(key, value string) error { ), ) if err != nil { - return err + log.Error(err) + return conf.DefaultConfig } // load the config if err := c.Load(); err != nil { - return err + log.Error(err) + return conf.DefaultConfig } - // set a value - c.Set(value, key) - - // write the file - return ioutil.WriteFile(fp, c.Bytes(), 0644) -} - -func filePath() (string, error) { - usr, err := user.Current() - if err != nil { - return "", err - } - return filepath.Join(usr.HomeDir, FileName), nil + // return the conf + return c } From afe6861e2f87b0246ff1fa63a6e0ca39730a1129 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Fri, 28 Feb 2020 15:07:55 +0000 Subject: [PATCH 333/788] Update the k8s deployment to use metadata labels & custom source (#1271) --- runtime/kubernetes/service.go | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 7a761437..15d05bcb 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -3,7 +3,6 @@ package kubernetes import ( "encoding/json" "strings" - "time" log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/runtime" @@ -34,12 +33,15 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kservice := client.NewService(name, version, c.Type) kdeploy := client.NewDeployment(name, version, c.Type) - if len(c.Source) > 0 { - for i := range kdeploy.Spec.Template.PodSpec.Containers { - kdeploy.Spec.Template.PodSpec.Containers[i].Image = c.Source - kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{} - kdeploy.Spec.Template.PodSpec.Containers[i].Args = []string{name} - } + // ensure the metadata is set + if kdeploy.Spec.Template.Metadata.Annotations == nil { + kdeploy.Spec.Template.Metadata.Annotations = make(map[string]string) + } + + // add the service metadata to the k8s labels, do this first so we + // don't override any labels used by the runtime, e.g. name + for k, v := range s.Metadata { + kdeploy.Metadata.Annotations[k] = v } // attach our values to the deployment; name, version, source @@ -51,11 +53,16 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kdeploy.Metadata.Annotations["owner"] = "micro" kdeploy.Metadata.Annotations["group"] = "micro" - // set a build timestamp to the current time - if kdeploy.Spec.Template.Metadata.Annotations == nil { - kdeploy.Spec.Template.Metadata.Annotations = make(map[string]string) + // update the deployment is a custom source is provided + if len(c.Source) > 0 { + for i := range kdeploy.Spec.Template.PodSpec.Containers { + kdeploy.Spec.Template.PodSpec.Containers[i].Image = c.Source + kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{} + kdeploy.Spec.Template.PodSpec.Containers[i].Args = []string{name} + } + + kdeploy.Metadata.Annotations["source"] = c.Source } - kdeploy.Spec.Template.Metadata.Annotations["build"] = time.Now().Format(time.RFC3339) // define the environment values used by the container env := make([]client.EnvVar, 0, len(c.Env)) From d0a978bd5075035b95eddd218ad57fb37671c964 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 29 Feb 2020 03:31:59 +0300 Subject: [PATCH 334/788] redesign logger (#1272) * redesign logger Signed-off-by: Vasiliy Tolstov --- logger/default.go | 14 ---------- logger/helper.go | 61 +++++++++++++++++++++++++++++++++++++++++++ logger/logger.go | 8 +----- logger/logger_test.go | 9 +++++++ 4 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 logger/helper.go create mode 100644 logger/logger_test.go diff --git a/logger/default.go b/logger/default.go index 6fa2b009..ce4498ef 100644 --- a/logger/default.go +++ b/logger/default.go @@ -13,7 +13,6 @@ import ( type defaultLogger struct { sync.RWMutex opts Options - err error } // Init(opts...) should only overwrite provided options @@ -35,13 +34,6 @@ func (l *defaultLogger) Fields(fields map[string]interface{}) Logger { return l } -func (l *defaultLogger) Error(err error) Logger { - l.Lock() - l.err = err - l.Unlock() - return l -} - func copyFields(src map[string]interface{}) map[string]interface{} { dst := make(map[string]interface{}, len(src)) for k, v := range src { @@ -58,9 +50,6 @@ func (l *defaultLogger) Log(level Level, v ...interface{}) { l.RLock() fields := copyFields(l.opts.Fields) - if l.err != nil { - fields["error"] = l.err.Error() - } l.RUnlock() fields["level"] = level.String() @@ -88,9 +77,6 @@ func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) { l.RLock() fields := copyFields(l.opts.Fields) - if l.err != nil { - fields["error"] = l.err.Error() - } l.RUnlock() fields["level"] = level.String() diff --git a/logger/helper.go b/logger/helper.go new file mode 100644 index 00000000..90a9ea13 --- /dev/null +++ b/logger/helper.go @@ -0,0 +1,61 @@ +package logger + +type Helper struct { + Logger +} + +func NewHelper(log Logger) *Helper { + return &Helper{log} +} + +func (h *Helper) Info(args ...interface{}) { + h.Logger.Log(InfoLevel, args...) +} + +func (h *Helper) Infof(template string, args ...interface{}) { + h.Logger.Logf(InfoLevel, template, args...) +} + +func (h *Helper) Trace(args ...interface{}) { + h.Logger.Log(TraceLevel, args...) +} + +func (h *Helper) Tracef(template string, args ...interface{}) { + h.Logger.Logf(TraceLevel, template, args...) +} + +func (h *Helper) Debug(args ...interface{}) { + h.Logger.Log(DebugLevel, args...) +} + +func (h *Helper) Debugf(template string, args ...interface{}) { + h.Logger.Logf(DebugLevel, template, args...) +} + +func (h *Helper) Warn(args ...interface{}) { + h.Logger.Log(WarnLevel, args...) +} + +func (h *Helper) Warnf(template string, args ...interface{}) { + h.Logger.Logf(WarnLevel, template, args...) +} + +func (h *Helper) Error(args ...interface{}) { + h.Logger.Log(ErrorLevel, args...) +} + +func (h *Helper) Errorf(template string, args ...interface{}) { + h.Logger.Logf(ErrorLevel, template, args...) +} + +func (h *Helper) Fatal(args ...interface{}) { + h.Logger.Log(ErrorLevel, args...) +} + +func (h *Helper) Fatalf(template string, args ...interface{}) { + h.Logger.Logf(ErrorLevel, template, args...) +} + +func (h *Helper) WithError(err error) *Helper { + return &Helper{h.Logger.Fields(map[string]interface{}{"error": err})} +} diff --git a/logger/logger.go b/logger/logger.go index 1c0dc826..ad3b41a1 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -3,7 +3,7 @@ package logger var ( // Default logger - DefaultLogger Logger = NewLogger() + DefaultLogger Logger = NewHelper(NewLogger()) ) // Logger is a generic logging interface @@ -12,8 +12,6 @@ type Logger interface { Init(options ...Option) error // The Logger options Options() Options - // Error set `error` field to be logged - Error(err error) Logger // Fields set fields to always be logged Fields(fields map[string]interface{}) Logger // Log writes a log entry @@ -43,7 +41,3 @@ func Logf(level Level, format string, v ...interface{}) { func String() string { return DefaultLogger.String() } - -func WithError(err error) Logger { - return DefaultLogger.Error(err) -} diff --git a/logger/logger_test.go b/logger/logger_test.go new file mode 100644 index 00000000..95d9c388 --- /dev/null +++ b/logger/logger_test.go @@ -0,0 +1,9 @@ +package logger + +import "testing" + +func TestLogger(t *testing.T) { + l := NewLogger(WithLevel(TraceLevel)) + h := NewHelper(l) + h.Trace("trace level") +} From 6b8930a9605ce5fc46e9ee381fc45f19d153ca14 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 29 Feb 2020 03:39:41 +0300 Subject: [PATCH 335/788] add new helper method to logger (#1273) Signed-off-by: Vasiliy Tolstov --- logger/helper.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/logger/helper.go b/logger/helper.go index 90a9ea13..2c7be09c 100644 --- a/logger/helper.go +++ b/logger/helper.go @@ -59,3 +59,7 @@ func (h *Helper) Fatalf(template string, args ...interface{}) { func (h *Helper) WithError(err error) *Helper { return &Helper{h.Logger.Fields(map[string]interface{}{"error": err})} } + +func (h *Helper) WithFields(fields map[string]interface{}) *Helper { + return &Helper{h.Logger.Fields(fields)} +} From 0754229878779019aecb68606e781b942be15a23 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 29 Feb 2020 23:00:29 +0300 Subject: [PATCH 336/788] broker/memory: add codec support (#1276) allow easy testing of other services with memory broker and also allows to more deeply simulate real brokers Signed-off-by: Vasiliy Tolstov --- broker/memory/memory.go | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/broker/memory/memory.go b/broker/memory/memory.go index 36554237..1f9bea86 100644 --- a/broker/memory/memory.go +++ b/broker/memory/memory.go @@ -2,6 +2,7 @@ package memory import ( + "context" "errors" "math/rand" "sync" @@ -9,6 +10,7 @@ import ( "github.com/google/uuid" "github.com/micro/go-micro/v2/broker" + log "github.com/micro/go-micro/v2/logger" maddr "github.com/micro/go-micro/v2/util/addr" mnet "github.com/micro/go-micro/v2/util/net" ) @@ -23,8 +25,9 @@ type memoryBroker struct { } type memoryEvent struct { + opts broker.Options topic string - message *broker.Message + message interface{} } type memorySubscriber struct { @@ -85,7 +88,7 @@ func (m *memoryBroker) Init(opts ...broker.Option) error { return nil } -func (m *memoryBroker) Publish(topic string, message *broker.Message, opts ...broker.PublishOption) error { +func (m *memoryBroker) Publish(topic string, msg *broker.Message, opts ...broker.PublishOption) error { m.RLock() if !m.connected { m.RUnlock() @@ -98,9 +101,21 @@ func (m *memoryBroker) Publish(topic string, message *broker.Message, opts ...br return nil } + var v interface{} + if m.opts.Codec != nil { + buf, err := m.opts.Codec.Marshal(msg) + if err != nil { + return err + } + v = buf + } else { + v = msg + } + p := &memoryEvent{ topic: topic, - message: message, + message: v, + opts: m.opts, } for _, sub := range subs { @@ -163,7 +178,19 @@ func (m *memoryEvent) Topic() string { } func (m *memoryEvent) Message() *broker.Message { - return m.message + switch v := m.message.(type) { + case *broker.Message: + return v + case []byte: + msg := &broker.Message{} + if err := m.opts.Codec.Unmarshal(v, msg); err != nil { + log.Errorf("[memory]: failed to unmarshal: %v\n", err) + return nil + } + return msg + } + + return nil } func (m *memoryEvent) Ack() error { @@ -184,7 +211,10 @@ func (m *memorySubscriber) Unsubscribe() error { } func NewBroker(opts ...broker.Option) broker.Broker { - var options broker.Options + options := broker.Options{ + Context: context.Background(), + } + rand.Seed(time.Now().UnixNano()) for _, o := range opts { o(&options) From d8377e09c95504e883884990f8a9226c42a0a89e Mon Sep 17 00:00:00 2001 From: Sumanth Chinthagunta Date: Sat, 29 Feb 2020 13:55:15 -0800 Subject: [PATCH 337/788] feat(dockerfile): adding dumb-init to base image (#1278) --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4d993447..228b07d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ RUN mkdir /user && \ echo 'nobody:x:65534:' > /user/group ENV GO111MODULE=on -RUN apk --no-cache add make git gcc libtool musl-dev ca-certificates && \ +RUN apk --no-cache add make git gcc libtool musl-dev ca-certificates dumb-init && \ rm -rf /var/cache/apk/* /tmp/* WORKDIR / From 9200c7020247b1eab6227747da8baff22b7490e7 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Sun, 1 Mar 2020 22:09:06 +0000 Subject: [PATCH 338/788] Replace validation error with regex for cockroach namespace (#1270) Co-authored-by: Asim Aslam --- store/cockroach/cockroach.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 0e0dc38e..63e16f15 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -5,9 +5,9 @@ import ( "database/sql" "fmt" "net/url" + "regexp" "strings" "time" - "unicode" "github.com/lib/pq" log "github.com/micro/go-micro/v2/logger" @@ -206,16 +206,17 @@ func (s *sqlStore) configure() error { prefix = DefaultPrefix } - for _, r := range namespace { - if !unicode.IsLetter(r) { - return errors.New("store.namespace must only contain letters") - } + // store.namespace must only contain letters + reg, err := regexp.Compile("[^a-zA-Z0-9]+") + if err != nil { + return errors.New("error compiling regex for namespace") } + namespace = reg.ReplaceAllString(namespace, "") source := nodes[0] // check if it is a standard connection string eg: host=%s port=%d user=%s password=%s dbname=%s sslmode=disable // if err is nil which means it would be a URL like postgre://xxxx?yy=zz - _, err := url.Parse(source) + _, err = url.Parse(source) if err != nil { if !strings.Contains(source, " ") { source = fmt.Sprintf("host=%s", source) From b555269b1bcc49c8ae6ceb87d777385adfbddafc Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 2 Mar 2020 17:18:36 +0300 Subject: [PATCH 339/788] copy fields in helper (#1281) Signed-off-by: Vasiliy Tolstov --- logger/helper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logger/helper.go b/logger/helper.go index 2c7be09c..5bc87d10 100644 --- a/logger/helper.go +++ b/logger/helper.go @@ -61,5 +61,5 @@ func (h *Helper) WithError(err error) *Helper { } func (h *Helper) WithFields(fields map[string]interface{}) *Helper { - return &Helper{h.Logger.Fields(fields)} + return &Helper{h.Logger.Fields(copyFields(fields))} } From 1f2e067f7134dbf5c57dc2b1cae57a6d1d684309 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 2 Mar 2020 15:49:10 +0000 Subject: [PATCH 340/788] k8s runtime - get status from pods (#1283) --- runtime/kubernetes/kubernetes.go | 53 ++++++++++++++------------------ util/kubernetes/client/types.go | 12 ++++++-- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 293597a5..760a824a 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -48,12 +48,20 @@ func (k *kubernetes) getService(labels map[string]string) ([]*runtime.Service, e Kind: "deployment", Value: depList, } - - // get the deployment from k8s if err := k.client.Get(d, labels); err != nil { return nil, err } + // get the pods from k8s + podList := new(client.PodList) + p := &client.Resource{ + Kind: "pod", + Value: podList, + } + if err := k.client.Get(p, labels); err != nil { + return nil, err + } + // service map svcMap := make(map[string]*runtime.Service) @@ -107,37 +115,22 @@ func (k *kubernetes) getService(labels map[string]string) ([]*runtime.Service, e svc.Metadata[k] = v } - // parse out deployment status and inject into service metadata - if len(kdep.Status.Conditions) > 0 { - var status string - switch kdep.Status.Conditions[0].Type { - case "Available": - status = "running" - delete(svc.Metadata, "error") - case "Progressing": + // get the status from the pods + status := "unknown" + if len(podList.Items) > 0 { + switch podList.Items[0].Status.Conditions[0].Type { + case "PodScheduled": status = "starting" - delete(svc.Metadata, "error") - default: - status = "error" - svc.Metadata["error"] = kdep.Status.Conditions[0].Message + case "Initialized": + status = "starting" + case "Ready": + status = "ready" + case "ContainersReady": + status = "ready" } - // pick the last known condition type and mark the service status with it - log.Debugf("Runtime setting %s service deployment status: %v", name, status) - svc.Metadata["status"] = status } - - // parse out deployment build - if build, ok := kdep.Spec.Template.Metadata.Annotations["build"]; ok { - buildTime, err := time.Parse(time.RFC3339, build) - if err != nil { - log.Debugf("Runtime failed parsing build time for %s: %v", name, err) - continue - } - svc.Metadata["build"] = fmt.Sprintf("%d", buildTime.Unix()) - continue - } - // if no build annotation is found, set it to current time - svc.Metadata["build"] = fmt.Sprintf("%d", time.Now().Unix()) + log.Debugf("Runtime setting %s service deployment status: %v", name, status) + svc.Metadata["status"] = status } } diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index f437bccb..b82a80df 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -103,8 +103,16 @@ type Pod struct { // PodStatus type PodStatus struct { - PodIP string `json:"podIP"` - Phase string `json:"phase"` + PodIP string `json:"podIP"` + Phase string `json:"phase"` + Conditions []PodCondition `json:"conditions,omitempty"` +} + +// PodCondition describes the state of pod +type PodCondition struct { + Type string `json:"type"` + Reason string `json:"reason,omitempty"` + Message string `json:"message,omitempty"` } // Resource is API resource From 7cad77bfc060e03bd6d0232424790a427f69297e Mon Sep 17 00:00:00 2001 From: Pieter Voorwinden <40570182+PieterVoorwinden@users.noreply.github.com> Date: Mon, 2 Mar 2020 17:17:26 +0100 Subject: [PATCH 341/788] Initialize header to prevent assignment to entry in nil map error (#1282) Co-authored-by: Vasiliy Tolstov --- transport/http_transport.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/transport/http_transport.go b/transport/http_transport.go index 3e8bce8b..2dfe7944 100644 --- a/transport/http_transport.go +++ b/transport/http_transport.go @@ -192,6 +192,9 @@ func (h *httpTransportSocket) Recv(m *Message) error { if m == nil { return errors.New("message passed in is nil") } + if m.Header == nil { + m.Header = make(map[string]string, len(h.r.Header)) + } // process http 1 if h.r.ProtoMajor == 1 { @@ -224,10 +227,6 @@ func (h *httpTransportSocket) Recv(m *Message) error { r.Body.Close() m.Body = b - if m.Header == nil { - m.Header = make(map[string]string, len(r.Header)) - } - // set headers for k, v := range r.Header { if len(v) > 0 { From f6102bde70d344de1b80f30b1333766b0e8e207a Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Mon, 2 Mar 2020 18:14:25 +0000 Subject: [PATCH 342/788] Add a cache to workers KV storage implementation (#1284) * cloudflare-cache * go mod tidy --- go.mod | 1 + go.sum | 5 ++++- store/cloudflare/cloudflare.go | 30 ++++++++++++++++++++++++++++- store/cloudflare/cloudflare_test.go | 1 + store/cloudflare/options.go | 10 ++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 3e58e15b..33c35ba1 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.13 require ( github.com/BurntSushi/toml v0.3.1 + github.com/ReneKroon/ttlcache v1.6.0 github.com/beevik/ntp v0.2.0 github.com/bitly/go-simplejson v0.5.0 github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect diff --git a/go.sum b/go.sum index 3c3fc7aa..c0cf2229 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,8 @@ github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tT github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= +github.com/ReneKroon/ttlcache v1.6.0 h1:aO+GDNVKTQmcuI0H78PXCR9E59JMiGfSXHAkVBUlzbA= +github.com/ReneKroon/ttlcache v1.6.0/go.mod h1:DG6nbhXKUQhrExfwwLuZUdH7UnRDDRA1IW+nBuCssvs= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/akamai/AkamaiOPEN-edgegrid-golang v0.9.0/go.mod h1:zpDJeKyp9ScW4NNrbdr+Eyxvry3ilGPewKoXw3XGN1k= @@ -284,7 +286,6 @@ github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= -github.com/micro/go-micro v1.18.0 h1:gP70EZVHpJuUIT0YWth192JmlIci+qMOEByHm83XE9E= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= @@ -435,6 +436,8 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/goleak v0.10.0 h1:G3eWbSNIskeRqtsN/1uI5B+eP73y3JUuBsv9AZjehb4= +go.uber.org/goleak v0.10.0/go.mod h1:VCZuO8V8mFPlL0F5J5GK1rtHV3DrFcQ1R8ryq7FK0aI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index 7feac885..cbc0a365 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -19,6 +19,8 @@ import ( "github.com/micro/go-micro/v2/store" "github.com/pkg/errors" + + "github.com/ReneKroon/ttlcache" ) const ( @@ -35,6 +37,8 @@ type workersKV struct { namespace string // http client to use httpClient *http.Client + // cache + cache *ttlcache.Cache } // apiResponse is a cloudflare v4 api response @@ -103,6 +107,16 @@ func (w *workersKV) Init(opts ...store.Option) error { if len(w.options.Namespace) > 0 { w.namespace = w.options.Namespace } + ttl := w.options.Context.Value("STORE_CACHE_TTL") + if ttl != nil { + ttlint64, ok := ttl.(int64) + if !ok { + log.Fatal("STORE_CACHE_TTL from context must be type int64") + } + w.cache = ttlcache.NewCache() + w.cache.SetTTL(time.Duration(ttlint64)) + w.cache.SkipTtlExtensionOnHit(true) + } return nil } @@ -191,6 +205,15 @@ func (w *workersKV) Read(key string, opts ...store.ReadOption) ([]*store.Record, var records []*store.Record for _, k := range keys { + if w.cache != nil { + if resp, hit := w.cache.Get(k); hit { + if record, ok := resp.(*store.Record); ok { + records = append(records, record) + continue + } + } + } + path := fmt.Sprintf("accounts/%s/storage/kv/namespaces/%s/values/%s", w.account, w.namespace, url.PathEscape(k)) response, headers, status, err := w.request(ctx, http.MethodGet, path, nil, make(http.Header)) if err != nil { @@ -210,6 +233,7 @@ func (w *workersKV) Read(key string, opts ...store.ReadOption) ([]*store.Record, } record.Expiry = time.Until(time.Unix(expiryUnix, 0)) } + w.cache.Set(record.Key, record) records = append(records, record) } @@ -217,6 +241,10 @@ func (w *workersKV) Read(key string, opts ...store.ReadOption) ([]*store.Record, } func (w *workersKV) Write(r *store.Record) error { + // Set it in local cache, with the global TTL from options + if w.cache != nil { + w.cache.Set(r.Key, r) + } ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() @@ -336,7 +364,7 @@ func (w *workersKV) String() string { return "cloudflare" } -// New returns a cloudflare Store implementation. +// NewStore returns a cloudflare Store implementation. // Account ID, Token and Namespace must either be passed as options or // environment variables. If set as env vars we expect the following; // CF_API_TOKEN to a cloudflare API token scoped to Workers KV. diff --git a/store/cloudflare/cloudflare_test.go b/store/cloudflare/cloudflare_test.go index ee5deee1..dbf78c26 100644 --- a/store/cloudflare/cloudflare_test.go +++ b/store/cloudflare/cloudflare_test.go @@ -24,6 +24,7 @@ func TestCloudflare(t *testing.T) { Token(apiToken), Account(accountID), Namespace(kvID), + CacheTTL(60000000000), ) records, err := wkv.List() diff --git a/store/cloudflare/options.go b/store/cloudflare/options.go index 8b307024..71331d12 100644 --- a/store/cloudflare/options.go +++ b/store/cloudflare/options.go @@ -51,3 +51,13 @@ func Namespace(ns string) store.Option { o.Namespace = ns } } + +// CacheTTL sets the timeout in nanoseconds of the read/write cache +func CacheTTL(ttl int64) store.Option { + return func(o *store.Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, "STORE_CACHE_TTL", ttl) + } +} From 89ba602e17acbec740e5f27af7b490e539f2193b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 3 Mar 2020 11:07:38 +0300 Subject: [PATCH 343/788] logger fixes and improvements (#1285) * fix helper fields * add metadata output for default logger Signed-off-by: Vasiliy Tolstov --- logger/default.go | 25 +++++++++++++++++++++++-- logger/helper.go | 37 ++++++++++++++++++++++--------------- logger/logger_test.go | 10 ++++++++-- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/logger/default.go b/logger/default.go index ce4498ef..4eb0e1b6 100644 --- a/logger/default.go +++ b/logger/default.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "sort" "sync" "time" @@ -59,14 +60,24 @@ func (l *defaultLogger) Log(level Level, v ...interface{}) { Message: fmt.Sprint(v...), Metadata: make(map[string]string, len(fields)), } + + keys := make([]string, 0, len(fields)) for k, v := range fields { + keys = append(keys, k) rec.Metadata[k] = fmt.Sprintf("%v", v) } + sort.Strings(keys) + metadata := "" + + for _, k := range keys { + metadata += fmt.Sprintf(" %s=%v", k, fields[k]) + } + dlog.DefaultLog.Write(rec) t := rec.Timestamp.Format("2006-01-02 15:04:05") - fmt.Printf("%s %v\n", t, rec.Message) + fmt.Printf("%s %s %v\n", t, metadata, rec.Message) } func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) { @@ -86,14 +97,24 @@ func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) { Message: fmt.Sprintf(format, v...), Metadata: make(map[string]string, len(fields)), } + + keys := make([]string, 0, len(fields)) for k, v := range fields { + keys = append(keys, k) rec.Metadata[k] = fmt.Sprintf("%v", v) } + sort.Strings(keys) + metadata := "" + + for _, k := range keys { + metadata += fmt.Sprintf(" %s=%v", k, fields[k]) + } + dlog.DefaultLog.Write(rec) t := rec.Timestamp.Format("2006-01-02 15:04:05") - fmt.Printf("%s %v\n", t, rec.Message) + fmt.Printf("%s %s %v\n", t, metadata, rec.Message) } func (n *defaultLogger) Options() Options { diff --git a/logger/helper.go b/logger/helper.go index 5bc87d10..3ccd0cf0 100644 --- a/logger/helper.go +++ b/logger/helper.go @@ -2,64 +2,71 @@ package logger type Helper struct { Logger + fields map[string]interface{} } func NewHelper(log Logger) *Helper { - return &Helper{log} + return &Helper{Logger: log} } func (h *Helper) Info(args ...interface{}) { - h.Logger.Log(InfoLevel, args...) + h.Logger.Fields(h.fields).Log(InfoLevel, args...) } func (h *Helper) Infof(template string, args ...interface{}) { - h.Logger.Logf(InfoLevel, template, args...) + h.Logger.Fields(h.fields).Logf(InfoLevel, template, args...) } func (h *Helper) Trace(args ...interface{}) { - h.Logger.Log(TraceLevel, args...) + h.Logger.Fields(h.fields).Log(TraceLevel, args...) } func (h *Helper) Tracef(template string, args ...interface{}) { - h.Logger.Logf(TraceLevel, template, args...) + h.Logger.Fields(h.fields).Logf(TraceLevel, template, args...) } func (h *Helper) Debug(args ...interface{}) { - h.Logger.Log(DebugLevel, args...) + h.Logger.Fields(h.fields).Log(DebugLevel, args...) } func (h *Helper) Debugf(template string, args ...interface{}) { - h.Logger.Logf(DebugLevel, template, args...) + h.Logger.Fields(h.fields).Logf(DebugLevel, template, args...) } func (h *Helper) Warn(args ...interface{}) { - h.Logger.Log(WarnLevel, args...) + h.Logger.Fields(h.fields).Log(WarnLevel, args...) } func (h *Helper) Warnf(template string, args ...interface{}) { - h.Logger.Logf(WarnLevel, template, args...) + h.Logger.Fields(h.fields).Logf(WarnLevel, template, args...) } func (h *Helper) Error(args ...interface{}) { - h.Logger.Log(ErrorLevel, args...) + h.Logger.Fields(h.fields).Log(ErrorLevel, args...) } func (h *Helper) Errorf(template string, args ...interface{}) { - h.Logger.Logf(ErrorLevel, template, args...) + h.Logger.Fields(h.fields).Logf(ErrorLevel, template, args...) } func (h *Helper) Fatal(args ...interface{}) { - h.Logger.Log(ErrorLevel, args...) + h.Logger.Fields(h.fields).Log(ErrorLevel, args...) } func (h *Helper) Fatalf(template string, args ...interface{}) { - h.Logger.Logf(ErrorLevel, template, args...) + h.Logger.Fields(h.fields).Logf(ErrorLevel, template, args...) } func (h *Helper) WithError(err error) *Helper { - return &Helper{h.Logger.Fields(map[string]interface{}{"error": err})} + fields := copyFields(h.fields) + fields["error"] = err + return &Helper{Logger: h.Logger, fields: fields} } func (h *Helper) WithFields(fields map[string]interface{}) *Helper { - return &Helper{h.Logger.Fields(copyFields(fields))} + nfields := copyFields(fields) + for k, v := range h.fields { + nfields[k] = v + } + return &Helper{Logger: h.Logger, fields: nfields} } diff --git a/logger/logger_test.go b/logger/logger_test.go index 95d9c388..70d559bb 100644 --- a/logger/logger_test.go +++ b/logger/logger_test.go @@ -4,6 +4,12 @@ import "testing" func TestLogger(t *testing.T) { l := NewLogger(WithLevel(TraceLevel)) - h := NewHelper(l) - h.Trace("trace level") + h1 := NewHelper(l).WithFields(map[string]interface{}{"key1": "val1"}) + h1.Trace("trace_msg1") + h1.Warn("warn_msg1") + + h2 := NewHelper(l).WithFields(map[string]interface{}{"key2": "val2"}) + h2.Trace("trace_msg2") + h2.Warn("warn_msg2") + } From bc71989e2cd44caf8e937d9eb889d140e313543d Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 3 Mar 2020 13:15:26 +0000 Subject: [PATCH 344/788] int64 -> time.Duration (#1287) --- store/cloudflare/cloudflare.go | 7 +++++-- store/cloudflare/options.go | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index cbc0a365..fcf38778 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -109,12 +109,12 @@ func (w *workersKV) Init(opts ...store.Option) error { } ttl := w.options.Context.Value("STORE_CACHE_TTL") if ttl != nil { - ttlint64, ok := ttl.(int64) + ttlduration, ok := ttl.(time.Duration) if !ok { log.Fatal("STORE_CACHE_TTL from context must be type int64") } w.cache = ttlcache.NewCache() - w.cache.SetTTL(time.Duration(ttlint64)) + w.cache.SetTTL(ttlduration) w.cache.SkipTtlExtensionOnHit(true) } return nil @@ -279,6 +279,9 @@ func (w *workersKV) Write(r *store.Record) error { } func (w *workersKV) Delete(key string) error { + if w.cache != nil { + w.cache.Remove(key) + } ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() diff --git a/store/cloudflare/options.go b/store/cloudflare/options.go index 71331d12..dd2aee36 100644 --- a/store/cloudflare/options.go +++ b/store/cloudflare/options.go @@ -2,6 +2,7 @@ package cloudflare import ( "context" + "time" "github.com/micro/go-micro/v2/store" ) @@ -53,7 +54,7 @@ func Namespace(ns string) store.Option { } // CacheTTL sets the timeout in nanoseconds of the read/write cache -func CacheTTL(ttl int64) store.Option { +func CacheTTL(ttl time.Duration) store.Option { return func(o *store.Options) { if o.Context == nil { o.Context = context.Background() From eebd69c995a329f1caa204251d973b96bc05c751 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 3 Mar 2020 13:35:49 +0000 Subject: [PATCH 345/788] Change from renekroon/ttlcache to patrickmn/go-cache (#1288) --- go.mod | 2 +- go.sum | 6 ++---- store/cloudflare/cloudflare.go | 14 ++++++-------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 33c35ba1..cb4fbcb2 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.13 require ( github.com/BurntSushi/toml v0.3.1 - github.com/ReneKroon/ttlcache v1.6.0 github.com/beevik/ntp v0.2.0 github.com/bitly/go-simplejson v0.5.0 github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect @@ -47,6 +46,7 @@ require ( github.com/nats-io/nats.go v1.9.1 github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c + github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 diff --git a/go.sum b/go.sum index c0cf2229..17c35f27 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,6 @@ github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tT github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= -github.com/ReneKroon/ttlcache v1.6.0 h1:aO+GDNVKTQmcuI0H78PXCR9E59JMiGfSXHAkVBUlzbA= -github.com/ReneKroon/ttlcache v1.6.0/go.mod h1:DG6nbhXKUQhrExfwwLuZUdH7UnRDDRA1IW+nBuCssvs= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/akamai/AkamaiOPEN-edgegrid-golang v0.9.0/go.mod h1:zpDJeKyp9ScW4NNrbdr+Eyxvry3ilGPewKoXw3XGN1k= @@ -349,6 +347,8 @@ github.com/oracle/oci-go-sdk v7.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukw github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014/go.mod h1:joRatxRJaZBsY3JAOEMcoOp05CnZzsx4scTxi95DHyQ= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= +github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= +github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -436,8 +436,6 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/goleak v0.10.0 h1:G3eWbSNIskeRqtsN/1uI5B+eP73y3JUuBsv9AZjehb4= -go.uber.org/goleak v0.10.0/go.mod h1:VCZuO8V8mFPlL0F5J5GK1rtHV3DrFcQ1R8ryq7FK0aI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index fcf38778..52505508 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -20,7 +20,7 @@ import ( "github.com/micro/go-micro/v2/store" "github.com/pkg/errors" - "github.com/ReneKroon/ttlcache" + "github.com/patrickmn/go-cache" ) const ( @@ -38,7 +38,7 @@ type workersKV struct { // http client to use httpClient *http.Client // cache - cache *ttlcache.Cache + cache *cache.Cache } // apiResponse is a cloudflare v4 api response @@ -113,9 +113,7 @@ func (w *workersKV) Init(opts ...store.Option) error { if !ok { log.Fatal("STORE_CACHE_TTL from context must be type int64") } - w.cache = ttlcache.NewCache() - w.cache.SetTTL(ttlduration) - w.cache.SkipTtlExtensionOnHit(true) + w.cache = cache.New(ttlduration, 3*ttlduration) } return nil } @@ -233,7 +231,7 @@ func (w *workersKV) Read(key string, opts ...store.ReadOption) ([]*store.Record, } record.Expiry = time.Until(time.Unix(expiryUnix, 0)) } - w.cache.Set(record.Key, record) + w.cache.Set(record.Key, record, cache.DefaultExpiration) records = append(records, record) } @@ -243,7 +241,7 @@ func (w *workersKV) Read(key string, opts ...store.ReadOption) ([]*store.Record, func (w *workersKV) Write(r *store.Record) error { // Set it in local cache, with the global TTL from options if w.cache != nil { - w.cache.Set(r.Key, r) + w.cache.Set(r.Key, r, cache.DefaultExpiration) } ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() @@ -280,7 +278,7 @@ func (w *workersKV) Write(r *store.Record) error { func (w *workersKV) Delete(key string) error { if w.cache != nil { - w.cache.Remove(key) + w.cache.Delete(key) } ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() From beb5e80e87dfb149775d26cbe28d9cfd65ab3dda Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 3 Mar 2020 13:54:56 +0000 Subject: [PATCH 346/788] Fix nil pointer dereference (#1289) --- store/cloudflare/cloudflare.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index 52505508..f36f644a 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -231,7 +231,9 @@ func (w *workersKV) Read(key string, opts ...store.ReadOption) ([]*store.Record, } record.Expiry = time.Until(time.Unix(expiryUnix, 0)) } - w.cache.Set(record.Key, record, cache.DefaultExpiration) + if w.cache != nil { + w.cache.Set(record.Key, record, cache.DefaultExpiration) + } records = append(records, record) } From 49ffc60afbdb96df7057bbf2236b743713f374d0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 3 Mar 2020 16:47:15 +0000 Subject: [PATCH 347/788] Use Foo.Call on /foo (#1286) Co-authored-by: Jake Sanders --- api/resolver/micro/route.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/resolver/micro/route.go b/api/resolver/micro/route.go index 96b128c8..b2f94b01 100644 --- a/api/resolver/micro/route.go +++ b/api/resolver/micro/route.go @@ -18,6 +18,11 @@ func apiRoute(p string) (string, string) { p = strings.TrimPrefix(p, "/") parts := strings.Split(p, "/") + // if we have 1 part assume name Name.Call + if len(parts) == 1 && len(parts[0]) > 0 { + return parts[0], methodName(append(parts, "Call")) + } + // If we've got two or less parts // Use first part as service // Use all parts as method From 3f0c28a815ae0107342883f7e6bdca79fc18b45a Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 3 Mar 2020 18:15:50 +0000 Subject: [PATCH 348/788] Expiration is actually a unix timestamp (#1290) * Expiration is actually a unix timestamp * int -> int64 --- store/cloudflare/cloudflare.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index f36f644a..07d2113f 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -47,12 +47,12 @@ type apiResponse struct { ID string `json:"id"` Type string `json:"type"` Name string `json:"name"` - Expiration string `json:"expiration"` + Expiration int64 `json:"expiration"` Content string `json:"content"` Proxiable bool `json:"proxiable"` Proxied bool `json:"proxied"` - TTL int `json:"ttl"` - Priority int `json:"priority"` + TTL int64 `json:"ttl"` + Priority int64 `json:"priority"` Locked bool `json:"locked"` ZoneID string `json:"zone_id"` ZoneName string `json:"zone_name"` From 6a9001bdb1603d1a4eca8eeebd4adbc1e2bc053f Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 4 Mar 2020 09:54:52 +0000 Subject: [PATCH 349/788] Set auth account in context (#1293) --- auth/auth.go | 42 +++++++++++++++++++++++++++++++++++++++++ util/wrapper/wrapper.go | 32 ++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index f98b2a67..06ef3b5d 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -2,7 +2,11 @@ package auth import ( + "context" + "encoding/json" "time" + + "github.com/micro/go-micro/v2/metadata" ) // Auth providers authentication and authorization @@ -53,3 +57,41 @@ type Account struct { // Any other associated metadata Metadata map[string]string `json:"metadata"` } + +const ( + // MetadataKey is the key used when storing the account + // in metadata + MetadataKey = "auth-account" +) + +// AccountFromContext gets the account from the context, which +// is set by the auth wrapper at the start of a call. If the account +// is not set, a nil account will be returned. The error is only returned +// when there was a problem retrieving an account +func AccountFromContext(ctx context.Context) (*Account, error) { + str, ok := metadata.Get(ctx, MetadataKey) + // there was no account set + if !ok { + return nil, nil + } + + var acc *Account + // metadata is stored as a string, so unmarshal to an account + if err := json.Unmarshal([]byte(str), &acc); err != nil { + return nil, err + } + + return acc, nil +} + +// ContextWithAccount sets the account in the context +func ContextWithAccount(ctx context.Context, account *Account) (context.Context, error) { + // metadata is stored as a string, so marshal to bytes + bytes, err := json.Marshal(account) + if err != nil { + return ctx, err + } + + // generate a new context with the MetadataKey set + return metadata.Set(ctx, MetadataKey, string(bytes)), nil +} diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index b83aeca0..80dc702b 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -164,13 +164,6 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { return h(ctx, req, rsp) } - // Exclude any user excluded endpoints - for _, e := range a.Options().Exclude { - if e == req.Endpoint() { - return h(ctx, req, rsp) - } - } - // Extract the token if present. Note: if noop is being used // then the token can be blank without erroring var token string @@ -184,10 +177,31 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { } // Verify the token - if _, err := a.Verify(token); err != nil { - return errors.Unauthorized("go.micro.auth", err.Error()) + account, authErr := a.Verify(token) + + // If there is an account, set it in the context + if authErr == nil { + var err error + ctx, err = auth.ContextWithAccount(ctx, account) + + if err != nil { + return err + } } + // Return if the user disabled auth on this endpoint + for _, e := range a.Options().Exclude { + if e == req.Endpoint() { + return h(ctx, req, rsp) + } + } + + // If the authErr is set, prevent the user from calling the endpoint + if authErr != nil { + return errors.Unauthorized("go.micro.auth", authErr.Error()) + } + + // The user is authorised, allow the call return h(ctx, req, rsp) } } From 6d803d9e4514ee3320fa1f0231939ee0e5907493 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 4 Mar 2020 11:40:53 +0000 Subject: [PATCH 350/788] Implement api/server/cors (#1294) --- api/server/cors/cors.go | 43 +++++++++++++++++++++++++++++++++++++++++ api/server/http/http.go | 9 ++++++++- api/server/options.go | 7 +++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 api/server/cors/cors.go diff --git a/api/server/cors/cors.go b/api/server/cors/cors.go new file mode 100644 index 00000000..090d6632 --- /dev/null +++ b/api/server/cors/cors.go @@ -0,0 +1,43 @@ +package cors + +import ( + "net/http" +) + +// CombinedCORSHandler wraps a server and provides CORS headers +func CombinedCORSHandler(h http.Handler) http.Handler { + return corsHandler{h} +} + +type corsHandler struct { + handler http.Handler +} + +func (c corsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + SetHeaders(w, r) + + if r.Method == "OPTIONS" { + return + } + + c.handler.ServeHTTP(w, r) +} + +// SetHeaders sets the CORS headers +func SetHeaders(w http.ResponseWriter, r *http.Request) { + set := func(w http.ResponseWriter, k, v string) { + if v := w.Header().Get(k); len(v) > 0 { + return + } + w.Header().Set(k, v) + } + + if origin := r.Header.Get("Origin"); len(origin) > 0 { + set(w, "Access-Control-Allow-Origin", origin) + } else { + set(w, "Access-Control-Allow-Origin", "*") + } + + set(w, "Access-Control-Allow-Methods", "POST, PATCH, GET, OPTIONS, PUT, DELETE") + set(w, "Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization") +} diff --git a/api/server/http/http.go b/api/server/http/http.go index f5fe5d24..214f203e 100644 --- a/api/server/http/http.go +++ b/api/server/http/http.go @@ -10,6 +10,7 @@ import ( "github.com/gorilla/handlers" "github.com/micro/go-micro/v2/api/server" + "github.com/micro/go-micro/v2/api/server/cors" log "github.com/micro/go-micro/v2/logger" ) @@ -45,7 +46,13 @@ func (s *httpServer) Init(opts ...server.Option) error { } func (s *httpServer) Handle(path string, handler http.Handler) { - s.mux.Handle(path, handlers.CombinedLoggingHandler(os.Stdout, handler)) + h := handlers.CombinedLoggingHandler(os.Stdout, handler) + + if s.opts.EnableCORS { + h = cors.CombinedCORSHandler(h) + } + + s.mux.Handle(path, h) } func (s *httpServer) Start() error { diff --git a/api/server/options.go b/api/server/options.go index 687e0926..99be1a03 100644 --- a/api/server/options.go +++ b/api/server/options.go @@ -10,12 +10,19 @@ type Option func(o *Options) type Options struct { EnableACME bool + EnableCORS bool ACMEProvider acme.Provider EnableTLS bool ACMEHosts []string TLSConfig *tls.Config } +func EnableCORS(b bool) Option { + return func(o *Options) { + o.EnableCORS = b + } +} + func EnableACME(b bool) Option { return func(o *Options) { o.EnableACME = b From 9386f36a130016ff6737f7aa8cd4f33c0346b928 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 4 Mar 2020 13:46:01 +0000 Subject: [PATCH 351/788] Exit on log.Fatal (#1297) --- logger/helper.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/logger/helper.go b/logger/helper.go index 3ccd0cf0..00ac1304 100644 --- a/logger/helper.go +++ b/logger/helper.go @@ -1,5 +1,7 @@ package logger +import "os" + type Helper struct { Logger fields map[string]interface{} @@ -51,10 +53,12 @@ func (h *Helper) Errorf(template string, args ...interface{}) { func (h *Helper) Fatal(args ...interface{}) { h.Logger.Fields(h.fields).Log(ErrorLevel, args...) + os.Exit(1) } func (h *Helper) Fatalf(template string, args ...interface{}) { h.Logger.Fields(h.fields).Logf(ErrorLevel, template, args...) + os.Exit(1) } func (h *Helper) WithError(err error) *Helper { From 67c26c71b6e5f60155dc01266ba068da6aab08be Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 4 Mar 2020 15:37:17 +0000 Subject: [PATCH 352/788] add jitter (#1298) --- util/jitter/jitter.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 util/jitter/jitter.go diff --git a/util/jitter/jitter.go b/util/jitter/jitter.go new file mode 100644 index 00000000..24e0700d --- /dev/null +++ b/util/jitter/jitter.go @@ -0,0 +1,17 @@ +// Package jitter provides a random jitter +package jitter + +import ( + "math/rand" + "time" +) + +var ( + r = rand.New(rand.NewSource(time.Now().UnixNano())) +) + +// Do returns a random time to jitter with max cap specified +func Do(d time.Duration) time.Duration { + v := r.Float64() * float64(d.Nanoseconds()) + return time.Duration(v) +} From ce2ba7100268d4f5f499a4150d433e520a58d962 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 5 Mar 2020 10:29:50 +0300 Subject: [PATCH 353/788] server: subscribe to topic with own name if router not nil (#1295) * server: subscribe to topic with own name if router not nil Signed-off-by: Vasiliy Tolstov --- server/rpc_server.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/server/rpc_server.go b/server/rpc_server.go index eb079883..173f4f66 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -630,14 +630,17 @@ func (s *rpcServer) Register() error { // set what we're advertising s.opts.Advertise = addr - // subscribe to the topic with own name - sub, err := s.opts.Broker.Subscribe(config.Name, s.HandleEvent) - if err != nil { - return err - } + // router can exchange messages + if s.opts.Router != nil { + // subscribe to the topic with own name + sub, err := s.opts.Broker.Subscribe(config.Name, s.HandleEvent) + if err != nil { + return err + } - // save the subscriber - s.subscriber = sub + // save the subscriber + s.subscriber = sub + } // subscribe for all of the subscribers for sb := range s.subscribers { @@ -654,11 +657,11 @@ func (s *rpcServer) Register() error { opts = append(opts, broker.DisableAutoAck()) } - log.Infof("Subscribing to topic: %s", sub.Topic()) sub, err := config.Broker.Subscribe(sb.Topic(), s.HandleEvent, opts...) if err != nil { return err } + log.Infof("Subscribing to topic: %s", sub.Topic()) s.subscribers[sb] = []broker.Subscriber{sub} } From d807dac2a7c3377e0c30af45b022afd9c384050b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 5 Mar 2020 17:45:31 +0300 Subject: [PATCH 354/788] server/grpc: avoid panic in case of nil Header (#1303) Signed-off-by: Vasiliy Tolstov --- server/grpc/subscriber.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/grpc/subscriber.go b/server/grpc/subscriber.go index bfe54b8f..e77f3d79 100644 --- a/server/grpc/subscriber.go +++ b/server/grpc/subscriber.go @@ -178,6 +178,11 @@ func (g *grpcServer) createSubHandler(sb *subscriber, opts server.Options) broke }() msg := p.Message() + // if we don't ave headers, create empty map + if msg.Header == nil { + msg.Header = make(map[string]string) + } + ct := msg.Header["Content-Type"] if len(ct) == 0 { msg.Header["Content-Type"] = defaultContentType From a851b9db7afed0032330e0a0ec44ffe63c9b2bde Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Thu, 5 Mar 2020 14:55:46 +0000 Subject: [PATCH 355/788] Comment typo in gRPC subscriber (#1304) --- server/grpc/subscriber.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/grpc/subscriber.go b/server/grpc/subscriber.go index e77f3d79..c36071fd 100644 --- a/server/grpc/subscriber.go +++ b/server/grpc/subscriber.go @@ -178,7 +178,7 @@ func (g *grpcServer) createSubHandler(sb *subscriber, opts server.Options) broke }() msg := p.Message() - // if we don't ave headers, create empty map + // if we don't have headers, create empty map if msg.Header == nil { msg.Header = make(map[string]string) } From ae60bea8d89f99b234f97bc3c55efc6aa46bb9a0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 6 Mar 2020 14:40:47 +0000 Subject: [PATCH 356/788] add stream fix (#1305) --- util/stream/stream.go | 87 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 util/stream/stream.go diff --git a/util/stream/stream.go b/util/stream/stream.go new file mode 100644 index 00000000..9348009f --- /dev/null +++ b/util/stream/stream.go @@ -0,0 +1,87 @@ +// Package stream encapsulates streams within streams +package stream + +import ( + "context" + "sync" + + "github.com/micro/go-micro/client" + "github.com/micro/go-micro/codec" + "github.com/micro/go-micro/metadata" + "github.com/micro/go-micro/server" +) + +type Stream interface { + Context() context.Context + SendMsg(interface{}) error + RecvMsg(interface{}) error + Close() error +} + +type stream struct { + Stream + + sync.RWMutex + err error + request *request +} + +type request struct { + client.Request + context context.Context +} + +func (r *request) Codec() codec.Reader { + return r.Request.Codec().(codec.Reader) +} + +func (r *request) Header() map[string]string { + md, _ := metadata.FromContext(r.context) + return md +} + +func (r *request) Read() ([]byte, error) { + return nil, nil +} + +func (s *stream) Request() server.Request { + return s.request +} + +func (s *stream) Send(v interface{}) error { + err := s.Stream.SendMsg(v) + if err != nil { + s.Lock() + s.err = err + s.Unlock() + } + return err +} + +func (s *stream) Recv(v interface{}) error { + err := s.Stream.RecvMsg(v) + if err != nil { + s.Lock() + s.err = err + s.Unlock() + } + return err +} + +func (s *stream) Error() error { + s.RLock() + defer s.RUnlock() + return s.err +} + +// New returns a new encapsulated stream +// Proto stream within a server.Stream +func New(service, endpoint string, req interface{}, s Stream) server.Stream { + return &stream{ + Stream: s, + request: &request{ + context: s.Context(), + Request: client.DefaultClient.NewRequest(service, endpoint, req), + }, + } +} From a864f812f14385394fbb9e2fb001eb786f4d70b4 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 6 Mar 2020 18:44:56 +0300 Subject: [PATCH 357/788] web: fix ipv6 address issue (#1308) Signed-off-by: Vasiliy Tolstov --- web/service.go | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/web/service.go b/web/service.go index 5d242e8d..b133539d 100644 --- a/web/service.go +++ b/web/service.go @@ -8,7 +8,6 @@ import ( "os" "os/signal" "path/filepath" - "strconv" "strings" "sync" "syscall" @@ -48,35 +47,35 @@ func newService(opts ...Option) Service { } func (s *service) genSrv() *registry.Service { + var host string + var port string + var err error + // default host:port - parts := strings.Split(s.opts.Address, ":") - host := strings.Join(parts[:len(parts)-1], ":") - port, _ := strconv.Atoi(parts[len(parts)-1]) + if len(s.opts.Address) > 0 { + host, port, err = net.SplitHostPort(s.opts.Address) + if err != nil { + log.Fatal(err) + } + } // check the advertise address first // if it exists then use it, otherwise // use the address if len(s.opts.Advertise) > 0 { - parts = strings.Split(s.opts.Advertise, ":") - - // we have host:port - if len(parts) > 1 { - // set the host - host = strings.Join(parts[:len(parts)-1], ":") - - // get the port - if aport, _ := strconv.Atoi(parts[len(parts)-1]); aport > 0 { - port = aport - } - } else { - host = parts[0] + host, port, err = net.SplitHostPort(s.opts.Address) + if err != nil { + log.Fatal(err) } } addr, err := maddr.Extract(host) if err != nil { - // best effort localhost - addr = "127.0.0.1" + log.Fatal(err) + } + + if strings.Count(addr, ":") > 0 { + addr = "[" + addr + "]" } return ®istry.Service{ @@ -84,7 +83,7 @@ func (s *service) genSrv() *registry.Service { Version: s.opts.Version, Nodes: []*registry.Node{{ Id: s.opts.Id, - Address: fmt.Sprintf("%s:%d", addr, port), + Address: fmt.Sprintf("%s:%s", addr, port), Metadata: s.opts.Metadata, }}, } From 11be2c68b997c1c5613e267f92bca71c5fa6f49b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 7 Mar 2020 00:17:57 +0300 Subject: [PATCH 358/788] util/stream: fix imports (#1310) Signed-off-by: Vasiliy Tolstov --- util/stream/stream.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/stream/stream.go b/util/stream/stream.go index 9348009f..22f0703e 100644 --- a/util/stream/stream.go +++ b/util/stream/stream.go @@ -5,10 +5,10 @@ import ( "context" "sync" - "github.com/micro/go-micro/client" - "github.com/micro/go-micro/codec" - "github.com/micro/go-micro/metadata" - "github.com/micro/go-micro/server" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/codec" + "github.com/micro/go-micro/v2/metadata" + "github.com/micro/go-micro/v2/server" ) type Stream interface { From 8ee56072549dee5f7b29e8c99b295a8682622305 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 7 Mar 2020 00:25:16 +0300 Subject: [PATCH 359/788] [WIP]: broker ErrorHandler option (#1296) * broker ErrorHandler option Signed-off-by: Vasiliy Tolstov * rewrite Event interface, add error Signed-off-by: Vasiliy Tolstov * implement new interface Signed-off-by: Vasiliy Tolstov * change ErrorHandler func to broker.Handler Signed-off-by: Vasiliy Tolstov * fix Signed-off-by: Vasiliy Tolstov --- broker/broker.go | 1 + broker/default.go | 29 +++++++++++++++++++++++++---- broker/memory/memory.go | 10 ++++++++++ broker/nats/nats.go | 29 +++++++++++++++++++++++++---- broker/options.go | 19 ++++++++++++++++--- broker/service/subscriber.go | 11 ++++++++--- server/rpc_event.go | 5 +++++ tunnel/broker/broker.go | 4 ++++ 8 files changed, 94 insertions(+), 14 deletions(-) diff --git a/broker/broker.go b/broker/broker.go index 97845f12..b1ce35bd 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -28,6 +28,7 @@ type Event interface { Topic() string Message() *Message Ack() error + Error() error } // Subscriber is a convenience return type for the Subscribe method diff --git a/broker/default.go b/broker/default.go index b8b8ffe1..05eef916 100644 --- a/broker/default.go +++ b/broker/default.go @@ -53,8 +53,9 @@ type subscriber struct { } type publication struct { - t string - m *Message + t string + err error + m *Message } func (p *publication) Topic() string { @@ -70,6 +71,10 @@ func (p *publication) Ack() error { return nil } +func (p *publication) Error() error { + return p.err +} + func (s *subscriber) Options() SubscribeOptions { return s.opts } @@ -390,10 +395,26 @@ func (n *natsBroker) Subscribe(topic string, handler Handler, opts ...SubscribeO fn := func(msg *nats.Msg) { var m Message - if err := n.opts.Codec.Unmarshal(msg.Data, &m); err != nil { + pub := &publication{t: msg.Subject} + eh := n.opts.ErrorHandler + err := n.opts.Codec.Unmarshal(msg.Data, &m) + pub.err = err + pub.m = &m + if err != nil { + m.Body = msg.Data + log.Error(err) + if eh != nil { + eh(pub) + } return } - handler(&publication{m: &m, t: msg.Subject}) + if err := handler(pub); err != nil { + pub.err = err + log.Error(err) + if eh != nil { + eh(pub) + } + } } var sub *nats.Subscription diff --git a/broker/memory/memory.go b/broker/memory/memory.go index 1f9bea86..2a449467 100644 --- a/broker/memory/memory.go +++ b/broker/memory/memory.go @@ -27,6 +27,7 @@ type memoryBroker struct { type memoryEvent struct { opts broker.Options topic string + err error message interface{} } @@ -120,6 +121,11 @@ func (m *memoryBroker) Publish(topic string, msg *broker.Message, opts ...broker for _, sub := range subs { if err := sub.handler(p); err != nil { + p.err = err + if eh := m.opts.ErrorHandler; eh != nil { + eh(p) + continue + } return err } } @@ -197,6 +203,10 @@ func (m *memoryEvent) Ack() error { return nil } +func (m *memoryEvent) Error() error { + return m.err +} + func (m *memorySubscriber) Options() broker.SubscribeOptions { return m.opts } diff --git a/broker/nats/nats.go b/broker/nats/nats.go index 89bfd1e7..1af597eb 100644 --- a/broker/nats/nats.go +++ b/broker/nats/nats.go @@ -50,8 +50,9 @@ type subscriber struct { } type publication struct { - t string - m *broker.Message + t string + err error + m *broker.Message } func (p *publication) Topic() string { @@ -67,6 +68,10 @@ func (p *publication) Ack() error { return nil } +func (p *publication) Error() error { + return p.err +} + func (s *subscriber) Options() broker.SubscribeOptions { return s.opts } @@ -375,10 +380,26 @@ func (n *natsBroker) Subscribe(topic string, handler broker.Handler, opts ...bro fn := func(msg *nats.Msg) { var m broker.Message - if err := n.opts.Codec.Unmarshal(msg.Data, &m); err != nil { + pub := &publication{t: msg.Subject} + eh := n.opts.ErrorHandler + err := n.opts.Codec.Unmarshal(msg.Data, &m) + pub.err = err + pub.m = &m + if err != nil { + m.Body = msg.Data + log.Error(err) + if eh != nil { + eh(pub) + } return } - handler(&publication{m: &m, t: msg.Subject}) + if err := handler(pub); err != nil { + pub.err = err + log.Error(err) + if eh != nil { + eh(pub) + } + } } var sub *nats.Subscription diff --git a/broker/options.go b/broker/options.go index 3fdc4dbc..b3317d24 100644 --- a/broker/options.go +++ b/broker/options.go @@ -9,9 +9,14 @@ import ( ) type Options struct { - Addrs []string - Secure bool - Codec codec.Marshaler + Addrs []string + Secure bool + Codec codec.Marshaler + + // Handler executed when error happens in broker mesage + // processing + ErrorHandler Handler + TLSConfig *tls.Config // Registry used for clustering Registry registry.Registry @@ -81,6 +86,14 @@ func DisableAutoAck() SubscribeOption { } } +// ErrorHandler will catch all broker errors that cant be handled +// in normal way, for example Codec errors +func ErrorHandler(h Handler) Option { + return func(o *Options) { + o.ErrorHandler = h + } +} + // Queue sets the name of the queue to share messages on func Queue(name string) SubscribeOption { return func(o *SubscribeOptions) { diff --git a/broker/service/subscriber.go b/broker/service/subscriber.go index 2e92ad43..662d6d50 100644 --- a/broker/service/subscriber.go +++ b/broker/service/subscriber.go @@ -17,6 +17,7 @@ type serviceSub struct { type serviceEvent struct { topic string + err error message *broker.Message } @@ -32,6 +33,10 @@ func (s *serviceEvent) Ack() error { return nil } +func (s *serviceEvent) Error() error { + return s.err +} + func (s *serviceSub) isClosed() bool { select { case <-s.closed: @@ -71,14 +76,14 @@ func (s *serviceSub) run() error { return err } - // TODO: handle error - s.handler(&serviceEvent{ + p := &serviceEvent{ topic: s.topic, message: &broker.Message{ Header: msg.Header, Body: msg.Body, }, - }) + } + p.err = s.handler(p) } } diff --git a/server/rpc_event.go b/server/rpc_event.go index fe2a946a..f45f6c87 100644 --- a/server/rpc_event.go +++ b/server/rpc_event.go @@ -7,6 +7,7 @@ import ( // event is a broker event we handle on the server transport type event struct { + err error message *broker.Message } @@ -19,6 +20,10 @@ func (e *event) Message() *broker.Message { return e.message } +func (e *event) Error() error { + return e.err +} + func (e *event) Topic() string { return e.message.Header["Micro-Topic"] } diff --git a/tunnel/broker/broker.go b/tunnel/broker/broker.go index 1b904e95..259115dd 100644 --- a/tunnel/broker/broker.go +++ b/tunnel/broker/broker.go @@ -163,6 +163,10 @@ func (t *tunEvent) Ack() error { return nil } +func (t *tunEvent) Error() error { + return nil +} + func NewBroker(opts ...broker.Option) broker.Broker { options := broker.Options{ Context: context.Background(), From 9a7a65f05ecacd89ad901424ad03635ce899b651 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Sat, 7 Mar 2020 11:06:57 +0000 Subject: [PATCH 360/788] Auth Provider (#1309) * auth provider mock interface * Auth Provider Options * Implement API Server Auth Package * Add weh utils * Add Login URL * Auth Provider Options * Add auth provider scope and setting token in cookie * Remove auth_login_url flag Co-authored-by: Asim Aslam Co-authored-by: Ben Toogood --- api/server/auth/auth.go | 70 ++++++++++++++++++++++++++++++++++++ api/server/http/http.go | 3 ++ auth/auth.go | 5 ++- auth/options.go | 20 +++++++++++ auth/provider/basic/basic.go | 34 ++++++++++++++++++ auth/provider/oauth/oauth.go | 42 ++++++++++++++++++++++ auth/provider/options.go | 47 ++++++++++++++++++++++++ auth/provider/provider.go | 28 +++++++++++++++ config/cmd/cmd.go | 67 ++++++++++++++++++++++++++++++++++ util/http/http.go | 35 ++++++++++++++++++ 10 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 api/server/auth/auth.go create mode 100644 auth/provider/basic/basic.go create mode 100644 auth/provider/oauth/oauth.go create mode 100644 auth/provider/options.go create mode 100644 auth/provider/provider.go diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go new file mode 100644 index 00000000..84a36607 --- /dev/null +++ b/api/server/auth/auth.go @@ -0,0 +1,70 @@ +package auth + +import ( + "net/http" + "strings" + + "github.com/micro/go-micro/v2/auth" + "github.com/micro/go-micro/v2/metadata" +) + +// CombinedAuthHandler wraps a server and authenticates requests +func CombinedAuthHandler(h http.Handler) http.Handler { + return authHandler{ + handler: h, + auth: auth.DefaultAuth, + } +} + +type authHandler struct { + handler http.Handler + auth auth.Auth +} + +const ( + // BearerScheme is the prefix in the auth header + BearerScheme = "Bearer " +) + +func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { + loginURL := h.auth.Options().LoginURL + + // Return if the user disabled auth on this endpoint + excludes := h.auth.Options().Exclude + if len(loginURL) > 0 { + excludes = append(excludes, loginURL) + } + for _, e := range excludes { + if e == req.URL.Path { + h.handler.ServeHTTP(w, req) + return + } + } + + var token string + if header, ok := metadata.Get(req.Context(), "Authorization"); ok { + // Extract the auth token from the request + if strings.HasPrefix(header, BearerScheme) { + token = header[len(BearerScheme):] + } + } else { + // Get the token out the cookies if not provided in headers + if c, err := req.Cookie(auth.CookieName); err != nil && c != nil { + token = c.Value + } + } + + // If the token is valid, allow the request + if _, err := h.auth.Verify(token); err == nil { + h.handler.ServeHTTP(w, req) + return + } + + // If there is no auth login url set, 401 + if loginURL == "" { + w.WriteHeader(401) + } + + // Redirect to the login path + http.Redirect(w, req, loginURL, http.StatusTemporaryRedirect) +} diff --git a/api/server/http/http.go b/api/server/http/http.go index 214f203e..1fed42b1 100644 --- a/api/server/http/http.go +++ b/api/server/http/http.go @@ -8,6 +8,8 @@ import ( "os" "sync" + "github.com/micro/go-micro/v2/api/server/auth" + "github.com/gorilla/handlers" "github.com/micro/go-micro/v2/api/server" "github.com/micro/go-micro/v2/api/server/cors" @@ -47,6 +49,7 @@ func (s *httpServer) Init(opts ...server.Option) error { func (s *httpServer) Handle(path string, handler http.Handler) { h := handlers.CombinedLoggingHandler(os.Stdout, handler) + h = auth.CombinedAuthHandler(handler) if s.opts.EnableCORS { h = cors.CombinedCORSHandler(h) diff --git a/auth/auth.go b/auth/auth.go index 06ef3b5d..36ee3f4c 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -44,7 +44,7 @@ type Role struct { // Account provided by an auth provider type Account struct { - // ID of the account (UUID or email) + // ID of the account (UUIDV4, email or username) Id string `json:"id"` // Token used to authenticate Token string `json:"token"` @@ -62,6 +62,9 @@ const ( // MetadataKey is the key used when storing the account // in metadata MetadataKey = "auth-account" + // CookieName is the name of the cookie which stores the + // auth token + CookieName = "micro-token" ) // AccountFromContext gets the account from the context, which diff --git a/auth/options.go b/auth/options.go index 059c3931..4f49d819 100644 --- a/auth/options.go +++ b/auth/options.go @@ -1,5 +1,7 @@ package auth +import "github.com/micro/go-micro/v2/auth/provider" + type Options struct { // Token is an auth token Token string @@ -9,6 +11,10 @@ type Options struct { PrivateKey string // Endpoints to exclude Exclude []string + // Provider is an auth provider + Provider provider.Provider + // LoginURL is the relative url path where a user can login + LoginURL string } type Option func(o *Options) @@ -41,6 +47,20 @@ func Token(t string) Option { } } +// Provider set the auth provider +func Provider(p provider.Provider) Option { + return func(o *Options) { + o.Provider = p + } +} + +// LoginURL sets the auth LoginURL +func LoginURL(url string) Option { + return func(o *Options) { + o.LoginURL = url + } +} + type GenerateOptions struct { // Metadata associated with the account Metadata map[string]string diff --git a/auth/provider/basic/basic.go b/auth/provider/basic/basic.go new file mode 100644 index 00000000..413053ef --- /dev/null +++ b/auth/provider/basic/basic.go @@ -0,0 +1,34 @@ +package basic + +import ( + "github.com/micro/go-micro/v2/auth/provider" +) + +// NewProvider returns an initialised basic provider +func NewProvider(opts ...provider.Option) provider.Provider { + var options provider.Options + for _, o := range opts { + o(&options) + } + return &basic{options} +} + +type basic struct { + opts provider.Options +} + +func (b *basic) String() string { + return "basic" +} + +func (b *basic) Options() provider.Options { + return b.opts +} + +func (b *basic) Endpoint() string { + return "" +} + +func (b *basic) Redirect() string { + return "" +} diff --git a/auth/provider/oauth/oauth.go b/auth/provider/oauth/oauth.go new file mode 100644 index 00000000..f43c45f2 --- /dev/null +++ b/auth/provider/oauth/oauth.go @@ -0,0 +1,42 @@ +package oauth + +import ( + "fmt" + + "github.com/micro/go-micro/v2/auth/provider" +) + +// NewProvider returns an initialised oauth provider +func NewProvider(opts ...provider.Option) provider.Provider { + var options provider.Options + for _, o := range opts { + o(&options) + } + return &oauth{options} +} + +type oauth struct { + opts provider.Options +} + +func (o *oauth) String() string { + return "oauth" +} + +func (o *oauth) Options() provider.Options { + return o.opts +} + +func (o *oauth) Endpoint() string { + s := fmt.Sprintf("%v?client_id=%v", o.opts.Endpoint, o.opts.ClientID) + + if scope := o.opts.Scope; len(scope) > 0 { + s = fmt.Sprintf("%v&scope=%v", s, scope) + } + + return s +} + +func (o *oauth) Redirect() string { + return o.opts.Redirect +} diff --git a/auth/provider/options.go b/auth/provider/options.go new file mode 100644 index 00000000..930df479 --- /dev/null +++ b/auth/provider/options.go @@ -0,0 +1,47 @@ +package provider + +// Option returns a function which sets an option +type Option func(*Options) + +// Options a provider can have +type Options struct { + // ClientID is the application's ID. + ClientID string + // ClientSecret is the application's secret. + ClientSecret string + // Endpoint for the provider + Endpoint string + // Redirect url incase of UI + Redirect string + // Scope of the oauth request + Scope string +} + +// Credentials is an option which sets the client id and secret +func Credentials(id, secret string) Option { + return func(o *Options) { + o.ClientID = id + o.ClientSecret = secret + } +} + +// Endpoint sets the endpoint option +func Endpoint(e string) Option { + return func(o *Options) { + o.Endpoint = e + } +} + +// Redirect sets the Redirect option +func Redirect(r string) Option { + return func(o *Options) { + o.Redirect = r + } +} + +// Scope sets the oauth scope +func Scope(s string) Option { + return func(o *Options) { + o.Scope = s + } +} diff --git a/auth/provider/provider.go b/auth/provider/provider.go new file mode 100644 index 00000000..86a4504d --- /dev/null +++ b/auth/provider/provider.go @@ -0,0 +1,28 @@ +// Package provider is an external auth provider e.g oauth +package provider + +import ( + "time" +) + +// Provider is an auth provider +type Provider interface { + // String returns the name of the provider + String() string + // Options returns the options of a provider + Options() Options + // Endpoint for the provider + Endpoint() string + // Redirect url incase of UI + Redirect() string +} + +// Grant is a granted authorisation +type Grant struct { + // token for reuse + Token string + // Expiry of the token + Expiry time.Time + // Scopes associated with grant + Scopes []string +} diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index fbb253dc..9e1d0039 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -7,6 +7,8 @@ import ( "strings" "time" + "github.com/micro/go-micro/v2/auth/provider" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" @@ -70,6 +72,10 @@ import ( jwtAuth "github.com/micro/go-micro/v2/auth/jwt" sAuth "github.com/micro/go-micro/v2/auth/service" storeAuth "github.com/micro/go-micro/v2/auth/store" + + // auth providers + "github.com/micro/go-micro/v2/auth/provider/basic" + "github.com/micro/go-micro/v2/auth/provider/oauth" ) type Cmd interface { @@ -269,6 +275,36 @@ var ( EnvVars: []string{"MICRO_AUTH_EXCLUDE"}, Usage: "Comma-separated list of endpoints excluded from authentication, e.g. Users.ListUsers", }, + &cli.StringFlag{ + Name: "auth_provider", + EnvVars: []string{"MICRO_AUTH_PROVIDER"}, + Usage: "Auth provider used to login user", + }, + &cli.StringFlag{ + Name: "auth_provider_client_id", + EnvVars: []string{"MICRO_AUTH_PROVIDER_CLIENT_ID"}, + Usage: "The client id to be used for oauth", + }, + &cli.StringFlag{ + Name: "auth_provider_client_secret", + EnvVars: []string{"MICRO_AUTH_PROVIDER_CLIENT_SECRET"}, + Usage: "The client secret to be used for oauth", + }, + &cli.StringFlag{ + Name: "auth_provider_endpoint", + EnvVars: []string{"MICRO_AUTH_PROVIDER_ENDPOINT"}, + Usage: "The enpoint to be used for oauth", + }, + &cli.StringFlag{ + Name: "auth_provider_redirect", + EnvVars: []string{"MICRO_AUTH_PROVIDER_REDIRECT"}, + Usage: "The redirect to be used for oauth", + }, + &cli.StringFlag{ + Name: "auth_provider_scope", + EnvVars: []string{"MICRO_AUTH_PROVIDER_SCOPE"}, + Usage: "The scope to be used for oauth", + }, } DefaultBrokers = map[string]func(...broker.Option) broker.Broker{ @@ -328,6 +364,11 @@ var ( "jwt": jwtAuth.NewAuth, } + DefaultAuthProviders = map[string]func(...provider.Option) provider.Provider{ + "oauth": oauth.NewProvider, + "basic": basic.NewProvider, + } + DefaultProfiles = map[string]func(...profile.Option) profile.Profile{ "http": http.NewProfile, "pprof": pprof.NewProfile, @@ -627,6 +668,32 @@ func (c *cmd) Before(ctx *cli.Context) error { authOpts = append(authOpts, auth.Exclude(ctx.StringSlice("auth_exclude")...)) } + if name := ctx.String("auth_provider"); len(name) > 0 { + p, ok := DefaultAuthProviders[name] + if !ok { + return fmt.Errorf("AuthProvider %s not found", name) + } + + var provOpts []provider.Option + + clientID := ctx.String("auth_provider_client_id") + clientSecret := ctx.String("auth_provider_client_secret") + if len(clientID) > 0 || len(clientSecret) > 0 { + provOpts = append(provOpts, provider.Credentials(clientID, clientSecret)) + } + if e := ctx.String("auth_provider_endpoint"); len(e) > 0 { + provOpts = append(provOpts, provider.Endpoint(e)) + } + if r := ctx.String("auth_provider_redirect"); len(r) > 0 { + provOpts = append(provOpts, provider.Redirect(r)) + } + if s := ctx.String("auth_provider_scope"); len(s) > 0 { + provOpts = append(provOpts, provider.Scope(s)) + } + + authOpts = append(authOpts, auth.Provider(p(provOpts...))) + } + if len(authOpts) > 0 { if err := (*c.opts.Auth).Init(authOpts...); err != nil { log.Fatalf("Error configuring auth: %v", err) diff --git a/util/http/http.go b/util/http/http.go index 055374ed..3b743c2a 100644 --- a/util/http/http.go +++ b/util/http/http.go @@ -1,12 +1,47 @@ package http import ( + "encoding/json" + "fmt" + "log" "net/http" "github.com/micro/go-micro/v2/client/selector" "github.com/micro/go-micro/v2/registry" ) +// Write sets the status and body on a http ResponseWriter +func Write(w http.ResponseWriter, contentType string, status int, body string) { + w.Header().Set("Content-Length", fmt.Sprintf("%v", len(body))) + w.Header().Set("Content-Type", contentType) + w.WriteHeader(status) + fmt.Fprintf(w, `%v`, body) +} + +// WriteBadRequestError sets a 400 status code +func WriteBadRequestError(w http.ResponseWriter, err error) { + rawBody, err := json.Marshal(map[string]string{ + "error": err.Error(), + }) + if err != nil { + WriteInternalServerError(w, err) + return + } + Write(w, "application/json", 400, string(rawBody)) +} + +// WriteInternalServerError sets a 500 status code +func WriteInternalServerError(w http.ResponseWriter, err error) { + rawBody, err := json.Marshal(map[string]string{ + "error": err.Error(), + }) + if err != nil { + log.Println(err) + return + } + Write(w, "application/json", 500, string(rawBody)) +} + func NewRoundTripper(opts ...Option) http.RoundTripper { options := Options{ Registry: registry.DefaultRegistry, From 077063c21209ad3019e1da5b731294607fe6550f Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 7 Mar 2020 21:05:00 +0300 Subject: [PATCH 361/788] util/addr: check ip addrs before return Signed-off-by: Vasiliy Tolstov --- util/addr/addr.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/util/addr/addr.go b/util/addr/addr.go index fafe8b56..2fa52b25 100644 --- a/util/addr/addr.go +++ b/util/addr/addr.go @@ -79,8 +79,8 @@ func Extract(addr string) (string, error) { } addrs = append(addrs, loAddrs...) - var ipAddr []byte - var publicIP []byte + var ipAddr string + var publicIP string for _, rawAddr := range addrs { var ip net.IP @@ -94,22 +94,30 @@ func Extract(addr string) (string, error) { } if !isPrivateIP(ip.String()) { - publicIP = ip + publicIP = ip.String() continue } - ipAddr = ip + ipAddr = ip.String() break } // return private ip - if ipAddr != nil { - return net.IP(ipAddr).String(), nil + if len(ipAddr) > 0 { + a := net.ParseIP(ipAddr) + if a == nil { + return "", fmt.Errorf("ip addr %s is invalid", ipAddr) + } + return a.String(), nil } // return public or virtual ip - if publicIP != nil { - return net.IP(publicIP).String(), nil + if len(publicIP) > 0 { + a := net.ParseIP(publicIP) + if a == nil { + return "", fmt.Errorf("ip addr %s is invalid", publicIP) + } + return a.String(), nil } return "", fmt.Errorf("No IP address found, and explicit IP not provided") From 55c19afb0b98eb35afb491cbaaff107e10cb25e2 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 7 Mar 2020 21:28:48 +0300 Subject: [PATCH 362/788] registry/mdns: fix ipv6 addr in mdns registry Signed-off-by: Vasiliy Tolstov --- registry/mdns_registry.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/registry/mdns_registry.go b/registry/mdns_registry.go index fe952d22..44bb6c47 100644 --- a/registry/mdns_registry.go +++ b/registry/mdns_registry.go @@ -148,7 +148,6 @@ func (m *mdnsRegistry) Register(service *Service, opts ...RegisterOption) error continue } - // host, pt, err := net.SplitHostPort(node.Address) if err != nil { gerr = err @@ -270,10 +269,20 @@ func (m *mdnsRegistry) GetService(service string) ([]*Service, error) { Endpoints: txt.Endpoints, } } - + addr := "" + // prefer ipv4 addrs + if e.AddrV4 != nil { + addr = e.AddrV4.String() + // else use ipv6 + } else if e.AddrV6 != nil { + addr = "[" + e.AddrV6.String() + "]" + } else { + // broken endpoint + continue + } s.Nodes = append(s.Nodes, &Node{ Id: strings.TrimSuffix(e.Name, "."+p.Service+"."+p.Domain+"."), - Address: fmt.Sprintf("%s:%d", e.AddrV4.String(), e.Port), + Address: fmt.Sprintf("%s:%d", addr, e.Port), Metadata: txt.Metadata, }) From 8ecbdc1cd62ce2c875611679376eda81d23d98ff Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 7 Mar 2020 23:19:48 +0300 Subject: [PATCH 363/788] registry/mdns: add logging for invalid endpoint Signed-off-by: Vasiliy Tolstov --- registry/mdns_registry.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/registry/mdns_registry.go b/registry/mdns_registry.go index 44bb6c47..8563ecac 100644 --- a/registry/mdns_registry.go +++ b/registry/mdns_registry.go @@ -11,6 +11,7 @@ import ( "time" "github.com/google/uuid" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/mdns" ) @@ -277,7 +278,7 @@ func (m *mdnsRegistry) GetService(service string) ([]*Service, error) { } else if e.AddrV6 != nil { addr = "[" + e.AddrV6.String() + "]" } else { - // broken endpoint + log.Infof("[mdns]: invalid endpoint received: %v", e) continue } s.Nodes = append(s.Nodes, &Node{ From e3ce45495a33030f97622f877eb5bcdd5c123f0b Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 9 Mar 2020 09:23:42 +0000 Subject: [PATCH 364/788] os.Exit on log.Fatal (#1316) * os.Exit on log.Fatal * Fix TestOptions Co-authored-by: Ben Toogood --- logger/level.go | 7 ++++++- web/service_test.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/logger/level.go b/logger/level.go index e4f953d9..14249813 100644 --- a/logger/level.go +++ b/logger/level.go @@ -1,6 +1,9 @@ package logger -import "fmt" +import ( + "fmt" + "os" +) type Level int8 @@ -105,8 +108,10 @@ func Errorf(template string, args ...interface{}) { func Fatal(args ...interface{}) { DefaultLogger.Log(FatalLevel, args...) + os.Exit(1) } func Fatalf(template string, args ...interface{}) { DefaultLogger.Logf(FatalLevel, template, args...) + os.Exit(1) } diff --git a/web/service_test.go b/web/service_test.go index 99b36ae5..f2e270c5 100644 --- a/web/service_test.go +++ b/web/service_test.go @@ -156,7 +156,7 @@ func TestOptions(t *testing.T) { name = "service-name" id = "service-id" version = "service-version" - address = "service-addr" + address = "service-addr:8080" advertise = "service-adv" reg = memory.NewRegistry() registerTTL = 123 * time.Second From b344171c80ca6bcae8dd1ce1eebedd15a00acb0a Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 9 Mar 2020 10:21:49 +0000 Subject: [PATCH 365/788] URL Encode Provider.Endpoint() (#1317) Co-authored-by: Ben Toogood --- auth/provider/oauth/oauth.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/auth/provider/oauth/oauth.go b/auth/provider/oauth/oauth.go index f43c45f2..527e6afa 100644 --- a/auth/provider/oauth/oauth.go +++ b/auth/provider/oauth/oauth.go @@ -2,6 +2,7 @@ package oauth import ( "fmt" + "net/url" "github.com/micro/go-micro/v2/auth/provider" ) @@ -28,13 +29,17 @@ func (o *oauth) Options() provider.Options { } func (o *oauth) Endpoint() string { - s := fmt.Sprintf("%v?client_id=%v", o.opts.Endpoint, o.opts.ClientID) + var params url.Values if scope := o.opts.Scope; len(scope) > 0 { - s = fmt.Sprintf("%v&scope=%v", s, scope) + params.Add("scope", scope) } - return s + if redir := o.opts.Redirect; len(redir) > 0 { + params.Add("redirect_uri", redir) + } + + return fmt.Sprintf("%v?%v", o.opts.Endpoint, params.Encode()) } func (o *oauth) Redirect() string { From 43b0dbb123c446dc6a135fc19abde705cd3b6c05 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 9 Mar 2020 20:10:08 +0300 Subject: [PATCH 366/788] tunnel: reduce allocation and improve performance (#1320) * tunnel: reduce allocation and improve performance BenchmarkSha256Old-16 100000 156748 ns/op 11835 B/op 168 allocs/op BenchmarkSha256Old-16 100000 156229 ns/op 11819 B/op 168 allocs/op BenchmarkSha256New-16 100000 154751 ns/op 11107 B/op 161 allocs/op BenchmarkSha256New-16 100000 154263 ns/op 11110 B/op 161 allocs/op simple change lowers allocations and brings performance Signed-off-by: Vasiliy Tolstov * fix Signed-off-by: Vasiliy Tolstov * tunnel: reuse buf in Decrypt Signed-off-by: Vasiliy Tolstov * fix unneeded conversations Signed-off-by: Vasiliy Tolstov * base32 string is smaller than hex string Signed-off-by: Vasiliy Tolstov --- tunnel/crypto.go | 19 +++++++------------ tunnel/crypto_test.go | 4 ++-- tunnel/default.go | 2 +- tunnel/listener.go | 2 +- tunnel/session.go | 26 +++++++++++++------------- 5 files changed, 24 insertions(+), 29 deletions(-) diff --git a/tunnel/crypto.go b/tunnel/crypto.go index e7f5a2f0..fd76eb95 100644 --- a/tunnel/crypto.go +++ b/tunnel/crypto.go @@ -14,22 +14,17 @@ var ( // gcmStandardNonceSize from crypto/cipher/gcm.go is 12 bytes // 100 - is max size of pool noncePool = bpool.NewBytePool(100, 12) - hashPool = bpool.NewBytePool(1024*32, 32) ) // hash hahes the data into 32 bytes key and returns it // hash uses sha256 underneath to hash the supplied key -func hash(key string) []byte { - hasher := sha256.New() - hasher.Write([]byte(key)) - out := hashPool.Get() - defer hashPool.Put(out[:0]) - out = hasher.Sum(out[:0]) - return out +func hash(key []byte) []byte { + sum := sha256.Sum256(key) + return sum[:] } // Encrypt encrypts data and returns the encrypted data -func Encrypt(data []byte, key string) ([]byte, error) { +func Encrypt(data []byte, key []byte) ([]byte, error) { // generate a new AES cipher using our 32 byte key c, err := aes.NewCipher(hash(key)) if err != nil { @@ -59,7 +54,7 @@ func Encrypt(data []byte, key string) ([]byte, error) { } // Decrypt decrypts the payload and returns the decrypted data -func Decrypt(data []byte, key string) ([]byte, error) { +func Decrypt(data []byte, key []byte) ([]byte, error) { // generate AES cipher for decrypting the message c, err := aes.NewCipher(hash(key)) if err != nil { @@ -81,10 +76,10 @@ func Decrypt(data []byte, key string) ([]byte, error) { // NOTE: we need to parse out nonce from the payload // we prepend the nonce to every encrypted payload nonce, ciphertext := data[:nonceSize], data[nonceSize:] - plaintext, err := gcm.Open(nil, nonce, ciphertext, nil) + ciphertext, err = gcm.Open(ciphertext[:0], nonce, ciphertext, nil) if err != nil { return nil, err } - return plaintext, nil + return ciphertext, nil } diff --git a/tunnel/crypto_test.go b/tunnel/crypto_test.go index 6f8498b9..4faac2cf 100644 --- a/tunnel/crypto_test.go +++ b/tunnel/crypto_test.go @@ -6,7 +6,7 @@ import ( ) func TestEncrypt(t *testing.T) { - key := "tokenpassphrase" + key := []byte("tokenpassphrase") data := []byte("supersecret") cipherText, err := Encrypt(data, key) @@ -21,7 +21,7 @@ func TestEncrypt(t *testing.T) { } func TestDecrypt(t *testing.T) { - key := "tokenpassphrase" + key := []byte("tokenpassphrase") data := []byte("supersecret") cipherText, err := Encrypt(data, key) diff --git a/tunnel/default.go b/tunnel/default.go index 398f52ad..7cb636dd 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -131,7 +131,7 @@ func (t *tun) newSession(channel, sessionId string) (*session, bool) { recv: make(chan *message, 128), send: t.send, errChan: make(chan error, 1), - key: t.token + channel + sessionId, + key: []byte(t.token + channel + sessionId), } // save session diff --git a/tunnel/listener.go b/tunnel/listener.go index 4e35360b..dedde945 100644 --- a/tunnel/listener.go +++ b/tunnel/listener.go @@ -78,7 +78,7 @@ func (t *tunListener) process() { // create a new session session sess = &session{ // the session key - key: t.token + m.channel + sessionId, + key: []byte(t.token + m.channel + sessionId), // the id of the remote side tunnel: m.tunnel, // the channel diff --git a/tunnel/session.go b/tunnel/session.go index 6dd90a3d..be34e55f 100644 --- a/tunnel/session.go +++ b/tunnel/session.go @@ -1,7 +1,7 @@ package tunnel import ( - "encoding/hex" + "encoding/base32" "io" "time" @@ -48,7 +48,7 @@ type session struct { // the error response errChan chan error // key for session encryption - key string + key []byte } // message is sent over the send channel @@ -348,8 +348,8 @@ func (s *session) Send(m *transport.Message) error { log.Debugf("failed to encrypt message header %s: %v", k, err) return err } - // hex encode the encrypted header value - data.Header[k] = hex.EncodeToString(val) + // add the encrypted header value + data.Header[k] = base32.StdEncoding.EncodeToString(val) } // create a new message @@ -391,33 +391,33 @@ func (s *session) Recv(m *transport.Message) error { log.Tracef("Received %+v from recv backlog", msg) - key := s.token + s.channel + msg.session + key := []byte(s.token + s.channel + msg.session) // decrypt the received payload using the token // we have to used msg.session because multicast has a shared // session id of "multicast" in this session struct on // the listener side - body, err := Decrypt(msg.data.Body, key) + msg.data.Body, err = Decrypt(msg.data.Body, key) if err != nil { log.Debugf("failed to decrypt message body: %v", err) return err } - msg.data.Body = body - // encrypt all the headers + // dencrypt all the headers for k, v := range msg.data.Header { - // hex decode the header values - h, err := hex.DecodeString(v) + // decode the header values + h, err := base32.StdEncoding.DecodeString(v) if err != nil { log.Debugf("failed to decode message header %s: %v", k, err) return err } - // encrypt the transport message payload - val, err := Decrypt([]byte(h), key) + + // dencrypt the transport message payload + val, err := Decrypt(h, key) if err != nil { log.Debugf("failed to decrypt message header %s: %v", k, err) return err } - // hex encode the encrypted header value + // add decrypted header value msg.data.Header[k] = string(val) } From 1a4f608ed139edf017e8be5591782eefffb543b7 Mon Sep 17 00:00:00 2001 From: mlboy Date: Tue, 10 Mar 2020 01:16:31 +0800 Subject: [PATCH 367/788] add: auth add generate options Expiry for set token expires (#1319) Co-authored-by: mlboy Co-authored-by: Asim Aslam --- auth/jwt/jwt.go | 3 +-- auth/options.go | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go index b2aab0a8..49e1ff19 100644 --- a/auth/jwt/jwt.go +++ b/auth/jwt/jwt.go @@ -3,7 +3,6 @@ package jwt import ( "encoding/base64" "errors" - "time" "github.com/dgrijalva/jwt-go" "github.com/micro/go-micro/v2/auth" @@ -77,7 +76,7 @@ func (s *svc) Generate(id string, ops ...auth.GenerateOption) (*auth.Account, er account := jwt.NewWithClaims(jwt.SigningMethodRS256, AuthClaims{ id, options.Roles, options.Metadata, jwt.StandardClaims{ Subject: id, - ExpiresAt: time.Now().Add(time.Hour * 24).Unix(), + ExpiresAt: options.Expiry.Unix(), }, }) diff --git a/auth/options.go b/auth/options.go index 4f49d819..68b357b7 100644 --- a/auth/options.go +++ b/auth/options.go @@ -1,6 +1,10 @@ package auth -import "github.com/micro/go-micro/v2/auth/provider" +import ( + "time" + + "github.com/micro/go-micro/v2/auth/provider" +) type Options struct { // Token is an auth token @@ -66,6 +70,8 @@ type GenerateOptions struct { Metadata map[string]string // Roles/scopes associated with the account Roles []*Role + //Expiry of the token + Expiry time.Time } type GenerateOption func(o *GenerateOptions) @@ -84,12 +90,22 @@ func Roles(rs []*Role) func(o *GenerateOptions) { } } +// Expiry for the generated account's token expires +func Expiry(ex time.Time) func(o *GenerateOptions) { + return func(o *GenerateOptions) { + o.Expiry = ex + } +} + // NewGenerateOptions from a slice of options func NewGenerateOptions(opts ...GenerateOption) GenerateOptions { var options GenerateOptions for _, o := range opts { o(&options) } - + //set defualt expiry of token + if options.Expiry.IsZero() { + options.Expiry = time.Now().Add(time.Hour * 24) + } return options } From 241614ff686eacb13f4f6f45d15dce88898d5da6 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 9 Mar 2020 23:43:05 +0300 Subject: [PATCH 368/788] add helper function to determine logger level (#1321) * add helper function to determine logger level Signed-off-by: Vasiliy Tolstov --- logger/level.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/logger/level.go b/logger/level.go index 14249813..11fabe4b 100644 --- a/logger/level.go +++ b/logger/level.go @@ -115,3 +115,12 @@ func Fatalf(template string, args ...interface{}) { DefaultLogger.Logf(FatalLevel, template, args...) os.Exit(1) } + +// Returns true if the given level is at or above the current logger level +func V(lvl Level, log Logger) bool { + l := DefaultLogger + if log != nil { + l = log + } + return l.Options().Level >= lvl +} From ed83c27f0e384347e7080acab7b2901a3217fc10 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 10 Mar 2020 15:21:43 +0000 Subject: [PATCH 369/788] add websocket streaming to api rpc handler (#1326) --- api/handler/rpc/rpc.go | 14 +++- api/handler/rpc/stream.go | 150 ++++++++++++++++++++++++++++++++++++++ client/grpc/codec.go | 8 +- 3 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 api/handler/rpc/stream.go diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index daf601a1..5804dbc8 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -104,9 +104,20 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // micro client c := h.opts.Service.Client() + // create context + cx := ctx.FromRequest(r) + + // if stream we currently only support json + if isStream(r, service) { + serveWebsocket(cx, w, r, service, c) + return + } + // create strategy so := selector.WithStrategy(strategy(service.Services)) + // walk the standard call path + // get payload br, err := requestPayload(r) if err != nil { @@ -114,9 +125,6 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - // create context - cx := ctx.FromRequest(r) - var rsp []byte switch { diff --git a/api/handler/rpc/stream.go b/api/handler/rpc/stream.go new file mode 100644 index 00000000..29eee41b --- /dev/null +++ b/api/handler/rpc/stream.go @@ -0,0 +1,150 @@ +package rpc + +import ( + "context" + "encoding/json" + "net/http" + "strings" + + "github.com/gorilla/websocket" + "github.com/micro/go-micro/v2/api" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/selector" +) + +var upgrader = websocket.Upgrader{ + ReadBufferSize: 1024, + WriteBufferSize: 1024, +} + +// serveWebsocket will stream rpc back over websockets assuming json +func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request, service *api.Service, c client.Client) { + // upgrade the connection + conn, err := upgrader.Upgrade(w, r, nil) + if err != nil { + return + } + // close on exit + defer conn.Close() + + // wait for the first request so we know + _, p, err := conn.ReadMessage() + if err != nil { + return + } + + // send to backend + // default to trying json + var request json.RawMessage + // if the extracted payload isn't empty lets use it + if len(p) > 0 { + request = json.RawMessage(p) + } + + // create a request to the backend + req := c.NewRequest( + service.Name, + service.Endpoint.Name, + &request, + client.WithContentType("application/json"), + ) + + so := selector.WithStrategy(strategy(service.Services)) + + // create a new stream + stream, err := c.Stream(ctx, req, client.WithSelectOption(so)) + if err != nil { + return + } + + // send the first request for the client + // since + if err := stream.Send(request); err != nil { + return + } + + go writeLoop(conn, stream) + + resp := stream.Response() + + // receive from stream and send to client + for { + // read backend response body + body, err := resp.Read() + if err != nil { + return + } + + // write the response + if err := conn.WriteMessage(websocket.TextMessage, body); err != nil { + return + } + } +} + +// writeLoop +func writeLoop(conn *websocket.Conn, stream client.Stream) { + // close stream when done + defer stream.Close() + + for { + _, p, err := conn.ReadMessage() + if err != nil { + return + } + + // send to backend + // default to trying json + var request json.RawMessage + // if the extracted payload isn't empty lets use it + if len(p) > 0 { + request = json.RawMessage(p) + } + + if err := stream.Send(request); err != nil { + return + } + } +} + +func isStream(r *http.Request, srv *api.Service) bool { + // check if it's a web socket + if !isWebSocket(r) { + return false + } + + // check if the endpoint supports streaming + for _, service := range srv.Services { + for _, ep := range service.Endpoints { + // skip if it doesn't match the name + if ep.Name != srv.Endpoint.Name { + continue + } + + // matched if the name + if v := ep.Metadata["stream"]; v == "true" { + return true + } + } + } + + return false +} + +func isWebSocket(r *http.Request) bool { + contains := func(key, val string) bool { + vv := strings.Split(r.Header.Get(key), ",") + for _, v := range vv { + if val == strings.ToLower(strings.TrimSpace(v)) { + return true + } + } + return false + } + + if contains("Connection", "upgrade") && contains("Upgrade", "websocket") { + return true + } + + return false +} diff --git a/client/grpc/codec.go b/client/grpc/codec.go index 0366675a..9f89647a 100644 --- a/client/grpc/codec.go +++ b/client/grpc/codec.go @@ -117,7 +117,9 @@ func (jsonCodec) Marshal(v interface{}) ([]byte, error) { return []byte(s), err } - + if b, ok := v.(*bytes.Frame); ok { + return b.Data, nil + } return json.Marshal(v) } @@ -125,6 +127,10 @@ func (jsonCodec) Unmarshal(data []byte, v interface{}) error { if len(data) == 0 { return nil } + if b, ok := v.(*bytes.Frame); ok { + b.Data = data + return nil + } if pb, ok := v.(proto.Message); ok { return jsonpb.Unmarshal(b.NewReader(data), pb) } From 48b2a5c37c5eb767c15fe3f8755241ebab05ac97 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 10 Mar 2020 16:47:01 +0000 Subject: [PATCH 370/788] Fix Auth Headers (#1324) Co-authored-by: Ben Toogood --- api/server/auth/auth.go | 8 ++++---- api/server/cors/cors.go | 1 + client/grpc/grpc.go | 9 ++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 84a36607..c57c7b50 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/micro/go-micro/v2/auth" - "github.com/micro/go-micro/v2/metadata" ) // CombinedAuthHandler wraps a server and authenticates requests @@ -42,15 +41,16 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } var token string - if header, ok := metadata.Get(req.Context(), "Authorization"); ok { + if header := req.Header.Get("Authorization"); len(header) > 0 { // Extract the auth token from the request if strings.HasPrefix(header, BearerScheme) { token = header[len(BearerScheme):] } } else { // Get the token out the cookies if not provided in headers - if c, err := req.Cookie(auth.CookieName); err != nil && c != nil { - token = c.Value + if c, err := req.Cookie("micro-token"); err == nil && c != nil { + token = strings.TrimPrefix(c.Value, auth.CookieName+"=") + req.Header.Set("Authorization", BearerScheme+token) } } diff --git a/api/server/cors/cors.go b/api/server/cors/cors.go index 090d6632..6c030e0c 100644 --- a/api/server/cors/cors.go +++ b/api/server/cors/cors.go @@ -38,6 +38,7 @@ func SetHeaders(w http.ResponseWriter, r *http.Request) { set(w, "Access-Control-Allow-Origin", "*") } + set(w, "Access-Control-Allow-Credentials", "true") set(w, "Access-Control-Allow-Methods", "POST, PATCH, GET, OPTIONS, PUT, DELETE") set(w, "Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization") } diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index e1043afe..c0900655 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -123,7 +123,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R if md, ok := metadata.FromContext(ctx); ok { header = make(map[string]string, len(md)) for k, v := range md { - header[k] = v + header[strings.ToLower(k)] = v } } else { header = make(map[string]string) @@ -133,9 +133,12 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R header["timeout"] = fmt.Sprintf("%d", opts.RequestTimeout) // set the content type for the request header["x-content-type"] = req.ContentType() + // set the authorization token if one is saved locally - if token, err := config.Get("token"); err == nil && len(token) > 0 { - header["authorization"] = BearerScheme + token + if len(header["authorization"]) == 0 { + if token, err := config.Get("token"); err == nil && len(token) > 0 { + header["authorization"] = BearerScheme + token + } } md := gmetadata.New(header) From 4125ae8d5324102549223b40ca9258785906314d Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 10 Mar 2020 22:52:06 +0000 Subject: [PATCH 371/788] Add secrets interface to config/secrets (#1325) * Interface for secrets * Add secretbox secrets implementation * Start working on box * typo * Add asymmetric encryption implementation * go mod tidy * Fix review comments Co-authored-by: Asim Aslam --- config/secrets/box/box.go | 89 ++++++++++++++++++++++ config/secrets/box/box_test.go | 63 +++++++++++++++ config/secrets/secretbox/secretbox.go | 73 ++++++++++++++++++ config/secrets/secretbox/secretbox_test.go | 56 ++++++++++++++ config/secrets/secrets.go | 82 ++++++++++++++++++++ 5 files changed, 363 insertions(+) create mode 100644 config/secrets/box/box.go create mode 100644 config/secrets/box/box_test.go create mode 100644 config/secrets/secretbox/secretbox.go create mode 100644 config/secrets/secretbox/secretbox_test.go create mode 100644 config/secrets/secrets.go diff --git a/config/secrets/box/box.go b/config/secrets/box/box.go new file mode 100644 index 00000000..54192c3d --- /dev/null +++ b/config/secrets/box/box.go @@ -0,0 +1,89 @@ +// Package box is an asymmetric implementation of config/secrets using nacl/box +package box + +import ( + "github.com/micro/go-micro/v2/config/secrets" + "github.com/pkg/errors" + naclbox "golang.org/x/crypto/nacl/box" + + "crypto/rand" +) + +const keyLength = 32 + +type box struct { + options secrets.Options + + publicKey [keyLength]byte + privateKey [keyLength]byte +} + +// NewCodec returns a nacl-box codec +func NewCodec(opts ...secrets.Option) secrets.Codec { + b := &box{} + for _, o := range opts { + o(&b.options) + } + return b +} + +// Init initialises a box +func (b *box) Init(opts ...secrets.Option) error { + for _, o := range opts { + o(&b.options) + } + if len(b.options.PrivateKey) != keyLength || len(b.options.PublicKey) != keyLength { + return errors.Errorf("a public key and a private key of length %d must both be provided", keyLength) + } + copy(b.privateKey[:], b.options.PrivateKey) + copy(b.publicKey[:], b.options.PublicKey) + return nil +} + +// Options returns options +func (b *box) Options() secrets.Options { + return b.options +} + +// String returns nacl-box +func (*box) String() string { + return "nacl-box" +} + +// Encrypt encrypts a message with the sender's private key and the receipient's public key +func (b *box) Encrypt(in []byte, opts ...secrets.EncryptOption) ([]byte, error) { + var options secrets.EncryptOptions + for _, o := range opts { + o(&options) + } + if len(options.RecipientPublicKey) != keyLength { + return []byte{}, errors.New("recepient's public key must be provided") + } + var recipientPublicKey [keyLength]byte + copy(recipientPublicKey[:], options.RecipientPublicKey) + var nonce [24]byte + if _, err := rand.Reader.Read(nonce[:]); err != nil { + return []byte{}, errors.Wrap(err, "couldn't obtain a random nonce from crypto/rand") + } + return naclbox.Seal(nonce[:], in, &nonce, &recipientPublicKey, &b.privateKey), nil +} + +// Decrypt Decrypts a message with the receiver's private key and the sender's public key +func (b *box) Decrypt(in []byte, opts ...secrets.DecryptOption) ([]byte, error) { + var options secrets.DecryptOptions + for _, o := range opts { + o(&options) + } + if len(options.SenderPublicKey) != keyLength { + return []byte{}, errors.New("sender's public key bust be provided") + } + var nonce [24]byte + var senderPublicKey [32]byte + copy(nonce[:], in[:24]) + copy(senderPublicKey[:], options.SenderPublicKey) + decrypted, ok := naclbox.Open(nil, in[24:], &nonce, &senderPublicKey, &b.privateKey) + if !ok { + return []byte{}, errors.New("incoming message couldn't be verified / decrypted") + } + return decrypted, nil +} diff --git a/config/secrets/box/box_test.go b/config/secrets/box/box_test.go new file mode 100644 index 00000000..77a5559a --- /dev/null +++ b/config/secrets/box/box_test.go @@ -0,0 +1,63 @@ +package box + +import ( + "crypto/rand" + "reflect" + "testing" + + "github.com/micro/go-micro/v2/config/secrets" + naclbox "golang.org/x/crypto/nacl/box" +) + +func TestBox(t *testing.T) { + alicePublicKey, alicePrivateKey, err := naclbox.GenerateKey(rand.Reader) + if err != nil { + t.Fatal(err) + } + bobPublicKey, bobPrivateKey, err := naclbox.GenerateKey(rand.Reader) + if err != nil { + t.Fatal(err) + } + alice, bob := NewCodec(secrets.PublicKey(alicePublicKey[:]), secrets.PrivateKey(alicePrivateKey[:])), NewCodec() + if err := alice.Init(); err != nil { + t.Error(err) + } + if err := bob.Init(secrets.PublicKey(bobPublicKey[:]), secrets.PrivateKey(bobPrivateKey[:])); err != nil { + t.Error(err) + } + if alice.String() != "nacl-box" { + t.Error("String() doesn't return nacl-box") + } + aliceSecret := []byte("Why is a raven like a writing-desk?") + if _, err := alice.Encrypt(aliceSecret); err == nil { + t.Error("alice.Encrypt succeded without a public key") + } + enc, err := alice.Encrypt(aliceSecret, secrets.RecipientPublicKey(bob.Options().PublicKey)) + if err != nil { + t.Error("alice.Encrypt failed") + } + if _, err := bob.Decrypt(enc); err == nil { + t.Error("bob.Decrypt succeded without a public key") + } + if dec, err := bob.Decrypt(enc, secrets.SenderPublicKey(alice.Options().PublicKey)); err == nil { + if !reflect.DeepEqual(dec, aliceSecret) { + t.Errorf("Bob's decrypted message didn't match Alice's encrypted message: %v != %v", aliceSecret, dec) + } + } else { + t.Errorf("bob.Decrypt failed (%s)", err) + } + + bobSecret := []byte("I haven't the slightest idea") + enc, err = bob.Encrypt(bobSecret, secrets.RecipientPublicKey(alice.Options().PublicKey)) + if err != nil { + t.Error(err) + } + dec, err := alice.Decrypt(enc, secrets.SenderPublicKey(bob.Options().PrivateKey)) + if err == nil { + t.Error(err) + } + dec, err = alice.Decrypt(enc, secrets.SenderPublicKey(bob.Options().PublicKey)) + if !reflect.DeepEqual(dec, bobSecret) { + t.Errorf("Alice's decrypted message didn't match Bob's encrypted message %v != %v", bobSecret, dec) + } +} diff --git a/config/secrets/secretbox/secretbox.go b/config/secrets/secretbox/secretbox.go new file mode 100644 index 00000000..31c36ea3 --- /dev/null +++ b/config/secrets/secretbox/secretbox.go @@ -0,0 +1,73 @@ +// Package secretbox is a config/secrets implementation that uses nacl/secretbox +// to do symmetric encryption / verification +package secretbox + +import ( + "github.com/micro/go-micro/v2/config/secrets" + "github.com/pkg/errors" + "golang.org/x/crypto/nacl/secretbox" + + "crypto/rand" +) + +const keyLength = 32 + +type secretBox struct { + options secrets.Options + + secretKey [keyLength]byte +} + +// NewCodec returns a secretbox codec +func NewCodec(opts ...secrets.Option) secrets.Codec { + sb := &secretBox{} + for _, o := range opts { + o(&sb.options) + } + return sb +} + +func (s *secretBox) Init(opts ...secrets.Option) error { + for _, o := range opts { + o(&s.options) + } + if len(s.options.SecretKey) == 0 { + return errors.New("no secret key is defined") + } + if len(s.options.SecretKey) != keyLength { + return errors.Errorf("secret key must be %d bytes long", keyLength) + } + copy(s.secretKey[:], s.options.SecretKey) + return nil +} + +func (s *secretBox) Options() secrets.Options { + return s.options +} + +func (s *secretBox) String() string { + return "nacl-secretbox" +} + +func (s *secretBox) Encrypt(in []byte, opts ...secrets.EncryptOption) ([]byte, error) { + // no opts are expected, so they are ignored + + // there must be a unique nonce for each message + var nonce [24]byte + if _, err := rand.Reader.Read(nonce[:]); err != nil { + return []byte{}, errors.Wrap(err, "couldn't obtain a random nonce from crypto/rand") + } + return secretbox.Seal(nonce[:], in, &nonce, &s.secretKey), nil +} + +func (s *secretBox) Decrypt(in []byte, opts ...secrets.DecryptOption) ([]byte, error) { + // no options are expected, so they are ignored + + var decryptNonce [24]byte + copy(decryptNonce[:], in[:24]) + decrypted, ok := secretbox.Open(nil, in[24:], &decryptNonce, &s.secretKey) + if !ok { + return []byte{}, errors.New("decryption failed (is the key set correctly?)") + } + return decrypted, nil +} diff --git a/config/secrets/secretbox/secretbox_test.go b/config/secrets/secretbox/secretbox_test.go new file mode 100644 index 00000000..04c3a2f5 --- /dev/null +++ b/config/secrets/secretbox/secretbox_test.go @@ -0,0 +1,56 @@ +package secretbox + +import ( + "encoding/base64" + "reflect" + "testing" + + "github.com/micro/go-micro/v2/config/secrets" +) + +func TestSecretBox(t *testing.T) { + secretKey, err := base64.StdEncoding.DecodeString("4jbVgq8FsAV7vy+n8WqEZrl7BUtNqh3fYT5RXzXOPFY=") + if err != nil { + t.Fatal(err) + } + + s := NewCodec() + + if err := s.Init(); err == nil { + t.Error("Secretbox accepted an empty secret key") + } + if err := s.Init(secrets.SecretKey([]byte("invalid"))); err == nil { + t.Error("Secretbox accepted a secret key that is invalid") + } + + if err := s.Init(secrets.SecretKey(secretKey)); err != nil { + t.Fatal(err) + } + + o := s.Options() + if !reflect.DeepEqual(o.SecretKey, secretKey) { + t.Error("Init() didn't set secret key correctly") + } + if s.String() != "nacl-secretbox" { + t.Error(s.String() + " should be nacl-secretbox") + } + + // Try 10 times to get different nonces + for i := 0; i < 10; i++ { + message := []byte(`Can you hear me, Major Tom?`) + + encrypted, err := s.Encrypt(message) + if err != nil { + t.Errorf("Failed to encrypt message (%s)", err) + } + + decrypted, err := s.Decrypt(encrypted) + if err != nil { + t.Errorf("Failed to decrypt encrypted message (%s)", err) + } + + if !reflect.DeepEqual(message, decrypted) { + t.Errorf("Decrypted Message dod not match encrypted message") + } + } +} diff --git a/config/secrets/secrets.go b/config/secrets/secrets.go new file mode 100644 index 00000000..b2ec4c07 --- /dev/null +++ b/config/secrets/secrets.go @@ -0,0 +1,82 @@ +// Package secrets is an interface for encrypting and decrypting secrets +package secrets + +import "context" + +// Codec encrypts or decrypts arbitrary data. The data should be as small as possible +type Codec interface { + Init(...Option) error + Options() Options + String() string + Decrypt([]byte, ...DecryptOption) ([]byte, error) + Encrypt([]byte, ...EncryptOption) ([]byte, error) +} + +// Options is a codec's options +// SecretKey or both PublicKey and PrivateKey should be set depending on the +// underlying implementation +type Options struct { + SecretKey []byte + PrivateKey []byte + PublicKey []byte + Context context.Context +} + +// Option sets options +type Option func(*Options) + +// SecretKey sets the symmetric secret key +func SecretKey(key []byte) Option { + return func(o *Options) { + o.SecretKey = make([]byte, len(key)) + copy(o.SecretKey, key) + } +} + +// PublicKey sets the asymmetric Public Key of this codec +func PublicKey(key []byte) Option { + return func(o *Options) { + o.PublicKey = make([]byte, len(key)) + copy(o.PublicKey, key) + } +} + +// PrivateKey sets the asymmetric Private Key of this codec +func PrivateKey(key []byte) Option { + return func(o *Options) { + o.PrivateKey = make([]byte, len(key)) + copy(o.PrivateKey, key) + } +} + +// DecryptOptions can be passed to Codec.Decrypt +type DecryptOptions struct { + SenderPublicKey []byte +} + +// DecryptOption sets DecryptOptions +type DecryptOption func(*DecryptOptions) + +// SenderPublicKey is the Public Key of the Codec that encrypted this message +func SenderPublicKey(key []byte) DecryptOption { + return func(d *DecryptOptions) { + d.SenderPublicKey = make([]byte, len(key)) + copy(d.SenderPublicKey, key) + } +} + +// EncryptOptions can be passed to Codec.Encrypt +type EncryptOptions struct { + RecipientPublicKey []byte +} + +// EncryptOption Sets EncryptOptions +type EncryptOption func(*EncryptOptions) + +// RecipientPublicKey is the Public Key of the Codec that will decrypt this message +func RecipientPublicKey(key []byte) EncryptOption { + return func(e *EncryptOptions) { + e.RecipientPublicKey = make([]byte, len(key)) + copy(e.RecipientPublicKey, key) + } +} From 7b385bf163d309137a3b3898d78cbd953d8ef677 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 11 Mar 2020 20:55:39 +0300 Subject: [PATCH 372/788] minimize allocations in logger and tunnel code (#1323) * logs alloc Signed-off-by: Vasiliy Tolstov * fix allocs Signed-off-by: Vasiliy Tolstov * fix allocs Signed-off-by: Vasiliy Tolstov * tunnel allocs Signed-off-by: Vasiliy Tolstov * try to fix tunnel Signed-off-by: Vasiliy Tolstov * cache cipher for send Signed-off-by: Vasiliy Tolstov * more logger Signed-off-by: Vasiliy Tolstov * more logger Signed-off-by: Vasiliy Tolstov * more logger Signed-off-by: Vasiliy Tolstov * more logger Signed-off-by: Vasiliy Tolstov * more logger Signed-off-by: Vasiliy Tolstov * more logger Signed-off-by: Vasiliy Tolstov * more logger Signed-off-by: Vasiliy Tolstov --- agent/input/discord/conn.go | 6 +- agent/input/telegram/conn.go | 6 +- api/handler/broker/broker.go | 10 +- api/server/http/http.go | 8 +- broker/default.go | 18 +- broker/memory/memory.go | 6 +- broker/nats/nats.go | 14 +- broker/service/service.go | 28 ++- broker/service/subscriber.go | 6 +- config/cmd/cmd.go | 24 +-- config/source/service/service.go | 6 +- logger/helper.go | 40 +++- network/default.go | 276 +++++++++++++++++++-------- proxy/mucp/mucp.go | 26 ++- registry/cache/cache.go | 10 +- registry/etcd/etcd.go | 22 ++- registry/kubernetes/watcher.go | 6 +- registry/mdns_registry.go | 6 +- registry/memory/memory.go | 30 ++- router/default.go | 66 +++++-- router/default_test.go | 11 +- router/table.go | 14 +- runtime/default.go | 54 ++++-- runtime/kubernetes/kubernetes.go | 35 +++- runtime/kubernetes/service.go | 26 ++- runtime/local/build/docker/docker.go | 4 +- runtime/service.go | 6 +- server/grpc/grpc.go | 52 +++-- server/grpc/server.go | 40 ++-- server/grpc/subscriber.go | 8 +- server/rpc_router.go | 1 - server/rpc_server.go | 14 +- server/server.go | 16 +- service.go | 12 +- store/cockroach/cockroach.go | 4 +- sync/cron.go | 14 +- transport/grpc/handler.go | 4 +- tunnel/crypto.go | 32 ++-- tunnel/crypto_test.go | 16 +- tunnel/default.go | 182 +++++++++++++----- tunnel/link.go | 11 +- tunnel/listener.go | 10 +- tunnel/options.go | 2 + tunnel/session.go | 68 +++++-- util/kubernetes/client/client.go | 20 +- web/service.go | 26 ++- web/web.go | 3 + 47 files changed, 917 insertions(+), 382 deletions(-) diff --git a/agent/input/discord/conn.go b/agent/input/discord/conn.go index 8d5d70d1..ac9af037 100644 --- a/agent/input/discord/conn.go +++ b/agent/input/discord/conn.go @@ -7,7 +7,7 @@ import ( "github.com/bwmarrin/discordgo" "github.com/micro/go-micro/v2/agent/input" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" ) type discordConn struct { @@ -74,7 +74,9 @@ func (dc *discordConn) Send(e *input.Event) error { fields := strings.Split(e.To, ":") _, err := dc.master.session.ChannelMessageSend(fields[0], string(e.Data)) if err != nil { - log.Error("[bot][loop][send]", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("[bot][loop][send]", err) + } } return nil } diff --git a/agent/input/telegram/conn.go b/agent/input/telegram/conn.go index 41ecae72..b0cb4f33 100644 --- a/agent/input/telegram/conn.go +++ b/agent/input/telegram/conn.go @@ -7,7 +7,7 @@ import ( "github.com/forestgiant/sliceutil" "github.com/micro/go-micro/v2/agent/input" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" tgbotapi "gopkg.in/telegram-bot-api.v4" ) @@ -104,7 +104,9 @@ func (tc *telegramConn) Send(event *input.Event) error { if err != nil { // probably it could be because of nested HTML tags -- telegram doesn't allow nested tags - log.Error("[telegram][Send] error:", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("[telegram][Send] error:", err) + } msgConfig.Text = "This bot couldn't send the response (Internal error)" tc.input.api.Send(msgConfig) } diff --git a/api/handler/broker/broker.go b/api/handler/broker/broker.go index 6a503e37..8f82446b 100644 --- a/api/handler/broker/broker.go +++ b/api/handler/broker/broker.go @@ -14,7 +14,7 @@ import ( "github.com/gorilla/websocket" "github.com/micro/go-micro/v2/api/handler" "github.com/micro/go-micro/v2/broker" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" ) const ( @@ -136,7 +136,9 @@ func (c *conn) writeLoop() { }() if err != nil { - log.Error(err.Error()) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err.Error()) + } return } @@ -214,7 +216,9 @@ func (b *brokerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ws, err := b.u.Upgrade(w, r, nil) if err != nil { - log.Error(err.Error()) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err.Error()) + } return } diff --git a/api/server/http/http.go b/api/server/http/http.go index 1fed42b1..0af91256 100644 --- a/api/server/http/http.go +++ b/api/server/http/http.go @@ -13,7 +13,7 @@ import ( "github.com/gorilla/handlers" "github.com/micro/go-micro/v2/api/server" "github.com/micro/go-micro/v2/api/server/cors" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" ) type httpServer struct { @@ -75,7 +75,9 @@ func (s *httpServer) Start() error { return err } - log.Infof("HTTP API Listening on %s", l.Addr().String()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("HTTP API Listening on %s", l.Addr().String()) + } s.mtx.Lock() s.address = l.Addr().String() @@ -84,7 +86,7 @@ func (s *httpServer) Start() error { go func() { if err := http.Serve(l, s.mux); err != nil { // temporary fix - //log.Fatal(err) + //logger.Fatal(err) } }() diff --git a/broker/default.go b/broker/default.go index 05eef916..ae6562ce 100644 --- a/broker/default.go +++ b/broker/default.go @@ -11,7 +11,7 @@ import ( "time" "github.com/micro/go-micro/v2/codec/json" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/addr" "github.com/nats-io/nats-server/v2/server" @@ -172,7 +172,9 @@ func (n *natsBroker) serve(exit chan bool) error { for _, node := range service.Nodes { u, err := url.Parse("nats://" + node.Address) if err != nil { - log.Info(err) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Info(err) + } continue } // append to the cluster routes @@ -247,7 +249,9 @@ func (n *natsBroker) serve(exit chan bool) error { select { case err := <-n.closeCh: if err != nil { - log.Info(err) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Info(err) + } } case <-exit: // deregister on exit @@ -402,7 +406,9 @@ func (n *natsBroker) Subscribe(topic string, handler Handler, opts ...SubscribeO pub.m = &m if err != nil { m.Body = msg.Data - log.Error(err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } if eh != nil { eh(pub) } @@ -410,7 +416,9 @@ func (n *natsBroker) Subscribe(topic string, handler Handler, opts ...SubscribeO } if err := handler(pub); err != nil { pub.err = err - log.Error(err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } if eh != nil { eh(pub) } diff --git a/broker/memory/memory.go b/broker/memory/memory.go index 2a449467..5424f378 100644 --- a/broker/memory/memory.go +++ b/broker/memory/memory.go @@ -10,7 +10,7 @@ import ( "github.com/google/uuid" "github.com/micro/go-micro/v2/broker" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" maddr "github.com/micro/go-micro/v2/util/addr" mnet "github.com/micro/go-micro/v2/util/net" ) @@ -190,7 +190,9 @@ func (m *memoryEvent) Message() *broker.Message { case []byte: msg := &broker.Message{} if err := m.opts.Codec.Unmarshal(v, msg); err != nil { - log.Errorf("[memory]: failed to unmarshal: %v\n", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("[memory]: failed to unmarshal: %v\n", err) + } return nil } return msg diff --git a/broker/nats/nats.go b/broker/nats/nats.go index 1af597eb..01b59d18 100644 --- a/broker/nats/nats.go +++ b/broker/nats/nats.go @@ -13,7 +13,7 @@ import ( "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/codec/json" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/addr" "github.com/nats-io/nats-server/v2/server" @@ -169,7 +169,9 @@ func (n *natsBroker) serve(exit chan bool) error { for _, node := range service.Nodes { u, err := url.Parse("nats://" + node.Address) if err != nil { - log.Error(err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } continue } // append to the cluster routes @@ -387,7 +389,9 @@ func (n *natsBroker) Subscribe(topic string, handler broker.Handler, opts ...bro pub.m = &m if err != nil { m.Body = msg.Data - log.Error(err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } if eh != nil { eh(pub) } @@ -395,7 +399,9 @@ func (n *natsBroker) Subscribe(topic string, handler broker.Handler, opts ...bro } if err := handler(pub); err != nil { pub.err = err - log.Error(err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } if eh != nil { eh(pub) } diff --git a/broker/service/service.go b/broker/service/service.go index a52400ba..0ce2f00e 100644 --- a/broker/service/service.go +++ b/broker/service/service.go @@ -8,7 +8,7 @@ import ( "github.com/micro/go-micro/v2/broker" pb "github.com/micro/go-micro/v2/broker/service/proto" "github.com/micro/go-micro/v2/client" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" ) type serviceBroker struct { @@ -45,7 +45,9 @@ func (b *serviceBroker) Options() broker.Options { } func (b *serviceBroker) Publish(topic string, msg *broker.Message, opts ...broker.PublishOption) error { - log.Debugf("Publishing to topic %s broker %v", topic, b.Addrs) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Publishing to topic %s broker %v", topic, b.Addrs) + } _, err := b.Client.Publish(context.TODO(), &pb.PublishRequest{ Topic: topic, Message: &pb.Message{ @@ -61,7 +63,9 @@ func (b *serviceBroker) Subscribe(topic string, handler broker.Handler, opts ... for _, o := range opts { o(&options) } - log.Debugf("Subscribing to topic %s queue %s broker %v", topic, options.Queue, b.Addrs) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Subscribing to topic %s queue %s broker %v", topic, options.Queue, b.Addrs) + } stream, err := b.Client.Subscribe(context.TODO(), &pb.SubscribeRequest{ Topic: topic, Queue: options.Queue, @@ -83,19 +87,27 @@ func (b *serviceBroker) Subscribe(topic string, handler broker.Handler, opts ... for { select { case <-sub.closed: - log.Debugf("Unsubscribed from topic %s", topic) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Unsubscribed from topic %s", topic) + } return default: - // run the subscriber - log.Debugf("Streaming from broker %v to topic [%s] queue [%s]", b.Addrs, topic, options.Queue) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + // run the subscriber + logger.Debugf("Streaming from broker %v to topic [%s] queue [%s]", b.Addrs, topic, options.Queue) + } if err := sub.run(); err != nil { - log.Debugf("Resubscribing to topic %s broker %v", topic, b.Addrs) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Resubscribing to topic %s broker %v", topic, b.Addrs) + } stream, err := b.Client.Subscribe(context.TODO(), &pb.SubscribeRequest{ Topic: topic, Queue: options.Queue, }, client.WithAddress(b.Addrs...), client.WithRequestTimeout(time.Hour)) if err != nil { - log.Debugf("Failed to resubscribe to topic %s: %v", topic, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Failed to resubscribe to topic %s: %v", topic, err) + } time.Sleep(time.Second) continue } diff --git a/broker/service/subscriber.go b/broker/service/subscriber.go index 662d6d50..c11ec962 100644 --- a/broker/service/subscriber.go +++ b/broker/service/subscriber.go @@ -3,7 +3,7 @@ package service import ( "github.com/micro/go-micro/v2/broker" pb "github.com/micro/go-micro/v2/broker/service/proto" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" ) type serviceSub struct { @@ -62,7 +62,9 @@ func (s *serviceSub) run() error { // TODO: do not fail silently msg, err := s.stream.Recv() if err != nil { - log.Debugf("Streaming error for subcription to topic %s: %v", s.Topic(), err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Streaming error for subcription to topic %s: %v", s.Topic(), err) + } // close the exit channel close(exit) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 9e1d0039..5daad43f 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -17,7 +17,7 @@ import ( "github.com/micro/go-micro/v2/debug/profile/http" "github.com/micro/go-micro/v2/debug/profile/pprof" "github.com/micro/go-micro/v2/debug/trace" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/server" @@ -537,13 +537,13 @@ func (c *cmd) Before(ctx *cli.Context) error { clientOpts = append(clientOpts, client.Registry(*c.opts.Registry)) if err := (*c.opts.Selector).Init(selector.Registry(*c.opts.Registry)); err != nil { - log.Fatalf("Error configuring registry: %v", err) + logger.Fatalf("Error configuring registry: %v", err) } clientOpts = append(clientOpts, client.Selector(*c.opts.Selector)) if err := (*c.opts.Broker).Init(broker.Registry(*c.opts.Registry)); err != nil { - log.Fatalf("Error configuring broker: %v", err) + logger.Fatalf("Error configuring broker: %v", err) } } @@ -590,31 +590,31 @@ func (c *cmd) Before(ctx *cli.Context) error { if len(ctx.String("broker_address")) > 0 { if err := (*c.opts.Broker).Init(broker.Addrs(strings.Split(ctx.String("broker_address"), ",")...)); err != nil { - log.Fatalf("Error configuring broker: %v", err) + logger.Fatalf("Error configuring broker: %v", err) } } if len(ctx.String("registry_address")) > 0 { if err := (*c.opts.Registry).Init(registry.Addrs(strings.Split(ctx.String("registry_address"), ",")...)); err != nil { - log.Fatalf("Error configuring registry: %v", err) + logger.Fatalf("Error configuring registry: %v", err) } } if len(ctx.String("transport_address")) > 0 { if err := (*c.opts.Transport).Init(transport.Addrs(strings.Split(ctx.String("transport_address"), ",")...)); err != nil { - log.Fatalf("Error configuring transport: %v", err) + logger.Fatalf("Error configuring transport: %v", err) } } if len(ctx.String("store_address")) > 0 { if err := (*c.opts.Store).Init(store.Nodes(strings.Split(ctx.String("store_address"), ",")...)); err != nil { - log.Fatalf("Error configuring store: %v", err) + logger.Fatalf("Error configuring store: %v", err) } } if len(ctx.String("store_namespace")) > 0 { if err := (*c.opts.Store).Init(store.Namespace(ctx.String("store_address"))); err != nil { - log.Fatalf("Error configuring store: %v", err) + logger.Fatalf("Error configuring store: %v", err) } } @@ -648,7 +648,7 @@ func (c *cmd) Before(ctx *cli.Context) error { if len(ctx.String("runtime_source")) > 0 { if err := (*c.opts.Runtime).Init(runtime.WithSource(ctx.String("runtime_source"))); err != nil { - log.Fatalf("Error configuring runtime: %v", err) + logger.Fatalf("Error configuring runtime: %v", err) } } @@ -696,7 +696,7 @@ func (c *cmd) Before(ctx *cli.Context) error { if len(authOpts) > 0 { if err := (*c.opts.Auth).Init(authOpts...); err != nil { - log.Fatalf("Error configuring auth: %v", err) + logger.Fatalf("Error configuring auth: %v", err) } } @@ -729,14 +729,14 @@ func (c *cmd) Before(ctx *cli.Context) error { // Lets set it up if len(serverOpts) > 0 { if err := (*c.opts.Server).Init(serverOpts...); err != nil { - log.Fatalf("Error configuring server: %v", err) + logger.Fatalf("Error configuring server: %v", err) } } // Use an init option? if len(clientOpts) > 0 { if err := (*c.opts.Client).Init(clientOpts...); err != nil { - log.Fatalf("Error configuring client: %v", err) + logger.Fatalf("Error configuring client: %v", err) } } diff --git a/config/source/service/service.go b/config/source/service/service.go index 5e71ab17..52dfe223 100644 --- a/config/source/service/service.go +++ b/config/source/service/service.go @@ -6,7 +6,7 @@ import ( "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/config/source" proto "github.com/micro/go-micro/v2/config/source/service/proto" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" ) var ( @@ -36,7 +36,9 @@ func (m *service) Read() (set *source.ChangeSet, err error) { func (m *service) Watch() (w source.Watcher, err error) { stream, err := m.client.Watch(context.Background(), &proto.WatchRequest{Key: m.key, Path: m.path}) if err != nil { - log.Error("watch err: ", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("watch err: ", err) + } return } return newWatcher(stream) diff --git a/logger/helper.go b/logger/helper.go index 00ac1304..a78f907d 100644 --- a/logger/helper.go +++ b/logger/helper.go @@ -12,52 +12,88 @@ func NewHelper(log Logger) *Helper { } func (h *Helper) Info(args ...interface{}) { + if !h.Logger.Options().Level.Enabled(InfoLevel) { + return + } h.Logger.Fields(h.fields).Log(InfoLevel, args...) } func (h *Helper) Infof(template string, args ...interface{}) { + if !h.Logger.Options().Level.Enabled(InfoLevel) { + return + } h.Logger.Fields(h.fields).Logf(InfoLevel, template, args...) } func (h *Helper) Trace(args ...interface{}) { + if !h.Logger.Options().Level.Enabled(TraceLevel) { + return + } h.Logger.Fields(h.fields).Log(TraceLevel, args...) } func (h *Helper) Tracef(template string, args ...interface{}) { + if !h.Logger.Options().Level.Enabled(TraceLevel) { + return + } h.Logger.Fields(h.fields).Logf(TraceLevel, template, args...) } func (h *Helper) Debug(args ...interface{}) { + if !h.Logger.Options().Level.Enabled(DebugLevel) { + return + } h.Logger.Fields(h.fields).Log(DebugLevel, args...) } func (h *Helper) Debugf(template string, args ...interface{}) { + if !h.Logger.Options().Level.Enabled(DebugLevel) { + return + } h.Logger.Fields(h.fields).Logf(DebugLevel, template, args...) } func (h *Helper) Warn(args ...interface{}) { + if !h.Logger.Options().Level.Enabled(WarnLevel) { + return + } h.Logger.Fields(h.fields).Log(WarnLevel, args...) } func (h *Helper) Warnf(template string, args ...interface{}) { + if !h.Logger.Options().Level.Enabled(WarnLevel) { + return + } h.Logger.Fields(h.fields).Logf(WarnLevel, template, args...) } func (h *Helper) Error(args ...interface{}) { + if !h.Logger.Options().Level.Enabled(ErrorLevel) { + return + } h.Logger.Fields(h.fields).Log(ErrorLevel, args...) } func (h *Helper) Errorf(template string, args ...interface{}) { + if !h.Logger.Options().Level.Enabled(ErrorLevel) { + return + } h.Logger.Fields(h.fields).Logf(ErrorLevel, template, args...) } func (h *Helper) Fatal(args ...interface{}) { - h.Logger.Fields(h.fields).Log(ErrorLevel, args...) + if !h.Logger.Options().Level.Enabled(FatalLevel) { + return + } + h.Logger.Fields(h.fields).Log(FatalLevel, args...) os.Exit(1) } func (h *Helper) Fatalf(template string, args ...interface{}) { - h.Logger.Fields(h.fields).Logf(ErrorLevel, template, args...) + if !h.Logger.Options().Level.Enabled(FatalLevel) { + return + } + h.Logger.Fields(h.fields).Logf(FatalLevel, template, args...) os.Exit(1) } diff --git a/network/default.go b/network/default.go index 5e116b85..f777b8c4 100644 --- a/network/default.go +++ b/network/default.go @@ -15,7 +15,7 @@ import ( "github.com/micro/go-micro/v2/client" cmucp "github.com/micro/go-micro/v2/client/mucp" rtr "github.com/micro/go-micro/v2/client/selector/router" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/network/resolver/dns" pbNet "github.com/micro/go-micro/v2/network/service/proto" "github.com/micro/go-micro/v2/proxy" @@ -223,7 +223,7 @@ func (n *network) acceptNetConn(l tunnel.Listener, recv chan *message) { conn, err := l.Accept() if err != nil { sleep := backoff.Do(i) - log.Debugf("Network tunnel [%s] accept error: %v, backing off for %v", ControlChannel, err, sleep) + logger.Debugf("Network tunnel [%s] accept error: %v, backing off for %v", ControlChannel, err, sleep) time.Sleep(sleep) i++ continue @@ -232,7 +232,7 @@ func (n *network) acceptNetConn(l tunnel.Listener, recv chan *message) { select { case <-n.closed: if err := conn.Close(); err != nil { - log.Debugf("Network tunnel [%s] failed to close connection: %v", NetworkChannel, err) + logger.Debugf("Network tunnel [%s] failed to close connection: %v", NetworkChannel, err) } return default: @@ -250,7 +250,9 @@ func (n *network) acceptCtrlConn(l tunnel.Listener, recv chan *message) { conn, err := l.Accept() if err != nil { sleep := backoff.Do(i) - log.Debugf("Network tunnel [%s] accept error: %v, backing off for %v", ControlChannel, err, sleep) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network tunnel [%s] accept error: %v, backing off for %v", ControlChannel, err, sleep) + } time.Sleep(sleep) i++ continue @@ -259,7 +261,9 @@ func (n *network) acceptCtrlConn(l tunnel.Listener, recv chan *message) { select { case <-n.closed: if err := conn.Close(); err != nil { - log.Debugf("Network tunnel [%s] failed to close connection: %v", ControlChannel, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network tunnel [%s] failed to close connection: %v", ControlChannel, err) + } } return default: @@ -355,7 +359,9 @@ func (n *network) advertise(advertChan <-chan *router.Advert) { for i := 0; i < max; i++ { if peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()); peer != nil { if err := n.sendTo("advert", ControlChannel, peer, msg); err != nil { - log.Debugf("Network failed to advertise routes to %s: %v", peer.Id(), err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed to advertise routes to %s: %v", peer.Id(), err) + } } } } @@ -371,7 +377,9 @@ func (n *network) initNodes(startup bool) { // NOTE: this condition never fires // as resolveNodes() never returns error if err != nil && !startup { - log.Debugf("Network failed to init nodes: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed to init nodes: %v", err) + } return } @@ -390,8 +398,10 @@ func (n *network) initNodes(startup bool) { init = append(init, node) } - // initialize the tunnel - log.Tracef("Network initialising nodes %+v\n", init) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + // initialize the tunnel + logger.Tracef("Network initialising nodes %+v\n", init) + } n.tunnel.Init( tunnel.Nodes(nodes...), @@ -403,7 +413,9 @@ func (n *network) resolveNodes() ([]string, error) { // resolve the network address to network nodes records, err := n.options.Resolver.Resolve(n.options.Name) if err != nil { - log.Debugf("Network failed to resolve nodes: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed to resolve nodes: %v", err) + } } // sort by lowest priority @@ -444,7 +456,9 @@ func (n *network) resolveNodes() ([]string, error) { // resolve anything that looks like a host name records, err := dns.Resolve(node) if err != nil { - log.Debugf("Failed to resolve %v %v", node, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Failed to resolve %v %v", node, err) + } continue } @@ -464,7 +478,9 @@ func (n *network) handleNetConn(s tunnel.Session, msg chan *message) { for { m := new(transport.Message) if err := s.Recv(m); err != nil { - log.Debugf("Network tunnel [%s] receive error: %v", NetworkChannel, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network tunnel [%s] receive error: %v", NetworkChannel, err) + } switch err { case io.EOF, tunnel.ErrReadTimeout: s.Close() @@ -497,7 +513,9 @@ func (n *network) handleCtrlConn(s tunnel.Session, msg chan *message) { for { m := new(transport.Message) if err := s.Recv(m); err != nil { - log.Debugf("Network tunnel [%s] receive error: %v", ControlChannel, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network tunnel [%s] receive error: %v", ControlChannel, err) + } switch err { case io.EOF, tunnel.ErrReadTimeout: s.Close() @@ -575,12 +593,15 @@ func (n *network) getRouteMetric(router string, gateway string, link string) int return 2 } - log.Tracef("Network looking up %s link to gateway: %s", link, gateway) - + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Network looking up %s link to gateway: %s", link, gateway) + } // attempt to find link based on gateway address lnk, ok := n.peerLinks[gateway] if !ok { - log.Debugf("Network failed to find a link to gateway: %s", gateway) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed to find a link to gateway: %s", gateway) + } // no link found so infinite metric returned return math.MaxInt64 } @@ -598,11 +619,15 @@ func (n *network) getRouteMetric(router string, gateway string, link string) int // make sure length is non-zero if length == 0 { - log.Debugf("Link length is 0 %v %v", link, lnk.Length()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Link length is 0 %v %v", link, lnk.Length()) + } length = 10e9 } - log.Tracef("Network calculated metric %v delay %v length %v distance %v", (delay*length*int64(hops))/10e6, delay, length, hops) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Network calculated metric %v delay %v length %v distance %v", (delay*length*int64(hops))/10e6, delay, length, hops) + } return (delay * length * int64(hops)) / 10e6 } @@ -626,7 +651,9 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { pbRtrAdvert := &pbRtr.Advert{} if err := proto.Unmarshal(m.msg.Body, pbRtrAdvert); err != nil { - log.Debugf("Network fail to unmarshal advert message: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network fail to unmarshal advert message: %v", err) + } continue } @@ -634,14 +661,17 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { if pbRtrAdvert.Id == n.options.Id { continue } - - log.Debugf("Network received advert message from: %s", pbRtrAdvert.Id) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network received advert message from: %s", pbRtrAdvert.Id) + } // loookup advertising node in our peer topology advertNode := n.node.GetPeerNode(pbRtrAdvert.Id) if advertNode == nil { // if we can't find the node in our topology (MaxDepth) we skipp prcessing adverts - log.Debugf("Network skipping advert message from unknown peer: %s", pbRtrAdvert.Id) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network skipping advert message from unknown peer: %s", pbRtrAdvert.Id) + } continue } @@ -658,7 +688,9 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { // if the origin router is not the advertising node peer // we can't rule out potential routing loops so we bail here if peer := advertNode.GetPeerNode(event.Route.Router); peer == nil { - log.Debugf("Network skipping advert message from peer: %s", pbRtrAdvert.Id) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network skipping advert message from peer: %s", pbRtrAdvert.Id) + } continue } } @@ -676,7 +708,9 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { // calculate route metric and add to the advertised metric // we need to make sure we do not overflow math.MaxInt64 metric := n.getRouteMetric(event.Route.Router, event.Route.Gateway, event.Route.Link) - log.Tracef("Network metric for router %s and gateway %s: %v", event.Route.Router, event.Route.Gateway, metric) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Network metric for router %s and gateway %s: %v", event.Route.Router, event.Route.Gateway, metric) + } // check we don't overflow max int 64 if d := route.Metric + metric; d <= 0 { @@ -698,7 +732,9 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { // if no events are eligible for processing continue if len(events) == 0 { - log.Tracef("Network no events to be processed by router: %s", n.options.Id) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Network no events to be processed by router: %s", n.options.Id) + } continue } @@ -711,9 +747,13 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { Events: events, } - log.Tracef("Network router %s processing advert: %s", n.Id(), advert.Id) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Network router %s processing advert: %s", n.Id(), advert.Id) + } if err := n.router.Process(advert); err != nil { - log.Debugf("Network failed to process advert %s: %v", advert.Id, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed to process advert %s: %v", advert.Id, err) + } } } case <-n.closed: @@ -743,7 +783,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { pbNetConnect := &pbNet.Connect{} if err := proto.Unmarshal(m.msg.Body, pbNetConnect); err != nil { - log.Debugf("Network tunnel [%s] connect unmarshal error: %v", NetworkChannel, err) + logger.Debugf("Network tunnel [%s] connect unmarshal error: %v", NetworkChannel, err) continue } @@ -752,7 +792,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { continue } - log.Debugf("Network received connect message from: %s", pbNetConnect.Node.Id) + logger.Debugf("Network received connect message from: %s", pbNetConnect.Node.Id) peer := &node{ id: pbNetConnect.Node.Id, @@ -768,15 +808,15 @@ func (n *network) processNetChan(listener tunnel.Listener) { // TODO: should we do this only if we manage to add a peer // What should we do if the peer links failed to be updated? if err := n.updatePeerLinks(peer); err != nil { - log.Debugf("Network failed updating peer links: %s", err) + logger.Debugf("Network failed updating peer links: %s", err) } // add peer to the list of node peers if err := n.AddPeer(peer); err == ErrPeerExists { - log.Tracef("Network peer exists, refreshing: %s", peer.id) + logger.Tracef("Network peer exists, refreshing: %s", peer.id) // update lastSeen time for the peer if err := n.RefreshPeer(peer.id, peer.link, now); err != nil { - log.Debugf("Network failed refreshing peer %s: %v", peer.id, err) + logger.Debugf("Network failed refreshing peer %s: %v", peer.id, err) } } @@ -796,14 +836,14 @@ func (n *network) processNetChan(listener tunnel.Listener) { // get a list of the best routes for each service in our routing table routes, err := n.getProtoRoutes() if err != nil { - log.Debugf("Network node %s failed listing routes: %v", n.id, err) + logger.Debugf("Network node %s failed listing routes: %v", n.id, err) } // attached the routes to the message msg.Routes = routes // send sync message to the newly connected peer if err := n.sendTo("sync", NetworkChannel, peer, msg); err != nil { - log.Debugf("Network failed to send sync message: %v", err) + logger.Debugf("Network failed to send sync message: %v", err) } }() case "peer": @@ -812,7 +852,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { pbNetPeer := &pbNet.Peer{} if err := proto.Unmarshal(m.msg.Body, pbNetPeer); err != nil { - log.Debugf("Network tunnel [%s] peer unmarshal error: %v", NetworkChannel, err) + logger.Debugf("Network tunnel [%s] peer unmarshal error: %v", NetworkChannel, err) continue } @@ -821,7 +861,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { continue } - log.Debugf("Network received peer message from: %s %s", pbNetPeer.Node.Id, pbNetPeer.Node.Address) + logger.Debugf("Network received peer message from: %s %s", pbNetPeer.Node.Id, pbNetPeer.Node.Address) peer := &node{ id: pbNetPeer.Node.Id, @@ -837,7 +877,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { // TODO: should we do this only if we manage to add a peer // What should we do if the peer links failed to be updated? if err := n.updatePeerLinks(peer); err != nil { - log.Debugf("Network failed updating peer links: %s", err) + logger.Debugf("Network failed updating peer links: %s", err) } // if it's a new peer i.e. we do not have it in our graph, we request full sync @@ -853,29 +893,29 @@ func (n *network) processNetChan(listener tunnel.Listener) { // get a list of the best routes for each service in our routing table routes, err := n.getProtoRoutes() if err != nil { - log.Debugf("Network node %s failed listing routes: %v", n.id, err) + logger.Debugf("Network node %s failed listing routes: %v", n.id, err) } // attached the routes to the message msg.Routes = routes // send sync message to the newly connected peer if err := n.sendTo("sync", NetworkChannel, peer, msg); err != nil { - log.Debugf("Network failed to send sync message: %v", err) + logger.Debugf("Network failed to send sync message: %v", err) } }() continue // if we already have the peer in our graph, skip further steps } else if err != ErrPeerExists { - log.Debugf("Network got error adding peer %v", err) + logger.Debugf("Network got error adding peer %v", err) continue } - log.Tracef("Network peer exists, refreshing: %s", pbNetPeer.Node.Id) + logger.Tracef("Network peer exists, refreshing: %s", pbNetPeer.Node.Id) // update lastSeen time for the peer if err := n.RefreshPeer(peer.id, peer.link, now); err != nil { - log.Debugf("Network failed refreshing peer %s: %v", pbNetPeer.Node.Id, err) + logger.Debugf("Network failed refreshing peer %s: %v", pbNetPeer.Node.Id, err) } // NOTE: we don't unpack MaxDepth toplogy @@ -883,9 +923,9 @@ func (n *network) processNetChan(listener tunnel.Listener) { // update the link peer.link = m.msg.Header["Micro-Link"] - log.Tracef("Network updating topology of node: %s", n.node.id) + logger.Tracef("Network updating topology of node: %s", n.node.id) if err := n.node.UpdatePeer(peer); err != nil { - log.Debugf("Network failed to update peers: %v", err) + logger.Debugf("Network failed to update peers: %v", err) } // tell the connect loop that we've been discovered @@ -901,7 +941,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { pbNetSync := &pbNet.Sync{} if err := proto.Unmarshal(m.msg.Body, pbNetSync); err != nil { - log.Debugf("Network tunnel [%s] sync unmarshal error: %v", NetworkChannel, err) + logger.Debugf("Network tunnel [%s] sync unmarshal error: %v", NetworkChannel, err) continue } @@ -910,7 +950,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { continue } - log.Debugf("Network received sync message from: %s", pbNetSync.Peer.Node.Id) + logger.Debugf("Network received sync message from: %s", pbNetSync.Peer.Node.Id) peer := &node{ id: pbNetSync.Peer.Node.Id, @@ -926,15 +966,21 @@ func (n *network) processNetChan(listener tunnel.Listener) { // TODO: should we do this only if we manage to add a peer // What should we do if the peer links failed to be updated? if err := n.updatePeerLinks(peer); err != nil { - log.Debugf("Network failed updating peer links: %s", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed updating peer links: %s", err) + } } // add peer to the list of node peers if err := n.node.AddPeer(peer); err == ErrPeerExists { - log.Tracef("Network peer exists, refreshing: %s", peer.id) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Network peer exists, refreshing: %s", peer.id) + } // update lastSeen time for the existing node if err := n.RefreshPeer(peer.id, peer.link, now); err != nil { - log.Debugf("Network failed refreshing peer %s: %v", peer.id, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed refreshing peer %s: %v", peer.id, err) + } } } @@ -947,7 +993,9 @@ func (n *network) processNetChan(listener tunnel.Listener) { route := pbUtil.ProtoToRoute(pbRoute) // continue if we are the originator of the route if route.Router == n.router.Options().Id { - log.Debugf("Network node %s skipping route addition: route already present", n.id) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network node %s skipping route addition: route already present", n.id) + } continue } @@ -972,7 +1020,9 @@ func (n *network) processNetChan(listener tunnel.Listener) { routes, err := n.router.Table().Query(q...) if err != nil && err != router.ErrRouteNotFound { - log.Debugf("Network node %s failed listing best routes for %s: %v", n.id, route.Service, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network node %s failed listing best routes for %s: %v", n.id, route.Service, err) + } continue } @@ -980,7 +1030,9 @@ func (n *network) processNetChan(listener tunnel.Listener) { // create the new route we have just received if len(routes) == 0 { if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { - log.Debugf("Network node %s failed to add route: %v", n.id, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network node %s failed to add route: %v", n.id, err) + } } continue } @@ -1006,14 +1058,18 @@ func (n *network) processNetChan(listener tunnel.Listener) { // add route to the routing table if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute { - log.Debugf("Network node %s failed to add route: %v", n.id, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network node %s failed to add route: %v", n.id, err) + } } } // update your sync timestamp // NOTE: this might go away as we will be doing full table advert to random peer if err := n.RefreshSync(now); err != nil { - log.Debugf("Network failed refreshing sync time: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed refreshing sync time: %v", err) + } } go func() { @@ -1022,13 +1078,17 @@ func (n *network) processNetChan(listener tunnel.Listener) { // advertise yourself to the new node if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { - log.Debugf("Network failed to advertise peers: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed to advertise peers: %v", err) + } } }() case "close": pbNetClose := &pbNet.Close{} if err := proto.Unmarshal(m.msg.Body, pbNetClose); err != nil { - log.Debugf("Network tunnel [%s] close unmarshal error: %v", NetworkChannel, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network tunnel [%s] close unmarshal error: %v", NetworkChannel, err) + } continue } @@ -1037,7 +1097,9 @@ func (n *network) processNetChan(listener tunnel.Listener) { continue } - log.Debugf("Network received close message from: %s", pbNetClose.Node.Id) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network received close message from: %s", pbNetClose.Node.Id) + } peer := &node{ id: pbNetClose.Node.Id, @@ -1045,11 +1107,15 @@ func (n *network) processNetChan(listener tunnel.Listener) { } if err := n.DeletePeerNode(peer.id); err != nil { - log.Debugf("Network failed to delete node %s routes: %v", peer.id, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed to delete node %s routes: %v", peer.id, err) + } } if err := n.prunePeerRoutes(peer); err != nil { - log.Debugf("Network failed pruning peer %s routes: %v", peer.id, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed pruning peer %s routes: %v", peer.id, err) + } } // NOTE: we should maybe advertise this to the network so we converge faster on closed nodes @@ -1166,7 +1232,9 @@ func (n *network) manage() { // set the link via peer links l, ok := n.peerLinks[peer.address] if ok { - log.Debugf("Network link not found for peer %s cannot announce", peer.id) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network link not found for peer %s cannot announce", peer.id) + } continue } link = l.Id() @@ -1192,7 +1260,9 @@ func (n *network) manage() { for _, peer := range peers { // advertise yourself to the network if err := n.sendTo("peer", NetworkChannel, peer, msg); err != nil { - log.Debugf("Network failed to advertise peer %s: %v", peer.id, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed to advertise peer %s: %v", peer.id, err) + } continue } @@ -1214,32 +1284,41 @@ func (n *network) manage() { // unknown link and peer so lets do the connect flow if err := n.sendTo("connect", NetworkChannel, peer, msg); err != nil { - log.Debugf("Network failed to connect %s: %v", peer.id, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed to connect %s: %v", peer.id, err) + } continue } links[peer.link] = time.Now() } case <-prune.C: - log.Debugf("Network node %s pruning stale peers", n.id) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network node %s pruning stale peers", n.id) + } pruned := n.PruneStalePeers(PruneTime) for id, peer := range pruned { - log.Debugf("Network peer exceeded prune time: %s", id) - + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network peer exceeded prune time: %s", id) + } n.Lock() delete(n.peerLinks, peer.address) n.Unlock() if err := n.prunePeerRoutes(peer); err != nil { - log.Debugf("Network failed pruning peer %s routes: %v", id, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed pruning peer %s routes: %v", id, err) + } } } // get a list of all routes routes, err := n.options.Router.Table().List() if err != nil { - log.Debugf("Network failed listing routes when pruning peers: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed listing routes when pruning peers: %v", err) + } continue } @@ -1261,7 +1340,9 @@ func (n *network) manage() { } // otherwise delete all the routes originated by it if err := n.pruneRoutes(router.QueryRouter(route.Router)); err != nil { - log.Debugf("Network failed deleting routes by %s: %v", route.Router, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed deleting routes by %s: %v", route.Router, err) + } } } case <-netsync.C: @@ -1291,14 +1372,18 @@ func (n *network) manage() { // get a list of the best routes for each service in our routing table routes, err := n.getProtoRoutes() if err != nil { - log.Debugf("Network node %s failed listing routes: %v", n.id, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network node %s failed listing routes: %v", n.id, err) + } } // attached the routes to the message msg.Routes = routes // send sync message to the newly connected peer if err := n.sendTo("sync", NetworkChannel, peer, msg); err != nil { - log.Debugf("Network failed to send sync message: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed to send sync message: %v", err) + } } }() case <-resolve.C: @@ -1348,7 +1433,9 @@ func (n *network) sendConnect() { } if err := n.sendMsg("connect", NetworkChannel, msg); err != nil { - log.Debugf("Network failed to send connect message: %s", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed to send connect message: %s", err) + } } } @@ -1367,9 +1454,13 @@ func (n *network) sendTo(method, channel string, peer *node, msg proto.Message) if peerNode := n.GetPeerNode(peer.id); peerNode != nil { // update node status when error happens peerNode.status.err.Update(err) - log.Debugf("Network increment peer %v error count to: %d", peerNode, peerNode, peerNode.status.Error().Count()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network increment peer %v error count to: %d", peerNode, peerNode, peerNode.status.Error().Count()) + } if count := peerNode.status.Error().Count(); count == MaxPeerErrors { - log.Debugf("Network peer %v error count exceeded %d. Prunning.", peerNode, MaxPeerErrors) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network peer %v error count exceeded %d. Prunning.", peerNode, MaxPeerErrors) + } n.PrunePeer(peerNode.id) } } @@ -1383,8 +1474,9 @@ func (n *network) sendTo(method, channel string, peer *node, msg proto.Message) id = peer.link } - log.Debugf("Network sending %s message from: %s to %s", method, n.options.Id, id) - + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network sending %s message from: %s to %s", method, n.options.Id, id) + } tmsg := &transport.Message{ Header: map[string]string{ "Micro-Method": method, @@ -1400,12 +1492,18 @@ func (n *network) sendTo(method, channel string, peer *node, msg proto.Message) if err := c.Send(tmsg); err != nil { // TODO: Lookup peer in our graph if peerNode := n.GetPeerNode(peer.id); peerNode != nil { - log.Debugf("Network found peer %s: %v", peer.id, peerNode) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network found peer %s: %v", peer.id, peerNode) + } // update node status when error happens peerNode.status.err.Update(err) - log.Debugf("Network increment node peer %p %v count to: %d", peerNode, peerNode, peerNode.status.Error().Count()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network increment node peer %p %v count to: %d", peerNode, peerNode, peerNode.status.Error().Count()) + } if count := peerNode.status.Error().Count(); count == MaxPeerErrors { - log.Debugf("Network node peer %v count exceeded %d: %d", peerNode, MaxPeerErrors, peerNode.status.Error().Count()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network node peer %v count exceeded %d: %d", peerNode, MaxPeerErrors, peerNode.status.Error().Count()) + } n.PrunePeer(peerNode.id) } } @@ -1431,7 +1529,9 @@ func (n *network) sendMsg(method, channel string, msg proto.Message) error { } n.RUnlock() - log.Debugf("Network sending %s message from: %s", method, n.options.Id) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network sending %s message from: %s", method, n.options.Id) + } return client.Send(&transport.Message{ Header: map[string]string{ @@ -1448,7 +1548,9 @@ func (n *network) updatePeerLinks(peer *node) error { linkId := peer.link - log.Tracef("Network looking up link %s in the peer links", linkId) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Network looking up link %s in the peer links", linkId) + } // lookup the peer link var peerLink tunnel.Link @@ -1464,8 +1566,10 @@ func (n *network) updatePeerLinks(peer *node) error { return ErrPeerLinkNotFound } - // if the peerLink is found in the returned links update peerLinks - log.Tracef("Network updating peer links for peer %s", peer.address) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + // if the peerLink is found in the returned links update peerLinks + logger.Tracef("Network updating peer links for peer %s", peer.address) + } // lookup a link and update it if better link is available if link, ok := n.peerLinks[peer.address]; ok { @@ -1547,7 +1651,9 @@ func (n *network) connect() { // well functioning tunnel clients as "discovered" will be false until the // n.discovered channel is read at some point later on. if err := n.createClients(); err != nil { - log.Debugf("Failed to recreate network/control clients: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Failed to recreate network/control clients: %v", err) + } continue } @@ -1756,7 +1862,9 @@ func (n *network) Close() error { } if err := n.sendMsg("close", NetworkChannel, msg); err != nil { - log.Debugf("Network failed to send close message: %s", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Network failed to send close message: %s", err) + } } <-time.After(time.Millisecond * 100) } diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index d9edf14a..f2acdc4c 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -15,7 +15,7 @@ import ( "github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/codec/bytes" "github.com/micro/go-micro/v2/errors" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/proxy" "github.com/micro/go-micro/v2/router" @@ -163,7 +163,9 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route filteredRoutes = append(filteredRoutes, route) } - log.Tracef("Proxy filtered routes %+v\n", filteredRoutes) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Proxy filtered routes %+v\n", filteredRoutes) + } return filteredRoutes } @@ -259,7 +261,9 @@ func (p *Proxy) manageRoutes(route router.Route, action string) error { p.Lock() defer p.Unlock() - log.Tracef("Proxy taking route action %v %+v\n", action, route) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Proxy taking route action %v %+v\n", action, route) + } switch action { case "create", "update": @@ -309,7 +313,9 @@ func (p *Proxy) ProcessMessage(ctx context.Context, msg server.Message) error { // TODO: check that we're not broadcast storming by sending to the same topic // that we're actually subscribed to - log.Tracef("Proxy received message for %s", msg.Topic()) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Proxy received message for %s", msg.Topic()) + } var errors []string @@ -350,7 +356,9 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server return errors.BadRequest("go.micro.proxy", "service name is blank") } - log.Tracef("Proxy received request for %s", service) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Proxy received request for %s", service) + } // are we network routing or local routing if len(p.Links) == 0 { @@ -410,7 +418,9 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server opts = append(opts, client.WithAddress(addresses...)) } - log.Tracef("Proxy calling %+v\n", addresses) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Proxy calling %+v\n", addresses) + } // serve the normal way return p.serveRequest(ctx, p.Client, service, endpoint, req, rsp, opts...) } @@ -433,7 +443,9 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server continue } - log.Tracef("Proxy using route %+v\n", route) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Proxy using route %+v\n", route) + } // set the address to call addresses := toNodes([]router.Route{route}) diff --git a/registry/cache/cache.go b/registry/cache/cache.go index 689c6e35..a68e32ef 100644 --- a/registry/cache/cache.go +++ b/registry/cache/cache.go @@ -7,7 +7,7 @@ import ( "sync" "time" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" ) @@ -339,7 +339,9 @@ func (c *cache) run() { c.setStatus(err) if a > 3 { - log.Info("rcache: ", err, " backing off ", d) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Info("rcache: ", err, " backing off ", d) + } a = 0 } @@ -362,7 +364,9 @@ func (c *cache) run() { c.setStatus(err) if b > 3 { - log.Info("rcache: ", err, " backing off ", d) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Info("rcache: ", err, " backing off ", d) + } b = 0 } diff --git a/registry/etcd/etcd.go b/registry/etcd/etcd.go index 40ba3b03..630fdbaf 100644 --- a/registry/etcd/etcd.go +++ b/registry/etcd/etcd.go @@ -15,7 +15,7 @@ import ( "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" hash "github.com/mitchellh/hashstructure" "go.uber.org/zap" @@ -191,13 +191,17 @@ func (e *etcdRegistry) registerNode(s *registry.Service, node *registry.Node, op // renew the lease if it exists if leaseID > 0 { - log.Tracef("Renewing existing lease for %s %d", s.Name, leaseID) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Renewing existing lease for %s %d", s.Name, leaseID) + } if _, err := e.client.KeepAliveOnce(context.TODO(), leaseID); err != nil { if err != rpctypes.ErrLeaseNotFound { return err } - log.Tracef("Lease not found for %s %d", s.Name, leaseID) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Lease not found for %s %d", s.Name, leaseID) + } // lease not found do register leaseNotFound = true } @@ -216,7 +220,9 @@ func (e *etcdRegistry) registerNode(s *registry.Service, node *registry.Node, op // the service is unchanged, skip registering if ok && v == h && !leaseNotFound { - log.Tracef("Service %s node %s unchanged skipping registration", s.Name, node.Id) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Service %s node %s unchanged skipping registration", s.Name, node.Id) + } return nil } @@ -245,7 +251,9 @@ func (e *etcdRegistry) registerNode(s *registry.Service, node *registry.Node, op } } - log.Tracef("Registering %s id %s with lease %v and ttl %v", service.Name, node.Id, lgr, options.TTL) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Registering %s id %s with lease %v and ttl %v", service.Name, node.Id, lgr, options.TTL) + } // create an entry for the node if lgr != nil { _, err = e.client.Put(ctx, nodePath(service.Name, node.Id), encode(service), clientv3.WithLease(lgr.ID)) @@ -284,7 +292,9 @@ func (e *etcdRegistry) Deregister(s *registry.Service) error { ctx, cancel := context.WithTimeout(context.Background(), e.options.Timeout) defer cancel() - log.Tracef("Deregistering %s id %s", s.Name, node.Id) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Deregistering %s id %s", s.Name, node.Id) + } _, err := e.client.Delete(ctx, nodePath(s.Name, node.Id)) if err != nil { return err diff --git a/registry/kubernetes/watcher.go b/registry/kubernetes/watcher.go index 5c54a1b6..89bffed6 100644 --- a/registry/kubernetes/watcher.go +++ b/registry/kubernetes/watcher.go @@ -6,7 +6,7 @@ import ( "strings" "sync" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/kubernetes/client" ) @@ -132,7 +132,9 @@ func (k *k8sWatcher) buildPodResults(pod *client.Pod, cache *client.Pod) []*regi func (k *k8sWatcher) handleEvent(event client.Event) { var pod client.Pod if err := json.Unmarshal([]byte(event.Object), &pod); err != nil { - log.Info("K8s Watcher: Couldnt unmarshal event object from pod") + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Info("K8s Watcher: Couldnt unmarshal event object from pod") + } return } diff --git a/registry/mdns_registry.go b/registry/mdns_registry.go index 8563ecac..7be88162 100644 --- a/registry/mdns_registry.go +++ b/registry/mdns_registry.go @@ -11,7 +11,7 @@ import ( "time" "github.com/google/uuid" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/mdns" ) @@ -278,7 +278,9 @@ func (m *mdnsRegistry) GetService(service string) ([]*Service, error) { } else if e.AddrV6 != nil { addr = "[" + e.AddrV6.String() + "]" } else { - log.Infof("[mdns]: invalid endpoint received: %v", e) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("[mdns]: invalid endpoint received: %v", e) + } continue } s.Nodes = append(s.Nodes, &Node{ diff --git a/registry/memory/memory.go b/registry/memory/memory.go index 3dc96f46..cde49b96 100644 --- a/registry/memory/memory.go +++ b/registry/memory/memory.go @@ -7,7 +7,7 @@ import ( "time" "github.com/google/uuid" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" ) @@ -75,7 +75,9 @@ func (m *Registry) ttlPrune() { for version, record := range records { for id, n := range record.Nodes { if n.TTL != 0 && time.Since(n.LastSeen) > n.TTL { - log.Debugf("Registry TTL expired for node %s of service %s", n.Id, name) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Registry TTL expired for node %s of service %s", n.Id, name) + } delete(m.records[name][version].Nodes, id) } } @@ -158,7 +160,9 @@ func (m *Registry) Register(s *registry.Service, opts ...registry.RegisterOption if _, ok := m.records[s.Name][s.Version]; !ok { m.records[s.Name][s.Version] = r - log.Debugf("Registry added new service: %s, version: %s", s.Name, s.Version) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Registry added new service: %s, version: %s", s.Name, s.Version) + } go m.sendEvent(®istry.Result{Action: "update", Service: s}) return nil } @@ -184,14 +188,18 @@ func (m *Registry) Register(s *registry.Service, opts ...registry.RegisterOption } if addedNodes { - log.Debugf("Registry added new node to service: %s, version: %s", s.Name, s.Version) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Registry added new node to service: %s, version: %s", s.Name, s.Version) + } go m.sendEvent(®istry.Result{Action: "update", Service: s}) return nil } // refresh TTL and timestamp for _, n := range s.Nodes { - log.Debugf("Updated registration for service: %s, version: %s", s.Name, s.Version) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Updated registration for service: %s, version: %s", s.Name, s.Version) + } m.records[s.Name][s.Version].Nodes[n.Id].TTL = options.TTL m.records[s.Name][s.Version].Nodes[n.Id].LastSeen = time.Now() } @@ -207,18 +215,24 @@ func (m *Registry) Deregister(s *registry.Service) error { if _, ok := m.records[s.Name][s.Version]; ok { for _, n := range s.Nodes { if _, ok := m.records[s.Name][s.Version].Nodes[n.Id]; ok { - log.Debugf("Registry removed node from service: %s, version: %s", s.Name, s.Version) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Registry removed node from service: %s, version: %s", s.Name, s.Version) + } delete(m.records[s.Name][s.Version].Nodes, n.Id) } } if len(m.records[s.Name][s.Version].Nodes) == 0 { delete(m.records[s.Name], s.Version) - log.Debugf("Registry removed service: %s, version: %s", s.Name, s.Version) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Registry removed service: %s, version: %s", s.Name, s.Version) + } } } if len(m.records[s.Name]) == 0 { delete(m.records, s.Name) - log.Debugf("Registry removed service: %s", s.Name) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Registry removed service: %s", s.Name) + } } go m.sendEvent(®istry.Result{Action: "delete", Service: s}) } diff --git a/router/default.go b/router/default.go index 47da6ba0..9026886b 100644 --- a/router/default.go +++ b/router/default.go @@ -10,7 +10,7 @@ import ( "time" "github.com/google/uuid" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" ) @@ -308,11 +308,15 @@ func (m adverts) process(a *advert) error { // suppress/recover the event based on its penalty level switch { case a.penalty > AdvertSuppress && !a.isSuppressed: - log.Debugf("Router suppressing advert %d %.2f for route %s %s", hash, a.penalty, service, address) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Router suppressing advert %d %.2f for route %s %s", hash, a.penalty, service, address) + } a.isSuppressed = true a.suppressTime = time.Now() case a.penalty < AdvertRecover && a.isSuppressed: - log.Debugf("Router recovering advert %d %.2f for route %s %s", hash, a.penalty, service, address) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Router recovering advert %d %.2f for route %s %s", hash, a.penalty, service, address) + } a.isSuppressed = false } @@ -357,14 +361,18 @@ func (r *router) advertiseEvents() error { // routing table watcher w, err = r.Watch() if err != nil { - log.Errorf("Error creating watcher: %v", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("Error creating watcher: %v", err) + } time.Sleep(time.Second) continue } } if err := r.watchTable(w); err != nil { - log.Errorf("Error watching table: %v", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("Error watching table: %v", err) + } time.Sleep(time.Second) } @@ -391,7 +399,9 @@ func (r *router) advertiseEvents() error { for key, advert := range adverts { // process the advert if err := adverts.process(advert); err != nil { - log.Debugf("Router failed processing advert %d: %v", key, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Router failed processing advert %d: %v", key, err) + } continue } // if suppressed go to the next advert @@ -416,7 +426,9 @@ func (r *router) advertiseEvents() error { // advertise events to subscribers if len(events) > 0 { - log.Debugf("Router publishing %d events", len(events)) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Router publishing %d events", len(events)) + } go r.publishAdvert(RouteUpdate, events) } case e := <-r.eventChan: @@ -437,7 +449,9 @@ func (r *router) advertiseEvents() error { now := time.Now() - log.Debugf("Router processing table event %s for service %s %s", e.Type, e.Route.Service, e.Route.Address) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Router processing table event %s for service %s %s", e.Type, e.Route.Service, e.Route.Address) + } // check if we have already registered the route hash := e.Route.Hash() @@ -459,7 +473,9 @@ func (r *router) advertiseEvents() error { // process the advert if err := adverts.process(a); err != nil { - log.Debugf("Router error processing advert %d: %v", hash, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Router error processing advert %d: %v", hash, err) + } continue } @@ -467,7 +483,9 @@ func (r *router) advertiseEvents() error { a.lastSeen = now // increment the penalty a.penalty += Penalty - log.Debugf("Router advert %d for route %s %s event penalty: %f", hash, a.event.Route.Service, a.event.Route.Address, a.penalty) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Router advert %d for route %s %s event penalty: %f", hash, a.event.Route.Service, a.event.Route.Address, a.penalty) + } case <-r.exit: if w != nil { w.Stop() @@ -542,14 +560,18 @@ func (r *router) Start() error { if w == nil { w, err = r.options.Registry.Watch() if err != nil { - log.Errorf("failed creating registry watcher: %v", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("failed creating registry watcher: %v", err) + } time.Sleep(time.Second) continue } } if err := r.watchRegistry(w); err != nil { - log.Errorf("Error watching the registry: %v", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("Error watching the registry: %v", err) + } time.Sleep(time.Second) } @@ -606,7 +628,9 @@ func (r *router) Advertise() (<-chan *Advert, error) { return default: if err := r.advertiseEvents(); err != nil { - log.Errorf("Error adveritising events: %v", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("Error adveritising events: %v", err) + } } } }() @@ -626,19 +650,25 @@ func (r *router) Process(a *Advert) error { return events[i].Timestamp.Before(events[j].Timestamp) }) - log.Tracef("Router %s processing advert from: %s", r.options.Id, a.Id) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Router %s processing advert from: %s", r.options.Id, a.Id) + } for _, event := range events { // skip if the router is the origin of this route if event.Route.Router == r.options.Id { - log.Tracef("Router skipping processing its own route: %s", r.options.Id) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Router skipping processing its own route: %s", r.options.Id) + } continue } // create a copy of the route route := event.Route action := event.Type - log.Tracef("Router %s applying %s from router %s for service %s %s", r.options.Id, action, route.Router, route.Service, route.Address) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("Router %s applying %s from router %s for service %s %s", r.options.Id, action, route.Router, route.Service, route.Address) + } if err := r.manageRoute(route, action.String()); err != nil { return fmt.Errorf("failed applying action %s to routing table: %s", action, err) @@ -661,7 +691,9 @@ func (r *router) flushRouteEvents(evType EventType) ([]*Event, error) { return nil, err } - log.Debugf("Router advertising %d routes with strategy %s", len(routes), r.options.Advertise) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Router advertising %d routes with strategy %s", len(routes), r.options.Advertise) + } // build a list of events to advertise events := make([]*Event, len(routes)) diff --git a/router/default_test.go b/router/default_test.go index 42a79595..19d36423 100644 --- a/router/default_test.go +++ b/router/default_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry/memory" ) @@ -30,7 +29,7 @@ func TestRouterStartStop(t *testing.T) { if err := r.Stop(); err != nil { t.Errorf("failed to stop router: %v", err) } - log.Debugf("TestRouterStartStop STOPPED") + t.Logf("TestRouterStartStop STOPPED") } func TestRouterAdvertise(t *testing.T) { @@ -50,7 +49,7 @@ func TestRouterAdvertise(t *testing.T) { // receive announce event ann := <-ch - log.Debugf("received announce advert: %v", ann) + t.Logf("received announce advert: %v", ann) // Generate random unique routes nrRoutes := 5 @@ -82,9 +81,9 @@ func TestRouterAdvertise(t *testing.T) { wg.Done() defer close(createDone) for _, route := range routes { - log.Debugf("Creating route %v", route) + t.Logf("Creating route %v", route) if err := r.Table().Create(route); err != nil { - log.Debugf("Failed to create route: %v", err) + t.Logf("Failed to create route: %v", err) errChan <- err return } @@ -106,7 +105,7 @@ func TestRouterAdvertise(t *testing.T) { t.Errorf("failed advertising events: %v", advertErr) default: // do nothing for now - log.Debugf("Router advert received: %v", advert) + t.Logf("Router advert received: %v", advert) adverts += len(advert.Events) } return diff --git a/router/table.go b/router/table.go index 649cea65..cd5e5815 100644 --- a/router/table.go +++ b/router/table.go @@ -6,7 +6,7 @@ import ( "time" "github.com/google/uuid" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" ) var ( @@ -68,7 +68,9 @@ func (t *table) Create(r Route) error { // add new route to the table for the route destination if _, ok := t.routes[service][sum]; !ok { t.routes[service][sum] = r - log.Debugf("Router emitting %s for route: %s", Create, r.Address) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Router emitting %s for route: %s", Create, r.Address) + } go t.sendEvent(&Event{Type: Create, Timestamp: time.Now(), Route: r}) return nil } @@ -93,7 +95,9 @@ func (t *table) Delete(r Route) error { } delete(t.routes[service], sum) - log.Debugf("Router emitting %s for route: %s", Delete, r.Address) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Router emitting %s for route: %s", Delete, r.Address) + } go t.sendEvent(&Event{Type: Delete, Timestamp: time.Now(), Route: r}) return nil @@ -114,7 +118,9 @@ func (t *table) Update(r Route) error { if _, ok := t.routes[service][sum]; !ok { t.routes[service][sum] = r - log.Debugf("Router emitting %s for route: %s", Update, r.Address) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Router emitting %s for route: %s", Update, r.Address) + } go t.sendEvent(&Event{Type: Update, Timestamp: time.Now(), Route: r}) return nil } diff --git a/runtime/default.go b/runtime/default.go index fdd1ed25..8230e8df 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -5,7 +5,7 @@ import ( "sync" "time" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" ) type runtime struct { @@ -71,7 +71,9 @@ func (r *runtime) run(events <-chan Event) { return nil } - log.Debugf("Runtime updating service %s", name) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime updating service %s", name) + } // this will cause a delete followed by created if err := r.Update(service.Service); err != nil { @@ -97,9 +99,13 @@ func (r *runtime) run(events <-chan Event) { } // TODO: check service error - log.Debugf("Runtime starting %s", service.Name) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime starting %s", service.Name) + } if err := service.Start(); err != nil { - log.Debugf("Runtime error starting %s: %v", service.Name, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime error starting %s: %v", service.Name, err) + } } } r.RUnlock() @@ -108,12 +114,18 @@ func (r *runtime) run(events <-chan Event) { continue } // TODO: check service error - log.Debugf("Runtime starting service %s", service.Name) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime starting service %s", service.Name) + } if err := service.Start(); err != nil { - log.Debugf("Runtime error starting service %s: %v", service.Name, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime error starting service %s: %v", service.Name, err) + } } case event := <-events: - log.Debugf("Runtime received notification event: %v", event) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime received notification event: %v", event) + } // NOTE: we only handle Update events for now switch event.Type { case Update: @@ -122,11 +134,15 @@ func (r *runtime) run(events <-chan Event) { service, ok := r.services[event.Service] r.RUnlock() if !ok { - log.Debugf("Runtime unknown service: %s", event.Service) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime unknown service: %s", event.Service) + } continue } if err := processEvent(event, service); err != nil { - log.Debugf("Runtime error updating service %s: %v", event.Service, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime error updating service %s: %v", event.Service, err) + } } continue } @@ -138,12 +154,16 @@ func (r *runtime) run(events <-chan Event) { // if blank service was received we update all services for _, service := range services { if err := processEvent(event, service); err != nil { - log.Debugf("Runtime error updating service %s: %v", service.Name, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime error updating service %s: %v", service.Name, err) + } } } } case <-r.closed: - log.Debugf("Runtime stopped") + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime stopped") + } return } } @@ -242,7 +262,9 @@ func (r *runtime) Delete(s *Service) error { r.Lock() defer r.Unlock() - log.Debugf("Runtime deleting service %s", s.Name) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime deleting service %s", s.Name) + } if s, ok := r.services[s.Name]; ok { // check if running if s.Running() { @@ -295,7 +317,9 @@ func (r *runtime) Start() error { events, err = r.options.Scheduler.Notify() if err != nil { // TODO: should we bail here? - log.Debugf("Runtime failed to start update notifier") + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime failed to start update notifier") + } } } @@ -324,7 +348,9 @@ func (r *runtime) Stop() error { // stop all the services for _, service := range r.services { - log.Debugf("Runtime stopping %s", service.Name) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime stopping %s", service.Name) + } service.Stop() } // stop the scheduler diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 760a824a..a6590547 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -7,7 +7,7 @@ import ( "sync" "time" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/util/kubernetes/client" ) @@ -129,7 +129,9 @@ func (k *kubernetes) getService(labels map[string]string) ([]*runtime.Service, e status = "ready" } } - log.Debugf("Runtime setting %s service deployment status: %v", name, status) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime setting %s service deployment status: %v", name, status) + } svc.Metadata["status"] = status } } @@ -156,7 +158,9 @@ func (k *kubernetes) run(events <-chan runtime.Event) { // - do we even need the ticker for k8s services? case event := <-events: // NOTE: we only handle Update events for now - log.Debugf("Runtime received notification event: %v", event) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime received notification event: %v", event) + } switch event.Type { case runtime.Update: // only process if there's an actual service @@ -188,7 +192,9 @@ func (k *kubernetes) run(events <-chan runtime.Event) { }, labels) if err != nil { - log.Debugf("Runtime update failed to get service %s: %v", event.Service, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime update failed to get service %s: %v", event.Service, err) + } continue } @@ -215,16 +221,21 @@ func (k *kubernetes) run(events <-chan runtime.Event) { // update the build time service.Spec.Template.Metadata.Annotations["build"] = event.Timestamp.Format(time.RFC3339) - - log.Debugf("Runtime updating service: %s deployment: %s", event.Service, service.Metadata.Name) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime updating service: %s deployment: %s", event.Service, service.Metadata.Name) + } if err := k.client.Update(deploymentResource(&service)); err != nil { - log.Debugf("Runtime failed to update service %s: %v", event.Service, err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime failed to update service %s: %v", event.Service, err) + } continue } } } case <-k.closed: - log.Debugf("Runtime stopped") + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime stopped") + } return } } @@ -313,7 +324,9 @@ func (k *kubernetes) List() ([]*runtime.Service, error) { "micro": k.options.Type, } - log.Debugf("Runtime listing all micro services") + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime listing all micro services") + } return k.getService(labels) } @@ -365,7 +378,9 @@ func (k *kubernetes) Start() error { events, err = k.options.Scheduler.Notify() if err != nil { // TODO: should we bail here? - log.Debugf("Runtime failed to start update notifier") + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime failed to start update notifier") + } } } diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 15d05bcb..73a9099d 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -4,7 +4,7 @@ import ( "encoding/json" "strings" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/util/kubernetes/api" "github.com/micro/go-micro/v2/util/kubernetes/client" @@ -108,7 +108,9 @@ func serviceResource(s *client.Service) *client.Resource { func (s *service) Start(k client.Client) error { // create deployment first; if we fail, we dont create service if err := k.Create(deploymentResource(s.kdeploy)); err != nil { - log.Debugf("Runtime failed to create deployment: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime failed to create deployment: %v", err) + } s.Status("error", err) v := parseError(err) if v.Reason == "AlreadyExists" { @@ -118,7 +120,9 @@ func (s *service) Start(k client.Client) error { } // create service now that the deployment has been created if err := k.Create(serviceResource(s.kservice)); err != nil { - log.Debugf("Runtime failed to create service: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime failed to create service: %v", err) + } s.Status("error", err) v := parseError(err) if v.Reason == "AlreadyExists" { @@ -135,13 +139,17 @@ func (s *service) Start(k client.Client) error { func (s *service) Stop(k client.Client) error { // first attempt to delete service if err := k.Delete(serviceResource(s.kservice)); err != nil { - log.Debugf("Runtime failed to delete service: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime failed to delete service: %v", err) + } s.Status("error", err) return err } // delete deployment once the service has been deleted if err := k.Delete(deploymentResource(s.kdeploy)); err != nil { - log.Debugf("Runtime failed to delete deployment: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime failed to delete deployment: %v", err) + } s.Status("error", err) return err } @@ -153,12 +161,16 @@ func (s *service) Stop(k client.Client) error { func (s *service) Update(k client.Client) error { if err := k.Update(deploymentResource(s.kdeploy)); err != nil { - log.Debugf("Runtime failed to update deployment: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime failed to update deployment: %v", err) + } s.Status("error", err) return err } if err := k.Update(serviceResource(s.kservice)); err != nil { - log.Debugf("Runtime failed to update service: %v", err) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime failed to update service: %v", err) + } return err } diff --git a/runtime/local/build/docker/docker.go b/runtime/local/build/docker/docker.go index 01bc18a4..e164df55 100644 --- a/runtime/local/build/docker/docker.go +++ b/runtime/local/build/docker/docker.go @@ -9,7 +9,7 @@ import ( "path/filepath" docker "github.com/fsouza/go-dockerclient" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/runtime/local/build" ) @@ -84,7 +84,7 @@ func NewBuilder(opts ...build.Option) build.Builder { endpoint := "unix:///var/run/docker.sock" client, err := docker.NewClient(endpoint) if err != nil { - log.Fatal(err) + logger.Fatal(err) } return &Builder{ Options: options, diff --git a/runtime/service.go b/runtime/service.go index c93bec73..c211d91b 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -6,7 +6,7 @@ import ( "sync" "time" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/runtime/local/build" "github.com/micro/go-micro/v2/runtime/local/process" proc "github.com/micro/go-micro/v2/runtime/local/process/os" @@ -111,7 +111,9 @@ func (s *service) Start() error { delete(s.Metadata, "error") // TODO: pull source & build binary - log.Debugf("Runtime service %s forking new process", s.Service.Name) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime service %s forking new process", s.Service.Name) + } p, err := s.Process.Fork(s.Exec) if err != nil { s.Metadata["status"] = "error" diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 66539132..4015780d 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -17,7 +17,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/errors" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" meta "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/server" @@ -358,8 +358,10 @@ func (g *grpcServer) processRequest(stream grpc.ServerStream, service *service, fn := func(ctx context.Context, req server.Request, rsp interface{}) (err error) { defer func() { if r := recover(); r != nil { - log.Error("panic recovered: ", r) - log.Error(string(debug.Stack())) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("panic recovered: ", r) + logger.Error(string(debug.Stack())) + } err = errors.InternalServerError("go.micro.server", "panic recovered: %v", r) } }() @@ -658,7 +660,9 @@ func (g *grpcServer) Register() error { g.Unlock() if !registered { - log.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) + } } // create registry options @@ -693,7 +697,9 @@ func (g *grpcServer) Register() error { opts = append(opts, broker.DisableAutoAck()) } - log.Infof("Subscribing to topic: %s", sb.Topic()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Subscribing to topic: %s", sb.Topic()) + } sub, err := config.Broker.Subscribe(sb.Topic(), handler, opts...) if err != nil { return err @@ -745,7 +751,9 @@ func (g *grpcServer) Deregister() error { Nodes: []*registry.Node{node}, } - log.Infof("Deregistering node: %s", node.Id) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Deregistering node: %s", node.Id) + } if err := config.Registry.Deregister(service); err != nil { return err } @@ -761,7 +769,9 @@ func (g *grpcServer) Deregister() error { for sb, subs := range g.subscribers { for _, sub := range subs { - log.Infof("Unsubscribing from topic: %s", sub.Topic()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Unsubscribing from topic: %s", sub.Topic()) + } sub.Unsubscribe() } g.subscribers[sb] = nil @@ -807,7 +817,9 @@ func (g *grpcServer) Start() error { } } - log.Infof("Server [grpc] Listening on %s", ts.Addr().String()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Server [grpc] Listening on %s", ts.Addr().String()) + } g.Lock() g.opts.Address = ts.Addr().String() g.Unlock() @@ -819,18 +831,24 @@ func (g *grpcServer) Start() error { return err } - log.Infof("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address()) + } } // announce self to the world if err := g.Register(); err != nil { - log.Errorf("Server register error: ", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("Server register error: ", err) + } } // micro: go ts.Accept(s.accept) go func() { if err := g.srv.Serve(ts); err != nil { - log.Errorf("gRPC Server start error: ", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("gRPC Server start error: ", err) + } } }() @@ -852,7 +870,9 @@ func (g *grpcServer) Start() error { // register self on interval case <-t.C: if err := g.Register(); err != nil { - log.Error("Server register error: ", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("Server register error: ", err) + } } // wait for exit case ch = <-g.exit: @@ -862,7 +882,9 @@ func (g *grpcServer) Start() error { // deregister self if err := g.Deregister(); err != nil { - log.Error("Server deregister error: ", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("Server deregister error: ", err) + } } // wait for waitgroup @@ -887,7 +909,9 @@ func (g *grpcServer) Start() error { // close transport ch <- nil - log.Infof("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address()) + } // disconnect broker config.Broker.Disconnect() }() diff --git a/server/grpc/server.go b/server/grpc/server.go index 81bf9f7c..024a90f1 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -14,7 +14,7 @@ import ( "unicode" "unicode/utf8" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/server" ) @@ -86,7 +86,9 @@ func prepareEndpoint(method reflect.Method) *methodType { replyType = mtype.In(3) contextType = mtype.In(1) default: - log.Error("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn()) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn()) + } return nil } @@ -94,7 +96,9 @@ func prepareEndpoint(method reflect.Method) *methodType { // check stream type streamType := reflect.TypeOf((*server.Stream)(nil)).Elem() if !argType.Implements(streamType) { - log.Error(mname, "argument does not implement Streamer interface:", argType) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(mname, "argument does not implement Streamer interface:", argType) + } return nil } } else { @@ -102,30 +106,40 @@ func prepareEndpoint(method reflect.Method) *methodType { // First arg need not be a pointer. if !isExportedOrBuiltinType(argType) { - log.Error(mname, "argument type not exported:", argType) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(mname, "argument type not exported:", argType) + } return nil } if replyType.Kind() != reflect.Ptr { - log.Error("method", mname, "reply type not a pointer:", replyType) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("method", mname, "reply type not a pointer:", replyType) + } return nil } // Reply type must be exported. if !isExportedOrBuiltinType(replyType) { - log.Error("method", mname, "reply type not exported:", replyType) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("method", mname, "reply type not exported:", replyType) + } return nil } } // Endpoint() needs one out. if mtype.NumOut() != 1 { - log.Error("method", mname, "has wrong number of outs:", mtype.NumOut()) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("method", mname, "has wrong number of outs:", mtype.NumOut()) + } return nil } // The return type of the method must be error. if returnType := mtype.Out(0); returnType != typeOfError { - log.Error("method", mname, "returns", returnType.String(), "not error") + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("method", mname, "returns", returnType.String(), "not error") + } return nil } return &methodType{method: method, ArgType: argType, ReplyType: replyType, ContextType: contextType, stream: stream} @@ -142,11 +156,13 @@ func (server *rServer) register(rcvr interface{}) error { s.rcvr = reflect.ValueOf(rcvr) sname := reflect.Indirect(s.rcvr).Type().Name() if sname == "" { - log.Fatal("rpc: no service name for type", s.typ.String()) + logger.Fatal("rpc: no service name for type", s.typ.String()) } if !isExported(sname) { s := "rpc Register: type " + sname + " is not exported" - log.Error(s) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(s) + } return errors.New(s) } if _, present := server.serviceMap[sname]; present { @@ -165,7 +181,9 @@ func (server *rServer) register(rcvr interface{}) error { if len(s.method) == 0 { s := "rpc Register: type " + sname + " has no exported methods of suitable type" - log.Error(s) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(s) + } return errors.New(s) } server.serviceMap[s.name] = s diff --git a/server/grpc/subscriber.go b/server/grpc/subscriber.go index c36071fd..5ac957c2 100644 --- a/server/grpc/subscriber.go +++ b/server/grpc/subscriber.go @@ -9,7 +9,7 @@ import ( "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/errors" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/server" @@ -171,8 +171,10 @@ func (g *grpcServer) createSubHandler(sb *subscriber, opts server.Options) broke defer func() { if r := recover(); r != nil { - log.Error("panic recovered: ", r) - log.Error(string(debug.Stack())) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("panic recovered: ", r) + logger.Error(string(debug.Stack())) + } err = errors.InternalServerError("go.micro.server", "panic recovered: %v", r) } }() diff --git a/server/rpc_router.go b/server/rpc_router.go index 82b2c6b9..33561449 100644 --- a/server/rpc_router.go +++ b/server/rpc_router.go @@ -20,7 +20,6 @@ import ( "github.com/micro/go-micro/v2/codec" merrors "github.com/micro/go-micro/v2/errors" - log "github.com/micro/go-micro/v2/logger" ) var ( diff --git a/server/rpc_server.go b/server/rpc_server.go index 173f4f66..4619fa64 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -15,7 +15,7 @@ import ( "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/codec" raw "github.com/micro/go-micro/v2/codec/bytes" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/transport" @@ -158,8 +158,10 @@ func (s *rpcServer) ServeConn(sock transport.Socket) { // recover any panics if r := recover(); r != nil { - log.Error("panic recovered: ", r) - log.Error(string(debug.Stack())) + if logger.V(logger.ErrorLevel, log) { + log.Error("panic recovered: ", r) + log.Error(string(debug.Stack())) + } } }() @@ -377,8 +379,10 @@ func (s *rpcServer) ServeConn(sock transport.Socket) { // recover any panics for outbound process if r := recover(); r != nil { - log.Error("panic recovered: ", r) - log.Error(string(debug.Stack())) + if logger.V(logger.ErrorLevel, log) { + log.Error("panic recovered: ", r) + log.Error(string(debug.Stack())) + } } }() diff --git a/server/server.go b/server/server.go index e11bc14d..7b121b70 100644 --- a/server/server.go +++ b/server/server.go @@ -10,7 +10,7 @@ import ( "github.com/google/uuid" "github.com/micro/go-micro/v2/codec" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" ) @@ -139,6 +139,7 @@ var ( // NewServer creates a new server NewServer func(...Option) Server = newRpcServer + log = logger.NewHelper(logger.DefaultLogger).WithFields(map[string]interface{}{"service": "server"}) ) // DefaultOptions returns config options for the default service @@ -200,21 +201,26 @@ func Run() error { ch := make(chan os.Signal, 1) signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT) - log.Infof("Received signal %s", <-ch) - + if logger.V(logger.InfoLevel, log) { + log.Infof("Received signal %s", <-ch) + } return Stop() } // Start starts the default server func Start() error { config := DefaultServer.Options() - log.Infof("Starting server %s id %s", config.Name, config.Id) + if logger.V(logger.InfoLevel, log) { + log.Infof("Starting server %s id %s", config.Name, config.Id) + } return DefaultServer.Start() } // Stop stops the default server func Stop() error { - log.Infof("Stopping server") + if logger.V(logger.InfoLevel, log) { + log.Infof("Stopping server") + } return DefaultServer.Stop() } diff --git a/service.go b/service.go index 3ce750ae..a6c77469 100644 --- a/service.go +++ b/service.go @@ -14,7 +14,7 @@ import ( "github.com/micro/go-micro/v2/debug/service/handler" "github.com/micro/go-micro/v2/debug/stats" "github.com/micro/go-micro/v2/debug/trace" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/plugin" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/util/config" @@ -77,12 +77,12 @@ func (s *service) Init(opts ...Option) { // load the plugin c, err := plugin.Load(p) if err != nil { - log.Fatal(err) + logger.Fatal(err) } // initialise the plugin if err := plugin.Init(c); err != nil { - log.Fatal(err) + logger.Fatal(err) } } @@ -101,7 +101,7 @@ func (s *service) Init(opts ...Option) { cmd.Server(&s.opts.Server), cmd.Profile(&s.opts.Profile), ); err != nil { - log.Fatal(err) + logger.Fatal(err) } // TODO: replace Cmd.Init with config.Load @@ -194,7 +194,9 @@ func (s *service) Run() error { defer s.opts.Profile.Stop() } - log.Infof("Starting [service] %s", s.Name()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Starting [service] %s", s.Name()) + } if err := s.Start(); err != nil { return err diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 63e16f15..fcda1d6f 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -10,7 +10,7 @@ import ( "time" "github.com/lib/pq" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/store" "github.com/pkg/errors" ) @@ -264,7 +264,7 @@ func NewStore(opts ...store.Option) store.Store { // configure the store if err := s.configure(); err != nil { - log.Fatal(err) + logger.Fatal(err) } // return store diff --git a/sync/cron.go b/sync/cron.go index caf51e71..fddb7e49 100644 --- a/sync/cron.go +++ b/sync/cron.go @@ -5,7 +5,7 @@ import ( "math" "time" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/sync/leader/etcd" "github.com/micro/go-micro/v2/sync/task" "github.com/micro/go-micro/v2/sync/task/local" @@ -35,7 +35,9 @@ func (c *syncCron) Schedule(s task.Schedule, t task.Command) error { // leader election e, err := c.opts.Leader.Elect(id) if err != nil { - log.Errorf("[cron] leader election error: %v", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("[cron] leader election error: %v", err) + } time.Sleep(backoff(i)) i++ continue @@ -55,9 +57,13 @@ func (c *syncCron) Schedule(s task.Schedule, t task.Command) error { break Tick } - log.Infof("[cron] executing command %s", t.Name) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("[cron] executing command %s", t.Name) + } if err := c.opts.Task.Run(t); err != nil { - log.Errorf("[cron] error executing command %s: %v", t.Name, err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("[cron] error executing command %s: %v", t.Name, err) + } } // leader revoked case <-r: diff --git a/transport/grpc/handler.go b/transport/grpc/handler.go index d5a626a0..01ab2049 100644 --- a/transport/grpc/handler.go +++ b/transport/grpc/handler.go @@ -4,7 +4,7 @@ import ( "runtime/debug" "github.com/micro/go-micro/v2/errors" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/transport" pb "github.com/micro/go-micro/v2/transport/grpc/proto" "google.golang.org/grpc/peer" @@ -30,7 +30,7 @@ func (m *microTransport) Stream(ts pb.Transport_StreamServer) (err error) { defer func() { if r := recover(); r != nil { - log.Error(r, string(debug.Stack())) + logger.Error(r, string(debug.Stack())) sock.Close() err = errors.InternalServerError("go.micro.transport", "panic recovered: %v", r) } diff --git a/tunnel/crypto.go b/tunnel/crypto.go index fd76eb95..9f70c444 100644 --- a/tunnel/crypto.go +++ b/tunnel/crypto.go @@ -24,20 +24,8 @@ func hash(key []byte) []byte { } // Encrypt encrypts data and returns the encrypted data -func Encrypt(data []byte, key []byte) ([]byte, error) { - // generate a new AES cipher using our 32 byte key - c, err := aes.NewCipher(hash(key)) - if err != nil { - return nil, err - } - - // gcm or Galois/Counter Mode, is a mode of operation - // for symmetric key cryptographic block ciphers - // - https://en.wikipedia.org/wiki/Galois/Counter_Mode - gcm, err := cipher.NewGCM(c) - if err != nil { - return nil, err - } +func Encrypt(gcm cipher.AEAD, data []byte) ([]byte, error) { + var err error // get new byte array the size of the nonce from pool // NOTE: we might use smaller nonce size in the future @@ -54,19 +42,29 @@ func Encrypt(data []byte, key []byte) ([]byte, error) { } // Decrypt decrypts the payload and returns the decrypted data -func Decrypt(data []byte, key []byte) ([]byte, error) { - // generate AES cipher for decrypting the message +func newCipher(key []byte) (cipher.AEAD, error) { + var err error + + // generate a new AES cipher using our 32 byte key for decrypting the message c, err := aes.NewCipher(hash(key)) if err != nil { return nil, err } - // we use GCM to encrypt the payload + // gcm or Galois/Counter Mode, is a mode of operation + // for symmetric key cryptographic block ciphers + // - https://en.wikipedia.org/wiki/Galois/Counter_Mode gcm, err := cipher.NewGCM(c) if err != nil { return nil, err } + return gcm, nil +} + +func Decrypt(gcm cipher.AEAD, data []byte) ([]byte, error) { + var err error + nonceSize := gcm.NonceSize() if len(data) < nonceSize { diff --git a/tunnel/crypto_test.go b/tunnel/crypto_test.go index 4faac2cf..af0e6a28 100644 --- a/tunnel/crypto_test.go +++ b/tunnel/crypto_test.go @@ -7,9 +7,14 @@ import ( func TestEncrypt(t *testing.T) { key := []byte("tokenpassphrase") + gcm, err := newCipher(key) + if err != nil { + t.Fatal(err) + } + data := []byte("supersecret") - cipherText, err := Encrypt(data, key) + cipherText, err := Encrypt(gcm, data) if err != nil { t.Errorf("failed to encrypt data: %v", err) } @@ -22,14 +27,19 @@ func TestEncrypt(t *testing.T) { func TestDecrypt(t *testing.T) { key := []byte("tokenpassphrase") + gcm, err := newCipher(key) + if err != nil { + t.Fatal(err) + } + data := []byte("supersecret") - cipherText, err := Encrypt(data, key) + cipherText, err := Encrypt(gcm, data) if err != nil { t.Errorf("failed to encrypt data: %v", err) } - plainText, err := Decrypt(cipherText, key) + plainText, err := Decrypt(gcm, cipherText) if err != nil { t.Errorf("failed to decrypt data: %v", err) } diff --git a/tunnel/default.go b/tunnel/default.go index 7cb636dd..b573b4e9 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -8,7 +8,7 @@ import ( "time" "github.com/google/uuid" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/transport" ) @@ -120,7 +120,8 @@ func (t *tun) listChannels() []string { } // newSession creates a new session and saves it -func (t *tun) newSession(channel, sessionId string) (*session, bool) { +func (t *tun) newSession(channel, sessionId string) (*session, bool, error) { + // new session s := &session{ tunnel: t.id, @@ -133,6 +134,11 @@ func (t *tun) newSession(channel, sessionId string) (*session, bool) { errChan: make(chan error, 1), key: []byte(t.token + channel + sessionId), } + gcm, err := newCipher(s.key) + if err != nil { + return nil, false, err + } + s.gcm = gcm // save session t.Lock() @@ -140,14 +146,14 @@ func (t *tun) newSession(channel, sessionId string) (*session, bool) { if ok { // session already exists t.Unlock() - return nil, false + return nil, false, nil } t.sessions[channel+sessionId] = s t.Unlock() // return session - return s, true + return s, true, nil } // TODO: use tunnel id as part of the session @@ -193,11 +199,14 @@ func (t *tun) announce(channel, session string, link *link) { } } - log.Debugf("Tunnel sending announce for discovery of channel(s) %s", channel) - + if logger.V(logger.TraceLevel, log) { + log.Debugf("Tunnel sending announce for discovery of channel(s) %s", channel) + } // send back the announcement if err := link.Send(msg); err != nil { - log.Debugf("Tunnel failed to send announcement for channel(s) %s message: %v", channel, err) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel failed to send announcement for channel(s) %s message: %v", channel, err) + } } } @@ -241,18 +250,26 @@ func (t *tun) manageLink(link *link) { wait(DiscoverTime) // send a discovery message to the link - log.Debugf("Tunnel sending discover to link: %v", link.Remote()) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel sending discover to link: %v", link.Remote()) + } if err := t.sendMsg("discover", link); err != nil { - log.Debugf("Tunnel failed to send discover to link %s: %v", link.Remote(), err) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel failed to send discover to link %s: %v", link.Remote(), err) + } } case <-keepalive.C: // wait half the keepalive time wait(KeepAliveTime) // send keepalive message - log.Debugf("Tunnel sending keepalive to link: %v", link.Remote()) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel sending keepalive to link: %v", link.Remote()) + } if err := t.sendMsg("keepalive", link); err != nil { - log.Debugf("Tunnel error sending keepalive to link %v: %v", link.Remote(), err) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel error sending keepalive to link %v: %v", link.Remote(), err) + } t.delLink(link.Remote()) return } @@ -301,8 +318,9 @@ func (t *tun) manageLinks() { t.Lock() for link, node := range delLinks { - log.Debugf("Tunnel deleting dead link for %s", node) - + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel deleting dead link for %s", node) + } // check if the link exists l, ok := t.links[node] if ok { @@ -335,7 +353,9 @@ func (t *tun) manageLinks() { // if we're using quic it should be a max 10 second handshake period link, err := t.setupLink(node) if err != nil { - log.Debugf("Tunnel failed to setup node link to %s: %v", node, err) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel failed to setup node link to %s: %v", node, err) + } return } @@ -384,7 +404,9 @@ func (t *tun) process() { // if the link is not connected skip it if !connected { - log.Debugf("Link for node %s not connected", id) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Link for node %s not connected", id) + } err = ErrLinkDisconnected continue } @@ -428,7 +450,9 @@ func (t *tun) process() { // no links to send to if len(sendTo) == 0 { - log.Debugf("No links to send message type: %s channel: %s", msg.typ, msg.channel) + if logger.V(logger.DebugLevel, log) { + log.Debugf("No links to send message type: %s channel: %s", msg.typ, msg.channel) + } t.respond(msg, err) continue } @@ -454,7 +478,9 @@ func (t *tun) sendTo(links []*link, msg *message) error { // the function that sends the actual message send := func(link *link, msg *transport.Message) error { if err := link.Send(msg); err != nil { - log.Debugf("Tunnel error sending %+v to %s: %v", msg.Header, link.Remote(), err) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel error sending %+v to %s: %v", msg.Header, link.Remote(), err) + } t.delLink(link.Remote()) return err } @@ -493,7 +519,9 @@ func (t *tun) sendTo(links []*link, msg *message) error { // send the message for _, link := range links { // send the message via the current link - log.Tracef("Tunnel sending %+v to %s", newMsg.Header, link.Remote()) + if logger.V(logger.TraceLevel, log) { + log.Tracef("Tunnel sending %+v to %s", newMsg.Header, link.Remote()) + } // blast it in a go routine since its multicast/broadcast if msg.mode > Unicast { @@ -552,7 +580,9 @@ func (t *tun) delLink(remote string) { continue } // close and delete - log.Debugf("Tunnel deleting link node: %s remote: %s", id, link.Remote()) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel deleting link node: %s remote: %s", id, link.Remote()) + } link.Close() delete(t.links, id) } @@ -602,7 +632,9 @@ func (t *tun) listen(link *link) { // if its not connected throw away the link // the first message we process needs to be connect if !connected && mtype != "connect" { - log.Debugf("Tunnel link %s not connected", link.id) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel link %s not connected", link.id) + } return } @@ -611,7 +643,9 @@ func (t *tun) listen(link *link) { // discover, announce, session, keepalive switch mtype { case "connect": - log.Debugf("Tunnel link %s received connect message", link.Remote()) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel link %s received connect message", link.Remote()) + } link.Lock() @@ -644,11 +678,15 @@ func (t *tun) listen(link *link) { // if there is no channel then we close the link // as its a signal from the other side to close the connection if len(channel) == 0 { - log.Debugf("Tunnel link %s received close message", link.Remote()) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel link %s received close message", link.Remote()) + } return } - log.Debugf("Tunnel link %s received close message for %s", link.Remote(), channel) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel link %s received close message for %s", link.Remote(), channel) + } // the entire listener was closed by the remote side so we need to // remove the channel mapping for it. should we also close sessions? if sessionId == "listener" { @@ -673,13 +711,17 @@ func (t *tun) listen(link *link) { } // otherwise its a session mapping of sorts case "keepalive": - log.Debugf("Tunnel link %s received keepalive", link.Remote()) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel link %s received keepalive", link.Remote()) + } // save the keepalive link.keepalive() continue // a new connection dialled outbound case "open": - log.Debugf("Tunnel link %s received open %s %s", link.id, channel, sessionId) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel link %s received open %s %s", link.id, channel, sessionId) + } // we just let it pass through to be processed // an accept returned by the listener case "accept": @@ -697,11 +739,14 @@ func (t *tun) listen(link *link) { // a continued session case "session": // process message - log.Tracef("Tunnel received %+v from %s", msg.Header, link.Remote()) + if logger.V(logger.TraceLevel, log) { + log.Tracef("Tunnel received %+v from %s", msg.Header, link.Remote()) + } // an announcement of a channel listener case "announce": - log.Tracef("Tunnel received %+v from %s", msg.Header, link.Remote()) - + if logger.V(logger.TraceLevel, log) { + log.Tracef("Tunnel received %+v from %s", msg.Header, link.Remote()) + } // process the announcement channels := strings.Split(channel, ",") @@ -773,7 +818,9 @@ func (t *tun) listen(link *link) { s, exists = t.getSession(channel, "listener") // only return accept to the session case mtype == "accept": - log.Debugf("Tunnel received accept message for channel: %s session: %s", channel, sessionId) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel received accept message for channel: %s session: %s", channel, sessionId) + } s, exists = t.getSession(channel, sessionId) if exists && s.accepted { continue @@ -793,7 +840,9 @@ func (t *tun) listen(link *link) { // bail if no session or listener has been found if !exists { - log.Tracef("Tunnel skipping no channel: %s session: %s exists", channel, sessionId) + if logger.V(logger.TraceLevel, log) { + log.Tracef("Tunnel skipping no channel: %s session: %s exists", channel, sessionId) + } // drop it, we don't care about // messages we don't know about continue @@ -808,9 +857,9 @@ func (t *tun) listen(link *link) { default: // otherwise process } - - log.Tracef("Tunnel using channel: %s session: %s type: %s", s.channel, s.session, mtype) - + if logger.V(logger.TraceLevel, log) { + log.Tracef("Tunnel using channel: %s session: %s type: %s", s.channel, s.session, mtype) + } // construct a new transport message tmsg := &transport.Message{ Header: msg.Header, @@ -851,16 +900,19 @@ func (t *tun) sendMsg(method string, link *link) error { // setupLink connects to node and returns link if successful // It returns error if the link failed to be established func (t *tun) setupLink(node string) (*link, error) { - log.Debugf("Tunnel setting up link: %s", node) - + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel setting up link: %s", node) + } c, err := t.options.Transport.Dial(node) if err != nil { - log.Debugf("Tunnel failed to connect to %s: %v", node, err) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel failed to connect to %s: %v", node, err) + } return nil, err } - - log.Debugf("Tunnel connected to %s", node) - + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel connected to %s", node) + } // create a new link link := newLink(c) @@ -905,7 +957,9 @@ func (t *tun) setupLinks() { // create new link link, err := t.setupLink(node) if err != nil { - log.Debugf("Tunnel failed to setup node link to %s: %v", node, err) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel failed to setup node link to %s: %v", node, err) + } return } @@ -931,8 +985,9 @@ func (t *tun) connect() error { go func() { // accept inbound connections err := l.Accept(func(sock transport.Socket) { - log.Debugf("Tunnel accepted connection from %s", sock.Remote()) - + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel accepted connection from %s", sock.Remote()) + } // create a new link link := newLink(sock) @@ -1089,7 +1144,9 @@ func (t *tun) Close() error { return nil } - log.Debug("Tunnel closing") + if logger.V(logger.DebugLevel, log) { + log.Debug("Tunnel closing") + } select { case <-t.closed: @@ -1117,11 +1174,18 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { o(&options) } - log.Debugf("Tunnel dialing %s", channel) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel dialing %s", channel) + } // create a new session - c, ok := t.newSession(channel, t.newSessionId()) - if !ok { + c, ok, err := t.newSession(channel, t.newSessionId()) + if err != nil { + if logger.V(logger.DebugLevel, log) { + log.Error(err) + } + return nil, err + } else if !ok { return nil, errors.New("error dialing " + channel) } @@ -1171,7 +1235,9 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { if len(links) == 0 { // delete session and return error t.delSession(c.channel, c.session) - log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, ErrLinkNotFound) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, ErrLinkNotFound) + } return nil, ErrLinkNotFound } @@ -1206,7 +1272,9 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { err := c.Discover() if err != nil { t.delSession(c.channel, c.session) - log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, err) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, err) + } return nil, err } @@ -1244,7 +1312,9 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { if err := c.Open(); err != nil { // delete the session t.delSession(c.channel, c.session) - log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, err) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, err) + } return nil, err } @@ -1269,8 +1339,9 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { // Accept a connection on the address func (t *tun) Listen(channel string, opts ...ListenOption) (Listener, error) { - log.Debugf("Tunnel listening on %s", channel) - + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel listening on %s", channel) + } options := ListenOptions{ // Read timeout defaults to never Timeout: time.Duration(-1), @@ -1281,8 +1352,13 @@ func (t *tun) Listen(channel string, opts ...ListenOption) (Listener, error) { } // create a new session by hashing the address - c, ok := t.newSession(channel, "listener") - if !ok { + c, ok, err := t.newSession(channel, "listener") + if err != nil { + if logger.V(logger.ErrorLevel, log) { + log.Error(err) + } + return nil, err + } else if !ok { return nil, errors.New("already listening on " + channel) } diff --git a/tunnel/link.go b/tunnel/link.go index e698a280..5872d9df 100644 --- a/tunnel/link.go +++ b/tunnel/link.go @@ -8,7 +8,7 @@ import ( "time" "github.com/google/uuid" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/transport" ) @@ -268,8 +268,9 @@ func (l *link) manage() { // check the type of message switch { case bytes.Equal(p.message.Body, linkRequest): - log.Tracef("Link %s received link request", linkId) - + if logger.V(logger.TraceLevel, log) { + log.Tracef("Link %s received link request", linkId) + } // send response if err := send(linkResponse); err != nil { l.Lock() @@ -279,7 +280,9 @@ func (l *link) manage() { case bytes.Equal(p.message.Body, linkResponse): // set round trip time d := time.Since(now) - log.Tracef("Link %s received link response in %v", linkId, d) + if logger.V(logger.TraceLevel, log) { + log.Tracef("Link %s received link response in %v", linkId, d) + } // set the RTT l.setRTT(d) } diff --git a/tunnel/listener.go b/tunnel/listener.go index dedde945..d775804e 100644 --- a/tunnel/listener.go +++ b/tunnel/listener.go @@ -4,7 +4,7 @@ import ( "io" "sync" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" ) type tunListener struct { @@ -66,7 +66,9 @@ func (t *tunListener) process() { // get a session sess, ok := conns[sessionId] - log.Tracef("Tunnel listener received channel %s session %s type %s exists: %t", m.channel, m.session, m.typ, ok) + if logger.V(logger.TraceLevel, log) { + log.Tracef("Tunnel listener received channel %s session %s type %s exists: %t", m.channel, m.session, m.typ, ok) + } if !ok { // we only process open and session types switch m.typ { @@ -152,7 +154,9 @@ func (t *tunListener) process() { case <-sess.closed: delete(conns, sessionId) case sess.recv <- m: - log.Tracef("Tunnel listener sent to recv chan channel %s session %s type %s", m.channel, sessionId, m.typ) + if logger.V(logger.TraceLevel, log) { + log.Tracef("Tunnel listener sent to recv chan channel %s session %s type %s", m.channel, sessionId, m.typ) + } } } } diff --git a/tunnel/options.go b/tunnel/options.go index 166680d9..954ccd50 100644 --- a/tunnel/options.go +++ b/tunnel/options.go @@ -4,6 +4,7 @@ import ( "time" "github.com/google/uuid" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/transport" "github.com/micro/go-micro/v2/transport/quic" ) @@ -13,6 +14,7 @@ var ( DefaultAddress = ":0" // The shared default token DefaultToken = "go.micro.tunnel" + log = logger.NewHelper(logger.DefaultLogger).WithFields(map[string]interface{}{"service": "tunnel"}) ) type Option func(*Options) diff --git a/tunnel/session.go b/tunnel/session.go index be34e55f..8037546e 100644 --- a/tunnel/session.go +++ b/tunnel/session.go @@ -1,11 +1,13 @@ package tunnel import ( + "crypto/cipher" "encoding/base32" "io" + "sync" "time" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/transport" ) @@ -49,6 +51,9 @@ type session struct { errChan chan error // key for session encryption key []byte + // cipher for session + gcm cipher.AEAD + sync.RWMutex } // message is sent over the send channel @@ -166,7 +171,9 @@ func (s *session) waitFor(msgType string, timeout time.Duration) (*message, erro // ignore what we don't want if msg.typ != msgType { - log.Debugf("Tunnel received non %s message in waiting for %s", msg.typ, msgType) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel received non %s message in waiting for %s", msg.typ, msgType) + } continue } @@ -185,7 +192,9 @@ func (s *session) waitFor(msgType string, timeout time.Duration) (*message, erro // ignore what we don't want if msg.typ != msgType { - log.Debugf("Tunnel received non %s message in waiting for %s", msg.typ, msgType) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Tunnel received non %s message in waiting for %s", msg.typ, msgType) + } continue } @@ -327,8 +336,23 @@ func (s *session) Announce() error { // Send is used to send a message func (s *session) Send(m *transport.Message) error { + var err error + + s.RLock() + gcm := s.gcm + s.RUnlock() + + if gcm == nil { + gcm, err = newCipher(s.key) + if err != nil { + return err + } + s.Lock() + s.gcm = gcm + s.Unlock() + } // encrypt the transport message payload - body, err := Encrypt(m.Body, s.key) + body, err := Encrypt(gcm, m.Body) if err != nil { log.Debugf("failed to encrypt message body: %v", err) return err @@ -343,7 +367,7 @@ func (s *session) Send(m *transport.Message) error { // encrypt all the headers for k, v := range m.Header { // encrypt the transport message payload - val, err := Encrypt([]byte(v), s.key) + val, err := Encrypt(s.gcm, []byte(v)) if err != nil { log.Debugf("failed to encrypt message header %s: %v", k, err) return err @@ -362,8 +386,9 @@ func (s *session) Send(m *transport.Message) error { msg.link = "" } - log.Tracef("Appending %+v to send backlog", msg) - + if logger.V(logger.TraceLevel, log) { + log.Tracef("Appending to send backlog: %v", msg) + } // send the actual message if err := s.sendMsg(msg); err != nil { return err @@ -389,16 +414,27 @@ func (s *session) Recv(m *transport.Message) error { default: } - log.Tracef("Received %+v from recv backlog", msg) + if logger.V(logger.TraceLevel, log) { + log.Tracef("Received from recv backlog: %v", msg) + } + + gcm, err := newCipher([]byte(s.token + s.channel + msg.session)) + if err != nil { + if logger.V(logger.ErrorLevel, log) { + log.Errorf("unable to create cipher: %v", err) + } + return err + } - key := []byte(s.token + s.channel + msg.session) // decrypt the received payload using the token // we have to used msg.session because multicast has a shared // session id of "multicast" in this session struct on // the listener side - msg.data.Body, err = Decrypt(msg.data.Body, key) + msg.data.Body, err = Decrypt(gcm, msg.data.Body) if err != nil { - log.Debugf("failed to decrypt message body: %v", err) + if logger.V(logger.DebugLevel, log) { + log.Debugf("failed to decrypt message body: %v", err) + } return err } @@ -407,14 +443,18 @@ func (s *session) Recv(m *transport.Message) error { // decode the header values h, err := base32.StdEncoding.DecodeString(v) if err != nil { - log.Debugf("failed to decode message header %s: %v", k, err) + if logger.V(logger.DebugLevel, log) { + log.Debugf("failed to decode message header %s: %v", k, err) + } return err } // dencrypt the transport message payload - val, err := Decrypt(h, key) + val, err := Decrypt(gcm, h) if err != nil { - log.Debugf("failed to decrypt message header %s: %v", k, err) + if logger.V(logger.DebugLevel, log) { + log.Debugf("failed to decrypt message header %s: %v", k, err) + } return err } // add decrypted header value diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 1e702a32..2b9d7db0 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -12,7 +12,7 @@ import ( "path" "strings" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/util/kubernetes/api" ) @@ -190,7 +190,9 @@ func (c *client) Watch(r *Resource, opts ...WatchOption) (Watcher, error) { // NewService returns default micro kubernetes service definition func NewService(name, version, typ string) *Service { - log.Tracef("kubernetes default service: name: %s, version: %s", name, version) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("kubernetes default service: name: %s, version: %s", name, version) + } Labels := map[string]string{ "name": name, @@ -227,7 +229,9 @@ func NewService(name, version, typ string) *Service { // NewService returns default micro kubernetes deployment definition func NewDeployment(name, version, typ string) *Deployment { - log.Tracef("kubernetes default deployment: name: %s, version: %s", name, version) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("kubernetes default deployment: name: %s, version: %s", name, version) + } Labels := map[string]string{ "name": name, @@ -303,26 +307,26 @@ func NewClusterClient() *client { s, err := os.Stat(serviceAccountPath) if err != nil { - log.Fatal(err) + logger.Fatal(err) } if s == nil || !s.IsDir() { - log.Fatal(errors.New("service account not found")) + logger.Fatal(errors.New("service account not found")) } token, err := ioutil.ReadFile(path.Join(serviceAccountPath, "token")) if err != nil { - log.Fatal(err) + logger.Fatal(err) } t := string(token) ns, err := detectNamespace() if err != nil { - log.Fatal(err) + logger.Fatal(err) } crt, err := CertPoolFromFile(path.Join(serviceAccountPath, "ca.crt")) if err != nil { - log.Fatal(err) + logger.Fatal(err) } c := &http.Client{ diff --git a/web/service.go b/web/service.go index b133539d..0cd683a4 100644 --- a/web/service.go +++ b/web/service.go @@ -15,7 +15,7 @@ import ( "github.com/micro/cli/v2" "github.com/micro/go-micro/v2" - log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" maddr "github.com/micro/go-micro/v2/util/addr" mhttp "github.com/micro/go-micro/v2/util/http" @@ -125,7 +125,9 @@ func (s *service) register() error { // use RegisterCheck func before register if err := s.opts.RegisterCheck(s.opts.Context); err != nil { - log.Errorf("Server %s-%s register check error: %s", s.opts.Name, s.opts.Id, err) + if logger.V(logger.ErrorLevel, log) { + log.Errorf("Server %s-%s register check error: %s", s.opts.Name, s.opts.Id, err) + } return err } @@ -190,7 +192,9 @@ func (s *service) start() error { if s.static { _, err := os.Stat(static) if err == nil { - log.Infof("Enabling static file serving from %s", static) + if logger.V(logger.InfoLevel, log) { + log.Infof("Enabling static file serving from %s", static) + } s.mux.Handle("/", http.FileServer(http.Dir(static))) } } @@ -222,7 +226,9 @@ func (s *service) start() error { ch <- l.Close() }() - log.Infof("Listening on %v", l.Addr().String()) + if logger.V(logger.InfoLevel, log) { + log.Infof("Listening on %v", l.Addr().String()) + } return nil } @@ -244,7 +250,9 @@ func (s *service) stop() error { s.exit <- ch s.running = false - log.Info("Stopping") + if logger.V(logger.InfoLevel, log) { + log.Info("Stopping") + } for _, fn := range s.opts.AfterStop { if err := fn(); err != nil { @@ -391,10 +399,14 @@ func (s *service) Run() error { select { // wait on kill signal case sig := <-ch: - log.Infof("Received signal %s", sig) + if logger.V(logger.InfoLevel, log) { + log.Infof("Received signal %s", sig) + } // wait on context cancel case <-s.opts.Context.Done(): - log.Info("Received context shutdown") + if logger.V(logger.InfoLevel, log) { + log.Info("Received context shutdown") + } } // exit reg loop diff --git a/web/web.go b/web/web.go index 5c06c2ae..ae3eb7f1 100644 --- a/web/web.go +++ b/web/web.go @@ -7,6 +7,7 @@ import ( "time" "github.com/google/uuid" + "github.com/micro/go-micro/v2/logger" ) // Service is a web service with service discovery built in @@ -35,6 +36,8 @@ var ( // static directory DefaultStaticDir = "html" DefaultRegisterCheck = func(context.Context) error { return nil } + + log = logger.NewHelper(logger.DefaultLogger).WithFields(map[string]interface{}{"service": "web"}) ) // NewService returns a new web.Service From f55493993c9fafcd4402d8c3a6010c0afbcf0106 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 11 Mar 2020 22:31:24 +0000 Subject: [PATCH 373/788] set namespace rather than key (#1331) --- config/source/service/options.go | 6 +- config/source/service/proto/service.pb.go | 117 +++++++++--------- .../source/service/proto/service.pb.micro.go | 18 +-- config/source/service/proto/service.proto | 8 +- config/source/service/service.go | 28 +++-- 5 files changed, 94 insertions(+), 83 deletions(-) diff --git a/config/source/service/options.go b/config/source/service/options.go index ea80e1bd..27565a79 100644 --- a/config/source/service/options.go +++ b/config/source/service/options.go @@ -7,7 +7,7 @@ import ( ) type serviceNameKey struct{} -type keyKey struct{} +type namespaceKey struct{} type pathKey struct{} func ServiceName(name string) source.Option { @@ -19,12 +19,12 @@ func ServiceName(name string) source.Option { } } -func Key(key string) source.Option { +func Namespace(namespace string) source.Option { return func(o *source.Options) { if o.Context == nil { o.Context = context.Background() } - o.Context = context.WithValue(o.Context, keyKey{}, key) + o.Context = context.WithValue(o.Context, namespaceKey{}, namespace) } } diff --git a/config/source/service/proto/service.pb.go b/config/source/service/proto/service.pb.go index 47ab08e5..e66ca37b 100644 --- a/config/source/service/proto/service.pb.go +++ b/config/source/service/proto/service.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: go-micro/config/source/service/proto/service.proto +// source: github.com/micro/go-micro/config/source/service/proto/service.proto package service @@ -35,7 +35,7 @@ func (m *ChangeSet) Reset() { *m = ChangeSet{} } func (m *ChangeSet) String() string { return proto.CompactTextString(m) } func (*ChangeSet) ProtoMessage() {} func (*ChangeSet) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{0} + return fileDescriptor_54fcef0de4ea31b3, []int{0} } func (m *ChangeSet) XXX_Unmarshal(b []byte) error { @@ -92,7 +92,7 @@ func (m *ChangeSet) GetTimestamp() int64 { } type Change struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` ChangeSet *ChangeSet `protobuf:"bytes,3,opt,name=changeSet,proto3" json:"changeSet,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -104,7 +104,7 @@ func (m *Change) Reset() { *m = Change{} } func (m *Change) String() string { return proto.CompactTextString(m) } func (*Change) ProtoMessage() {} func (*Change) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{1} + return fileDescriptor_54fcef0de4ea31b3, []int{1} } func (m *Change) XXX_Unmarshal(b []byte) error { @@ -125,9 +125,9 @@ func (m *Change) XXX_DiscardUnknown() { var xxx_messageInfo_Change proto.InternalMessageInfo -func (m *Change) GetKey() string { +func (m *Change) GetNamespace() string { if m != nil { - return m.Key + return m.Namespace } return "" } @@ -157,7 +157,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{2} + return fileDescriptor_54fcef0de4ea31b3, []int{2} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -195,7 +195,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{3} + return fileDescriptor_54fcef0de4ea31b3, []int{3} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -227,7 +227,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{4} + return fileDescriptor_54fcef0de4ea31b3, []int{4} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -265,7 +265,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{5} + return fileDescriptor_54fcef0de4ea31b3, []int{5} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -297,7 +297,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{6} + return fileDescriptor_54fcef0de4ea31b3, []int{6} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -335,7 +335,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{7} + return fileDescriptor_54fcef0de4ea31b3, []int{7} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -366,7 +366,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{8} + return fileDescriptor_54fcef0de4ea31b3, []int{8} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -398,7 +398,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{9} + return fileDescriptor_54fcef0de4ea31b3, []int{9} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -427,7 +427,7 @@ func (m *ListResponse) GetValues() []*Change { } type ReadRequest struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -438,7 +438,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{10} + return fileDescriptor_54fcef0de4ea31b3, []int{10} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -459,9 +459,9 @@ func (m *ReadRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ReadRequest proto.InternalMessageInfo -func (m *ReadRequest) GetKey() string { +func (m *ReadRequest) GetNamespace() string { if m != nil { - return m.Key + return m.Namespace } return "" } @@ -484,7 +484,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{11} + return fileDescriptor_54fcef0de4ea31b3, []int{11} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -513,7 +513,7 @@ func (m *ReadResponse) GetChange() *Change { } type WatchRequest struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -524,7 +524,7 @@ func (m *WatchRequest) Reset() { *m = WatchRequest{} } func (m *WatchRequest) String() string { return proto.CompactTextString(m) } func (*WatchRequest) ProtoMessage() {} func (*WatchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{12} + return fileDescriptor_54fcef0de4ea31b3, []int{12} } func (m *WatchRequest) XXX_Unmarshal(b []byte) error { @@ -545,9 +545,9 @@ func (m *WatchRequest) XXX_DiscardUnknown() { var xxx_messageInfo_WatchRequest proto.InternalMessageInfo -func (m *WatchRequest) GetKey() string { +func (m *WatchRequest) GetNamespace() string { if m != nil { - return m.Key + return m.Namespace } return "" } @@ -560,7 +560,7 @@ func (m *WatchRequest) GetPath() string { } type WatchResponse struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` ChangeSet *ChangeSet `protobuf:"bytes,2,opt,name=changeSet,proto3" json:"changeSet,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -571,7 +571,7 @@ func (m *WatchResponse) Reset() { *m = WatchResponse{} } func (m *WatchResponse) String() string { return proto.CompactTextString(m) } func (*WatchResponse) ProtoMessage() {} func (*WatchResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_05971a9aaecb0484, []int{13} + return fileDescriptor_54fcef0de4ea31b3, []int{13} } func (m *WatchResponse) XXX_Unmarshal(b []byte) error { @@ -592,9 +592,9 @@ func (m *WatchResponse) XXX_DiscardUnknown() { var xxx_messageInfo_WatchResponse proto.InternalMessageInfo -func (m *WatchResponse) GetKey() string { +func (m *WatchResponse) GetNamespace() string { if m != nil { - return m.Key + return m.Namespace } return "" } @@ -624,37 +624,38 @@ func init() { } func init() { - proto.RegisterFile("go-micro/config/source/service/proto/service.proto", fileDescriptor_05971a9aaecb0484) + proto.RegisterFile("github.com/micro/go-micro/config/source/service/proto/service.proto", fileDescriptor_54fcef0de4ea31b3) } -var fileDescriptor_05971a9aaecb0484 = []byte{ - // 443 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xcf, 0x6a, 0xdb, 0x40, - 0x10, 0xc6, 0x2d, 0xdb, 0x51, 0xab, 0xb1, 0x24, 0x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, 0x11, 0x4c, 0x23, 0xd6, 0x07, 0x68, 0xaf, 0xe9, 0x65, 0x63, 0xc8, 0x7a, - 0xa0, 0xd2, 0x88, 0xf5, 0x09, 0x64, 0x23, 0xfc, 0x00, 0x57, 0x66, 0x59, 0x18, 0xb1, 0xfe, 0xaa, - 0xd3, 0x98, 0x0d, 0x76, 0x98, 0x8d, 0x6e, 0xbc, 0xdf, 0xbe, 0x79, 0xed, 0xb7, 0xff, 0x02, 0x00, - 0x00, 0xff, 0xff, 0xea, 0xa0, 0x1e, 0x8e, 0x23, 0x04, 0x00, 0x00, +var fileDescriptor_54fcef0de4ea31b3 = []byte{ + // 455 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xcd, 0x8e, 0x9b, 0x30, + 0x10, 0xc7, 0x43, 0x92, 0xa5, 0x65, 0x02, 0xa4, 0xf2, 0xa1, 0x42, 0xa8, 0x52, 0x23, 0xa4, 0x4a, + 0x51, 0xab, 0x9a, 0x55, 0xfa, 0x00, 0xad, 0x94, 0x1e, 0x7b, 0xa2, 0xaa, 0xf6, 0xec, 0x75, 0x66, + 0x03, 0xea, 0x12, 0x53, 0x6c, 0xf6, 0x1d, 0xf6, 0xad, 0x2b, 0x7f, 0xb0, 0x40, 0x0e, 0x91, 0xb2, + 0x37, 0xcf, 0xd7, 0x7f, 0xc6, 0xfe, 0x0d, 0xc0, 0xfe, 0x58, 0xa9, 0xb2, 0xbb, 0xa7, 0x5c, 0xd4, + 0x79, 0x5d, 0xf1, 0x56, 0xe4, 0x47, 0xf1, 0xd5, 0x1e, 0xb8, 0x38, 0x3d, 0x54, 0xc7, 0x5c, 0x8a, + 0xae, 0xe5, 0x98, 0x4b, 0x6c, 0x9f, 0x2a, 0x8e, 0x79, 0xd3, 0x0a, 0x25, 0x7a, 0x8b, 0x1a, 0x2b, + 0x7b, 0xf6, 0x20, 0xd8, 0x97, 0xec, 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0x28, 0x5a, + 0x77, 0xf6, 0x1d, 0x56, 0x05, 0xb2, 0x43, 0x3f, 0xc1, 0xd5, 0xcf, 0xae, 0x3b, 0x5a, 0x81, 0xa1, + 0xe3, 0xe5, 0x3b, 0xfc, 0x80, 0xf0, 0x8e, 0x29, 0x5e, 0xbe, 0xbe, 0xe5, 0x1d, 0x44, 0x4e, 0xc1, + 0xf5, 0xbc, 0x2c, 0x31, 0x59, 0x8c, 0xf9, 0x85, 0xc5, 0xd8, 0x3d, 0xcf, 0xc1, 0xdf, 0x9b, 0x0f, + 0x87, 0x7c, 0x01, 0xdf, 0x12, 0x27, 0x31, 0x9d, 0x2c, 0x4b, 0xba, 0xa6, 0x67, 0xab, 0x30, 0xd3, + 0xc9, 0x16, 0x2d, 0x89, 0xe9, 0x64, 0x2b, 0xd2, 0x35, 0x3d, 0x63, 0x6e, 0x92, 0x2d, 0x43, 0x12, + 0xd3, 0x09, 0xfe, 0x74, 0x4d, 0xcf, 0xe0, 0xce, 0xc8, 0x27, 0x58, 0x6a, 0x9e, 0x24, 0xa4, 0x23, + 0xca, 0x69, 0x44, 0xc7, 0x90, 0x6d, 0x9a, 0x86, 0x40, 0x42, 0x3a, 0x82, 0x99, 0x46, 0x74, 0x4c, + 0x26, 0x9b, 0x91, 0xcf, 0x70, 0x63, 0x1e, 0x8e, 0x44, 0x74, 0x8c, 0x20, 0x8d, 0xe9, 0xe4, 0x3d, + 0xb3, 0xd9, 0xad, 0x77, 0xef, 0x9b, 0xbf, 0xc3, 0xb7, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcb, + 0x26, 0xcb, 0xd9, 0x64, 0x04, 0x00, 0x00, } diff --git a/config/source/service/proto/service.pb.micro.go b/config/source/service/proto/service.pb.micro.go index f88a9b15..4e69cf12 100644 --- a/config/source/service/proto/service.pb.micro.go +++ b/config/source/service/proto/service.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: go-micro/config/source/service/proto/service.proto +// source: github.com/micro/go-micro/config/source/service/proto/service.proto package service @@ -48,12 +48,6 @@ type configService struct { } func NewConfigService(name string, c client.Client) ConfigService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "config" - } return &configService{ c: c, name: name, @@ -123,6 +117,7 @@ func (c *configService) Watch(ctx context.Context, in *WatchRequest, opts ...cli } type Config_WatchService interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -137,6 +132,10 @@ func (x *configServiceWatch) Close() error { return x.stream.Close() } +func (x *configServiceWatch) Context() context.Context { + return x.stream.Context() +} + func (x *configServiceWatch) SendMsg(m interface{}) error { return x.stream.Send(m) } @@ -214,6 +213,7 @@ func (h *configHandler) Watch(ctx context.Context, stream server.Stream) error { } type Config_WatchStream interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -228,6 +228,10 @@ func (x *configWatchStream) Close() error { return x.stream.Close() } +func (x *configWatchStream) Context() context.Context { + return x.stream.Context() +} + func (x *configWatchStream) SendMsg(m interface{}) error { return x.stream.Send(m) } diff --git a/config/source/service/proto/service.proto b/config/source/service/proto/service.proto index ac0359ce..91e563ac 100644 --- a/config/source/service/proto/service.proto +++ b/config/source/service/proto/service.proto @@ -18,7 +18,7 @@ message ChangeSet { } message Change { - string key = 1; + string namespace = 1; string path = 2; ChangeSet changeSet = 3; } @@ -48,7 +48,7 @@ message ListResponse { } message ReadRequest { - string key = 1; + string namespace = 1; string path = 2; } @@ -57,11 +57,11 @@ message ReadResponse { } message WatchRequest { - string key = 1; + string namespace = 1; string path = 2; } message WatchResponse { - string key = 1; + string namespace = 1; ChangeSet changeSet = 2; } diff --git a/config/source/service/service.go b/config/source/service/service.go index 52dfe223..29e1bf65 100644 --- a/config/source/service/service.go +++ b/config/source/service/service.go @@ -10,22 +10,25 @@ import ( ) var ( - DefaultName = "go.micro.config" - DefaultKey = "NAMESPACE:CONFIG" - DefaultPath = "" - DefaultClient = client.DefaultClient + DefaultName = "go.micro.config" + DefaultNamespace = "global" + DefaultPath = "" + DefaultClient = client.DefaultClient ) type service struct { serviceName string - key string + namespace string path string opts source.Options client proto.ConfigService } func (m *service) Read() (set *source.ChangeSet, err error) { - req, err := m.client.Read(context.Background(), &proto.ReadRequest{Key: m.key, Path: m.path}) + req, err := m.client.Read(context.Background(), &proto.ReadRequest{ + Namespace: m.namespace, + Path: m.path, + }) if err != nil { return nil, err } @@ -34,7 +37,10 @@ func (m *service) Read() (set *source.ChangeSet, err error) { } func (m *service) Watch() (w source.Watcher, err error) { - stream, err := m.client.Watch(context.Background(), &proto.WatchRequest{Key: m.key, Path: m.path}) + stream, err := m.client.Watch(context.Background(), &proto.WatchRequest{ + Namespace: m.namespace, + Path: m.path, + }) if err != nil { if logger.V(logger.ErrorLevel, logger.DefaultLogger) { logger.Error("watch err: ", err) @@ -60,7 +66,7 @@ func NewSource(opts ...source.Option) source.Source { } addr := DefaultName - key := DefaultKey + namespace := DefaultNamespace path := DefaultPath if options.Context != nil { @@ -69,9 +75,9 @@ func NewSource(opts ...source.Option) source.Source { addr = a } - k, ok := options.Context.Value(keyKey{}).(string) + k, ok := options.Context.Value(namespaceKey{}).(string) if ok { - key = k + namespace = k } p, ok := options.Context.Value(pathKey{}).(string) @@ -83,7 +89,7 @@ func NewSource(opts ...source.Option) source.Source { s := &service{ serviceName: addr, opts: options, - key: key, + namespace: namespace, path: path, client: proto.NewConfigService(addr, DefaultClient), } From 1ca4619506bded1c721d7ac3b131aec7c9e0bdef Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 11 Mar 2020 23:09:42 +0000 Subject: [PATCH 374/788] return store.ErrNotFound (#1332) --- store/cloudflare/cloudflare.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index 07d2113f..b6177c66 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -218,6 +218,10 @@ func (w *workersKV) Read(key string, opts ...store.ReadOption) ([]*store.Record, return records, err } if status < 200 || status >= 300 { + if status == 404 { + return nil, store.ErrNotFound + } + return records, errors.New("Received unexpected Status " + strconv.Itoa(status) + string(response)) } record := &store.Record{ From be9c6141f5fb4078d38a83a6e4150efcb5ee1d36 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 12 Mar 2020 09:05:09 +0000 Subject: [PATCH 375/788] delete options (#1333) --- config/options/default.go | 34 ------------------ config/options/options.go | 76 --------------------------------------- 2 files changed, 110 deletions(-) delete mode 100644 config/options/default.go delete mode 100644 config/options/options.go diff --git a/config/options/default.go b/config/options/default.go deleted file mode 100644 index 96d8f4c8..00000000 --- a/config/options/default.go +++ /dev/null @@ -1,34 +0,0 @@ -package options - -type defaultOptions struct { - opts *Values -} - -type stringKey struct{} - -func (d *defaultOptions) Init(opts ...Option) error { - if d.opts == nil { - d.opts = new(Values) - } - for _, o := range opts { - if err := d.opts.Option(o); err != nil { - return err - } - } - return nil -} - -func (d *defaultOptions) Values() *Values { - return d.opts -} - -func (d *defaultOptions) String() string { - if d.opts == nil { - d.opts = new(Values) - } - n, ok := d.opts.Get(stringKey{}) - if ok { - return n.(string) - } - return "Values" -} diff --git a/config/options/options.go b/config/options/options.go deleted file mode 100644 index b465ba63..00000000 --- a/config/options/options.go +++ /dev/null @@ -1,76 +0,0 @@ -// Package options provides a way to initialise options -package options - -import ( - "log" - "sync" -) - -// Options is used for initialisation -type Options interface { - // Initialise options - Init(...Option) error - // Options returns the current options - Values() *Values - // The name for who these options exist - String() string -} - -// Values holds the set of option values and protects them -type Values struct { - sync.RWMutex - values map[interface{}]interface{} -} - -// Option gives access to options -type Option func(o *Values) error - -// Get a value from options -func (o *Values) Get(k interface{}) (interface{}, bool) { - o.RLock() - defer o.RUnlock() - v, ok := o.values[k] - return v, ok -} - -// Set a value in the options -func (o *Values) Set(k, v interface{}) error { - o.Lock() - defer o.Unlock() - if o.values == nil { - o.values = map[interface{}]interface{}{} - } - o.values[k] = v - return nil -} - -// SetOption executes an option -func (o *Values) Option(op Option) error { - return op(o) -} - -// WithValue allows you to set any value within the options -func WithValue(k, v interface{}) Option { - return func(o *Values) error { - return o.Set(k, v) - } -} - -// WithOption gives you the ability to create an option that accesses values -func WithOption(o Option) Option { - return o -} - -// String sets the string -func WithString(s string) Option { - return WithValue(stringKey{}, s) -} - -// NewOptions returns a new initialiser -func NewOptions(opts ...Option) Options { - o := new(defaultOptions) - if err := o.Init(opts...); err != nil { - log.Fatal(err) - } - return o -} From eef4825be4d61518eaf33d9f0d598ffb24b356ad Mon Sep 17 00:00:00 2001 From: chengguoqiang Date: Thu, 12 Mar 2020 18:09:38 +0800 Subject: [PATCH 376/788] Update etcd.go (#1334) add leaseId to the trace log --- registry/etcd/etcd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/etcd/etcd.go b/registry/etcd/etcd.go index 630fdbaf..8b7a65e1 100644 --- a/registry/etcd/etcd.go +++ b/registry/etcd/etcd.go @@ -252,7 +252,7 @@ func (e *etcdRegistry) registerNode(s *registry.Service, node *registry.Node, op } if logger.V(logger.TraceLevel, logger.DefaultLogger) { - logger.Tracef("Registering %s id %s with lease %v and ttl %v", service.Name, node.Id, lgr, options.TTL) + logger.Tracef("Registering %s id %s with lease %v and leaseID %v and ttl %v", service.Name, node.Id, lgr, lgr.ID, options.TTL) } // create an entry for the node if lgr != nil { From 20ce61da5a16fd77913e67429d665c8b7d74b570 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 12 Mar 2020 13:11:35 +0000 Subject: [PATCH 377/788] Oauth google fixes (#1330) * Fix Auth Headers * Tweak Oauth to work for Google Co-authored-by: Ben Toogood Co-authored-by: Asim Aslam --- auth/provider/oauth/oauth.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/auth/provider/oauth/oauth.go b/auth/provider/oauth/oauth.go index 527e6afa..52ae08a6 100644 --- a/auth/provider/oauth/oauth.go +++ b/auth/provider/oauth/oauth.go @@ -3,6 +3,7 @@ package oauth import ( "fmt" "net/url" + "strings" "github.com/micro/go-micro/v2/auth/provider" ) @@ -29,13 +30,19 @@ func (o *oauth) Options() provider.Options { } func (o *oauth) Endpoint() string { - var params url.Values + params := make(url.Values) + params.Add("response_type", "code") - if scope := o.opts.Scope; len(scope) > 0 { - params.Add("scope", scope) + if clientID := o.opts.ClientID; len(clientID) > 0 { + params.Add("client_id", clientID) } - if redir := o.opts.Redirect; len(redir) > 0 { + if scope := o.opts.Scope; len(scope) > 0 { + // spaces are url encoded since this cannot be passed in env vars + params.Add("scope", strings.ReplaceAll(scope, "%20", " ")) + } + + if redir := o.Redirect(); len(redir) > 0 { params.Add("redirect_uri", redir) } From 1b4e881d74e0bab6a079e0da85f0eea334518779 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Thu, 12 Mar 2020 13:41:30 +0000 Subject: [PATCH 378/788] Rewrite the store interface (#1335) * WIP store rewrite * Fix memory store tests * Store hard expiry times rather than duration! * Clarify memory test * Add limit to store interface * Implement suffix option * Don't return nils from noop store * Fix syncmap * Start fixing store service * wip service and cache * Use _ for special characters in cockroachdb namespace * Improve cockroach namespace comment * Use service name as default store namespace * Fixes * Implement Store Scope * Start fixing etcd * implement read and write with expiry and prefix * Fix etcd tests * Fix cockroach store * Fix cloudflare interface * Fix certmagic / cloudflare store * comment lint * cache isn't implemented yet * Only prepare DB staements once Co-authored-by: Ben Toogood Co-authored-by: ben-toogood --- api/server/acme/certmagic/certmagic.go | 2 +- api/server/acme/certmagic/storage.go | 8 +- go.mod | 8 +- go.sum | 33 +++ service.go | 8 + store/cache/cache.go | 39 +++ store/cache/cache_test.go | 15 ++ store/cloudflare/cloudflare.go | 24 +- store/cockroach/cockroach.go | 94 ++++--- store/cockroach/cockroach_test.go | 6 +- store/etcd/config.go | 178 +++++++++++++ store/etcd/etcd.go | 327 ++++++++++++++++------- store/etcd/etcd_test.go | 225 ++++++++++++++++ store/memory/memory.go | 349 ++++++++++++++++--------- store/memory/memory_test.go | 280 ++++++++++++++++++-- store/noop.go | 31 +++ store/options.go | 172 ++++++++++-- store/scope/scope.go | 51 ++++ store/service/proto/store.pb.go | 300 +++++++++++++++++---- store/service/proto/store.pb.micro.go | 136 +++++----- store/service/proto/store.proto | 40 ++- store/service/service.go | 27 +- store/store.go | 68 ++--- sync/map.go | 2 +- 24 files changed, 1905 insertions(+), 518 deletions(-) create mode 100644 store/cache/cache.go create mode 100644 store/cache/cache_test.go create mode 100644 store/etcd/config.go create mode 100644 store/etcd/etcd_test.go create mode 100644 store/noop.go create mode 100644 store/scope/scope.go diff --git a/api/server/acme/certmagic/certmagic.go b/api/server/acme/certmagic/certmagic.go index 81e485fc..0c62e4c7 100644 --- a/api/server/acme/certmagic/certmagic.go +++ b/api/server/acme/certmagic/certmagic.go @@ -48,7 +48,7 @@ func (c *certmagicProvider) TLSConfig(hosts ...string) (*tls.Config, error) { return certmagic.TLS(hosts) } -// New returns a certmagic provider +// NewProvider returns a certmagic provider func NewProvider(options ...acme.Option) acme.Provider { opts := acme.DefaultOptions() diff --git a/api/server/acme/certmagic/storage.go b/api/server/acme/certmagic/storage.go index 204269e6..dc805e98 100644 --- a/api/server/acme/certmagic/storage.go +++ b/api/server/acme/certmagic/storage.go @@ -88,16 +88,16 @@ func (s *storage) Exists(key string) bool { } func (s *storage) List(prefix string, recursive bool) ([]string, error) { - records, err := s.store.List() + keys, err := s.store.List() if err != nil { return nil, err } //nolint:prealloc var results []string - for _, r := range records { - if strings.HasPrefix(r.Key, prefix) { - results = append(results, r.Key) + for _, k := range keys { + if strings.HasPrefix(k, prefix) { + results = append(results, k) } } if recursive { diff --git a/go.mod b/go.mod index cb4fbcb2..1395da12 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c github.com/fsnotify/fsnotify v1.4.7 @@ -27,10 +28,8 @@ require ( github.com/gorilla/handlers v1.4.2 github.com/gorilla/websocket v1.4.1 github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect - github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/hashicorp/hcl v1.0.0 github.com/imdario/mergo v0.3.8 - github.com/jonboulle/clockwork v0.1.0 // indirect github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 github.com/json-iterator/go v1.1.9 github.com/kr/pretty v0.1.0 @@ -48,12 +47,10 @@ require ( github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 - github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 github.com/technoweenie/multipartstreamer v1.0.1 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect - github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect - go.etcd.io/bbolt v1.3.3 // indirect + go.etcd.io/etcd v0.5.0-alpha.5.0.20191031170918-4388404f56cb go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 @@ -63,5 +60,4 @@ require ( gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 - sigs.k8s.io/yaml v1.1.0 // indirect ) diff --git a/go.sum b/go.sum index 17c35f27..ffc6da3e 100644 --- a/go.sum +++ b/go.sum @@ -59,6 +59,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y= github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= @@ -75,6 +76,8 @@ github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wX github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.10.2 h1:VBodKICVPnwmDxstcW3biKcDSpFIfS/RELUXsZSBYK4= github.com/cloudflare/cloudflare-go v0.10.2/go.mod h1:qhVI5MKwBGhdNU89ZRz2plgYutcJ5PCekLxXn56w6SY= +github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa h1:OaNxuTZr7kxeODyLWsRMC+OD03aFUH+mW6r2d+MWa5Y= +github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko= github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= @@ -90,17 +93,22 @@ github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c= github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpu/goacmedns v0.0.1/go.mod h1:sesf/pNnCYwUevQEQfEwY0Y3DydlQWSGZbaMElOWxok= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -118,6 +126,8 @@ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKoh github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4 h1:qk/FSDDxo05wdJH28W+p5yivv7LuLYLRXPPD8KQCtZs= +github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= @@ -126,6 +136,7 @@ github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3 github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= @@ -164,6 +175,7 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -191,6 +203,7 @@ github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXi github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -203,16 +216,20 @@ github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/ github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg= github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.8.5 h1:2+KSC78XiO6Qy0hIjfc1OD9H+hsaJdJlb8Kqsd41CTE= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI= +github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= @@ -226,6 +243,7 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -274,7 +292,9 @@ github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1 github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= @@ -325,6 +345,7 @@ github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/Hzq github.com/nrdcg/dnspod-go v0.3.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgPTGKr6KQ= github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2SwKQ= github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw= +github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= @@ -398,6 +419,9 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1 github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4= +github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -411,11 +435,13 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= +github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc h1:yUaosFVTJwnltaHbSNC3i82I92quFs+OFPRl8kNMVwo= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= @@ -428,6 +454,8 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/etcd v0.5.0-alpha.5.0.20191031170918-4388404f56cb h1:OIEw2droD31lXVboIQzJFUuSJOxGFReUW6hmqTP10TE= +go.etcd.io/etcd v0.5.0-alpha.5.0.20191031170918-4388404f56cb/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -501,6 +529,7 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -538,6 +567,7 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= @@ -548,6 +578,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 h1:xQwXv67TxFo9nC1GJFyab5eq/5B590r6RlnL/G8Sz7w= @@ -608,12 +639,14 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= diff --git a/service.go b/service.go index a6c77469..9f5b6344 100644 --- a/service.go +++ b/service.go @@ -17,6 +17,7 @@ import ( "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/plugin" "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/store" "github.com/micro/go-micro/v2/util/config" "github.com/micro/go-micro/v2/util/wrapper" ) @@ -104,6 +105,13 @@ func (s *service) Init(opts ...Option) { logger.Fatal(err) } + // If the store has no namespace set, fallback to the + // services name + if len(store.DefaultStore.Options().Namespace) == 0 { + name := s.opts.Cmd.App().Name + store.DefaultStore.Init(store.Namespace(name)) + } + // TODO: replace Cmd.Init with config.Load // Right now we're just going to load a token // May need to re-read value on change diff --git a/store/cache/cache.go b/store/cache/cache.go new file mode 100644 index 00000000..1bb3852e --- /dev/null +++ b/store/cache/cache.go @@ -0,0 +1,39 @@ +package cache + +import ( + "github.com/micro/go-micro/v2/store" + "github.com/pkg/errors" +) + +// Cache implements a cache in front of a micro Store +type Cache struct { + options store.Options + store.Store + + stores []store.Store +} + +// NewStore returns new cache +func NewStore(opts ...store.Option) store.Store { + s := &Cache{ + options: store.Options{}, + stores: []store.Store{}, + } + for _, o := range opts { + o(&s.options) + } + return s +} + +// Init initialises a new cache +func (c *Cache) Init(opts ...store.Option) error { + for _, o := range opts { + o(&c.options) + } + for _, s := range c.stores { + if err := s.Init(); err != nil { + return errors.Wrapf(err, "Store %s failed to Init()", s.String()) + } + } + return nil +} diff --git a/store/cache/cache_test.go b/store/cache/cache_test.go new file mode 100644 index 00000000..bf01b9aa --- /dev/null +++ b/store/cache/cache_test.go @@ -0,0 +1,15 @@ +package cache + +// import "testing" + +// func TestCache(t *testing.T) { +// c := NewStore() +// if err := c.Init(); err != nil { +// //t.Fatal(err) +// } +// if results, err := c.Read("test"); err != nil { +// //t.Fatal(err) +// } else { +// println(results) +// } +// } diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index b6177c66..046276fa 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -159,25 +159,13 @@ func (w *workersKV) list(prefix string) ([]string, error) { // In the cloudflare workers KV implemention, List() doesn't guarantee // anything as the workers API is eventually consistent. -func (w *workersKV) List() ([]*store.Record, error) { +func (w *workersKV) List(opts ...store.ListOption) ([]string, error) { keys, err := w.list("") if err != nil { return nil, err } - var gerr error - var records []*store.Record - - for _, key := range keys { - r, err := w.Read(key) - if err != nil { - gerr = err - continue - } - records = append(records, r...) - } - - return records, gerr + return keys, nil } func (w *workersKV) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { @@ -244,7 +232,7 @@ func (w *workersKV) Read(key string, opts ...store.ReadOption) ([]*store.Record, return records, nil } -func (w *workersKV) Write(r *store.Record) error { +func (w *workersKV) Write(r *store.Record, opts ...store.WriteOption) error { // Set it in local cache, with the global TTL from options if w.cache != nil { w.cache.Set(r.Key, r, cache.DefaultExpiration) @@ -282,7 +270,7 @@ func (w *workersKV) Write(r *store.Record) error { return nil } -func (w *workersKV) Delete(key string) error { +func (w *workersKV) Delete(key string, opts ...store.DeleteOption) error { if w.cache != nil { w.cache.Delete(key) } @@ -371,6 +359,10 @@ func (w *workersKV) String() string { return "cloudflare" } +func (w *workersKV) Options() store.Options { + return w.options +} + // NewStore returns a cloudflare Store implementation. // Account ID, Token and Namespace must either be passed as options or // environment variables. If set as env vars we expect the following; diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index fcda1d6f..4bd92576 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -28,6 +28,11 @@ type sqlStore struct { database string table string + list *sql.Stmt + readOne *sql.Stmt + write *sql.Stmt + delete *sql.Stmt + options store.Options } @@ -40,13 +45,13 @@ func (s *sqlStore) Init(opts ...store.Option) error { } // List all the known records -func (s *sqlStore) List() ([]*store.Record, error) { - rows, err := s.db.Query(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s;", s.database, s.table)) - var records []*store.Record +func (s *sqlStore) List(opts ...store.ListOption) ([]string, error) { + rows, err := s.list.Query() + var keys []string var timehelper pq.NullTime if err != nil { if err == sql.ErrNoRows { - return records, nil + return keys, nil } return nil, err } @@ -54,7 +59,7 @@ func (s *sqlStore) List() ([]*store.Record, error) { for rows.Next() { record := &store.Record{} if err := rows.Scan(&record.Key, &record.Value, &timehelper); err != nil { - return records, err + return keys, err } if timehelper.Valid { if timehelper.Time.Before(time.Now()) { @@ -62,25 +67,25 @@ func (s *sqlStore) List() ([]*store.Record, error) { go s.Delete(record.Key) } else { record.Expiry = time.Until(timehelper.Time) - records = append(records, record) + keys = append(keys, record.Key) } } else { - records = append(records, record) + keys = append(keys, record.Key) } } rowErr := rows.Close() if rowErr != nil { // transaction rollback or something - return records, rowErr + return keys, rowErr } if err := rows.Err(); err != nil { - return records, err + return keys, err } - return records, nil + return keys, nil } -// Read all records with keys +// Read a single key func (s *sqlStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { var options store.ReadOptions for _, o := range opts { @@ -89,15 +94,10 @@ func (s *sqlStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, // TODO: make use of options.Prefix using WHERE key LIKE = ? - q, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key = $1;", s.database, s.table)) - if err != nil { - return nil, err - } - var records []*store.Record var timehelper pq.NullTime - row := q.QueryRow(key) + row := s.readOne.QueryRow(key) record := &store.Record{} if err := row.Scan(&record.Key, &record.Value, &timehelper); err != nil { if err == sql.ErrNoRows { @@ -121,20 +121,12 @@ func (s *sqlStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, } // Write records -func (s *sqlStore) Write(r *store.Record) error { - q, err := s.db.Prepare(fmt.Sprintf(`INSERT INTO %s.%s(key, value, expiry) - VALUES ($1, $2::bytea, $3) - ON CONFLICT (key) - DO UPDATE - SET value = EXCLUDED.value, expiry = EXCLUDED.expiry;`, s.database, s.table)) - if err != nil { - return err - } - +func (s *sqlStore) Write(r *store.Record, opts ...store.WriteOption) error { + var err error if r.Expiry != 0 { - _, err = q.Exec(r.Key, r.Value, time.Now().Add(r.Expiry)) + _, err = s.write.Exec(r.Key, r.Value, time.Now().Add(r.Expiry)) } else { - _, err = q.Exec(r.Key, r.Value, nil) + _, err = s.write.Exec(r.Key, r.Value, nil) } if err != nil { @@ -145,13 +137,8 @@ func (s *sqlStore) Write(r *store.Record) error { } // Delete records with keys -func (s *sqlStore) Delete(key string) error { - q, err := s.db.Prepare(fmt.Sprintf("DELETE FROM %s.%s WHERE key = $1;", s.database, s.table)) - if err != nil { - return err - } - - result, err := q.Exec(key) +func (s *sqlStore) Delete(key string, opts ...store.DeleteOption) error { + result, err := s.delete.Exec(key) if err != nil { return err } @@ -187,6 +174,31 @@ func (s *sqlStore) initDB() error { return errors.Wrap(err, "Couldn't create table") } + list, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s;", s.database, s.table)) + if err != nil { + return errors.Wrap(err, "List statement couldn't be prepared") + } + s.list = list + readOne, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key = $1;", s.database, s.table)) + if err != nil { + return errors.Wrap(err, "ReadOne statement couldn't be prepared") + } + s.readOne = readOne + write, err := s.db.Prepare(fmt.Sprintf(`INSERT INTO %s.%s(key, value, expiry) + VALUES ($1, $2::bytea, $3) + ON CONFLICT (key) + DO UPDATE + SET value = EXCLUDED.value, expiry = EXCLUDED.expiry;`, s.database, s.table)) + if err != nil { + return errors.Wrap(err, "Write statement couldn't be prepared") + } + s.write = write + delete, err := s.db.Prepare(fmt.Sprintf("DELETE FROM %s.%s WHERE key = $1;", s.database, s.table)) + if err != nil { + return errors.Wrap(err, "Delete statement couldn't be prepared") + } + s.delete = delete + return nil } @@ -206,12 +218,12 @@ func (s *sqlStore) configure() error { prefix = DefaultPrefix } - // store.namespace must only contain letters + // store.namespace must only contain letters, numbers and underscores reg, err := regexp.Compile("[^a-zA-Z0-9]+") if err != nil { return errors.New("error compiling regex for namespace") } - namespace = reg.ReplaceAllString(namespace, "") + namespace = reg.ReplaceAllString(namespace, "_") source := nodes[0] // check if it is a standard connection string eg: host=%s port=%d user=%s password=%s dbname=%s sslmode=disable @@ -250,7 +262,11 @@ func (s *sqlStore) String() string { return "cockroach" } -// New returns a new micro Store backed by sql +func (s *sqlStore) Options() store.Options { + return s.options +} + +// NewStore returns a new micro Store backed by sql func NewStore(opts ...store.Option) store.Store { var options store.Options for _, o := range opts { diff --git a/store/cockroach/cockroach_test.go b/store/cockroach/cockroach_test.go index 02354eac..38e36f5f 100644 --- a/store/cockroach/cockroach_test.go +++ b/store/cockroach/cockroach_test.go @@ -32,11 +32,11 @@ func TestSQL(t *testing.T) { store.Nodes(connection), ) - records, err := sqlStore.List() + keys, err := sqlStore.List() if err != nil { t.Error(err) } else { - t.Logf("%# v\n", pretty.Formatter(records)) + t.Logf("%# v\n", pretty.Formatter(keys)) } err = sqlStore.Write( @@ -80,7 +80,7 @@ func TestSQL(t *testing.T) { t.Error(err) } - records, err = sqlStore.Read("test") + records, err := sqlStore.Read("test") if err != nil { t.Error(err) } diff --git a/store/etcd/config.go b/store/etcd/config.go new file mode 100644 index 00000000..381abdb3 --- /dev/null +++ b/store/etcd/config.go @@ -0,0 +1,178 @@ +package etcd + +import ( + "context" + cryptotls "crypto/tls" + "time" + + "github.com/micro/go-micro/v2/store" + "go.etcd.io/etcd/clientv3" + "google.golang.org/grpc" +) + +// Implement all the options from https://pkg.go.dev/go.etcd.io/etcd/clientv3?tab=doc#Config +// Need to use non basic types in context.WithValue +type autoSyncInterval string +type dialTimeout string +type dialKeepAliveTime string +type dialKeepAliveTimeout string +type maxCallSendMsgSize string +type maxCallRecvMsgSize string +type tls string +type username string +type password string +type rejectOldCluster string +type dialOptions string +type clientContext string +type permitWithoutStream string + +// AutoSyncInterval is the interval to update endpoints with its latest members. +// 0 disables auto-sync. By default auto-sync is disabled. +func AutoSyncInterval(d time.Duration) store.Option { + return func(o *store.Options) { + o.Context = context.WithValue(o.Context, autoSyncInterval(""), d) + } +} + +// DialTimeout is the timeout for failing to establish a connection. +func DialTimeout(d time.Duration) store.Option { + return func(o *store.Options) { + o.Context = context.WithValue(o.Context, dialTimeout(""), d) + } +} + +// DialKeepAliveTime is the time after which client pings the server to see if +// transport is alive. +func DialKeepAliveTime(d time.Duration) store.Option { + return func(o *store.Options) { + o.Context = context.WithValue(o.Context, dialKeepAliveTime(""), d) + } +} + +// DialKeepAliveTimeout is the time that the client waits for a response for the +// keep-alive probe. If the response is not received in this time, the connection is closed. +func DialKeepAliveTimeout(d time.Duration) store.Option { + return func(o *store.Options) { + o.Context = context.WithValue(o.Context, dialKeepAliveTimeout(""), d) + } +} + +// MaxCallSendMsgSize is the client-side request send limit in bytes. +// If 0, it defaults to 2.0 MiB (2 * 1024 * 1024). +// Make sure that "MaxCallSendMsgSize" < server-side default send/recv limit. +// ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes"). +func MaxCallSendMsgSize(size int) store.Option { + return func(o *store.Options) { + o.Context = context.WithValue(o.Context, maxCallSendMsgSize(""), size) + } +} + +// MaxCallRecvMsgSize is the client-side response receive limit. +// If 0, it defaults to "math.MaxInt32", because range response can +// easily exceed request send limits. +// Make sure that "MaxCallRecvMsgSize" >= server-side default send/recv limit. +// ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes"). +func MaxCallRecvMsgSize(size int) store.Option { + return func(o *store.Options) { + o.Context = context.WithValue(o.Context, maxCallRecvMsgSize(""), size) + } +} + +// TLS holds the client secure credentials, if any. +func TLS(conf *cryptotls.Config) store.Option { + return func(o *store.Options) { + t := conf.Clone() + o.Context = context.WithValue(o.Context, tls(""), t) + } +} + +// Username is a user name for authentication. +func Username(u string) store.Option { + return func(o *store.Options) { + o.Context = context.WithValue(o.Context, username(""), u) + } +} + +// Password is a password for authentication. +func Password(p string) store.Option { + return func(o *store.Options) { + o.Context = context.WithValue(o.Context, password(""), p) + } +} + +// RejectOldCluster when set will refuse to create a client against an outdated cluster. +func RejectOldCluster(b bool) store.Option { + return func(o *store.Options) { + o.Context = context.WithValue(o.Context, rejectOldCluster(""), b) + } +} + +// DialOptions is a list of dial options for the grpc client (e.g., for interceptors). +// For example, pass "grpc.WithBlock()" to block until the underlying connection is up. +// Without this, Dial returns immediately and connecting the server happens in background. +func DialOptions(opts []grpc.DialOption) store.Option { + return func(o *store.Options) { + if len(opts) > 0 { + ops := make([]grpc.DialOption, len(opts)) + copy(ops, opts) + o.Context = context.WithValue(o.Context, dialOptions(""), ops) + } + } +} + +// ClientContext is the default etcd3 client context; it can be used to cancel grpc +// dial out andother operations that do not have an explicit context. +func ClientContext(ctx context.Context) store.Option { + return func(o *store.Options) { + o.Context = context.WithValue(o.Context, clientContext(""), ctx) + } +} + +// PermitWithoutStream when set will allow client to send keepalive pings to server without any active streams(RPCs). +func PermitWithoutStream(b bool) store.Option { + return func(o *store.Options) { + o.Context = context.WithValue(o.Context, permitWithoutStream(""), b) + } +} + +func (e *etcdStore) applyConfig(cfg *clientv3.Config) { + if v := e.options.Context.Value(autoSyncInterval("")); v != nil { + cfg.AutoSyncInterval = v.(time.Duration) + } + if v := e.options.Context.Value(dialTimeout("")); v != nil { + cfg.DialTimeout = v.(time.Duration) + } + if v := e.options.Context.Value(dialKeepAliveTime("")); v != nil { + cfg.DialKeepAliveTime = v.(time.Duration) + } + if v := e.options.Context.Value(dialKeepAliveTimeout("")); v != nil { + cfg.DialKeepAliveTimeout = v.(time.Duration) + } + if v := e.options.Context.Value(maxCallSendMsgSize("")); v != nil { + cfg.MaxCallSendMsgSize = v.(int) + } + if v := e.options.Context.Value(maxCallRecvMsgSize("")); v != nil { + cfg.MaxCallRecvMsgSize = v.(int) + } + if v := e.options.Context.Value(tls("")); v != nil { + cfg.TLS = v.(*cryptotls.Config) + } + if v := e.options.Context.Value(username("")); v != nil { + cfg.Username = v.(string) + } + if v := e.options.Context.Value(password("")); v != nil { + cfg.Username = v.(string) + } + if v := e.options.Context.Value(rejectOldCluster("")); v != nil { + cfg.RejectOldCluster = v.(bool) + } + if v := e.options.Context.Value(dialOptions("")); v != nil { + cfg.DialOptions = v.([]grpc.DialOption) + } + if v := e.options.Context.Value(clientContext("")); v != nil { + cfg.Context = v.(context.Context) + } + if v := e.options.Context.Value(permitWithoutStream("")); v != nil { + cfg.PermitWithoutStream = v.(bool) + } +} diff --git a/store/etcd/etcd.go b/store/etcd/etcd.go index fd896c7a..2462c55d 100644 --- a/store/etcd/etcd.go +++ b/store/etcd/etcd.go @@ -1,117 +1,268 @@ -// Package etcd is an etcd v3 implementation of kv +// Package etcd implements a go-micro/v2/store with etcd package etcd import ( + "bytes" "context" - "log" + "encoding/gob" + "math" + "strings" + "time" - client "github.com/coreos/etcd/clientv3" "github.com/micro/go-micro/v2/store" + "github.com/pkg/errors" + "go.etcd.io/etcd/clientv3" + "go.etcd.io/etcd/clientv3/namespace" ) -type ekv struct { +type etcdStore struct { options store.Options - kv client.KV + + client *clientv3.Client + config clientv3.Config } -func (e *ekv) Init(opts ...store.Option) error { +// NewStore returns a new etcd store +func NewStore(opts ...store.Option) store.Store { + e := &etcdStore{} for _, o := range opts { o(&e.options) } + e.init() + return e +} + +func (e *etcdStore) Init(opts ...store.Option) error { + for _, o := range opts { + o(&e.options) + } + return e.init() +} + +func (e *etcdStore) init() error { + // ensure context is non-nil + e.options.Context = context.Background() + // set up config + e.config = clientv3.Config{} + e.applyConfig(&e.config) + if len(e.options.Nodes) == 0 { + e.config.Endpoints = []string{"http://127.0.0.1:2379"} + } else { + e.config.Endpoints = make([]string, len(e.options.Nodes)) + copy(e.config.Endpoints, e.options.Nodes) + } + if e.client != nil { + e.client.Close() + } + client, err := clientv3.New(e.config) + if err != nil { + return err + } + e.client = client + ns := "" + if len(e.options.Prefix) > 0 { + ns = e.options.Prefix + } + if len(e.options.Namespace) > 0 { + ns = e.options.Namespace + "/" + ns + } + if len(ns) > 0 { + e.client.KV = namespace.NewKV(e.client.KV, ns) + e.client.Watcher = namespace.NewWatcher(e.client.Watcher, ns) + e.client.Lease = namespace.NewLease(e.client.Lease, ns) + } + return nil } -func (e *ekv) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { - var options store.ReadOptions - for _, o := range opts { - o(&options) - } - - var etcdOpts []client.OpOption - - // set options prefix - if options.Prefix { - etcdOpts = append(etcdOpts, client.WithPrefix()) - } - - keyval, err := e.kv.Get(context.Background(), key, etcdOpts...) - if err != nil { - return nil, err - } - - if keyval == nil || len(keyval.Kvs) == 0 { - return nil, store.ErrNotFound - } - - records := make([]*store.Record, 0, len(keyval.Kvs)) - - for _, kv := range keyval.Kvs { - records = append(records, &store.Record{ - Key: string(kv.Key), - Value: kv.Value, - // TODO: implement expiry - }) - } - - return records, nil +func (e *etcdStore) Options() store.Options { + return e.options } -func (e *ekv) Delete(key string) error { - _, err := e.kv.Delete(context.Background(), key) - return err -} - -func (e *ekv) Write(record *store.Record) error { - // TODO create lease to expire keys - _, err := e.kv.Put(context.Background(), record.Key, string(record.Value)) - return err -} - -func (e *ekv) List() ([]*store.Record, error) { - keyval, err := e.kv.Get(context.Background(), "/", client.WithPrefix()) - if err != nil { - return nil, err - } - if keyval == nil || len(keyval.Kvs) == 0 { - return nil, nil - } - vals := make([]*store.Record, 0, len(keyval.Kvs)) - for _, keyv := range keyval.Kvs { - vals = append(vals, &store.Record{ - Key: string(keyv.Key), - Value: keyv.Value, - }) - } - return vals, nil -} - -func (e *ekv) String() string { +func (e *etcdStore) String() string { return "etcd" } -func NewStore(opts ...store.Option) store.Store { - var options store.Options +func (e *etcdStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { + readOpts := store.ReadOptions{} + for _, o := range opts { + o(&readOpts) + } + if readOpts.Suffix { + return e.readSuffix(key, readOpts) + } + + var etcdOpts []clientv3.OpOption + if readOpts.Prefix { + etcdOpts = append(etcdOpts, clientv3.WithPrefix(), clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend)) + } + resp, err := e.client.KV.Get(context.Background(), key, etcdOpts...) + if err != nil { + return nil, err + } + if resp.Count == 0 && !(readOpts.Prefix || readOpts.Suffix) { + return nil, store.ErrNotFound + } + var records []*store.Record + for _, kv := range resp.Kvs { + ir := internalRecord{} + if err := gob.NewDecoder(bytes.NewReader(kv.Value)).Decode(&ir); err != nil { + return records, errors.Wrapf(err, "couldn't decode %s into internalRecord", err.Error()) + } + r := store.Record{ + Key: ir.Key, + Value: ir.Value, + } + if !ir.ExpiresAt.IsZero() { + r.Expiry = time.Until(ir.ExpiresAt) + } + records = append(records, &r) + } + if readOpts.Limit > 0 || readOpts.Offset > 0 { + return records[readOpts.Offset:min(readOpts.Limit, uint(len(records)))], nil + } + return records, nil +} + +func (e *etcdStore) readSuffix(key string, readOpts store.ReadOptions) ([]*store.Record, error) { + opts := []store.ListOption{store.ListSuffix(key)} + if readOpts.Prefix { + opts = append(opts, store.ListPrefix(key)) + } + keys, err := e.List(opts...) + if err != nil { + return nil, errors.Wrapf(err, "Couldn't list with suffix %s", key) + } + var records []*store.Record + for _, k := range keys { + resp, err := e.client.KV.Get(context.Background(), k) + if err != nil { + return nil, errors.Wrapf(err, "Couldn't get key %s", k) + } + ir := internalRecord{} + if err := gob.NewDecoder(bytes.NewReader(resp.Kvs[0].Value)).Decode(&ir); err != nil { + return records, errors.Wrapf(err, "couldn't decode %s into internalRecord", err.Error()) + } + r := store.Record{ + Key: ir.Key, + Value: ir.Value, + } + if !ir.ExpiresAt.IsZero() { + r.Expiry = time.Until(ir.ExpiresAt) + } + records = append(records, &r) + + } + if readOpts.Limit > 0 || readOpts.Offset > 0 { + return records[readOpts.Offset:min(readOpts.Limit, uint(len(records)))], nil + } + return records, nil +} + +func (e *etcdStore) Write(r *store.Record, opts ...store.WriteOption) error { + options := store.WriteOptions{} for _, o := range opts { o(&options) } - // get the endpoints - endpoints := options.Nodes + if len(opts) > 0 { + // Copy the record before applying options, or the incoming record will be mutated + newRecord := store.Record{} + newRecord.Key = r.Key + newRecord.Value = make([]byte, len(r.Value)) + copy(newRecord.Value, r.Value) + newRecord.Expiry = r.Expiry - if len(endpoints) == 0 { - endpoints = []string{"http://127.0.0.1:2379"} - } - - // TODO: parse addresses - c, err := client.New(client.Config{ - Endpoints: endpoints, - }) - if err != nil { - log.Fatal(err) - } - - return &ekv{ - options: options, - kv: client.NewKV(c), + if !options.Expiry.IsZero() { + newRecord.Expiry = time.Until(options.Expiry) + } + if options.TTL != 0 { + newRecord.Expiry = options.TTL + } + return e.write(&newRecord) } + return e.write(r) +} + +func (e *etcdStore) write(r *store.Record) error { + var putOpts []clientv3.OpOption + ir := &internalRecord{} + ir.Key = r.Key + ir.Value = make([]byte, len(r.Value)) + copy(ir.Value, r.Value) + if r.Expiry != 0 { + ir.ExpiresAt = time.Now().Add(r.Expiry) + var leasexpiry int64 + if r.Expiry.Seconds() < 5.0 { + // minimum etcd lease is 5 seconds + leasexpiry = 5 + } else { + leasexpiry = int64(math.Ceil(r.Expiry.Seconds())) + } + lr, err := e.client.Lease.Grant(context.Background(), leasexpiry) + if err != nil { + return errors.Wrapf(err, "couldn't grant an etcd lease for %s", r.Key) + } + putOpts = append(putOpts, clientv3.WithLease(lr.ID)) + } + b := &bytes.Buffer{} + if err := gob.NewEncoder(b).Encode(ir); err != nil { + return errors.Wrapf(err, "couldn't encode %s", r.Key) + } + _, err := e.client.KV.Put(context.Background(), ir.Key, string(b.Bytes()), putOpts...) + return errors.Wrapf(err, "couldn't put key %s in to etcd", err) +} + +func (e *etcdStore) Delete(key string, opts ...store.DeleteOption) error { + options := store.DeleteOptions{} + for _, o := range opts { + o(&options) + } + _, err := e.client.KV.Delete(context.Background(), key) + return errors.Wrapf(err, "couldn't delete key %s", key) +} + +func (e *etcdStore) List(opts ...store.ListOption) ([]string, error) { + options := store.ListOptions{} + for _, o := range opts { + o(&options) + } + searchPrefix := "" + if len(options.Prefix) > 0 { + searchPrefix = options.Prefix + } + resp, err := e.client.KV.Get(context.Background(), searchPrefix, clientv3.WithPrefix(), clientv3.WithKeysOnly(), clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend)) + if err != nil { + return nil, errors.Wrap(err, "couldn't list, etcd get failed") + } + if len(options.Suffix) == 0 { + keys := make([]string, resp.Count) + for i, kv := range resp.Kvs { + keys[i] = string(kv.Key) + } + return keys, nil + } + keys := []string{} + for _, kv := range resp.Kvs { + if strings.HasSuffix(string(kv.Key), options.Suffix) { + keys = append(keys, string(kv.Key)) + } + } + if options.Limit > 0 || options.Offset > 0 { + return keys[options.Offset:min(options.Limit, uint(len(keys)))], nil + } + return keys, nil +} + +type internalRecord struct { + Key string + Value []byte + ExpiresAt time.Time +} + +func min(i, j uint) uint { + if i < j { + return i + } + return j } diff --git a/store/etcd/etcd_test.go b/store/etcd/etcd_test.go new file mode 100644 index 00000000..fade2fce --- /dev/null +++ b/store/etcd/etcd_test.go @@ -0,0 +1,225 @@ +package etcd + +import ( + "fmt" + "testing" + "time" + + "github.com/kr/pretty" + "github.com/micro/go-micro/v2/store" +) + +func TestEtcd(t *testing.T) { + e := NewStore() + if err := e.Init(); err != nil { + t.Fatal(err) + } + //basictest(e, t) +} + +func basictest(s store.Store, t *testing.T) { + t.Logf("Testing store %s, with options %# v\n", s.String(), pretty.Formatter(s.Options())) + // Read and Write an expiring Record + if err := s.Write(&store.Record{ + Key: "Hello", + Value: []byte("World"), + Expiry: time.Second * 5, + }); err != nil { + t.Fatal(err) + } + if r, err := s.Read("Hello"); err != nil { + t.Fatal(err) + } else { + if len(r) != 1 { + t.Fatal("Read returned multiple records") + } + if r[0].Key != "Hello" { + t.Fatalf("Expected %s, got %s", "Hello", r[0].Key) + } + if string(r[0].Value) != "World" { + t.Fatalf("Expected %s, got %s", "World", r[0].Value) + } + } + time.Sleep(time.Second * 6) + if records, err := s.Read("Hello"); err != store.ErrNotFound { + t.Fatalf("Expected %# v, got %# v\nResults were %# v", store.ErrNotFound, err, pretty.Formatter(records)) + } + + // Write 3 records with various expiry and get with prefix + records := []*store.Record{ + &store.Record{ + Key: "foo", + Value: []byte("foofoo"), + }, + &store.Record{ + Key: "foobar", + Value: []byte("foobarfoobar"), + Expiry: time.Second * 5, + }, + &store.Record{ + Key: "foobarbaz", + Value: []byte("foobarbazfoobarbaz"), + Expiry: 2 * time.Second * 5, + }, + } + for _, r := range records { + if err := s.Write(r); err != nil { + t.Fatalf("Couldn't write k: %s, v: %# v (%s)", r.Key, pretty.Formatter(r.Value), err) + } + } + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { + t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 3 { + t.Fatalf("Expected 3 items, got %d", len(results)) + } + } + time.Sleep(time.Second * 6) + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { + t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 2 { + t.Fatalf("Expected 2 items, got %d", len(results)) + } + } + time.Sleep(time.Second * 5) + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { + t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 1 { + t.Fatalf("Expected 1 item, got %d", len(results)) + } + } + if err := s.Delete("foo", func(d *store.DeleteOptions) {}); err != nil { + t.Fatalf("Delete failed (%v)", err) + } + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { + t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 0 { + t.Fatalf("Expected 0 items, got %d (%# v)", len(results), pretty.Formatter(results)) + } + } + + // Write 3 records with various expiry and get with Suffix + records = []*store.Record{ + &store.Record{ + Key: "foo", + Value: []byte("foofoo"), + }, + &store.Record{ + Key: "barfoo", + Value: []byte("barfoobarfoo"), + Expiry: time.Second * 5, + }, + &store.Record{ + Key: "bazbarfoo", + Value: []byte("bazbarfoobazbarfoo"), + Expiry: 2 * time.Second * 5, + }, + } + for _, r := range records { + if err := s.Write(r); err != nil { + t.Fatalf("Couldn't write k: %s, v: %# v (%s)", r.Key, pretty.Formatter(r.Value), err) + } + } + if results, err := s.Read("foo", store.ReadSuffix()); err != nil { + t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 3 { + t.Fatalf("Expected 3 items, got %d", len(results)) + } + } + time.Sleep(time.Second * 6) + if results, err := s.Read("foo", store.ReadSuffix()); err != nil { + t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 2 { + t.Fatalf("Expected 2 items, got %d", len(results)) + } + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } + time.Sleep(time.Second * 5) + if results, err := s.Read("foo", store.ReadSuffix()); err != nil { + t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 1 { + t.Fatalf("Expected 1 item, got %d", len(results)) + } + t.Logf("Prefix test: %# v\n", pretty.Formatter(results)) + } + if err := s.Delete("foo"); err != nil { + t.Fatalf("Delete failed (%v)", err) + } + if results, err := s.Read("foo", store.ReadSuffix()); err != nil { + t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 0 { + t.Fatalf("Expected 0 items, got %d (%# v)", len(results), pretty.Formatter(results)) + } + } + + // Test Prefix, Suffix and WriteOptions + if err := s.Write(&store.Record{ + Key: "foofoobarbar", + Value: []byte("something"), + }, store.WriteTTL(time.Millisecond*100)); err != nil { + t.Fatal(err) + } + if err := s.Write(&store.Record{ + Key: "foofoo", + Value: []byte("something"), + }, store.WriteExpiry(time.Now().Add(time.Millisecond*100))); err != nil { + t.Fatal(err) + } + if err := s.Write(&store.Record{ + Key: "barbar", + Value: []byte("something"), + // TTL has higher precedence than expiry + }, store.WriteExpiry(time.Now().Add(time.Hour)), store.WriteTTL(time.Millisecond*100)); err != nil { + t.Fatal(err) + } + if results, err := s.Read("foo", store.ReadPrefix(), store.ReadSuffix()); err != nil { + t.Fatal(err) + } else { + if len(results) != 1 { + t.Fatalf("Expected 1 results, got %d: %# v", len(results), pretty.Formatter(results)) + } + } + time.Sleep(time.Second * 6) + if results, err := s.List(); err != nil { + t.Fatalf("List failed: %s", err) + } else { + if len(results) != 0 { + t.Fatal("Expiry options were not effective") + } + } + + s.Init() + for i := 0; i < 10; i++ { + s.Write(&store.Record{ + Key: fmt.Sprintf("a%d", i), + Value: []byte{}, + }) + } + if results, err := s.Read("a", store.ReadLimit(5), store.ReadPrefix()); err != nil { + t.Fatal(err) + } else { + if len(results) != 5 { + t.Fatal("Expected 5 results, got ", len(results)) + } + if results[0].Key != "a0" { + t.Fatalf("Expected a0, got %s", results[0].Key) + } + if results[4].Key != "a4" { + t.Fatalf("Expected a4, got %s", results[4].Key) + } + } + if results, err := s.Read("a", store.ReadLimit(30), store.ReadOffset(5), store.ReadPrefix()); err != nil { + t.Fatal(err) + } else { + if len(results) != 5 { + t.Fatal("Expected 5 results, got ", len(results)) + } + } +} diff --git a/store/memory/memory.go b/store/memory/memory.go index 00ce68b4..d9bdf1b3 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -2,154 +2,255 @@ package memory import ( + "sort" "strings" - "sync" "time" "github.com/micro/go-micro/v2/store" + + "github.com/patrickmn/go-cache" + "github.com/pkg/errors" ) +// NewStore returns a memory store +func NewStore(opts ...store.Option) store.Store { + s := &memoryStore{ + options: store.Options{}, + store: cache.New(cache.NoExpiration, 5*time.Minute), + } + for _, o := range opts { + o(&s.options) + } + return s +} + type memoryStore struct { options store.Options - sync.RWMutex - values map[string]*memoryRecord -} - -type memoryRecord struct { - r *store.Record - c time.Time + store *cache.Cache } func (m *memoryStore) Init(opts ...store.Option) error { + m.store.Flush() for _, o := range opts { o(&m.options) } return nil } -func (m *memoryStore) List() ([]*store.Record, error) { - m.RLock() - defer m.RUnlock() - - //nolint:prealloc - var values []*store.Record - - for _, v := range m.values { - // get expiry - d := v.r.Expiry - t := time.Since(v.c) - - if d > time.Duration(0) { - // expired - if t > d { - continue - } - // update expiry - v.r.Expiry -= t - v.c = time.Now() - } - - values = append(values, v.r) - } - - return values, nil -} - -func (m *memoryStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { - m.RLock() - defer m.RUnlock() - - var options store.ReadOptions - - for _, o := range opts { - o(&options) - } - - var vals []*memoryRecord - - if options.Prefix { - for _, v := range m.values { - if !strings.HasPrefix(v.r.Key, key) { - continue - } - vals = append(vals, v) - } - } else if options.Suffix { - for _, v := range m.values { - if !strings.HasSuffix(v.r.Key, key) { - continue - } - vals = append(vals, v) - } - } else { - v, ok := m.values[key] - if !ok { - return nil, store.ErrNotFound - } - vals = []*memoryRecord{v} - } - - //nolint:prealloc - var records []*store.Record - - for _, v := range vals { - // get expiry - d := v.r.Expiry - t := time.Since(v.c) - - // expired - if d > time.Duration(0) { - if t > d { - return nil, store.ErrNotFound - } - // update expiry - v.r.Expiry -= t - v.c = time.Now() - } - - records = append(records, v.r) - } - - return records, nil -} - -func (m *memoryStore) Write(r *store.Record) error { - m.Lock() - defer m.Unlock() - - // set the record - m.values[r.Key] = &memoryRecord{ - r: r, - c: time.Now(), - } - - return nil -} - -func (m *memoryStore) Delete(key string) error { - m.Lock() - defer m.Unlock() - - // delete the value - delete(m.values, key) - - return nil -} - func (m *memoryStore) String() string { return "memory" } -// NewStore returns a new store.Store -func NewStore(opts ...store.Option) store.Store { - var options store.Options +func (m *memoryStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { + readOpts := store.ReadOptions{} for _, o := range opts { - o(&options) + o(&readOpts) } - return &memoryStore{ - options: options, - values: make(map[string]*memoryRecord), + var keys []string + + // Handle Prefix / suffix + if readOpts.Prefix || readOpts.Suffix { + var opts []store.ListOption + if readOpts.Prefix { + opts = append(opts, store.ListPrefix(key)) + } + if readOpts.Suffix { + opts = append(opts, store.ListSuffix(key)) + } + opts = append(opts, store.ListLimit(readOpts.Limit)) + opts = append(opts, store.ListOffset(readOpts.Offset)) + k, err := m.List(opts...) + if err != nil { + return nil, errors.Wrap(err, "Memory: Read couldn't List()") + } + keys = k + } else { + keys = []string{key} } + + var results []*store.Record + for _, k := range keys { + r, err := m.get(k) + if err != nil { + return results, err + } + results = append(results, r) + } + + return results, nil +} + +func (m *memoryStore) get(k string) (*store.Record, error) { + if len(m.options.Suffix) > 0 { + k = k + m.options.Suffix + } + if len(m.options.Prefix) > 0 { + k = m.options.Prefix + "/" + k + } + if len(m.options.Namespace) > 0 { + k = m.options.Namespace + "/" + k + } + var storedRecord *internalRecord + r, found := m.store.Get(k) + if !found { + return nil, store.ErrNotFound + } + storedRecord, ok := r.(*internalRecord) + if !ok { + return nil, errors.New("Retrieved a non *internalRecord from the cache") + } + // Copy the record on the way out + newRecord := &store.Record{} + newRecord.Key = storedRecord.key + newRecord.Value = make([]byte, len(storedRecord.value)) + copy(newRecord.Value, storedRecord.value) + newRecord.Expiry = time.Until(storedRecord.expiresAt) + + return newRecord, nil +} + +func (m *memoryStore) Write(r *store.Record, opts ...store.WriteOption) error { + writeOpts := store.WriteOptions{} + for _, o := range opts { + o(&writeOpts) + } + + if len(opts) > 0 { + // Copy the record before applying options, or the incoming record will be mutated + newRecord := store.Record{} + newRecord.Key = r.Key + newRecord.Value = make([]byte, len(r.Value)) + copy(newRecord.Value, r.Value) + newRecord.Expiry = r.Expiry + + if !writeOpts.Expiry.IsZero() { + newRecord.Expiry = time.Until(writeOpts.Expiry) + } + if writeOpts.TTL != 0 { + newRecord.Expiry = writeOpts.TTL + } + m.set(&newRecord) + } else { + m.set(r) + } + return nil +} + +func (m *memoryStore) set(r *store.Record) { + key := r.Key + if len(m.options.Suffix) > 0 { + key = key + m.options.Suffix + } + if len(m.options.Prefix) > 0 { + key = m.options.Prefix + "/" + key + } + if len(m.options.Namespace) > 0 { + key = m.options.Namespace + "/" + key + } + + // copy the incoming record and then + // convert the expiry in to a hard timestamp + i := &internalRecord{} + i.key = r.Key + i.value = make([]byte, len(r.Value)) + copy(i.value, r.Value) + if r.Expiry != 0 { + i.expiresAt = time.Now().Add(r.Expiry) + } + + m.store.Set(key, i, r.Expiry) +} + +func (m *memoryStore) Delete(key string, opts ...store.DeleteOption) error { + deleteOptions := store.DeleteOptions{} + for _, o := range opts { + o(&deleteOptions) + } + m.delete(key) + return nil +} + +func (m *memoryStore) delete(key string) { + if len(m.options.Suffix) > 0 { + key = key + m.options.Suffix + } + if len(m.options.Prefix) > 0 { + key = m.options.Prefix + "/" + key + } + if len(m.options.Namespace) > 0 { + key = m.options.Namespace + "/" + key + } + m.store.Delete(key) +} + +func (m *memoryStore) Options() store.Options { + return m.options +} + +func (m *memoryStore) List(opts ...store.ListOption) ([]string, error) { + listOptions := store.ListOptions{} + + for _, o := range opts { + o(&listOptions) + } + allKeys := m.list(listOptions.Limit, listOptions.Offset) + + if len(listOptions.Prefix) > 0 { + var prefixKeys []string + for _, k := range allKeys { + if strings.HasPrefix(k, listOptions.Prefix) { + prefixKeys = append(prefixKeys, k) + } + } + allKeys = prefixKeys + } + if len(listOptions.Suffix) > 0 { + var suffixKeys []string + for _, k := range allKeys { + if strings.HasSuffix(k, listOptions.Suffix) { + suffixKeys = append(suffixKeys, k) + } + } + allKeys = suffixKeys + } + + return allKeys, nil +} + +func (m *memoryStore) list(limit, offset uint) []string { + allItems := m.store.Items() + allKeys := make([]string, len(allItems)) + i := 0 + for k := range allItems { + if len(m.options.Suffix) > 0 { + k = strings.TrimSuffix(k, m.options.Suffix) + } + if len(m.options.Namespace) > 0 { + k = strings.TrimPrefix(k, m.options.Namespace+"/") + } + if len(m.options.Prefix) > 0 { + k = strings.TrimPrefix(k, m.options.Prefix+"/") + } + allKeys[i] = k + i++ + } + if limit != 0 || offset != 0 { + sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] }) + min := func(i, j uint) uint { + if i < j { + return i + } + return j + } + return allKeys[offset:min(limit, uint(len(allKeys)))] + } + return allKeys +} + +type internalRecord struct { + key string + value []byte + expiresAt time.Time } diff --git a/store/memory/memory_test.go b/store/memory/memory_test.go index 27837e2f..26e04004 100644 --- a/store/memory/memory_test.go +++ b/store/memory/memory_test.go @@ -1,37 +1,265 @@ package memory import ( + "fmt" "testing" "time" + "github.com/kr/pretty" "github.com/micro/go-micro/v2/store" ) -func TestReadRecordExpire(t *testing.T) { - s := NewStore() - - var ( - key = "foo" - expire = 100 * time.Millisecond - ) - rec := &store.Record{ - Key: key, - Value: nil, - Expiry: expire, - } - s.Write(rec) - - rrec, err := s.Read(key) - if err != nil { - t.Fatal(err) - } - if rrec[0].Expiry >= expire { - t.Fatal("expiry of read record is not changed") - } - - time.Sleep(expire) - - if _, err := s.Read(key); err != store.ErrNotFound { - t.Fatal("expire elapsed, but key still accessable") +func TestMemoryReInit(t *testing.T) { + s := NewStore(store.Prefix("aaa")) + s.Init(store.Prefix("")) + if len(s.Options().Prefix) > 0 { + t.Error("Init didn't reinitialise the store") + } +} + +func TestMemoryBasic(t *testing.T) { + s := NewStore() + s.Init() + basictest(s, t) +} + +func TestMemoryPrefix(t *testing.T) { + s := NewStore() + s.Init(store.Prefix("some-prefix")) + basictest(s, t) +} + +func TestMemorySuffix(t *testing.T) { + s := NewStore() + s.Init(store.Suffix("some-suffix")) + basictest(s, t) +} + +func TestMemoryPrefixSuffix(t *testing.T) { + s := NewStore() + s.Init(store.Prefix("some-prefix"), store.Prefix("some-suffix")) + basictest(s, t) +} + +func TestMemoryNamespace(t *testing.T) { + s := NewStore() + s.Init(store.Namespace("some-namespace")) + basictest(s, t) +} + +func TestMemoryNamespacePrefix(t *testing.T) { + s := NewStore() + s.Init(store.Prefix("some-prefix"), store.Namespace("some-namespace")) + basictest(s, t) +} + +func basictest(s store.Store, t *testing.T) { + t.Logf("Testing store %s, with options %# v\n", s.String(), pretty.Formatter(s.Options())) + // Read and Write an expiring Record + if err := s.Write(&store.Record{ + Key: "Hello", + Value: []byte("World"), + Expiry: time.Millisecond * 100, + }); err != nil { + t.Error(err) + } + if r, err := s.Read("Hello"); err != nil { + t.Error(err) + } else { + if len(r) != 1 { + t.Error("Read returned multiple records") + } + if r[0].Key != "Hello" { + t.Errorf("Expected %s, got %s", "Hello", r[0].Key) + } + if string(r[0].Value) != "World" { + t.Errorf("Expected %s, got %s", "World", r[0].Value) + } + } + time.Sleep(time.Millisecond * 200) + if _, err := s.Read("Hello"); err != store.ErrNotFound { + t.Errorf("Expected %# v, got %# v", store.ErrNotFound, err) + } + + // Write 3 records with various expiry and get with prefix + records := []*store.Record{ + &store.Record{ + Key: "foo", + Value: []byte("foofoo"), + }, + &store.Record{ + Key: "foobar", + Value: []byte("foobarfoobar"), + Expiry: time.Millisecond * 100, + }, + &store.Record{ + Key: "foobarbaz", + Value: []byte("foobarbazfoobarbaz"), + Expiry: 2 * time.Millisecond * 100, + }, + } + for _, r := range records { + if err := s.Write(r); err != nil { + t.Errorf("Couldn't write k: %s, v: %# v (%s)", r.Key, pretty.Formatter(r.Value), err) + } + } + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 3 { + t.Errorf("Expected 3 items, got %d", len(results)) + } + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } + time.Sleep(time.Millisecond * 100) + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 2 { + t.Errorf("Expected 2 items, got %d", len(results)) + } + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } + time.Sleep(time.Millisecond * 100) + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 1 { + t.Errorf("Expected 1 item, got %d", len(results)) + } + t.Logf("Prefix test: %# v\n", pretty.Formatter(results)) + } + if err := s.Delete("foo", func(d *store.DeleteOptions) {}); err != nil { + t.Errorf("Delete failed (%v)", err) + } + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 0 { + t.Errorf("Expected 0 items, got %d (%# v)", len(results), pretty.Formatter(results)) + } + } + + // Write 3 records with various expiry and get with Suffix + records = []*store.Record{ + &store.Record{ + Key: "foo", + Value: []byte("foofoo"), + }, + &store.Record{ + Key: "barfoo", + Value: []byte("barfoobarfoo"), + Expiry: time.Millisecond * 100, + }, + &store.Record{ + Key: "bazbarfoo", + Value: []byte("bazbarfoobazbarfoo"), + Expiry: 2 * time.Millisecond * 100, + }, + } + for _, r := range records { + if err := s.Write(r); err != nil { + t.Errorf("Couldn't write k: %s, v: %# v (%s)", r.Key, pretty.Formatter(r.Value), err) + } + } + if results, err := s.Read("foo", store.ReadSuffix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 3 { + t.Errorf("Expected 3 items, got %d", len(results)) + } + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } + time.Sleep(time.Millisecond * 100) + if results, err := s.Read("foo", store.ReadSuffix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 2 { + t.Errorf("Expected 2 items, got %d", len(results)) + } + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } + time.Sleep(time.Millisecond * 100) + if results, err := s.Read("foo", store.ReadSuffix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 1 { + t.Errorf("Expected 1 item, got %d", len(results)) + } + t.Logf("Prefix test: %# v\n", pretty.Formatter(results)) + } + if err := s.Delete("foo"); err != nil { + t.Errorf("Delete failed (%v)", err) + } + if results, err := s.Read("foo", store.ReadSuffix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) + } else { + if len(results) != 0 { + t.Errorf("Expected 0 items, got %d (%# v)", len(results), pretty.Formatter(results)) + } + } + + // Test Prefix, Suffix and WriteOptions + if err := s.Write(&store.Record{ + Key: "foofoobarbar", + Value: []byte("something"), + }, store.WriteTTL(time.Millisecond*100)); err != nil { + t.Error(err) + } + if err := s.Write(&store.Record{ + Key: "foofoo", + Value: []byte("something"), + }, store.WriteExpiry(time.Now().Add(time.Millisecond*100))); err != nil { + t.Error(err) + } + if err := s.Write(&store.Record{ + Key: "barbar", + Value: []byte("something"), + // TTL has higher precedence than expiry + }, store.WriteExpiry(time.Now().Add(time.Hour)), store.WriteTTL(time.Millisecond*100)); err != nil { + t.Error(err) + } + if results, err := s.Read("foo", store.ReadPrefix(), store.ReadSuffix()); err != nil { + t.Error(err) + } else { + if len(results) != 1 { + t.Errorf("Expected 1 results, got %d: %# v", len(results), pretty.Formatter(results)) + } + } + time.Sleep(time.Millisecond * 100) + if results, err := s.List(); err != nil { + t.Errorf("List failed: %s", err) + } else { + if len(results) != 0 { + t.Error("Expiry options were not effective") + } + } + + s.Init() + for i := 0; i < 10; i++ { + s.Write(&store.Record{ + Key: fmt.Sprintf("a%d", i), + Value: []byte{}, + }) + } + if results, err := s.Read("a", store.ReadLimit(5), store.ReadPrefix()); err != nil { + t.Error(err) + } else { + if len(results) != 5 { + t.Error("Expected 5 results, got ", len(results)) + } + if results[0].Key != "a0" { + t.Errorf("Expected a0, got %s", results[0].Key) + } + if results[4].Key != "a4" { + t.Errorf("Expected a4, got %s", results[4].Key) + } + } + if results, err := s.Read("a", store.ReadLimit(30), store.ReadOffset(5), store.ReadPrefix()); err != nil { + t.Error(err) + } else { + if len(results) != 5 { + t.Error("Expected 5 results, got ", len(results)) + } } } diff --git a/store/noop.go b/store/noop.go new file mode 100644 index 00000000..0c6ebb4b --- /dev/null +++ b/store/noop.go @@ -0,0 +1,31 @@ +package store + +type noopStore struct{} + +func (n *noopStore) Init(opts ...Option) error { + return nil +} + +func (n *noopStore) Options() Options { + return Options{} +} + +func (n *noopStore) String() string { + return "noop" +} + +func (n *noopStore) Read(key string, opts ...ReadOption) ([]*Record, error) { + return []*Record{}, nil +} + +func (n *noopStore) Write(r *Record, opts ...WriteOption) error { + return nil +} + +func (n *noopStore) Delete(key string, opts ...DeleteOption) error { + return nil +} + +func (n *noopStore) List(opts ...ListOption) ([]string, error) { + return []string{}, nil +} diff --git a/store/options.go b/store/options.go index f1ed4f52..98b9915a 100644 --- a/store/options.go +++ b/store/options.go @@ -2,55 +2,181 @@ package store import ( "context" + "time" ) +// Options contains configuration for the Store type Options struct { - // nodes to connect to + // Nodes contains the addresses or other connection information of the backing storage. + // For example, an etcd implementation would contain the nodes of the cluster. + // A SQL implementation could contain one or more connection strings. Nodes []string - // Namespace of the store + // Namespace allows multiple isolated stores to be kept in one backend, if supported. + // For example multiple tables in a SQL store. Namespace string - // Prefix of the keys used + // Prefix sets a global prefix on all keys Prefix string - // Suffix of the keys used + // Suffix sets a global suffix on all keys Suffix string - // Alternative options + // Context should contain all implementation specific options, using context.WithValue. Context context.Context } +// Option sets values in Options type Option func(o *Options) -// Nodes is a list of nodes used to back the store +// Nodes contains the addresses or other connection information of the backing storage. +// For example, an etcd implementation would contain the nodes of the cluster. +// A SQL implementation could contain one or more connection strings. func Nodes(a ...string) Option { return func(o *Options) { o.Nodes = a } } -// Prefix sets a prefix to any key ids used -func Prefix(p string) Option { - return func(o *Options) { - o.Prefix = p - } -} - -// Namespace offers a way to have multiple isolated -// stores in the same backend, if supported. +// Namespace allows multiple isolated stores to be kept in one backend, if supported. +// For example multiple tables in a SQL store. func Namespace(ns string) Option { return func(o *Options) { o.Namespace = ns } } -// ReadPrefix uses the key as a prefix -func ReadPrefix() ReadOption { - return func(o *ReadOptions) { - o.Prefix = true +// Prefix sets a global prefix on all keys +func Prefix(p string) Option { + return func(o *Options) { + o.Prefix = p } } -// ReadSuffix uses the key as a suffix -func ReadSuffix() ReadOption { - return func(o *ReadOptions) { - o.Suffix = true +// Suffix sets a global suffix on all keys +func Suffix(s string) Option { + return func(o *Options) { + o.Suffix = s + } +} + +// WithContext sets the stores context, for any extra configuration +func WithContext(c context.Context) Option { + return func(o *Options) { + o.Context = c + } +} + +// ReadOptions configures an individual Read operation +type ReadOptions struct { + // Prefix returns all records that are prefixed with key + Prefix bool + // Suffix returns all records that have the suffix key + Suffix bool + // Limit limits the number of returned records + Limit uint + // Offset when combined with Limit supports pagination + Offset uint +} + +// ReadOption sets values in ReadOptions +type ReadOption func(r *ReadOptions) + +// ReadPrefix returns all records that are prefixed with key +func ReadPrefix() ReadOption { + return func(r *ReadOptions) { + r.Prefix = true + } +} + +// ReadSuffix returns all records that have the suffix key +func ReadSuffix() ReadOption { + return func(r *ReadOptions) { + r.Suffix = true + } +} + +// ReadLimit limits the number of responses to l +func ReadLimit(l uint) ReadOption { + return func(r *ReadOptions) { + r.Limit = l + } +} + +// ReadOffset starts returning responses from o. Use in conjunction with Limit for pagination +func ReadOffset(o uint) ReadOption { + return func(r *ReadOptions) { + r.Offset = o + } +} + +// WriteOptions configures an individual Write operation +// If Expiry and TTL are set TTL takes precedence +type WriteOptions struct { + // Expiry is the time the record expires + Expiry time.Time + // TTL is the time until the record expires + TTL time.Duration +} + +// WriteOption sets values in WriteOptions +type WriteOption func(w *WriteOptions) + +// WriteExpiry is the time the record expires +func WriteExpiry(t time.Time) WriteOption { + return func(w *WriteOptions) { + w.Expiry = t + } +} + +// WriteTTL is the time the record expires +func WriteTTL(d time.Duration) WriteOption { + return func(w *WriteOptions) { + w.TTL = d + } +} + +// DeleteOptions configures an individual Delete operation +type DeleteOptions struct{} + +// DeleteOption sets values in DeleteOptions +type DeleteOption func(d *DeleteOptions) + +// ListOptions configures an individual List operation +type ListOptions struct { + // Prefix returns all keys that are prefixed with key + Prefix string + // Suffix returns all keys that end with key + Suffix string + // Limit limits the number of returned keys + Limit uint + // Offset when combined with Limit supports pagination + Offset uint +} + +// ListOption sets values in ListOptions +type ListOption func(l *ListOptions) + +// ListPrefix returns all keys that are prefixed with key +func ListPrefix(p string) ListOption { + return func(l *ListOptions) { + l.Prefix = p + } +} + +// ListSuffix returns all keys that end with key +func ListSuffix(s string) ListOption { + return func(l *ListOptions) { + l.Suffix = s + } +} + +// ListLimit limits the number of returned keys to l +func ListLimit(l uint) ListOption { + return func(lo *ListOptions) { + lo.Limit = l + } +} + +// ListOffset starts returning responses from o. Use in conjunction with Limit for pagination. +func ListOffset(o uint) ListOption { + return func(l *ListOptions) { + l.Offset = o } } diff --git a/store/scope/scope.go b/store/scope/scope.go new file mode 100644 index 00000000..c78e1e1a --- /dev/null +++ b/store/scope/scope.go @@ -0,0 +1,51 @@ +package scope + +import ( + "fmt" + + "github.com/micro/go-micro/v2/store" +) + +// Scope extends the store, applying a prefix to each request +type Scope struct { + store.Store + prefix string +} + +// NewScope returns an initialised scope +func NewScope(s store.Store, prefix string) Scope { + return Scope{Store: s, prefix: prefix} +} + +func (s *Scope) Options() store.Options { + o := s.Store.Options() + o.Prefix = s.prefix + return o +} + +func (s *Scope) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { + key = fmt.Sprintf("%v/%v", s.prefix, key) + return s.Store.Read(key, opts...) +} + +func (s *Scope) Write(r *store.Record, opts ...store.WriteOption) error { + r.Key = fmt.Sprintf("%v/%v", s.prefix, r.Key) + return s.Store.Write(r, opts...) +} + +func (s *Scope) Delete(key string, opts ...store.DeleteOption) error { + key = fmt.Sprintf("%v/%v", s.prefix, key) + return s.Store.Delete(key, opts...) +} + +func (s *Scope) List(opts ...store.ListOption) ([]string, error) { + var lops store.ListOptions + for _, o := range opts { + o(&lops) + } + + key := fmt.Sprintf("%v/%v", s.prefix, lops.Prefix) + opts = append(opts, store.ListPrefix(key)) + + return s.Store.List(opts...) +} diff --git a/store/service/proto/store.pb.go b/store/service/proto/store.pb.go index 6a05463a..b7cd9979 100644 --- a/store/service/proto/store.pb.go +++ b/store/service/proto/store.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: micro/go-micro/store/service/proto/store.proto +// source: store.proto package go_micro_store @@ -25,7 +25,7 @@ type Record struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` // value in the record Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` - // timestamp in unix seconds + // time.Duration (signed int64 nanoseconds) Expiry int64 `protobuf:"varint,3,opt,name=expiry,proto3" json:"expiry,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -36,7 +36,7 @@ func (m *Record) Reset() { *m = Record{} } func (m *Record) String() string { return proto.CompactTextString(m) } func (*Record) ProtoMessage() {} func (*Record) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{0} + return fileDescriptor_98bbca36ef968dfc, []int{0} } func (m *Record) XXX_Unmarshal(b []byte) error { @@ -80,6 +80,9 @@ func (m *Record) GetExpiry() int64 { type ReadOptions struct { Prefix bool `protobuf:"varint,1,opt,name=prefix,proto3" json:"prefix,omitempty"` + Suffix bool `protobuf:"varint,2,opt,name=suffix,proto3" json:"suffix,omitempty"` + Limit uint64 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` + Offset uint64 `protobuf:"varint,4,opt,name=offset,proto3" json:"offset,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -89,7 +92,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{1} + return fileDescriptor_98bbca36ef968dfc, []int{1} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -117,6 +120,27 @@ func (m *ReadOptions) GetPrefix() bool { return false } +func (m *ReadOptions) GetSuffix() bool { + if m != nil { + return m.Suffix + } + return false +} + +func (m *ReadOptions) GetLimit() uint64 { + if m != nil { + return m.Limit + } + return 0 +} + +func (m *ReadOptions) GetOffset() uint64 { + if m != nil { + return m.Offset + } + return 0 +} + type ReadRequest struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` Options *ReadOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` @@ -129,7 +153,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{2} + return fileDescriptor_98bbca36ef968dfc, []int{2} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -175,7 +199,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{3} + return fileDescriptor_98bbca36ef968dfc, []int{3} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -203,18 +227,68 @@ func (m *ReadResponse) GetRecords() []*Record { return nil } -type WriteRequest struct { - Record *Record `protobuf:"bytes,1,opt,name=record,proto3" json:"record,omitempty"` +type WriteOptions struct { + // time.Time + Expiry int64 `protobuf:"varint,1,opt,name=expiry,proto3" json:"expiry,omitempty"` + // time.Duration + Ttl int64 `protobuf:"varint,2,opt,name=ttl,proto3" json:"ttl,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } +func (m *WriteOptions) Reset() { *m = WriteOptions{} } +func (m *WriteOptions) String() string { return proto.CompactTextString(m) } +func (*WriteOptions) ProtoMessage() {} +func (*WriteOptions) Descriptor() ([]byte, []int) { + return fileDescriptor_98bbca36ef968dfc, []int{4} +} + +func (m *WriteOptions) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_WriteOptions.Unmarshal(m, b) +} +func (m *WriteOptions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_WriteOptions.Marshal(b, m, deterministic) +} +func (m *WriteOptions) XXX_Merge(src proto.Message) { + xxx_messageInfo_WriteOptions.Merge(m, src) +} +func (m *WriteOptions) XXX_Size() int { + return xxx_messageInfo_WriteOptions.Size(m) +} +func (m *WriteOptions) XXX_DiscardUnknown() { + xxx_messageInfo_WriteOptions.DiscardUnknown(m) +} + +var xxx_messageInfo_WriteOptions proto.InternalMessageInfo + +func (m *WriteOptions) GetExpiry() int64 { + if m != nil { + return m.Expiry + } + return 0 +} + +func (m *WriteOptions) GetTtl() int64 { + if m != nil { + return m.Ttl + } + return 0 +} + +type WriteRequest struct { + Record *Record `protobuf:"bytes,1,opt,name=record,proto3" json:"record,omitempty"` + Options *WriteOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + func (m *WriteRequest) Reset() { *m = WriteRequest{} } func (m *WriteRequest) String() string { return proto.CompactTextString(m) } func (*WriteRequest) ProtoMessage() {} func (*WriteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{4} + return fileDescriptor_98bbca36ef968dfc, []int{5} } func (m *WriteRequest) XXX_Unmarshal(b []byte) error { @@ -242,6 +316,13 @@ func (m *WriteRequest) GetRecord() *Record { return nil } +func (m *WriteRequest) GetOptions() *WriteOptions { + if m != nil { + return m.Options + } + return nil +} + type WriteResponse struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -252,7 +333,7 @@ func (m *WriteResponse) Reset() { *m = WriteResponse{} } func (m *WriteResponse) String() string { return proto.CompactTextString(m) } func (*WriteResponse) ProtoMessage() {} func (*WriteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{5} + return fileDescriptor_98bbca36ef968dfc, []int{6} } func (m *WriteResponse) XXX_Unmarshal(b []byte) error { @@ -273,18 +354,50 @@ func (m *WriteResponse) XXX_DiscardUnknown() { var xxx_messageInfo_WriteResponse proto.InternalMessageInfo -type DeleteRequest struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +type DeleteOptions struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } +func (m *DeleteOptions) Reset() { *m = DeleteOptions{} } +func (m *DeleteOptions) String() string { return proto.CompactTextString(m) } +func (*DeleteOptions) ProtoMessage() {} +func (*DeleteOptions) Descriptor() ([]byte, []int) { + return fileDescriptor_98bbca36ef968dfc, []int{7} +} + +func (m *DeleteOptions) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteOptions.Unmarshal(m, b) +} +func (m *DeleteOptions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteOptions.Marshal(b, m, deterministic) +} +func (m *DeleteOptions) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteOptions.Merge(m, src) +} +func (m *DeleteOptions) XXX_Size() int { + return xxx_messageInfo_DeleteOptions.Size(m) +} +func (m *DeleteOptions) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteOptions.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteOptions proto.InternalMessageInfo + +type DeleteRequest struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Options *DeleteOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{6} + return fileDescriptor_98bbca36ef968dfc, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -312,6 +425,13 @@ func (m *DeleteRequest) GetKey() string { return "" } +func (m *DeleteRequest) GetOptions() *DeleteOptions { + if m != nil { + return m.Options + } + return nil +} + type DeleteResponse struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -322,7 +442,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{7} + return fileDescriptor_98bbca36ef968dfc, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -343,17 +463,81 @@ func (m *DeleteResponse) XXX_DiscardUnknown() { var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo -type ListRequest struct { +type ListOptions struct { + Prefix string `protobuf:"bytes,1,opt,name=prefix,proto3" json:"prefix,omitempty"` + Suffix string `protobuf:"bytes,2,opt,name=suffix,proto3" json:"suffix,omitempty"` + Limit uint64 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` + Offset uint64 `protobuf:"varint,4,opt,name=offset,proto3" json:"offset,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } +func (m *ListOptions) Reset() { *m = ListOptions{} } +func (m *ListOptions) String() string { return proto.CompactTextString(m) } +func (*ListOptions) ProtoMessage() {} +func (*ListOptions) Descriptor() ([]byte, []int) { + return fileDescriptor_98bbca36ef968dfc, []int{10} +} + +func (m *ListOptions) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListOptions.Unmarshal(m, b) +} +func (m *ListOptions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListOptions.Marshal(b, m, deterministic) +} +func (m *ListOptions) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListOptions.Merge(m, src) +} +func (m *ListOptions) XXX_Size() int { + return xxx_messageInfo_ListOptions.Size(m) +} +func (m *ListOptions) XXX_DiscardUnknown() { + xxx_messageInfo_ListOptions.DiscardUnknown(m) +} + +var xxx_messageInfo_ListOptions proto.InternalMessageInfo + +func (m *ListOptions) GetPrefix() string { + if m != nil { + return m.Prefix + } + return "" +} + +func (m *ListOptions) GetSuffix() string { + if m != nil { + return m.Suffix + } + return "" +} + +func (m *ListOptions) GetLimit() uint64 { + if m != nil { + return m.Limit + } + return 0 +} + +func (m *ListOptions) GetOffset() uint64 { + if m != nil { + return m.Offset + } + return 0 +} + +type ListRequest struct { + Options *ListOptions `protobuf:"bytes,1,opt,name=options,proto3" json:"options,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{8} + return fileDescriptor_98bbca36ef968dfc, []int{11} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -374,18 +558,25 @@ func (m *ListRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ListRequest proto.InternalMessageInfo +func (m *ListRequest) GetOptions() *ListOptions { + if m != nil { + return m.Options + } + return nil +} + type ListResponse struct { - Records []*Record `protobuf:"bytes,1,rep,name=records,proto3" json:"records,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Keys []string `protobuf:"bytes,2,rep,name=keys,proto3" json:"keys,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_f84ccc98e143ed3e, []int{9} + return fileDescriptor_98bbca36ef968dfc, []int{12} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -406,9 +597,9 @@ func (m *ListResponse) XXX_DiscardUnknown() { var xxx_messageInfo_ListResponse proto.InternalMessageInfo -func (m *ListResponse) GetRecords() []*Record { +func (m *ListResponse) GetKeys() []string { if m != nil { - return m.Records + return m.Keys } return nil } @@ -418,41 +609,48 @@ func init() { proto.RegisterType((*ReadOptions)(nil), "go.micro.store.ReadOptions") proto.RegisterType((*ReadRequest)(nil), "go.micro.store.ReadRequest") proto.RegisterType((*ReadResponse)(nil), "go.micro.store.ReadResponse") + proto.RegisterType((*WriteOptions)(nil), "go.micro.store.WriteOptions") proto.RegisterType((*WriteRequest)(nil), "go.micro.store.WriteRequest") proto.RegisterType((*WriteResponse)(nil), "go.micro.store.WriteResponse") + proto.RegisterType((*DeleteOptions)(nil), "go.micro.store.DeleteOptions") proto.RegisterType((*DeleteRequest)(nil), "go.micro.store.DeleteRequest") proto.RegisterType((*DeleteResponse)(nil), "go.micro.store.DeleteResponse") + proto.RegisterType((*ListOptions)(nil), "go.micro.store.ListOptions") proto.RegisterType((*ListRequest)(nil), "go.micro.store.ListRequest") proto.RegisterType((*ListResponse)(nil), "go.micro.store.ListResponse") } -func init() { - proto.RegisterFile("micro/go-micro/store/service/proto/store.proto", fileDescriptor_f84ccc98e143ed3e) -} +func init() { proto.RegisterFile("store.proto", fileDescriptor_98bbca36ef968dfc) } -var fileDescriptor_f84ccc98e143ed3e = []byte{ - // 364 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x4d, 0x4b, 0xc3, 0x40, - 0x10, 0x6d, 0x9a, 0x36, 0xd5, 0x49, 0x5b, 0xcb, 0x22, 0x25, 0xd4, 0x0f, 0xe2, 0x82, 0x90, 0x8b, - 0x69, 0xa9, 0x78, 0x15, 0xc1, 0x0f, 0x14, 0x04, 0x61, 0x05, 0x3d, 0xd7, 0x76, 0x2c, 0xc1, 0xda, - 0x8d, 0xbb, 0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c, 0xb4, 0x10, 0x1c, 0x0d, 0xa9, 0xe9, 0xca, - 0x05, 0x0c, 0x8b, 0xee, 0x41, 0xcb, 0xd4, 0xeb, 0x11, 0xe8, 0x09, 0xb4, 0x6e, 0x70, 0x86, 0x7f, - 0x8a, 0x85, 0x65, 0x69, 0x07, 0xda, 0x19, 0xc5, 0x14, 0xb5, 0xc0, 0x7d, 0x8c, 0x64, 0x62, 0x4a, - 0xd2, 0xb5, 0x74, 0xfa, 0xdf, 0xb5, 0x86, 0xdf, 0x55, 0xa8, 0x3f, 0xa7, 0x08, 0xb9, 0x85, 0x5a, - 0xaa, 0x45, 0x0a, 0x86, 0xe6, 0x1a, 0xf6, 0x0e, 0xb7, 0x83, 0x66, 0xba, 0xca, 0xc0, 0x22, 0xd7, - 0x50, 0x4b, 0x9d, 0x26, 0x5b, 0xef, 0x52, 0x2a, 0x93, 0x3f, 0x0e, 0xad, 0x90, 0x3b, 0xa8, 0x2b, - 0xb3, 0x48, 0x81, 0x98, 0xbf, 0x41, 0xef, 0xa8, 0x04, 0xfd, 0xd5, 0x79, 0x00, 0x47, 0x1b, 0x48, - 0x0a, 0xd4, 0x0d, 0xef, 0x7b, 0xc7, 0x65, 0x70, 0x26, 0xf5, 0xe6, 0xa8, 0x1f, 0x72, 0xfe, 0x13, - 0x00, 0x00, 0xff, 0xff, 0xf9, 0x20, 0x54, 0x71, 0x53, 0x03, 0x00, 0x00, +var fileDescriptor_98bbca36ef968dfc = []byte{ + // 463 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x5d, 0x6b, 0xd4, 0x40, + 0x14, 0xed, 0x6c, 0xb2, 0x69, 0xf7, 0x26, 0xd6, 0x65, 0x90, 0x12, 0xb4, 0x95, 0x30, 0x4f, 0x79, + 0x0a, 0x65, 0xc5, 0x8f, 0x47, 0xc1, 0x2a, 0x2a, 0x82, 0x30, 0x82, 0x82, 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f, 0xbf, 0x75, 0x80, 0x39, 0x9b, 0x38, 0xdd, 0xe2, 0x7c, 0x82, + 0xc4, 0xbd, 0x02, 0x9e, 0x78, 0xb7, 0x80, 0xf4, 0x7c, 0xea, 0x78, 0x0b, 0xf5, 0x1e, 0x62, 0xe3, + 0x05, 0x1e, 0x75, 0x6e, 0x52, 0x57, 0xdf, 0x3e, 0x72, 0x70, 0x8e, 0x7e, 0x25, 0xf6, 0x7f, 0xf5, + 0xe2, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa5, 0x11, 0xc3, 0x50, 0xbe, 0x04, 0x00, 0x00, } diff --git a/store/service/proto/store.pb.micro.go b/store/service/proto/store.pb.micro.go index 448ea6bc..321449b5 100644 --- a/store/service/proto/store.pb.micro.go +++ b/store/service/proto/store.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: micro/go-micro/store/service/proto/store.proto +// source: store.proto package go_micro_store @@ -34,10 +34,10 @@ var _ server.Option // Client API for Store service type StoreService interface { - List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (Store_ListService, error) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) Write(ctx context.Context, in *WriteRequest, opts ...client.CallOption) (*WriteResponse, error) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) + List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (Store_ListService, error) } type storeService struct { @@ -46,62 +46,12 @@ type storeService struct { } func NewStoreService(name string, c client.Client) StoreService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "go.micro.store" - } return &storeService{ c: c, name: name, } } -func (c *storeService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (Store_ListService, error) { - req := c.c.NewRequest(c.name, "Store.List", &ListRequest{}) - stream, err := c.c.Stream(ctx, req, opts...) - if err != nil { - return nil, err - } - if err := stream.Send(in); err != nil { - return nil, err - } - return &storeServiceList{stream}, nil -} - -type Store_ListService interface { - SendMsg(interface{}) error - RecvMsg(interface{}) error - Close() error - Recv() (*ListResponse, error) -} - -type storeServiceList struct { - stream client.Stream -} - -func (x *storeServiceList) Close() error { - return x.stream.Close() -} - -func (x *storeServiceList) SendMsg(m interface{}) error { - return x.stream.Send(m) -} - -func (x *storeServiceList) RecvMsg(m interface{}) error { - return x.stream.Recv(m) -} - -func (x *storeServiceList) Recv() (*ListResponse, error) { - m := new(ListResponse) - err := x.stream.Recv(m) - if err != nil { - return nil, err - } - return m, nil -} - func (c *storeService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) { req := c.c.NewRequest(c.name, "Store.Read", in) out := new(ReadResponse) @@ -132,21 +82,70 @@ func (c *storeService) Delete(ctx context.Context, in *DeleteRequest, opts ...cl return out, nil } +func (c *storeService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (Store_ListService, error) { + req := c.c.NewRequest(c.name, "Store.List", &ListRequest{}) + stream, err := c.c.Stream(ctx, req, opts...) + if err != nil { + return nil, err + } + if err := stream.Send(in); err != nil { + return nil, err + } + return &storeServiceList{stream}, nil +} + +type Store_ListService interface { + Context() context.Context + SendMsg(interface{}) error + RecvMsg(interface{}) error + Close() error + Recv() (*ListResponse, error) +} + +type storeServiceList struct { + stream client.Stream +} + +func (x *storeServiceList) Close() error { + return x.stream.Close() +} + +func (x *storeServiceList) Context() context.Context { + return x.stream.Context() +} + +func (x *storeServiceList) SendMsg(m interface{}) error { + return x.stream.Send(m) +} + +func (x *storeServiceList) RecvMsg(m interface{}) error { + return x.stream.Recv(m) +} + +func (x *storeServiceList) Recv() (*ListResponse, error) { + m := new(ListResponse) + err := x.stream.Recv(m) + if err != nil { + return nil, err + } + return m, nil +} + // Server API for Store service type StoreHandler interface { - List(context.Context, *ListRequest, Store_ListStream) error Read(context.Context, *ReadRequest, *ReadResponse) error Write(context.Context, *WriteRequest, *WriteResponse) error Delete(context.Context, *DeleteRequest, *DeleteResponse) error + List(context.Context, *ListRequest, Store_ListStream) error } func RegisterStoreHandler(s server.Server, hdlr StoreHandler, opts ...server.HandlerOption) error { type store interface { - List(ctx context.Context, stream server.Stream) error Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error Write(ctx context.Context, in *WriteRequest, out *WriteResponse) error Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error + List(ctx context.Context, stream server.Stream) error } type Store struct { store @@ -159,6 +158,18 @@ type storeHandler struct { StoreHandler } +func (h *storeHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error { + return h.StoreHandler.Read(ctx, in, out) +} + +func (h *storeHandler) Write(ctx context.Context, in *WriteRequest, out *WriteResponse) error { + return h.StoreHandler.Write(ctx, in, out) +} + +func (h *storeHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { + return h.StoreHandler.Delete(ctx, in, out) +} + func (h *storeHandler) List(ctx context.Context, stream server.Stream) error { m := new(ListRequest) if err := stream.Recv(m); err != nil { @@ -168,6 +179,7 @@ func (h *storeHandler) List(ctx context.Context, stream server.Stream) error { } type Store_ListStream interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -182,6 +194,10 @@ func (x *storeListStream) Close() error { return x.stream.Close() } +func (x *storeListStream) Context() context.Context { + return x.stream.Context() +} + func (x *storeListStream) SendMsg(m interface{}) error { return x.stream.Send(m) } @@ -193,15 +209,3 @@ func (x *storeListStream) RecvMsg(m interface{}) error { func (x *storeListStream) Send(m *ListResponse) error { return x.stream.Send(m) } - -func (h *storeHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error { - return h.StoreHandler.Read(ctx, in, out) -} - -func (h *storeHandler) Write(ctx context.Context, in *WriteRequest, out *WriteResponse) error { - return h.StoreHandler.Write(ctx, in, out) -} - -func (h *storeHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { - return h.StoreHandler.Delete(ctx, in, out) -} diff --git a/store/service/proto/store.proto b/store/service/proto/store.proto index 39bd8afc..a6462ad2 100644 --- a/store/service/proto/store.proto +++ b/store/service/proto/store.proto @@ -3,10 +3,10 @@ syntax = "proto3"; package go.micro.store; service Store { - rpc List(ListRequest) returns (stream ListResponse) {}; rpc Read(ReadRequest) returns (ReadResponse) {}; rpc Write(WriteRequest) returns (WriteResponse) {}; rpc Delete(DeleteRequest) returns (DeleteResponse) {}; + rpc List(ListRequest) returns (stream ListResponse) {}; } message Record { @@ -14,16 +14,19 @@ message Record { string key = 1; // value in the record bytes value = 2; - // timestamp in unix seconds + // time.Duration (signed int64 nanoseconds) int64 expiry = 3; } message ReadOptions { - bool prefix = 1; + bool prefix = 1; + bool suffix = 2; + uint64 limit = 3; + uint64 offset = 4; } message ReadRequest { - string key = 1; + string key = 1; ReadOptions options = 2; } @@ -31,20 +34,41 @@ message ReadResponse { repeated Record records = 1; } +message WriteOptions { + // time.Time + int64 expiry = 1; + // time.Duration + int64 ttl = 2; +} + message WriteRequest { - Record record = 1; + Record record = 1; + WriteOptions options = 2; } message WriteResponse {} +message DeleteOptions {} + message DeleteRequest { - string key = 1; + string key = 1; + DeleteOptions options = 2; } message DeleteResponse {} -message ListRequest {} +message ListOptions { + string prefix = 1; + string suffix = 2; + uint64 limit = 3; + uint64 offset = 4; +} + +message ListRequest { + ListOptions options = 1; +} message ListResponse { - repeated Record records = 1; + reserved 1; //repeated Record records = 1; + repeated string keys = 2; } diff --git a/store/service/service.go b/store/service/service.go index 713cda15..5b448a8c 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -24,6 +24,9 @@ type serviceStore struct { // Prefix to use Prefix string + // Suffix to use + Suffix string + // store service client Client pb.StoreService } @@ -56,14 +59,14 @@ func (s *serviceStore) Context() context.Context { } // Sync all the known records -func (s *serviceStore) List() ([]*store.Record, error) { +func (s *serviceStore) List(opts ...store.ListOption) ([]string, error) { stream, err := s.Client.List(s.Context(), &pb.ListRequest{}, client.WithAddress(s.Nodes...)) if err != nil { return nil, err } defer stream.Close() - var records []*store.Record + var keys []string for { rsp, err := stream.Recv() @@ -71,19 +74,15 @@ func (s *serviceStore) List() ([]*store.Record, error) { break } if err != nil { - return records, err + return keys, err } - for _, record := range rsp.Records { - records = append(records, &store.Record{ - Key: record.Key, - Value: record.Value, - Expiry: time.Duration(record.Expiry) * time.Second, - }) + for _, key := range rsp.Keys { + keys = append(keys, key) } } - return records, nil + return keys, nil } // Read a record with key @@ -117,7 +116,7 @@ func (s *serviceStore) Read(key string, opts ...store.ReadOption) ([]*store.Reco } // Write a record -func (s *serviceStore) Write(record *store.Record) error { +func (s *serviceStore) Write(record *store.Record, opts ...store.WriteOption) error { _, err := s.Client.Write(s.Context(), &pb.WriteRequest{ Record: &pb.Record{ Key: record.Key, @@ -130,7 +129,7 @@ func (s *serviceStore) Write(record *store.Record) error { } // Delete a record with key -func (s *serviceStore) Delete(key string) error { +func (s *serviceStore) Delete(key string, opts ...store.DeleteOption) error { _, err := s.Client.Delete(s.Context(), &pb.DeleteRequest{ Key: key, }, client.WithAddress(s.Nodes...)) @@ -141,6 +140,10 @@ func (s *serviceStore) String() string { return "service" } +func (s *serviceStore) Options() store.Options { + return s.options +} + // NewStore returns a new store service implementation func NewStore(opts ...store.Option) store.Store { var options store.Options diff --git a/store/store.go b/store/store.go index cf21ddee..21101cb8 100644 --- a/store/store.go +++ b/store/store.go @@ -1,4 +1,5 @@ -// Package store is an interface for distribute data storage. +// Package store is an interface for distributed data storage. +// The design document is located at https://github.com/micro/development/blob/master/design/store.md package store import ( @@ -7,66 +8,33 @@ import ( ) var ( - // ErrNotFound is returned when a Read key doesn't exist + // ErrNotFound is returned when a key doesn't exist ErrNotFound = errors.New("not found") - // Default store - DefaultStore Store = new(noop) + // DefaultStore is the memory store. + DefaultStore Store = new(noopStore) ) // Store is a data storage interface type Store interface { - // Initialise store options + // Init initialises the store. It must perform any required setup on the backing storage implementation and check that it is ready for use, returning any errors. Init(...Option) error - // List all the known records - List() ([]*Record, error) - // Read records with keys - Read(key string, opts ...ReadOption) ([]*Record, error) - // Write records - Write(*Record) error - // Delete records with keys - Delete(key string) error - // Name of the store + // Options allows you to view the current options. + Options() Options + // String returns the name of the implementation. String() string + // Read takes a single key name and optional ReadOptions. It returns matching []*Record or an error. + Read(key string, opts ...ReadOption) ([]*Record, error) + // Write() writes a record to the store, and returns an error if the record was not written. + Write(r *Record, opts ...WriteOption) error + // Delete removes the record with the corresponding key from the store. + Delete(key string, opts ...DeleteOption) error + // List returns any keys that match, or an empty list with no error if none matched. + List(opts ...ListOption) ([]string, error) } -// Record represents a data record +// Record is an item stored or retrieved from a Store type Record struct { Key string Value []byte Expiry time.Duration } - -type ReadOptions struct { - // Read key as a prefix - Prefix bool - // Read key as a suffix - Suffix bool -} - -type ReadOption func(o *ReadOptions) - -type noop struct{} - -func (n *noop) Init(...Option) error { - return nil -} - -func (n *noop) List() ([]*Record, error) { - return nil, nil -} - -func (n *noop) Read(key string, opts ...ReadOption) ([]*Record, error) { - return nil, nil -} - -func (n *noop) Write(rec *Record) error { - return nil -} - -func (n *noop) Delete(key string) error { - return nil -} - -func (n *noop) String() string { - return "noop" -} diff --git a/sync/map.go b/sync/map.go index 83736cff..edfeb6a9 100644 --- a/sync/map.go +++ b/sync/map.go @@ -90,7 +90,7 @@ func (m *syncMap) Delete(key interface{}) error { } func (m *syncMap) Iterate(fn func(key, val interface{}) error) error { - keyvals, err := m.opts.Store.List() + keyvals, err := m.opts.Store.Read("", store.ReadPrefix()) if err != nil { return err } From 47f1203e979dcb9c2a558641576efaea4ec94015 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 12 Mar 2020 18:13:03 +0000 Subject: [PATCH 379/788] Add Config to service options (#1336) Co-authored-by: Ben Toogood Co-authored-by: Asim Aslam --- config/cmd/cmd.go | 23 +++++++++++++++++-- config/cmd/options.go | 3 +++ config/config.go | 2 ++ config/default.go | 38 +++++++++++++++++--------------- config/source/service/service.go | 8 +++---- options.go | 10 +++++++++ 6 files changed, 60 insertions(+), 24 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 5daad43f..a43a4886 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -7,12 +7,13 @@ import ( "strings" "time" - "github.com/micro/go-micro/v2/auth/provider" - "github.com/micro/go-micro/v2/auth" + "github.com/micro/go-micro/v2/auth/provider" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/config" + configSrv "github.com/micro/go-micro/v2/config/source/service" "github.com/micro/go-micro/v2/debug/profile" "github.com/micro/go-micro/v2/debug/profile/http" "github.com/micro/go-micro/v2/debug/profile/pprof" @@ -305,6 +306,11 @@ var ( EnvVars: []string{"MICRO_AUTH_PROVIDER_SCOPE"}, Usage: "The scope to be used for oauth", }, + &cli.StringFlag{ + Name: "config", + EnvVars: []string{"MICRO_CONFIG"}, + Usage: "The source of the config to be used to get configuration", + }, } DefaultBrokers = map[string]func(...broker.Option) broker.Broker{ @@ -373,6 +379,10 @@ var ( "http": http.NewProfile, "pprof": pprof.NewProfile, } + + DefaultConfigs = map[string]func(...config.Option) (config.Config, error){ + "service": config.NewConfig, + } ) func init() { @@ -392,6 +402,7 @@ func newCmd(opts ...Option) Cmd { Store: &store.DefaultStore, Tracer: &trace.DefaultTracer, Profile: &profile.DefaultProfile, + Config: &config.DefaultConfig, Brokers: DefaultBrokers, Clients: DefaultClients, @@ -404,6 +415,7 @@ func newCmd(opts ...Option) Cmd { Tracers: DefaultTracers, Auths: DefaultAuths, Profiles: DefaultProfiles, + Configs: DefaultConfigs, } for _, o := range opts { @@ -700,6 +712,13 @@ func (c *cmd) Before(ctx *cli.Context) error { } } + if ctx.String("config") == "service" { + opt := config.WithSource(configSrv.NewSource()) + if err := (*c.opts.Config).Init(opt); err != nil { + logger.Fatalf("Error configuring config: %v", err) + } + } + // client opts if r := ctx.Int("client_retries"); r >= 0 { clientOpts = append(clientOpts, client.Retries(r)) diff --git a/config/cmd/options.go b/config/cmd/options.go index da58938f..2e4956ff 100644 --- a/config/cmd/options.go +++ b/config/cmd/options.go @@ -7,6 +7,7 @@ import ( "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/config" "github.com/micro/go-micro/v2/debug/profile" "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/registry" @@ -34,6 +35,7 @@ type Options struct { Tracer *trace.Tracer Auth *auth.Auth Profile *profile.Profile + Config *config.Config Brokers map[string]func(...broker.Option) broker.Broker Clients map[string]func(...client.Option) client.Client @@ -46,6 +48,7 @@ type Options struct { Tracers map[string]func(...trace.Option) trace.Tracer Auths map[string]func(...auth.Option) auth.Auth Profiles map[string]func(...profile.Option) profile.Profile + Configs map[string]func(...config.Option) (config.Config, error) // Other options for implementations of the interface // can be stored in a context diff --git a/config/config.go b/config/config.go index bd780874..d70d5778 100644 --- a/config/config.go +++ b/config/config.go @@ -14,6 +14,8 @@ import ( type Config interface { // provide the reader.Values interface reader.Values + // Init the config + Init(opts ...Option) error // Stop the config loader/watcher Close() error // Load config sources diff --git a/config/default.go b/config/default.go index 2c050462..e50024ed 100644 --- a/config/default.go +++ b/config/default.go @@ -31,38 +31,40 @@ type watcher struct { } func newConfig(opts ...Option) (Config, error) { - options := Options{ + var c config + + c.Init(opts...) + go c.run() + + return &c, nil +} + +func (c *config) Init(opts ...Option) error { + c.opts = Options{ Loader: memory.NewLoader(), Reader: json.NewReader(), } for _, o := range opts { - o(&options) + o(&c.opts) } - if err := options.Loader.Load(options.Source...); err != nil { - return nil, err - } - - snap, err := options.Loader.Snapshot() + err := c.opts.Loader.Load(c.opts.Source...) if err != nil { - return nil, err + return err } - vals, err := options.Reader.Values(snap.ChangeSet) + + c.snap, err = c.opts.Loader.Snapshot() if err != nil { - return nil, err + return err } - c := &config{ - exit: make(chan bool), - opts: options, - snap: snap, - vals: vals, + c.vals, err = c.opts.Reader.Values(c.snap.ChangeSet) + if err != nil { + return err } - go c.run() - - return c, nil + return nil } func (c *config) run() { diff --git a/config/source/service/service.go b/config/source/service/service.go index 29e1bf65..cc5499eb 100644 --- a/config/source/service/service.go +++ b/config/source/service/service.go @@ -13,7 +13,6 @@ var ( DefaultName = "go.micro.config" DefaultNamespace = "global" DefaultPath = "" - DefaultClient = client.DefaultClient ) type service struct { @@ -25,7 +24,8 @@ type service struct { } func (m *service) Read() (set *source.ChangeSet, err error) { - req, err := m.client.Read(context.Background(), &proto.ReadRequest{ + client := proto.NewConfigService(m.serviceName, client.DefaultClient) + req, err := client.Read(context.Background(), &proto.ReadRequest{ Namespace: m.namespace, Path: m.path, }) @@ -37,7 +37,8 @@ func (m *service) Read() (set *source.ChangeSet, err error) { } func (m *service) Watch() (w source.Watcher, err error) { - stream, err := m.client.Watch(context.Background(), &proto.WatchRequest{ + client := proto.NewConfigService(m.serviceName, client.DefaultClient) + stream, err := client.Watch(context.Background(), &proto.WatchRequest{ Namespace: m.namespace, Path: m.path, }) @@ -91,7 +92,6 @@ func NewSource(opts ...source.Option) source.Source { opts: options, namespace: namespace, path: path, - client: proto.NewConfigService(addr, DefaultClient), } return s diff --git a/options.go b/options.go index 289b224b..c90c17f3 100644 --- a/options.go +++ b/options.go @@ -9,6 +9,7 @@ import ( "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/config" "github.com/micro/go-micro/v2/config/cmd" "github.com/micro/go-micro/v2/debug/profile" "github.com/micro/go-micro/v2/debug/trace" @@ -27,6 +28,7 @@ type Options struct { Registry registry.Registry Transport transport.Transport Profile profile.Profile + Config config.Config // Before and After funcs BeforeStart []func() error @@ -46,6 +48,7 @@ func newOptions(opts ...Option) Options { Auth: auth.DefaultAuth, Broker: broker.DefaultBroker, Cmd: cmd.DefaultCmd, + Config: config.DefaultConfig, Client: client.DefaultClient, Server: server.DefaultServer, Registry: registry.DefaultRegistry, @@ -143,6 +146,13 @@ func Auth(a auth.Auth) Option { } } +// Config sets the config for the service +func Config(c config.Config) Option { + return func(o *Options) { + o.Config = c + } +} + // Selector sets the selector for the service client func Selector(s selector.Selector) Option { return func(o *Options) { From d8cfa7a2950a6a08639e4ab16d01abb156ffcc47 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 12 Mar 2020 18:47:40 +0000 Subject: [PATCH 380/788] add config to cmd (#1337) * add config to cmd * fix build --- config/cmd/options.go | 10 ++++++++-- options.go | 2 +- service.go | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/config/cmd/options.go b/config/cmd/options.go index 2e4956ff..d105ee2e 100644 --- a/config/cmd/options.go +++ b/config/cmd/options.go @@ -28,6 +28,7 @@ type Options struct { Registry *registry.Registry Selector *selector.Selector Transport *transport.Transport + Config *config.Config Client *client.Client Server *server.Server Runtime *runtime.Runtime @@ -35,9 +36,9 @@ type Options struct { Tracer *trace.Tracer Auth *auth.Auth Profile *profile.Profile - Config *config.Config Brokers map[string]func(...broker.Option) broker.Broker + Configs map[string]func(...config.Option) (config.Config, error) Clients map[string]func(...client.Option) client.Client Registries map[string]func(...registry.Option) registry.Registry Selectors map[string]func(...selector.Option) selector.Selector @@ -48,7 +49,6 @@ type Options struct { Tracers map[string]func(...trace.Option) trace.Tracer Auths map[string]func(...auth.Option) auth.Auth Profiles map[string]func(...profile.Option) profile.Profile - Configs map[string]func(...config.Option) (config.Config, error) // Other options for implementations of the interface // can be stored in a context @@ -82,6 +82,12 @@ func Broker(b *broker.Broker) Option { } } +func Config(c *config.Config) Option { + return func(o *Options) { + o.Config = c + } +} + func Selector(s *selector.Selector) Option { return func(o *Options) { o.Selector = s diff --git a/options.go b/options.go index c90c17f3..36e290a3 100644 --- a/options.go +++ b/options.go @@ -23,12 +23,12 @@ type Options struct { Auth auth.Auth Broker broker.Broker Cmd cmd.Cmd + Config config.Config Client client.Client Server server.Server Registry registry.Registry Transport transport.Transport Profile profile.Profile - Config config.Config // Before and After funcs BeforeStart []func() error diff --git a/service.go b/service.go index 9f5b6344..a47a38de 100644 --- a/service.go +++ b/service.go @@ -99,6 +99,7 @@ func (s *service) Init(opts ...Option) { cmd.Registry(&s.opts.Registry), cmd.Transport(&s.opts.Transport), cmd.Client(&s.opts.Client), + cmd.Config(&s.opts.Config), cmd.Server(&s.opts.Server), cmd.Profile(&s.opts.Profile), ); err != nil { From 62a644ddd898a75a19b89106312c1cf58f4acd70 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 13 Mar 2020 01:04:11 +0300 Subject: [PATCH 381/788] server/grpc: fix ordering of register and check for registered (#1338) Signed-off-by: Vasiliy Tolstov --- server/grpc/grpc.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 4015780d..671f2c07 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -659,10 +659,12 @@ func (g *grpcServer) Register() error { registered := g.registered g.Unlock() - if !registered { - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) - } + if registered { + return nil + } + + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) } // create registry options @@ -672,11 +674,6 @@ func (g *grpcServer) Register() error { return err } - // already registered? don't need to register subscribers - if registered { - return nil - } - g.Lock() defer g.Unlock() @@ -787,10 +784,10 @@ func (g *grpcServer) Start() error { g.RUnlock() return nil } - g.RUnlock() - config := g.Options() + g.RUnlock() + // micro: config.Transport.Listen(config.Address) var ts net.Listener @@ -822,10 +819,11 @@ func (g *grpcServer) Start() error { } g.Lock() g.opts.Address = ts.Addr().String() + subscribes := g.subscribers g.Unlock() // only connect if we're subscribed - if len(g.subscribers) > 0 { + if len(subscribes) > 0 { // connect to the broker if err := config.Broker.Connect(); err != nil { return err From 078dd4eb9bdfc0ea11e0d0e33696662152d2bbfb Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 13 Mar 2020 08:55:23 +0000 Subject: [PATCH 382/788] fix etcd (#1340) * fix etcd * update go mod --- go.mod | 8 +++++++- go.sum | 29 ----------------------------- store/etcd/config.go | 2 +- store/etcd/etcd.go | 4 ++-- 4 files changed, 10 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 1395da12..c77b4dd2 100644 --- a/go.mod +++ b/go.mod @@ -28,8 +28,11 @@ require ( github.com/gorilla/handlers v1.4.2 github.com/gorilla/websocket v1.4.1 github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect + github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect + github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect github.com/hashicorp/hcl v1.0.0 github.com/imdario/mergo v0.3.8 + github.com/jonboulle/clockwork v0.1.0 // indirect github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 github.com/json-iterator/go v1.1.9 github.com/kr/pretty v0.1.0 @@ -47,10 +50,12 @@ require ( github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 + github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 github.com/technoweenie/multipartstreamer v1.0.1 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect - go.etcd.io/etcd v0.5.0-alpha.5.0.20191031170918-4388404f56cb + github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect + go.etcd.io/bbolt v1.3.3 // indirect go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 @@ -60,4 +65,5 @@ require ( gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 + sigs.k8s.io/yaml v1.1.0 // indirect ) diff --git a/go.sum b/go.sum index ffc6da3e..a96be5b1 100644 --- a/go.sum +++ b/go.sum @@ -59,7 +59,6 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y= github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= @@ -76,8 +75,6 @@ github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wX github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.10.2 h1:VBodKICVPnwmDxstcW3biKcDSpFIfS/RELUXsZSBYK4= github.com/cloudflare/cloudflare-go v0.10.2/go.mod h1:qhVI5MKwBGhdNU89ZRz2plgYutcJ5PCekLxXn56w6SY= -github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa h1:OaNxuTZr7kxeODyLWsRMC+OD03aFUH+mW6r2d+MWa5Y= -github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko= github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= @@ -93,15 +90,12 @@ github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c= github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpu/goacmedns v0.0.1/go.mod h1:sesf/pNnCYwUevQEQfEwY0Y3DydlQWSGZbaMElOWxok= @@ -126,8 +120,6 @@ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKoh github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4 h1:qk/FSDDxo05wdJH28W+p5yivv7LuLYLRXPPD8KQCtZs= -github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= @@ -136,7 +128,6 @@ github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3 github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= @@ -175,7 +166,6 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -203,7 +193,6 @@ github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXi github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -216,12 +205,10 @@ github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/ github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg= github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= @@ -243,7 +230,6 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -292,9 +278,7 @@ github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1 github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= @@ -345,7 +329,6 @@ github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/Hzq github.com/nrdcg/dnspod-go v0.3.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgPTGKr6KQ= github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2SwKQ= github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw= -github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= @@ -419,9 +402,6 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1 github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= -github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4= -github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -435,13 +415,11 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= -github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc h1:yUaosFVTJwnltaHbSNC3i82I92quFs+OFPRl8kNMVwo= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= -github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= @@ -454,8 +432,6 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.etcd.io/etcd v0.5.0-alpha.5.0.20191031170918-4388404f56cb h1:OIEw2droD31lXVboIQzJFUuSJOxGFReUW6hmqTP10TE= -go.etcd.io/etcd v0.5.0-alpha.5.0.20191031170918-4388404f56cb/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -529,7 +505,6 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -567,7 +542,6 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= @@ -578,7 +552,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 h1:xQwXv67TxFo9nC1GJFyab5eq/5B590r6RlnL/G8Sz7w= @@ -639,14 +612,12 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= diff --git a/store/etcd/config.go b/store/etcd/config.go index 381abdb3..0e3ccb09 100644 --- a/store/etcd/config.go +++ b/store/etcd/config.go @@ -6,7 +6,7 @@ import ( "time" "github.com/micro/go-micro/v2/store" - "go.etcd.io/etcd/clientv3" + "github.com/coreos/etcd/clientv3" "google.golang.org/grpc" ) diff --git a/store/etcd/etcd.go b/store/etcd/etcd.go index 2462c55d..ad7d7279 100644 --- a/store/etcd/etcd.go +++ b/store/etcd/etcd.go @@ -11,8 +11,8 @@ import ( "github.com/micro/go-micro/v2/store" "github.com/pkg/errors" - "go.etcd.io/etcd/clientv3" - "go.etcd.io/etcd/clientv3/namespace" + "github.com/coreos/etcd/clientv3" + "github.com/coreos/etcd/clientv3/namespace" ) type etcdStore struct { From fbde872e7f0238ff864dd879a0d6ac0c3c7cc5d3 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 13 Mar 2020 12:30:44 +0300 Subject: [PATCH 383/788] Revert "server/grpc: fix ordering of register and check for registered (#1338)" (#1341) This reverts commit 62a644ddd898a75a19b89106312c1cf58f4acd70. --- server/grpc/grpc.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 671f2c07..4015780d 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -659,12 +659,10 @@ func (g *grpcServer) Register() error { registered := g.registered g.Unlock() - if registered { - return nil - } - - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) + if !registered { + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) + } } // create registry options @@ -674,6 +672,11 @@ func (g *grpcServer) Register() error { return err } + // already registered? don't need to register subscribers + if registered { + return nil + } + g.Lock() defer g.Unlock() @@ -784,10 +787,10 @@ func (g *grpcServer) Start() error { g.RUnlock() return nil } - config := g.Options() - g.RUnlock() + config := g.Options() + // micro: config.Transport.Listen(config.Address) var ts net.Listener @@ -819,11 +822,10 @@ func (g *grpcServer) Start() error { } g.Lock() g.opts.Address = ts.Addr().String() - subscribes := g.subscribers g.Unlock() // only connect if we're subscribed - if len(subscribes) > 0 { + if len(g.subscribers) > 0 { // connect to the broker if err := config.Broker.Connect(); err != nil { return err From 3543b275e08edd951bb8121a1a773c037154d759 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 13 Mar 2020 17:36:42 +0300 Subject: [PATCH 384/788] fix log level helper (#1342) Signed-off-by: Vasiliy Tolstov --- logger/helper.go | 4 +++- logger/level.go | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/logger/helper.go b/logger/helper.go index a78f907d..94c2f364 100644 --- a/logger/helper.go +++ b/logger/helper.go @@ -1,6 +1,8 @@ package logger -import "os" +import ( + "os" +) type Helper struct { Logger diff --git a/logger/level.go b/logger/level.go index 11fabe4b..915f0d47 100644 --- a/logger/level.go +++ b/logger/level.go @@ -116,11 +116,11 @@ func Fatalf(template string, args ...interface{}) { os.Exit(1) } -// Returns true if the given level is at or above the current logger level +// Returns true if the given level is at or lower the current logger level func V(lvl Level, log Logger) bool { l := DefaultLogger if log != nil { l = log } - return l.Options().Level >= lvl + return l.Options().Level <= lvl } From e803fb08554fa3890c90d4c180c751f3b35341db Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 13 Mar 2020 18:39:59 +0000 Subject: [PATCH 385/788] Runtime hacks (#1344) * Add Args/Image to runtime * remove the hacks --- runtime/default.go | 3 +- runtime/kubernetes/kubernetes.go | 49 ++++---- runtime/kubernetes/service.go | 16 +-- runtime/options.go | 35 ++++-- runtime/service.go | 8 +- runtime/service/proto/runtime.pb.go | 134 +++++++++++++--------- runtime/service/proto/runtime.pb.micro.go | 2 +- runtime/service/proto/runtime.proto | 10 +- runtime/service/service.go | 3 + store/etcd/config.go | 2 +- store/etcd/etcd.go | 4 +- util/kubernetes/client/client.go | 2 +- 12 files changed, 166 insertions(+), 102 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index 8230e8df..d1eaba54 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -184,7 +184,8 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error { } if len(options.Command) == 0 { - options.Command = []string{"go", "run", "."} + options.Command = []string{"go", "run"} + options.Args = []string{"."} } // create new service diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index a6590547..183ec6f7 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -2,8 +2,6 @@ package kubernetes import ( - "fmt" - "strings" "sync" "time" @@ -250,11 +248,6 @@ func (k *kubernetes) Init(opts ...runtime.Option) error { o(&k.options) } - // trim the source prefix if its a git url - if strings.HasPrefix(k.options.Source, "github.com") { - k.options.Source = strings.TrimPrefix(k.options.Source, "github.com/") - } - return nil } @@ -270,14 +263,20 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er o(&options) } - // hackish + // default type if it doesn't exist if len(options.Type) == 0 { options.Type = k.options.Type } - // determine the full source for this service - options.Source = k.sourceForService(s.Name) + // default the source if it doesn't exist + if len(s.Source) == 0 { + s.Source = k.options.Source + } + // determine the image from the source and options + options.Image = k.getImage(s, options) + + // create new service service := newService(s, options) // start the service @@ -334,10 +333,15 @@ func (k *kubernetes) List() ([]*runtime.Service, error) { // Update the service in place func (k *kubernetes) Update(s *runtime.Service) error { // create new kubernetes micro service - service := newService(s, runtime.CreateOptions{ - Type: k.options.Type, - Source: k.sourceForService(s.Name), - }) + opts := runtime.CreateOptions{ + Type: k.options.Type, + } + + // set image + opts.Image = k.getImage(s, opts) + + // new pseudo service + service := newService(s, opts) // update build time annotation service.kdeploy.Spec.Template.Metadata.Annotations["build"] = time.Now().Format(time.RFC3339) @@ -442,14 +446,15 @@ func NewRuntime(opts ...runtime.Option) runtime.Runtime { } } -// sourceForService determines the nested package name for github -// e.g src: docker.pkg.github.com/micro/services an srv: users/api -// would become docker.pkg.github.com/micro/services/users-api -func (k *kubernetes) sourceForService(name string) string { - if !strings.HasPrefix(k.options.Source, "docker.pkg.github.com") { - return k.options.Source +func (k *kubernetes) getImage(s *runtime.Service, options runtime.CreateOptions) string { + // use the image when its specified + if len(options.Image) > 0 { + return options.Image } - formattedName := strings.ReplaceAll(name, "/", "-") - return fmt.Sprintf("%v/%v", k.options.Source, formattedName) + if len(k.options.Image) > 0 { + return k.options.Image + } + + return "" } diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 73a9099d..5e751673 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -54,14 +54,12 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kdeploy.Metadata.Annotations["group"] = "micro" // update the deployment is a custom source is provided - if len(c.Source) > 0 { + if len(c.Image) > 0 { for i := range kdeploy.Spec.Template.PodSpec.Containers { - kdeploy.Spec.Template.PodSpec.Containers[i].Image = c.Source + kdeploy.Spec.Template.PodSpec.Containers[i].Image = c.Image kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{} - kdeploy.Spec.Template.PodSpec.Containers[i].Args = []string{name} + kdeploy.Spec.Template.PodSpec.Containers[i].Args = []string{} } - - kdeploy.Metadata.Annotations["source"] = c.Source } // define the environment values used by the container @@ -76,11 +74,15 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kdeploy.Spec.Template.PodSpec.Containers[0].Env = append(kdeploy.Spec.Template.PodSpec.Containers[0].Env, env...) } - // specify the command to exec - if strings.HasPrefix(c.Source, "github.com") && len(c.Command) > 0 { + // set the command if specified + if len(c.Command) > 0 { kdeploy.Spec.Template.PodSpec.Containers[0].Command = c.Command } + if len(c.Args) > 0 { + kdeploy.Spec.Template.PodSpec.Containers[0].Args = c.Args + } + return &service{ Service: s, kservice: kservice, diff --git a/runtime/options.go b/runtime/options.go index ab73a02e..489c6ee7 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -14,6 +14,8 @@ type Options struct { Type string // Source of the services repository Source string + // Base image to use + Image string } // WithSource sets the base image / repository @@ -37,14 +39,23 @@ func WithType(t string) Option { } } +// WithImage sets the image to use +func WithImage(t string) Option { + return func(o *Options) { + o.Image = t + } +} + type CreateOption func(o *CreateOptions) type ReadOption func(o *ReadOptions) // CreateOptions configure runtime services type CreateOptions struct { - // command to execute including args + // Command to execut Command []string + // Args to pass into command + Args []string // Environment to configure Env []string // Log output @@ -53,8 +64,8 @@ type CreateOptions struct { Type string // Retries before failing deploy Retries int - // Source of the service - Source string + // Specify the image to use + Image string } // ReadOptions queries runtime services @@ -74,18 +85,26 @@ func CreateType(t string) CreateOption { } } -// CreateSource sets the source of service to create -func CreateSource(t string) CreateOption { +// CreateImage sets the image to use +func CreateImage(img string) CreateOption { return func(o *CreateOptions) { - o.Source = t + o.Image = img } } // WithCommand specifies the command to execute -func WithCommand(args ...string) CreateOption { +func WithCommand(cmd ...string) CreateOption { return func(o *CreateOptions) { // set command - o.Command = args + o.Command = cmd + } +} + +// WithArgs specifies the command to execute +func WithArgs(args ...string) CreateOption { + return func(o *CreateOptions) { + // set command + o.Args = args } } diff --git a/runtime/service.go b/runtime/service.go index c211d91b..8f1dd6ab 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -3,6 +3,7 @@ package runtime import ( "io" "strconv" + "strings" "sync" "time" @@ -41,11 +42,8 @@ func newService(s *Service, c CreateOptions) *service { var args []string // set command - exec = c.Command[0] - // set args - if len(c.Command) > 1 { - args = c.Command[1:] - } + exec = strings.Join(c.Command, " ") + args = c.Args return &service{ Service: s, diff --git a/runtime/service/proto/runtime.pb.go b/runtime/service/proto/runtime.pb.go index 82161fff..4d8df642 100644 --- a/runtime/service/proto/runtime.pb.go +++ b/runtime/service/proto/runtime.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: runtime/service/proto/runtime.proto +// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto package go_micro_runtime @@ -38,7 +38,7 @@ func (m *Service) Reset() { *m = Service{} } func (m *Service) String() string { return proto.CompactTextString(m) } func (*Service) ProtoMessage() {} func (*Service) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{0} + return fileDescriptor_976fccef828ab1f0, []int{0} } func (m *Service) XXX_Unmarshal(b []byte) error { @@ -101,7 +101,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{1} + return fileDescriptor_976fccef828ab1f0, []int{1} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -153,10 +153,16 @@ func (m *Event) GetVersion() string { type CreateOptions struct { // command to pass in Command []string `protobuf:"bytes,1,rep,name=command,proto3" json:"command,omitempty"` + // args to pass into command + Args []string `protobuf:"bytes,2,rep,name=args,proto3" json:"args,omitempty"` // environment to pass in - Env []string `protobuf:"bytes,2,rep,name=env,proto3" json:"env,omitempty"` + Env []string `protobuf:"bytes,3,rep,name=env,proto3" json:"env,omitempty"` // output to send to - Output string `protobuf:"bytes,3,opt,name=output,proto3" json:"output,omitempty"` + Output string `protobuf:"bytes,4,opt,name=output,proto3" json:"output,omitempty"` + // create type of service + Type string `protobuf:"bytes,5,opt,name=type,proto3" json:"type,omitempty"` + // image to use + Image string `protobuf:"bytes,6,opt,name=image,proto3" json:"image,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -166,7 +172,7 @@ func (m *CreateOptions) Reset() { *m = CreateOptions{} } func (m *CreateOptions) String() string { return proto.CompactTextString(m) } func (*CreateOptions) ProtoMessage() {} func (*CreateOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{2} + return fileDescriptor_976fccef828ab1f0, []int{2} } func (m *CreateOptions) XXX_Unmarshal(b []byte) error { @@ -194,6 +200,13 @@ func (m *CreateOptions) GetCommand() []string { return nil } +func (m *CreateOptions) GetArgs() []string { + if m != nil { + return m.Args + } + return nil +} + func (m *CreateOptions) GetEnv() []string { if m != nil { return m.Env @@ -208,6 +221,20 @@ func (m *CreateOptions) GetOutput() string { return "" } +func (m *CreateOptions) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *CreateOptions) GetImage() string { + if m != nil { + return m.Image + } + return "" +} + type CreateRequest struct { Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` Options *CreateOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` @@ -220,7 +247,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{3} + return fileDescriptor_976fccef828ab1f0, []int{3} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -265,7 +292,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{4} + return fileDescriptor_976fccef828ab1f0, []int{4} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -302,7 +329,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{5} + return fileDescriptor_976fccef828ab1f0, []int{5} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -355,7 +382,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{6} + return fileDescriptor_976fccef828ab1f0, []int{6} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -394,7 +421,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{7} + return fileDescriptor_976fccef828ab1f0, []int{7} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -433,7 +460,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{8} + return fileDescriptor_976fccef828ab1f0, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -471,7 +498,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{9} + return fileDescriptor_976fccef828ab1f0, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -503,7 +530,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{10} + return fileDescriptor_976fccef828ab1f0, []int{10} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -541,7 +568,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{11} + return fileDescriptor_976fccef828ab1f0, []int{11} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -572,7 +599,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{12} + return fileDescriptor_976fccef828ab1f0, []int{12} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -604,7 +631,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{13} + return fileDescriptor_976fccef828ab1f0, []int{13} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -651,42 +678,45 @@ func init() { } func init() { - proto.RegisterFile("runtime/service/proto/runtime.proto", fileDescriptor_2434d8152598889b) + proto.RegisterFile("github.com/micro/go-micro/runtime/service/proto/runtime.proto", fileDescriptor_976fccef828ab1f0) } -var fileDescriptor_2434d8152598889b = []byte{ - // 521 bytes of a gzipped FileDescriptorProto +var fileDescriptor_976fccef828ab1f0 = []byte{ + // 563 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x4b, 0x6f, 0xd3, 0x40, - 0x10, 0xae, 0xeb, 0x34, 0x69, 0xc7, 0x18, 0x45, 0x2b, 0x84, 0x4c, 0xc5, 0x23, 0x32, 0x07, 0x7a, - 0x72, 0xa4, 0x54, 0x88, 0xd7, 0xb1, 0x09, 0x5c, 0x88, 0x90, 0x5c, 0xf5, 0x07, 0x2c, 0xc9, 0x08, - 0x59, 0xd4, 0xbb, 0xc6, 0xbb, 0xb6, 0x94, 0x13, 0x57, 0xfe, 0x1e, 0xff, 0x08, 0xed, 0x2b, 0xb6, - 0x53, 0x9b, 0x4b, 0x6e, 0x3b, 0xb3, 0x33, 0x9f, 0xbf, 0xc7, 0xca, 0xf0, 0xba, 0xac, 0x98, 0xcc, - 0x72, 0x9c, 0x0b, 0x2c, 0xeb, 0x6c, 0x83, 0xf3, 0xa2, 0xe4, 0x92, 0xcf, 0x6d, 0x37, 0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0xa2, 0xed, 0xb8, 0x04, 0x5a, 0x42, 0xdf, 0x78, 0xdc, 0xc4, 0x6b, + 0x2f, 0xc3, 0x26, 0x5e, 0x07, 0xf1, 0x68, 0x38, 0x63, 0x6d, 0x13, 0xdc, 0x5e, 0x74, 0x4d, 0x70, + 0x07, 0xa9, 0x68, 0x99, 0x2a, 0x88, 0x26, 0x99, 0xb5, 0xbc, 0x9a, 0x64, 0xd6, 0xf3, 0x0b, 0x4f, + 0x6e, 0xfb, 0xfa, 0xcf, 0x7f, 0xf5, 0x3f, 0x00, 0x00, 0xff, 0xff, 0x14, 0xdd, 0xee, 0x9f, 0x3a, + 0x06, 0x00, 0x00, } diff --git a/runtime/service/proto/runtime.pb.micro.go b/runtime/service/proto/runtime.pb.micro.go index 12b6691b..ddcba829 100644 --- a/runtime/service/proto/runtime.pb.micro.go +++ b/runtime/service/proto/runtime.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: runtime/service/proto/runtime.proto +// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto package go_micro_runtime diff --git a/runtime/service/proto/runtime.proto b/runtime/service/proto/runtime.proto index 9e0d7722..3fb235b9 100644 --- a/runtime/service/proto/runtime.proto +++ b/runtime/service/proto/runtime.proto @@ -31,10 +31,16 @@ message Event { message CreateOptions { // command to pass in repeated string command = 1; + // args to pass into command + repeated string args = 2; // environment to pass in - repeated string env = 2; + repeated string env = 3; // output to send to - string output = 3; + string output = 4; + // create type of service + string type = 5; + // image to use + string image = 6; } message CreateRequest { diff --git a/runtime/service/service.go b/runtime/service/service.go index f7e3e97a..96f3ebbd 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -50,7 +50,10 @@ func (s *svc) Create(svc *runtime.Service, opts ...runtime.CreateOption) error { }, Options: &pb.CreateOptions{ Command: options.Command, + Args: options.Args, Env: options.Env, + Type: options.Type, + Image: options.Image, }, } diff --git a/store/etcd/config.go b/store/etcd/config.go index 0e3ccb09..f50b7f54 100644 --- a/store/etcd/config.go +++ b/store/etcd/config.go @@ -5,8 +5,8 @@ import ( cryptotls "crypto/tls" "time" - "github.com/micro/go-micro/v2/store" "github.com/coreos/etcd/clientv3" + "github.com/micro/go-micro/v2/store" "google.golang.org/grpc" ) diff --git a/store/etcd/etcd.go b/store/etcd/etcd.go index ad7d7279..684366df 100644 --- a/store/etcd/etcd.go +++ b/store/etcd/etcd.go @@ -9,10 +9,10 @@ import ( "strings" "time" - "github.com/micro/go-micro/v2/store" - "github.com/pkg/errors" "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/clientv3/namespace" + "github.com/micro/go-micro/v2/store" + "github.com/pkg/errors" ) type etcdStore struct { diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 2b9d7db0..6786f6c7 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -271,7 +271,7 @@ func NewDeployment(name, version, typ string) *Deployment { Name: name, Image: DefaultImage, Env: []EnvVar{env}, - Command: []string{"go", "run", "main.go"}, + Command: []string{"go", "run", "."}, Ports: []ContainerPort{{ Name: "service-port", ContainerPort: 8080, From 60993e6275a6a7ceb54b30cf54c29901adbf38aa Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 14 Mar 2020 00:44:55 +0300 Subject: [PATCH 386/788] config/source/service: base64 fix (#1345) Signed-off-by: Vasiliy Tolstov --- config/source/service/proto/service.pb.go | 100 +++++++++--------- .../source/service/proto/service.pb.micro.go | 2 +- config/source/service/proto/service.proto | 2 +- config/source/service/util.go | 2 +- 4 files changed, 51 insertions(+), 55 deletions(-) diff --git a/config/source/service/proto/service.pb.go b/config/source/service/proto/service.pb.go index e66ca37b..deef8a75 100644 --- a/config/source/service/proto/service.pb.go +++ b/config/source/service/proto/service.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/config/source/service/proto/service.proto +// source: service.proto package service @@ -21,7 +21,7 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type ChangeSet struct { - Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` + Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` Checksum string `protobuf:"bytes,2,opt,name=checksum,proto3" json:"checksum,omitempty"` Format string `protobuf:"bytes,3,opt,name=format,proto3" json:"format,omitempty"` Source string `protobuf:"bytes,4,opt,name=source,proto3" json:"source,omitempty"` @@ -35,7 +35,7 @@ func (m *ChangeSet) Reset() { *m = ChangeSet{} } func (m *ChangeSet) String() string { return proto.CompactTextString(m) } func (*ChangeSet) ProtoMessage() {} func (*ChangeSet) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{0} + return fileDescriptor_a0b84a42fa06f626, []int{0} } func (m *ChangeSet) XXX_Unmarshal(b []byte) error { @@ -56,11 +56,11 @@ func (m *ChangeSet) XXX_DiscardUnknown() { var xxx_messageInfo_ChangeSet proto.InternalMessageInfo -func (m *ChangeSet) GetData() []byte { +func (m *ChangeSet) GetData() string { if m != nil { return m.Data } - return nil + return "" } func (m *ChangeSet) GetChecksum() string { @@ -104,7 +104,7 @@ func (m *Change) Reset() { *m = Change{} } func (m *Change) String() string { return proto.CompactTextString(m) } func (*Change) ProtoMessage() {} func (*Change) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{1} + return fileDescriptor_a0b84a42fa06f626, []int{1} } func (m *Change) XXX_Unmarshal(b []byte) error { @@ -157,7 +157,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{2} + return fileDescriptor_a0b84a42fa06f626, []int{2} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -195,7 +195,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{3} + return fileDescriptor_a0b84a42fa06f626, []int{3} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -227,7 +227,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{4} + return fileDescriptor_a0b84a42fa06f626, []int{4} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -265,7 +265,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{5} + return fileDescriptor_a0b84a42fa06f626, []int{5} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -297,7 +297,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{6} + return fileDescriptor_a0b84a42fa06f626, []int{6} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -335,7 +335,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{7} + return fileDescriptor_a0b84a42fa06f626, []int{7} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -366,7 +366,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{8} + return fileDescriptor_a0b84a42fa06f626, []int{8} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -398,7 +398,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{9} + return fileDescriptor_a0b84a42fa06f626, []int{9} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -438,7 +438,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{10} + return fileDescriptor_a0b84a42fa06f626, []int{10} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -484,7 +484,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{11} + return fileDescriptor_a0b84a42fa06f626, []int{11} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -524,7 +524,7 @@ func (m *WatchRequest) Reset() { *m = WatchRequest{} } func (m *WatchRequest) String() string { return proto.CompactTextString(m) } func (*WatchRequest) ProtoMessage() {} func (*WatchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{12} + return fileDescriptor_a0b84a42fa06f626, []int{12} } func (m *WatchRequest) XXX_Unmarshal(b []byte) error { @@ -571,7 +571,7 @@ func (m *WatchResponse) Reset() { *m = WatchResponse{} } func (m *WatchResponse) String() string { return proto.CompactTextString(m) } func (*WatchResponse) ProtoMessage() {} func (*WatchResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_54fcef0de4ea31b3, []int{13} + return fileDescriptor_a0b84a42fa06f626, []int{13} } func (m *WatchResponse) XXX_Unmarshal(b []byte) error { @@ -623,39 +623,35 @@ func init() { proto.RegisterType((*WatchResponse)(nil), "WatchResponse") } -func init() { - proto.RegisterFile("github.com/micro/go-micro/config/source/service/proto/service.proto", fileDescriptor_54fcef0de4ea31b3) -} +func init() { proto.RegisterFile("service.proto", fileDescriptor_a0b84a42fa06f626) } -var fileDescriptor_54fcef0de4ea31b3 = []byte{ - // 455 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xcd, 0x8e, 0x9b, 0x30, - 0x10, 0xc7, 0x43, 0x92, 0xa5, 0x65, 0x02, 0xa4, 0xf2, 0xa1, 0x42, 0xa8, 0x52, 0x23, 0xa4, 0x4a, - 0x51, 0xab, 0x9a, 0x55, 0xfa, 0x00, 0xad, 0x94, 0x1e, 0x7b, 0xa2, 0xaa, 0xf6, 0xec, 0x75, 0x66, - 0x03, 0xea, 0x12, 0x53, 0x6c, 0xf6, 0x1d, 0xf6, 0xad, 0x2b, 0x7f, 0xb0, 0x40, 0x0e, 0x91, 0xb2, - 0x37, 0xcf, 0xd7, 0x7f, 0xc6, 0xfe, 0x0d, 0xc0, 0xfe, 0x58, 0xa9, 0xb2, 0xbb, 0xa7, 0x5c, 0xd4, - 0x79, 0x5d, 0xf1, 0x56, 0xe4, 0x47, 0xf1, 0xd5, 0x1e, 0xb8, 0x38, 0x3d, 0x54, 0xc7, 0x5c, 0x8a, - 0xae, 0xe5, 0x98, 0x4b, 0x6c, 0x9f, 0x2a, 0x8e, 0x79, 0xd3, 0x0a, 0x25, 0x7a, 0x8b, 0x1a, 0x2b, - 0x7b, 0xf6, 0x20, 0xd8, 0x97, 0xec, 0x74, 0xc4, 0xdf, 0xa8, 0x08, 0x81, 0xe5, 0x81, 0x29, 0x96, - 0x78, 0x1b, 0x6f, 0x1b, 0x16, 0xe6, 0x4c, 0x52, 0x78, 0xcb, 0x4b, 0xe4, 0x7f, 0x65, 0x57, 0x27, - 0xf3, 0x8d, 0xb7, 0x0d, 0x8a, 0x17, 0x9b, 0xbc, 0x07, 0xff, 0x41, 0xb4, 0x35, 0x53, 0xc9, 0xc2, - 0x44, 0x9c, 0xa5, 0xfd, 0xb6, 0x77, 0xb2, 0xb4, 0x7e, 0x6b, 0x91, 0x0f, 0x10, 0xa8, 0xaa, 0x46, - 0xa9, 0x58, 0xdd, 0x24, 0x37, 0x1b, 0x6f, 0xbb, 0x28, 0x06, 0x47, 0x76, 0x00, 0xdf, 0x8e, 0xa2, - 0xf3, 0x4e, 0xac, 0x46, 0xd9, 0x30, 0x8e, 0x66, 0x98, 0xa0, 0x18, 0x1c, 0x7a, 0xca, 0x86, 0xa9, - 0xd2, 0x4d, 0x63, 0xce, 0x64, 0x0b, 0x01, 0xef, 0xaf, 0x61, 0x86, 0x59, 0xed, 0x80, 0xbe, 0x5c, - 0xac, 0x18, 0x82, 0xd9, 0x2d, 0x44, 0xfb, 0x16, 0x99, 0xc2, 0x02, 0xff, 0x75, 0x28, 0x15, 0xf9, - 0x08, 0xbe, 0x8d, 0x9a, 0x4e, 0xab, 0xdd, 0x1b, 0x57, 0x57, 0x38, 0x77, 0xf6, 0x0e, 0xe2, 0xbe, - 0x42, 0x36, 0xe2, 0x24, 0x51, 0x6b, 0xfc, 0x69, 0x0e, 0x57, 0x6a, 0xf4, 0x15, 0x83, 0xc6, 0x4f, - 0x7c, 0xc4, 0xeb, 0x34, 0xfa, 0x0a, 0xa7, 0x11, 0xc1, 0xea, 0x57, 0x25, 0x95, 0x53, 0xc8, 0x72, - 0x08, 0xad, 0x69, 0xc3, 0x5a, 0xf1, 0x89, 0x3d, 0x76, 0x28, 0x13, 0x6f, 0xb3, 0x98, 0x28, 0x5a, - 0x77, 0xf6, 0x1d, 0x56, 0x05, 0xb2, 0x43, 0x3f, 0xc1, 0xd5, 0xcf, 0xae, 0x3b, 0x5a, 0x81, 0xa1, - 0xe3, 0xe5, 0x3b, 0xfc, 0x80, 0xf0, 0x8e, 0x29, 0x5e, 0xbe, 0xbe, 0xe5, 0x1d, 0x44, 0x4e, 0xc1, - 0xf5, 0xbc, 0x2c, 0x31, 0x59, 0x8c, 0xf9, 0x85, 0xc5, 0xd8, 0x3d, 0xcf, 0xc1, 0xdf, 0x9b, 0x0f, - 0x87, 0x7c, 0x01, 0xdf, 0x12, 0x27, 0x31, 0x9d, 0x2c, 0x4b, 0xba, 0xa6, 0x67, 0xab, 0x30, 0xd3, - 0xc9, 0x16, 0x2d, 0x89, 0xe9, 0x64, 0x2b, 0xd2, 0x35, 0x3d, 0x63, 0x6e, 0x92, 0x2d, 0x43, 0x12, - 0xd3, 0x09, 0xfe, 0x74, 0x4d, 0xcf, 0xe0, 0xce, 0xc8, 0x27, 0x58, 0x6a, 0x9e, 0x24, 0xa4, 0x23, - 0xca, 0x69, 0x44, 0xc7, 0x90, 0x6d, 0x9a, 0x86, 0x40, 0x42, 0x3a, 0x82, 0x99, 0x46, 0x74, 0x4c, - 0x26, 0x9b, 0x91, 0xcf, 0x70, 0x63, 0x1e, 0x8e, 0x44, 0x74, 0x8c, 0x20, 0x8d, 0xe9, 0xe4, 0x3d, - 0xb3, 0xd9, 0xad, 0x77, 0xef, 0x9b, 0xbf, 0xc3, 0xb7, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xcb, - 0x26, 0xcb, 0xd9, 0x64, 0x04, 0x00, 0x00, +var fileDescriptor_a0b84a42fa06f626 = []byte{ + // 424 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xcd, 0x6a, 0xdb, 0x40, + 0x10,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0x4f, 0x60, 0x26, 0x21, + 0x9f, 0x92, 0x61, 0x0b, 0xfc, 0x08, 0x37, 0xe6, 0xe1, 0x30, 0xe4, 0x53, 0x04, 0x49, 0xc4, 0x67, + 0xef, 0xc9, 0x16, 0xb7, 0xde, 0x6f, 0xdf, 0xfc, 0x1d, 0xbe, 0xfc, 0x0b, 0x00, 0x00, 0xff, 0xff, + 0x1c, 0x3e, 0x57, 0xb0, 0x2e, 0x04, 0x00, 0x00, } diff --git a/config/source/service/proto/service.pb.micro.go b/config/source/service/proto/service.pb.micro.go index 4e69cf12..17c0288e 100644 --- a/config/source/service/proto/service.pb.micro.go +++ b/config/source/service/proto/service.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/config/source/service/proto/service.proto +// source: service.proto package service diff --git a/config/source/service/proto/service.proto b/config/source/service/proto/service.proto index 91e563ac..68ddabad 100644 --- a/config/source/service/proto/service.proto +++ b/config/source/service/proto/service.proto @@ -10,7 +10,7 @@ service Config { } message ChangeSet { - bytes data = 1; + string data = 1; string checksum = 2; string format = 3; string source = 4; diff --git a/config/source/service/util.go b/config/source/service/util.go index a2f71e45..ad301918 100644 --- a/config/source/service/util.go +++ b/config/source/service/util.go @@ -9,7 +9,7 @@ import ( func toChangeSet(c *proto.ChangeSet) *source.ChangeSet { return &source.ChangeSet{ - Data: c.Data, + Data: []byte(c.Data), Checksum: c.Checksum, Format: c.Format, Timestamp: time.Unix(c.Timestamp, 0), From 609f4826b35dfd01096e0407f7bb4878a15bcc16 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 14 Mar 2020 01:15:09 +0300 Subject: [PATCH 387/788] server: remove duplicate code (#1346) Signed-off-by: Vasiliy Tolstov --- server/rpc_router.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/server/rpc_router.go b/server/rpc_router.go index 33561449..d292880c 100644 --- a/server/rpc_router.go +++ b/server/rpc_router.go @@ -547,18 +547,6 @@ func (router *router) ProcessMessage(ctx context.Context, msg Message) (err erro req = req.Elem() } - if handler.reqType.Kind() == reflect.Ptr { - req = reflect.New(handler.reqType.Elem()) - } else { - req = reflect.New(handler.reqType) - isVal = true - } - - // if its a value get the element - if isVal { - req = req.Elem() - } - cc := msg.Codec() // read the header. mostly a noop From 0449138f61f5680ddc86a1d10581dc9e400ebc1a Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 14 Mar 2020 21:18:41 +0000 Subject: [PATCH 388/788] fix panic (#1348) --- runtime/kubernetes/service.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 5e751673..f04f9a14 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -38,6 +38,11 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kdeploy.Spec.Template.Metadata.Annotations = make(map[string]string) } + // create if non existent + if s.Metadata == nil { + s.Metadata = make(map[string]string) + } + // add the service metadata to the k8s labels, do this first so we // don't override any labels used by the runtime, e.g. name for k, v := range s.Metadata { From ca8684a886fa0f641f217e82bf6db73d6a040363 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 15 Mar 2020 15:09:18 +0000 Subject: [PATCH 389/788] fix k8s issues (#1349) --- runtime/kubernetes/kubernetes.go | 103 +++++++++++++++++++++++-------- 1 file changed, 78 insertions(+), 25 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 183ec6f7..6f23ba71 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -27,7 +27,7 @@ type kubernetes struct { // getService queries kubernetes for micro service // NOTE: this function is not thread-safe -func (k *kubernetes) getService(labels map[string]string) ([]*runtime.Service, error) { +func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { // get the service status serviceList := new(client.ServiceList) r := &client.Resource{ @@ -61,7 +61,7 @@ func (k *kubernetes) getService(labels map[string]string) ([]*runtime.Service, e } // service map - svcMap := make(map[string]*runtime.Service) + svcMap := make(map[string]*service) // collect info from kubernetes service for _, kservice := range serviceList.Items { @@ -71,15 +71,18 @@ func (k *kubernetes) getService(labels map[string]string) ([]*runtime.Service, e version := kservice.Metadata.Labels["version"] // save as service - svcMap[name+version] = &runtime.Service{ - Name: name, - Version: version, - Metadata: make(map[string]string), + svcMap[name+version] = &service{ + Service: &runtime.Service{ + Name: name, + Version: version, + Metadata: make(map[string]string), + }, + kservice: &kservice, } // copy annotations metadata into service metadata for k, v := range kservice.Metadata.Annotations { - svcMap[name+version].Metadata[k] = v + svcMap[name+version].Service.Metadata[k] = v } } @@ -99,9 +102,9 @@ func (k *kubernetes) getService(labels map[string]string) ([]*runtime.Service, e // set the service name, version and source // based on existing annotations we stored - svc.Name = kdep.Metadata.Annotations["name"] - svc.Version = kdep.Metadata.Annotations["version"] - svc.Source = kdep.Metadata.Annotations["source"] + svc.Service.Name = kdep.Metadata.Annotations["name"] + svc.Service.Version = kdep.Metadata.Annotations["version"] + svc.Service.Source = kdep.Metadata.Annotations["source"] // delete from metadata delete(kdep.Metadata.Annotations, "name") @@ -110,7 +113,7 @@ func (k *kubernetes) getService(labels map[string]string) ([]*runtime.Service, e // copy all annotations metadata into service metadata for k, v := range kdep.Metadata.Annotations { - svc.Metadata[k] = v + svc.Service.Metadata[k] = v } // get the status from the pods @@ -130,12 +133,14 @@ func (k *kubernetes) getService(labels map[string]string) ([]*runtime.Service, e if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Runtime setting %s service deployment status: %v", name, status) } - svc.Metadata["status"] = status + svc.Service.Metadata["status"] = status + // save deployment + svc.kdeploy = &kdep } } // collect all the services and return - services := make([]*runtime.Service, 0, len(serviceList.Items)) + services := make([]*service, 0, len(serviceList.Items)) for _, service := range svcMap { services = append(services, service) @@ -311,7 +316,17 @@ func (k *kubernetes) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error labels["micro"] = options.Type } - return k.getService(labels) + srvs, err := k.getService(labels) + if err != nil { + return nil, err + } + + var services []*runtime.Service + for _, service := range srvs { + services = append(services, service.Service) + } + + return services, nil } // List the managed services @@ -327,26 +342,64 @@ func (k *kubernetes) List() ([]*runtime.Service, error) { logger.Debugf("Runtime listing all micro services") } - return k.getService(labels) + srvs, err := k.getService(labels) + if err != nil { + return nil, err + } + + var services []*runtime.Service + for _, service := range srvs { + services = append(services, service.Service) + } + + return services, nil } // Update the service in place func (k *kubernetes) Update(s *runtime.Service) error { - // create new kubernetes micro service - opts := runtime.CreateOptions{ - Type: k.options.Type, + // get the existing service + // set the default labels + labels := map[string]string{ + "micro": k.options.Type, } - // set image - opts.Image = k.getImage(s, opts) + if len(s.Name) > 0 { + labels["name"] = client.Format(s.Name) + } - // new pseudo service - service := newService(s, opts) + if len(s.Version) > 0 { + labels["version"] = s.Version + } - // update build time annotation - service.kdeploy.Spec.Template.Metadata.Annotations["build"] = time.Now().Format(time.RFC3339) + // get the existing service + services, err := k.getService(labels) + if err != nil { + return err + } - return service.Update(k.client) + // update the relevant services + for _, service := range services { + // nil check + if service.kdeploy.Metadata == nil || service.kdeploy.Metadata.Annotations == nil { + md := new(client.Metadata) + md.Annotations = make(map[string]string) + service.kdeploy.Metadata = md + } + + // update metadata + for k, v := range s.Metadata { + service.kdeploy.Metadata.Annotations[k] = v + } + // update build time annotation + service.kdeploy.Spec.Template.Metadata.Annotations["build"] = time.Now().Format(time.RFC3339) + + // update the service + if err := service.Update(k.client); err != nil { + return err + } + } + + return nil } // Delete removes a service From d91c14eb30ea6745422c7bb7cf59b14ff7c7fb2e Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 16 Mar 2020 09:53:15 +0000 Subject: [PATCH 390/788] grpc client error fix (#1351) Co-authored-by: Ben Toogood --- client/grpc/grpc.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index c0900655..df1de990 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -445,6 +445,10 @@ func (g *grpcClient) Call(ctx context.Context, req client.Request, rsp interface // call backoff first. Someone may want an initial start delay t, err := callOpts.Backoff(ctx, req, i) if err != nil { + if verr, ok := err.(*errors.Error); ok { + return verr + } + return errors.InternalServerError("go.micro.client", err.Error()) } From 247707f5835bfed9da404c88dcb10d021c2c6a44 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 16 Mar 2020 10:30:56 +0000 Subject: [PATCH 391/788] Return store.ErrNotFound if not found when calling over rpc (#1353) Co-authored-by: Ben Toogood --- api/server/auth/auth.go | 1 + store/service/service.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index c57c7b50..a7391c18 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -63,6 +63,7 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // If there is no auth login url set, 401 if loginURL == "" { w.WriteHeader(401) + return } // Redirect to the login path diff --git a/store/service/service.go b/store/service/service.go index 5b448a8c..90443744 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -7,6 +7,7 @@ import ( "time" "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/store" pb "github.com/micro/go-micro/v2/store/service/proto" @@ -61,7 +62,9 @@ func (s *serviceStore) Context() context.Context { // Sync all the known records func (s *serviceStore) List(opts ...store.ListOption) ([]string, error) { stream, err := s.Client.List(s.Context(), &pb.ListRequest{}, client.WithAddress(s.Nodes...)) - if err != nil { + if verr, ok := err.(*errors.Error); ok && verr.Code == 404 { + return nil, store.ErrNotFound + } else if err != nil { return nil, err } defer stream.Close() @@ -98,7 +101,9 @@ func (s *serviceStore) Read(key string, opts ...store.ReadOption) ([]*store.Reco Prefix: options.Prefix, }, }, client.WithAddress(s.Nodes...)) - if err != nil { + if verr, ok := err.(*errors.Error); ok && verr.Code == 404 { + return nil, store.ErrNotFound + } else if err != nil { return nil, err } @@ -133,6 +138,9 @@ func (s *serviceStore) Delete(key string, opts ...store.DeleteOption) error { _, err := s.Client.Delete(s.Context(), &pb.DeleteRequest{ Key: key, }, client.WithAddress(s.Nodes...)) + if verr, ok := err.(*errors.Error); ok && verr.Code == 404 { + return store.ErrNotFound + } return err } From ac333d9d47f98dfd5050005d5396378d012c655d Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 16 Mar 2020 13:33:38 +0300 Subject: [PATCH 392/788] client/grpc: unwrap error after call (#1352) Signed-off-by: Vasiliy Tolstov --- client/grpc/grpc.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index df1de990..1f92b7c4 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -445,10 +445,6 @@ func (g *grpcClient) Call(ctx context.Context, req client.Request, rsp interface // call backoff first. Someone may want an initial start delay t, err := callOpts.Backoff(ctx, req, i) if err != nil { - if verr, ok := err.(*errors.Error); ok { - return verr - } - return errors.InternalServerError("go.micro.client", err.Error()) } @@ -469,6 +465,10 @@ func (g *grpcClient) Call(ctx context.Context, req client.Request, rsp interface // make the call err = gcall(ctx, node, req, rsp, callOpts) + if verr, ok := err.(*errors.Error); ok { + return verr + } + g.opts.Selector.Mark(service, node, err) return err } From 5712aafba93253b72616bd562e5d22836c1440b6 Mon Sep 17 00:00:00 2001 From: "li.peng" Date: Mon, 16 Mar 2020 18:45:33 +0800 Subject: [PATCH 393/788] fix: context cancel (#1350) Co-authored-by: Asim Aslam --- util/kubernetes/client/watch.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/kubernetes/client/watch.go b/util/kubernetes/client/watch.go index c55a406a..833ee534 100644 --- a/util/kubernetes/client/watch.go +++ b/util/kubernetes/client/watch.go @@ -98,10 +98,12 @@ func newWatcher(req *api.Request) (Watcher, error) { // do the raw request res, err := req.Raw() if err != nil { + cancel() return nil, err } if res.StatusCode < 200 || res.StatusCode >= 300 { + cancel() // close the response body res.Body.Close() // return an error From 03031a694da1b256d0d7f2afb1a2926954c63c85 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 16 Mar 2020 23:47:34 +0000 Subject: [PATCH 394/788] use pod phase/status (#1356) --- runtime/kubernetes/kubernetes.go | 25 ++++++++++++++----------- util/kubernetes/client/types.go | 3 ++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 6f23ba71..16240189 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -117,19 +117,22 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { } // get the status from the pods - status := "unknown" - if len(podList.Items) > 0 { - switch podList.Items[0].Status.Conditions[0].Type { - case "PodScheduled": - status = "starting" - case "Initialized": - status = "starting" - case "Ready": - status = "ready" - case "ContainersReady": - status = "ready" + var status string + + for _, item := range podList.Items { + switch item.Status.Phase { + case "Failed": + status = item.Status.Reason + default: + status = item.Status.Phase } } + + // unknown status + if len(status) == 0 { + status = "n/a" + } + if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Runtime setting %s service deployment status: %v", name, status) } diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index b82a80df..a747ad2a 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -103,9 +103,10 @@ type Pod struct { // PodStatus type PodStatus struct { + Conditions []PodCondition `json:"conditions,omitempty"` PodIP string `json:"podIP"` Phase string `json:"phase"` - Conditions []PodCondition `json:"conditions,omitempty"` + Reason string `json:"reason"` } // PodCondition describes the state of pod From ab7312706317f368c407ca70502cea7b548cc2a3 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 17 Mar 2020 14:27:20 +0300 Subject: [PATCH 395/788] grpc client/server fixes (#1355) * grpc client/server fixes Signed-off-by: Vasiliy Tolstov --- client/grpc/error.go | 27 +++++++++++++++------------ client/grpc/grpc.go | 2 +- errors/errors.go | 19 +++++++++++++++++++ errors/errors_test.go | 16 ++++++++++++++++ server/grpc/grpc.go | 19 +++++-------------- server/grpc/util.go | 11 ----------- store/service/service.go | 10 +++++++--- 7 files changed, 63 insertions(+), 41 deletions(-) diff --git a/client/grpc/error.go b/client/grpc/error.go index b625d1d8..1cd36842 100644 --- a/client/grpc/error.go +++ b/client/grpc/error.go @@ -17,18 +17,21 @@ func microError(err error) error { } // grpc error - if s, ok := status.FromError(err); ok { - details := s.Details() - if len(details) == 0 { - if e := errors.Parse(s.Message()); e.Code > 0 { - return e // actually a micro error - } - return errors.InternalServerError("go.micro.client", s.Message()) - } - // return first error from details - return details[0].(error) + s, ok := status.FromError(err) + if !ok { + return err } - // do nothing - return err + // return first error from details + if details := s.Details(); len(details) > 0 { + return microError(details[0].(error)) + } + + // try to decode micro *errors.Error + if e := errors.Parse(s.Message()); e.Code > 0 { + return e // actually a micro error + } + + // fallback + return errors.InternalServerError("go.micro.client", s.Message()) } diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 1f92b7c4..432ef539 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -465,11 +465,11 @@ func (g *grpcClient) Call(ctx context.Context, req client.Request, rsp interface // make the call err = gcall(ctx, node, req, rsp, callOpts) + g.opts.Selector.Mark(service, node, err) if verr, ok := err.(*errors.Error); ok { return verr } - g.opts.Selector.Mark(service, node, err) return err } diff --git a/errors/errors.go b/errors/errors.go index df6e6c9f..6c6598aa 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -115,3 +115,22 @@ func InternalServerError(id, format string, a ...interface{}) error { Status: http.StatusText(500), } } + +func Equal(err1 error, err2 error) bool { + verr1, ok1 := err1.(*Error) + verr2, ok2 := err2.(*Error) + + if ok1 != ok2 { + return false + } + + if !ok1 { + return err1 == err2 + } + + if verr1.Code != verr2.Code { + return false + } + + return true +} diff --git a/errors/errors_test.go b/errors/errors_test.go index 757d275d..662dd8d0 100644 --- a/errors/errors_test.go +++ b/errors/errors_test.go @@ -1,10 +1,26 @@ package errors import ( + er "errors" "net/http" "testing" ) +func TestEqual(t *testing.T) { + err1 := NotFound("myid1", "msg1") + err2 := NotFound("myid2", "msg2") + + if !Equal(err1, err2) { + t.Fatal("errors must be equal") + } + + err3 := er.New("my test err") + if Equal(err1, err3) { + t.Fatal("errors must be not equal") + } + +} + func TestErrors(t *testing.T) { testData := []*Error{ { diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 4015780d..af71aa5e 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -279,6 +279,9 @@ func (g *grpcServer) handler(srv interface{}, stream grpc.ServerStream) error { // serve the actual request using the request router if err := r.ServeRequest(ctx, request, response); err != nil { + if _, ok := status.FromError(err); ok { + return err + } return status.Errorf(codes.Internal, err.Error()) } @@ -379,7 +382,6 @@ func (g *grpcServer) processRequest(stream grpc.ServerStream, service *service, for i := len(g.opts.HdlrWrappers); i > 0; i-- { fn = g.opts.HdlrWrappers[i-1](fn) } - statusCode := codes.OK statusDesc := "" // execute the handler @@ -402,24 +404,19 @@ func (g *grpcServer) processRequest(stream grpc.ServerStream, service *service, if err != nil { return err } - case *rpcError: - // rpcError handling may be we have ability to attach it to details? - statusCode = verr.code - statusDesc = verr.desc - errStatus = status.New(statusCode, statusDesc) default: // default case user pass own error type that not proto based statusCode = convertCode(verr) statusDesc = verr.Error() errStatus = status.New(statusCode, statusDesc) } + return errStatus.Err() } if err := stream.SendMsg(replyv.Interface()); err != nil { return err } - return status.New(statusCode, statusDesc).Err() } } @@ -459,8 +456,7 @@ func (g *grpcServer) processStream(stream grpc.ServerStream, service *service, m statusCode := codes.OK statusDesc := "" - appErr := fn(ctx, r, ss) - if appErr != nil { + if appErr := fn(ctx, r, ss); appErr != nil { var err error var errStatus *status.Status switch verr := appErr.(type) { @@ -480,11 +476,6 @@ func (g *grpcServer) processStream(stream grpc.ServerStream, service *service, m if err != nil { return err } - case *rpcError: - // rpcError handling may be we have ability to attach it to details? - statusCode = verr.code - statusDesc = verr.desc - errStatus = status.New(statusCode, statusDesc) default: // default case user pass own error type that not proto based statusCode = convertCode(verr) diff --git a/server/grpc/util.go b/server/grpc/util.go index 05835488..dfb467ab 100644 --- a/server/grpc/util.go +++ b/server/grpc/util.go @@ -2,7 +2,6 @@ package grpc import ( "context" - "fmt" "io" "os" "sync" @@ -10,16 +9,6 @@ import ( "google.golang.org/grpc/codes" ) -// rpcError defines the status from an RPC. -type rpcError struct { - code codes.Code - desc string -} - -func (e *rpcError) Error() string { - return fmt.Sprintf("rpc error: code = %d desc = %s", e.code, e.desc) -} - // convertCode converts a standard Go error into its canonical code. Note that // this is only used to translate the error returned by the server applications. func convertCode(err error) codes.Code { diff --git a/store/service/service.go b/store/service/service.go index 90443744..b15340ff 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -62,7 +62,7 @@ func (s *serviceStore) Context() context.Context { // Sync all the known records func (s *serviceStore) List(opts ...store.ListOption) ([]string, error) { stream, err := s.Client.List(s.Context(), &pb.ListRequest{}, client.WithAddress(s.Nodes...)) - if verr, ok := err.(*errors.Error); ok && verr.Code == 404 { + if err != nil && errors.Equal(err, errors.NotFound("", "")) { return nil, store.ErrNotFound } else if err != nil { return nil, err @@ -101,7 +101,7 @@ func (s *serviceStore) Read(key string, opts ...store.ReadOption) ([]*store.Reco Prefix: options.Prefix, }, }, client.WithAddress(s.Nodes...)) - if verr, ok := err.(*errors.Error); ok && verr.Code == 404 { + if err != nil && errors.Equal(err, errors.NotFound("", "")) { return nil, store.ErrNotFound } else if err != nil { return nil, err @@ -129,6 +129,9 @@ func (s *serviceStore) Write(record *store.Record, opts ...store.WriteOption) er Expiry: int64(record.Expiry.Seconds()), }, }, client.WithAddress(s.Nodes...)) + if err != nil && errors.Equal(err, errors.NotFound("", "")) { + return store.ErrNotFound + } return err } @@ -138,9 +141,10 @@ func (s *serviceStore) Delete(key string, opts ...store.DeleteOption) error { _, err := s.Client.Delete(s.Context(), &pb.DeleteRequest{ Key: key, }, client.WithAddress(s.Nodes...)) - if verr, ok := err.(*errors.Error); ok && verr.Code == 404 { + if err != nil && errors.Equal(err, errors.NotFound("", "")) { return store.ErrNotFound } + return err } From b3c631dd3849521123aa1722f4f3841d28378e85 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 17 Mar 2020 16:03:49 +0000 Subject: [PATCH 396/788] Support Wildcard Auth Excludes (#1357) Co-authored-by: Ben Toogood --- api/server/auth/auth.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index a7391c18..e7bd6e6b 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -7,6 +7,11 @@ import ( "github.com/micro/go-micro/v2/auth" ) +var ( + // DefaultExcludes is the paths which are allowed by default + DefaultExcludes = []string{"/favicon.ico"} +) + // CombinedAuthHandler wraps a server and authenticates requests func CombinedAuthHandler(h http.Handler) http.Handler { return authHandler{ @@ -30,14 +35,24 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Return if the user disabled auth on this endpoint excludes := h.auth.Options().Exclude + excludes = append(excludes, DefaultExcludes...) if len(loginURL) > 0 { excludes = append(excludes, loginURL) } + for _, e := range excludes { + // is a standard exclude, e.g. /rpc if e == req.URL.Path { h.handler.ServeHTTP(w, req) return } + + // is a wildcard exclude, e.g. /services/* + wildcard := strings.Replace(e, "*", "", 1) + if strings.HasSuffix(e, "*") && strings.HasPrefix(req.URL.Path, wildcard) { + h.handler.ServeHTTP(w, req) + return + } } var token string From 638c2197363370b432812dced57fd55c3cdb5648 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 17 Mar 2020 16:15:23 +0000 Subject: [PATCH 397/788] Cockroach store feature completion (#1358) * Start fixing cockroach store * Add prefix, suffix, limit, offset for cockroachdb store --- store/cockroach/cockroach.go | 103 ++++++++++++++++++++++++++++-- store/cockroach/cockroach_test.go | 25 ++++++-- store/memory/memory_test.go | 10 +++ 3 files changed, 129 insertions(+), 9 deletions(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 4bd92576..d70b0c1c 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -28,10 +28,12 @@ type sqlStore struct { database string table string - list *sql.Stmt - readOne *sql.Stmt - write *sql.Stmt - delete *sql.Stmt + list *sql.Stmt + readOne *sql.Stmt + readMany *sql.Stmt + readOffset *sql.Stmt + write *sql.Stmt + delete *sql.Stmt options store.Options } @@ -92,7 +94,9 @@ func (s *sqlStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, o(&options) } - // TODO: make use of options.Prefix using WHERE key LIKE = ? + if options.Prefix || options.Suffix { + return s.read(key, options) + } var records []*store.Record var timehelper pq.NullTime @@ -120,6 +124,61 @@ func (s *sqlStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, return records, nil } +// Read Many records +func (s *sqlStore) read(key string, options store.ReadOptions) ([]*store.Record, error) { + pattern := "%" + if options.Prefix { + pattern = key + pattern + } + if options.Suffix { + pattern = pattern + key + } + var rows *sql.Rows + var err error + if options.Limit != 0 { + rows, err = s.readOffset.Query(pattern, options.Limit, options.Offset) + } else { + rows, err = s.readMany.Query(pattern) + } + if err != nil { + if err == sql.ErrNoRows { + return []*store.Record{}, nil + } + return []*store.Record{}, errors.Wrap(err, "sqlStore.read failed") + } + defer rows.Close() + var records []*store.Record + var timehelper pq.NullTime + + for rows.Next() { + record := &store.Record{} + if err := rows.Scan(&record.Key, &record.Value, &timehelper); err != nil { + return records, err + } + if timehelper.Valid { + if timehelper.Time.Before(time.Now()) { + // record has expired + go s.Delete(record.Key) + } else { + record.Expiry = time.Until(timehelper.Time) + records = append(records, record) + } + } else { + records = append(records, record) + } + } + rowErr := rows.Close() + if rowErr != nil { + // transaction rollback or something + return records, rowErr + } + if err := rows.Err(); err != nil { + return records, err + } + + return records, nil +} + // Write records func (s *sqlStore) Write(r *store.Record, opts ...store.WriteOption) error { var err error @@ -174,16 +233,44 @@ func (s *sqlStore) initDB() error { return errors.Wrap(err, "Couldn't create table") } + // Create Index + _, err = s.db.Exec(fmt.Sprintf(`CREATE INDEX IF NOT EXISTS "%s" ON %s.%s USING btree ("key")`, "key_index_"+s.table, s.database, s.table)) + if err != nil { + return err + } + list, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s;", s.database, s.table)) if err != nil { return errors.Wrap(err, "List statement couldn't be prepared") } + if s.list != nil { + s.list.Close() + } s.list = list readOne, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key = $1;", s.database, s.table)) if err != nil { return errors.Wrap(err, "ReadOne statement couldn't be prepared") } + if s.readOne != nil { + s.readOne.Close() + } s.readOne = readOne + readMany, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key LIKE $1;", s.database, s.table)) + if err != nil { + return errors.Wrap(err, "ReadMany statement couldn't be prepared") + } + if s.readMany != nil { + s.readMany.Close() + } + s.readMany = readMany + readOffset, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key LIKE $1 ORDER BY key DESC LIMIT $2 OFFSET $3;", s.database, s.table)) + if err != nil { + return errors.Wrap(err, "ReadOffset statement couldn't be prepared") + } + if s.readOffset != nil { + s.readOffset.Close() + } + s.readOffset = readOffset write, err := s.db.Prepare(fmt.Sprintf(`INSERT INTO %s.%s(key, value, expiry) VALUES ($1, $2::bytea, $3) ON CONFLICT (key) @@ -192,11 +279,17 @@ func (s *sqlStore) initDB() error { if err != nil { return errors.Wrap(err, "Write statement couldn't be prepared") } + if s.write != nil { + s.write.Close() + } s.write = write delete, err := s.db.Prepare(fmt.Sprintf("DELETE FROM %s.%s WHERE key = $1;", s.database, s.table)) if err != nil { return errors.Wrap(err, "Delete statement couldn't be prepared") } + if s.delete != nil { + s.delete.Close() + } s.delete = delete return nil diff --git a/store/cockroach/cockroach_test.go b/store/cockroach/cockroach_test.go index 38e36f5f..d9a95c1b 100644 --- a/store/cockroach/cockroach_test.go +++ b/store/cockroach/cockroach_test.go @@ -14,8 +14,8 @@ func TestSQL(t *testing.T) { connection := fmt.Sprintf( "host=%s port=%d user=%s sslmode=disable dbname=%s", "localhost", - 5432, - "jake", + 26257, + "root", "test", ) db, err := sql.Open("postgres", connection) @@ -32,6 +32,10 @@ func TestSQL(t *testing.T) { store.Nodes(connection), ) + if err := sqlStore.Init(); err != nil { + t.Fatal(err) + } + keys, err := sqlStore.List() if err != nil { t.Error(err) @@ -74,7 +78,7 @@ func TestSQL(t *testing.T) { err = sqlStore.Write(&store.Record{ Key: "test", Value: []byte("bar"), - Expiry: time.Minute, + Expiry: time.Second * 10, }) if err != nil { t.Error(err) @@ -89,7 +93,7 @@ func TestSQL(t *testing.T) { t.Error("Expected bar, got ", string(records[0].Value)) } - time.Sleep(61 * time.Second) + time.Sleep(11 * time.Second) _, err = sqlStore.Read("test") switch err { case nil: @@ -99,4 +103,17 @@ func TestSQL(t *testing.T) { case store.ErrNotFound: break } + sqlStore.Delete("bar") + sqlStore.Write(&store.Record{Key: "aaa", Value: []byte("bbb"), Expiry: 5 * time.Second}) + sqlStore.Write(&store.Record{Key: "aaaa", Value: []byte("bbb"), Expiry: 5 * time.Second}) + sqlStore.Write(&store.Record{Key: "aaaaa", Value: []byte("bbb"), Expiry: 5 * time.Second}) + results, err := sqlStore.Read("a", store.ReadPrefix()) + if len(results) != 3 { + t.Fatal("Results should have returned 3 records") + } + time.Sleep(6 * time.Second) + results, err = sqlStore.Read("a", store.ReadPrefix()) + if len(results) != 0 { + t.Fatal("Results should have returned 0 records") + } } diff --git a/store/memory/memory_test.go b/store/memory/memory_test.go index 26e04004..21f6d597 100644 --- a/store/memory/memory_test.go +++ b/store/memory/memory_test.go @@ -234,6 +234,16 @@ func basictest(s store.Store, t *testing.T) { t.Error("Expiry options were not effective") } } + s.Write(&store.Record{Key: "a", Value: []byte("a")}) + s.Write(&store.Record{Key: "aa", Value: []byte("aa")}) + s.Write(&store.Record{Key: "aaa", Value: []byte("aaa")}) + if results, err := s.Read("b", store.ReadPrefix()); err != nil { + t.Error(err) + } else { + if len(results) != 0 { + t.Errorf("Expected 0 results, got %d", len(results)) + } + } s.Init() for i := 0; i < 10; i++ { From 8a41d369f2e44c87a2ee25679f6c44b197cf5742 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 17 Mar 2020 16:59:57 +0000 Subject: [PATCH 398/788] Auth JWT ID Fix (#1359) * Auth JWT ID Fix * Remove unused ID in jwt claims Co-authored-by: Ben Toogood --- auth/jwt/jwt.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go index 49e1ff19..4db68d61 100644 --- a/auth/jwt/jwt.go +++ b/auth/jwt/jwt.go @@ -52,7 +52,6 @@ func (s *svc) Init(opts ...auth.Option) error { // AuthClaims to be encoded in the JWT type AuthClaims struct { - Id string `json:"id"` Roles []*auth.Role `json:"roles"` Metadata map[string]string `json:"metadata"` @@ -74,7 +73,7 @@ func (s *svc) Generate(id string, ops ...auth.GenerateOption) (*auth.Account, er options := auth.NewGenerateOptions(ops...) account := jwt.NewWithClaims(jwt.SigningMethodRS256, AuthClaims{ - id, options.Roles, options.Metadata, jwt.StandardClaims{ + options.Roles, options.Metadata, jwt.StandardClaims{ Subject: id, ExpiresAt: options.Expiry.Unix(), }, @@ -127,7 +126,7 @@ func (s *svc) Verify(token string) (*auth.Account, error) { } return &auth.Account{ - Id: claims.Id, + Id: claims.Subject, Metadata: claims.Metadata, Roles: claims.Roles, }, nil From 00cd2448a4b51cd80f36459dd866f9b4b9f1199a Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 17 Mar 2020 19:24:10 +0000 Subject: [PATCH 399/788] Fix bug where auth token is not set from cookie when excluded endpoint (#1360) Co-authored-by: Ben Toogood --- api/server/auth/auth.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index e7bd6e6b..81697214 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -31,11 +31,26 @@ const ( ) func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { - loginURL := h.auth.Options().LoginURL + // Extract the token from the request + var token string + if header := req.Header.Get("Authorization"); len(header) > 0 { + // Extract the auth token from the request + if strings.HasPrefix(header, BearerScheme) { + token = header[len(BearerScheme):] + } + } else { + // Get the token out the cookies if not provided in headers + if c, err := req.Cookie("micro-token"); err == nil && c != nil { + token = strings.TrimPrefix(c.Value, auth.CookieName+"=") + req.Header.Set("Authorization", BearerScheme+token) + } + } // Return if the user disabled auth on this endpoint excludes := h.auth.Options().Exclude excludes = append(excludes, DefaultExcludes...) + + loginURL := h.auth.Options().LoginURL if len(loginURL) > 0 { excludes = append(excludes, loginURL) } @@ -55,20 +70,6 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } } - var token string - if header := req.Header.Get("Authorization"); len(header) > 0 { - // Extract the auth token from the request - if strings.HasPrefix(header, BearerScheme) { - token = header[len(BearerScheme):] - } - } else { - // Get the token out the cookies if not provided in headers - if c, err := req.Cookie("micro-token"); err == nil && c != nil { - token = strings.TrimPrefix(c.Value, auth.CookieName+"=") - req.Header.Set("Authorization", BearerScheme+token) - } - } - // If the token is valid, allow the request if _, err := h.auth.Verify(token); err == nil { h.handler.ServeHTTP(w, req) From cd04111e3d56f8ecc284e70e282810bb2950bf3a Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 17 Mar 2020 20:04:16 +0000 Subject: [PATCH 400/788] Pass redirect_to param on auth (#1361) Co-authored-by: Ben Toogood --- api/server/auth/auth.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 81697214..e89f0233 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -1,7 +1,9 @@ package auth import ( + "fmt" "net/http" + "net/url" "strings" "github.com/micro/go-micro/v2/auth" @@ -83,5 +85,7 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } // Redirect to the login path - http.Redirect(w, req, loginURL, http.StatusTemporaryRedirect) + params := url.Values{"redirect_to": {req.URL.Path}} + loginWithRedirect := fmt.Sprintf("%v?%v", loginURL, params.Encode()) + http.Redirect(w, req, loginWithRedirect, http.StatusTemporaryRedirect) } From 41f8a8cb002df7c79ffd264698c38d98dfe989e5 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 18 Mar 2020 03:10:38 +0300 Subject: [PATCH 401/788] errors: add FromError func (#1362) Signed-off-by: Vasiliy Tolstov --- errors/errors.go | 10 ++++++++++ errors/errors_test.go | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/errors/errors.go b/errors/errors.go index 6c6598aa..70ffca9a 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -116,6 +116,7 @@ func InternalServerError(id, format string, a ...interface{}) error { } } +// Equal tries to compare errors func Equal(err1 error, err2 error) bool { verr1, ok1 := err1.(*Error) verr2, ok2 := err2.(*Error) @@ -134,3 +135,12 @@ func Equal(err1 error, err2 error) bool { return true } + +// FromError try to convert go error to *Error +func FromError(err error) *Error { + if verr, ok := err.(*Error); ok && verr != nil { + return verr + } + + return Parse(err.Error()) +} diff --git a/errors/errors_test.go b/errors/errors_test.go index 662dd8d0..44e72190 100644 --- a/errors/errors_test.go +++ b/errors/errors_test.go @@ -6,6 +6,20 @@ import ( "testing" ) +func TestFromError(t *testing.T) { + err := NotFound("go.micro.test", "%s", "example") + merr := FromError(err) + if merr.Id != "go.micro.test" || merr.Code != 404 { + t.Fatalf("invalid conversation %v != %v", err, merr) + } + err = er.New(err.Error()) + merr = FromError(err) + if merr.Id != "go.micro.test" || merr.Code != 404 { + t.Fatalf("invalid conversation %v != %v", err, merr) + } + +} + func TestEqual(t *testing.T) { err1 := NotFound("myid1", "msg1") err2 := NotFound("myid2", "msg2") From c91bf7e9e78b20af157455649e2f19a44f1aeedb Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Wed, 18 Mar 2020 16:39:36 +0000 Subject: [PATCH 402/788] [WIP] Store Sync (#1365) * Initial cache implementation * Write queue implementation * Accidentally started writing the storage sync service --- go.mod | 1 + go.sum | 2 + store/cache/cache.go | 39 -------------- store/cache/cache_test.go | 15 ------ sync/store/cache.go | 110 ++++++++++++++++++++++++++++++++++++++ sync/store/cache_test.go | 26 +++++++++ sync/store/manager.go | 89 ++++++++++++++++++++++++++++++ sync/store/options.go | 44 +++++++++++++++ 8 files changed, 272 insertions(+), 54 deletions(-) delete mode 100644 store/cache/cache.go delete mode 100644 store/cache/cache_test.go create mode 100644 sync/store/cache.go create mode 100644 sync/store/cache_test.go create mode 100644 sync/store/manager.go create mode 100644 sync/store/options.go diff --git a/go.mod b/go.mod index c77b4dd2..0dd4fc51 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible + github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c github.com/fsnotify/fsnotify v1.4.7 github.com/fsouza/go-dockerclient v1.6.0 diff --git a/go.sum b/go.sum index a96be5b1..557728a2 100644 --- a/go.sum +++ b/go.sum @@ -123,6 +123,8 @@ github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 h1:jFGzikHboUMRXmMBtwD/PbxoTHPs2919Irp/3rxMbvM= +github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1/go.mod h1:HvODWzv6Y6kBf3Ah2WzN1bHjDUezGLaAhwuWVwfpEJs= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= diff --git a/store/cache/cache.go b/store/cache/cache.go deleted file mode 100644 index 1bb3852e..00000000 --- a/store/cache/cache.go +++ /dev/null @@ -1,39 +0,0 @@ -package cache - -import ( - "github.com/micro/go-micro/v2/store" - "github.com/pkg/errors" -) - -// Cache implements a cache in front of a micro Store -type Cache struct { - options store.Options - store.Store - - stores []store.Store -} - -// NewStore returns new cache -func NewStore(opts ...store.Option) store.Store { - s := &Cache{ - options: store.Options{}, - stores: []store.Store{}, - } - for _, o := range opts { - o(&s.options) - } - return s -} - -// Init initialises a new cache -func (c *Cache) Init(opts ...store.Option) error { - for _, o := range opts { - o(&c.options) - } - for _, s := range c.stores { - if err := s.Init(); err != nil { - return errors.Wrapf(err, "Store %s failed to Init()", s.String()) - } - } - return nil -} diff --git a/store/cache/cache_test.go b/store/cache/cache_test.go deleted file mode 100644 index bf01b9aa..00000000 --- a/store/cache/cache_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package cache - -// import "testing" - -// func TestCache(t *testing.T) { -// c := NewStore() -// if err := c.Init(); err != nil { -// //t.Fatal(err) -// } -// if results, err := c.Read("test"); err != nil { -// //t.Fatal(err) -// } else { -// println(results) -// } -// } diff --git a/sync/store/cache.go b/sync/store/cache.go new file mode 100644 index 00000000..3c13e48a --- /dev/null +++ b/sync/store/cache.go @@ -0,0 +1,110 @@ +// Package store syncs multiple go-micro stores +package store + +import ( + "fmt" + "sync" + "time" + + "github.com/ef-ds/deque" + "github.com/micro/go-micro/v2/store" + "github.com/pkg/errors" +) + +// Cache implements a cache in front of go-micro Stores +type Cache interface { + store.Store + + // Force a full sync + Sync() error +} +type cache struct { + sOptions store.Options + cOptions Options + pendingWrites []*deque.Deque + pendingWriteTickers []*time.Ticker + sync.RWMutex +} + +// NewCache returns a new Cache +func NewCache(opts ...Option) Cache { + c := &cache{} + for _, o := range opts { + o(&c.cOptions) + } + if c.cOptions.SyncInterval == 0 { + c.cOptions.SyncInterval = 1 * time.Minute + } + if c.cOptions.SyncMultiplier == 0 { + c.cOptions.SyncMultiplier = 5 + } + return c +} + +// Init initialises the storeOptions +func (c *cache) Init(opts ...store.Option) error { + for _, o := range opts { + o(&c.sOptions) + } + if len(c.cOptions.Stores) == 0 { + return errors.New("the cache has no stores") + } + if c.sOptions.Context == nil { + return errors.New("please provide a context to the cache. Cancelling the context signals that the cache is being disposed and syncs the cache") + } + for _, s := range c.cOptions.Stores { + if err := s.Init(); err != nil { + return errors.Wrapf(err, "Store %s failed to Init()", s.String()) + } + } + c.pendingWrites = make([]*deque.Deque, len(c.cOptions.Stores)-1) + c.pendingWriteTickers = make([]*time.Ticker, len(c.cOptions.Stores)-1) + for i := 0; i < len(c.pendingWrites); i++ { + c.pendingWrites[i] = deque.New() + c.pendingWrites[i].Init() + c.pendingWriteTickers[i] = time.NewTicker(c.cOptions.SyncInterval * time.Duration(intpow(c.cOptions.SyncMultiplier, int64(i)))) + } + go c.cacheManager() + return nil +} + +// Options returns the cache's store options +func (c *cache) Options() store.Options { + return c.sOptions +} + +// String returns a printable string describing the cache +func (c *cache) String() string { + backends := make([]string, len(c.cOptions.Stores)) + for i, s := range c.cOptions.Stores { + backends[i] = s.String() + } + return fmt.Sprintf("cache %v", backends) +} + +func (c *cache) List(opts ...store.ListOption) ([]string, error) { + return c.cOptions.Stores[0].List(opts...) +} + +func (c *cache) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { + return c.cOptions.Stores[0].Read(key, opts...) +} + +func (c *cache) Write(r *store.Record, opts ...store.WriteOption) error { + return c.cOptions.Stores[0].Write(r, opts...) +} + +// Delete removes a key from the cache +func (c *cache) Delete(key string, opts ...store.DeleteOption) error { + return c.cOptions.Stores[0].Delete(key, opts...) +} + +func (c *cache) Sync() error { + return nil +} + +type internalRecord struct { + key string + value []byte + expiresAt time.Time +} diff --git a/sync/store/cache_test.go b/sync/store/cache_test.go new file mode 100644 index 00000000..23d3aecd --- /dev/null +++ b/sync/store/cache_test.go @@ -0,0 +1,26 @@ +package store + +import ( + "context" + "testing" + "time" + + "github.com/micro/go-micro/v2/store" + "github.com/micro/go-micro/v2/store/memory" +) + +func TestCacheTicker(t *testing.T) { + l0 := memory.NewStore() + l0.Init() + l1 := memory.NewStore() + l1.Init() + l2 := memory.NewStore() + l2.Init() + c := NewCache(Stores(l0, l1, l2), SyncInterval(1*time.Second), SyncMultiplier(2)) + + if err := c.Init(store.WithContext(context.Background())); err != nil { + t.Fatal(err) + } + + time.Sleep(30 * time.Second) +} diff --git a/sync/store/manager.go b/sync/store/manager.go new file mode 100644 index 00000000..58544aa4 --- /dev/null +++ b/sync/store/manager.go @@ -0,0 +1,89 @@ +package store + +import ( + "time" + + "github.com/micro/go-micro/v2/store" + "github.com/pkg/errors" +) + +type operation struct { + operation action + record *store.Record + deadline time.Time + retries int + maxiumum int +} + +// action represents the type of a queued operation +type action int + +const ( + readOp action = iota + 1 + writeOp + deleteOp + listOp +) + +func (c *cache) cacheManager() { + tickerAggregator := make(chan struct{ index int }) + for i, ticker := range c.pendingWriteTickers { + go func(index int, c chan struct{ index int }, t *time.Ticker) { + for range t.C { + c <- struct{ index int }{index: index} + } + }(i, tickerAggregator, ticker) + } + for { + select { + case i := <-tickerAggregator: + println(i.index, "ticked") + c.processQueue(i.index) + } + } +} + +func (c *cache) processQueue(index int) { + c.Lock() + defer c.Unlock() + q := c.pendingWrites[index] + for i := 0; i < q.Len(); i++ { + r, ok := q.PopFront() + if !ok { + panic(errors.Errorf("retrieved an invalid value from the L%d cache queue", index+1)) + } + ir, ok := r.(*internalRecord) + if !ok { + panic(errors.Errorf("retrieved a non-internal record from the L%d cache queue", index+1)) + } + if !ir.expiresAt.IsZero() && time.Now().After(ir.expiresAt) { + continue + } + nr := &store.Record{ + Key: ir.key, + } + nr.Value = make([]byte, len(ir.value)) + copy(nr.Value, ir.value) + if !ir.expiresAt.IsZero() { + nr.Expiry = time.Until(ir.expiresAt) + } + // Todo = internal queue also has to hold the corresponding store.WriteOptions + if err := c.cOptions.Stores[index+1].Write(nr); err != nil { + // some error, so queue for retry and bail + q.PushBack(ir) + return + } + } +} + +func intpow(x, y int64) int64 { + result := int64(1) + for 0 != y { + if 0 != (y & 1) { + result *= x + } + y >>= 1 + x *= x + } + return result +} diff --git a/sync/store/options.go b/sync/store/options.go new file mode 100644 index 00000000..f2a75534 --- /dev/null +++ b/sync/store/options.go @@ -0,0 +1,44 @@ +package store + +import ( + "time" + + "github.com/micro/go-micro/v2/store" +) + +// Options represents Cache options +type Options struct { + // Stores represents layers in the cache in ascending order. L0, L1, L2, etc + Stores []store.Store + // SyncInterval is the duration between syncs from L0 to L1 + SyncInterval time.Duration + // SyncMultiplier is the multiplication factor between each store. + SyncMultiplier int64 +} + +// Option sets Cache Options +type Option func(o *Options) + +// Stores sets the layers that make up the cache +func Stores(stores ...store.Store) Option { + return func(o *Options) { + o.Stores = make([]store.Store, len(stores)) + for i, s := range stores { + o.Stores[i] = s + } + } +} + +// SyncInterval sets the duration between syncs from L0 to L1 +func SyncInterval(d time.Duration) Option { + return func(o *Options) { + o.SyncInterval = d + } +} + +// SyncMultiplier sets the multiplication factor for time to wait each cache layer +func SyncMultiplier(i int64) Option { + return func(o *Options) { + o.SyncMultiplier = i + } +} From 1bd340701b9c8ddaf3d6770df7832cf5034b65d0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 18 Mar 2020 18:27:29 +0000 Subject: [PATCH 403/788] add k8s service ip to metadata (#1367) * add k8s service ip to metadata * go fmt * use same port as container --- runtime/kubernetes/kubernetes.go | 14 +++++++++++--- util/kubernetes/client/client.go | 2 +- util/kubernetes/client/types.go | 7 ++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 16240189..7ff267f5 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -2,6 +2,7 @@ package kubernetes import ( + "fmt" "sync" "time" @@ -70,8 +71,7 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { // version of the service version := kservice.Metadata.Labels["version"] - // save as service - svcMap[name+version] = &service{ + srv := &service{ Service: &runtime.Service{ Name: name, Version: version, @@ -80,10 +80,18 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { kservice: &kservice, } + // set the address + address := kservice.Spec.ClusterIP + port := kservice.Spec.Ports[0] + srv.Service.Metadata["address"] = fmt.Sprintf("%s:%d", address, port.Port) + // copy annotations metadata into service metadata for k, v := range kservice.Metadata.Annotations { - svcMap[name+version].Service.Metadata[k] = v + srv.Service.Metadata[k] = v } + + // save as service + svcMap[name+version] = srv } // collect additional info from kubernetes deployment diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 6786f6c7..e3cfc110 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -217,7 +217,7 @@ func NewService(name, version, typ string) *Service { Type: "ClusterIP", Selector: Labels, Ports: []ServicePort{{ - "service-port", 9090, "", + "service-port", 8080, "", }}, } diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index a747ad2a..cfbcd23c 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -132,9 +132,10 @@ type ServicePort struct { // ServiceSpec provides service configuration type ServiceSpec struct { - Type string `json:"type,omitempty"` - Selector map[string]string `json:"selector,omitempty"` - Ports []ServicePort `json:"ports,omitempty"` + ClusterIP string `json:"clusterIP"` + Type string `json:"type,omitempty"` + Selector map[string]string `json:"selector,omitempty"` + Ports []ServicePort `json:"ports,omitempty"` } // ServiceStatus From 99c3fe2bb8fb29d8042068f1e86434b23221a541 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 18 Mar 2020 21:50:52 +0000 Subject: [PATCH 404/788] fix status parsing (#1368) --- runtime/kubernetes/kubernetes.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 7ff267f5..ffea564f 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -124,27 +124,33 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { svc.Service.Metadata[k] = v } - // get the status from the pods - var status string + // parse out deployment status and inject into service metadata + if len(kdep.Status.Conditions) > 0 { + svc.Metadata["status"] = kdep.Status.Conditions[0].Type + delete(svc.Metadata, "error") + } else { + svc.Metadata["status"] = "n/a" + } + // get the real status for _, item := range podList.Items { + var status string + + // inspect the + if item.Metadata.Name != name { + continue + } + switch item.Status.Phase { case "Failed": status = item.Status.Reason default: status = item.Status.Phase } + + svc.Metadata["status"] = status } - // unknown status - if len(status) == 0 { - status = "n/a" - } - - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime setting %s service deployment status: %v", name, status) - } - svc.Service.Metadata["status"] = status // save deployment svc.kdeploy = &kdep } From 5ad7c36bd4534fa30c2af51bd2097f41a4a764b3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 18 Mar 2020 22:13:21 +0000 Subject: [PATCH 405/788] Fix labels for k8s (#1370) --- runtime/kubernetes/kubernetes.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index ffea564f..fc3e23fe 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -136,8 +136,12 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { for _, item := range podList.Items { var status string - // inspect the - if item.Metadata.Name != name { + // check the name + if item.Metadata.Labels["name"] != name { + continue + } + // check the version + if item.Metadata.Labels["version"] != version { continue } From 40ff6ddfcfcd5998bceff578f2fb728715d9b002 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 18 Mar 2020 22:47:03 +0000 Subject: [PATCH 406/788] sigh, further status changes (#1371) --- runtime/kubernetes/kubernetes.go | 16 ++++++++++++++++ util/kubernetes/client/types.go | 29 +++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index fc3e23fe..a6b301f3 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -152,6 +152,22 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { status = item.Status.Phase } + // now try get a deeper status + state := item.Status.Containers[0].State + + // set start time + if state.Running != nil { + svc.Metadata["started"] = state.Running.Started + } + + // set status from waiting + if v := state.Waiting; v != nil { + if len(v.Reason) > 0 { + status = v.Reason + } + } + // TODO: set from terminated + svc.Metadata["status"] = status } diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index cfbcd23c..b8bcf383 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -14,6 +14,12 @@ type EnvVar struct { Value string `json:"value,omitempty"` } +type Condition struct { + Started string `json:"startedAt,omitempty"` + Reason string `json:"reason,omitempty"` + Message string `json:"message,omitempty"` +} + // Container defined container runtime values type Container struct { Name string `json:"name"` @@ -34,8 +40,8 @@ type DeploymentSpec struct { // DeploymentCondition describes the state of deployment type DeploymentCondition struct { Type string `json:"type"` - Reason string `json:"reason,omitempty"` - Message string `json:"message,omitempty"` + reason string `json:"reason,omitempty"` + message string `json:"message,omitempty"` } // DeploymentStatus is returned when querying deployment @@ -103,10 +109,11 @@ type Pod struct { // PodStatus type PodStatus struct { - Conditions []PodCondition `json:"conditions,omitempty"` - PodIP string `json:"podIP"` - Phase string `json:"phase"` - Reason string `json:"reason"` + Conditions []PodCondition `json:"conditions,omitempty"` + Containers []ContainerStatus `json:"containerStatuses"` + PodIP string `json:"podIP"` + Phase string `json:"phase"` + Reason string `json:"reason"` } // PodCondition describes the state of pod @@ -116,6 +123,16 @@ type PodCondition struct { Message string `json:"message,omitempty"` } +type ContainerStatus struct { + State ContainerState `json:"state"` +} + +type ContainerState struct { + Running *Condition `json:"running"` + Terminated *Condition `json:"terminated"` + Waiting *Condition `json:"waiting"` +} + // Resource is API resource type Resource struct { Name string From cbb958def5284b7305d9d2c29006d70c1fe31533 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 19 Mar 2020 12:54:59 +0300 Subject: [PATCH 407/788] config: fix panic on multiple Close() (#1374) Signed-off-by: Vasiliy Tolstov --- config/default.go | 2 +- config/source/file/file_test.go | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/config/default.go b/config/default.go index e50024ed..0b70cbcf 100644 --- a/config/default.go +++ b/config/default.go @@ -44,7 +44,7 @@ func (c *config) Init(opts ...Option) error { Loader: memory.NewLoader(), Reader: json.NewReader(), } - + c.exit = make(chan bool) for _, o := range opts { o(&c.opts) } diff --git a/config/source/file/file_test.go b/config/source/file/file_test.go index f144a387..1d0a3ad0 100644 --- a/config/source/file/file_test.go +++ b/config/source/file/file_test.go @@ -1,4 +1,4 @@ -package file +package file_test import ( "fmt" @@ -6,8 +6,37 @@ import ( "path/filepath" "testing" "time" + + "github.com/micro/go-micro/v2/config" + "github.com/micro/go-micro/v2/config/source/file" ) +func TestConfig(t *testing.T) { + data := []byte(`{"foo": "bar"}`) + path := filepath.Join(os.TempDir(), fmt.Sprintf("file.%d", time.Now().UnixNano())) + fh, err := os.Create(path) + if err != nil { + t.Error(err) + } + defer func() { + fh.Close() + os.Remove(path) + }() + _, err = fh.Write(data) + if err != nil { + t.Error(err) + } + + conf, err := config.NewConfig() + if err != nil { + t.Fatal(err) + } + conf.Load(file.NewSource(file.WithPath(path))) + // simulate multiple close + go conf.Close() + go conf.Close() +} + func TestFile(t *testing.T) { data := []byte(`{"foo": "bar"}`) path := filepath.Join(os.TempDir(), fmt.Sprintf("file.%d", time.Now().UnixNano())) @@ -25,7 +54,7 @@ func TestFile(t *testing.T) { t.Error(err) } - f := NewSource(WithPath(path)) + f := file.NewSource(file.WithPath(path)) c, err := f.Read() if err != nil { t.Error(err) From 4c6f68d5378256ebff1dfa7f91c2cc6e6be382d2 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Thu, 19 Mar 2020 18:19:07 +0000 Subject: [PATCH 408/788] Implement store read cache (#1366) * Implement store read cache * Added cache tests and fixed a bug in memory store --- store/cache/cache.go | 131 ++++++++++++++++++++++++++++++++++++++ store/cache/cache_test.go | 97 ++++++++++++++++++++++++++++ store/memory/memory.go | 4 +- 3 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 store/cache/cache.go create mode 100644 store/cache/cache_test.go diff --git a/store/cache/cache.go b/store/cache/cache.go new file mode 100644 index 00000000..a52c2bb3 --- /dev/null +++ b/store/cache/cache.go @@ -0,0 +1,131 @@ +// Package cache implements a faulting style read cache on top of multiple micro stores +package cache + +import ( + "fmt" + + "github.com/micro/go-micro/v2/store" + "github.com/pkg/errors" +) + +type cache struct { + stores []store.Store + options store.Options +} + +// NewCache returns a new store using the underlying stores, which must be already Init()ialised +func NewCache(stores ...store.Store) store.Store { + c := &cache{} + c.stores = make([]store.Store, len(stores)) + for i, s := range stores { + c.stores[i] = s + } + return c +} + +func (c *cache) Init(...store.Option) error { + if len(c.stores) < 2 { + return errors.New("cache requires at least 2 stores") + } + return nil +} + +func (c *cache) Options() store.Options { + return c.options +} + +func (c *cache) String() string { + stores := make([]string, len(c.stores)) + for i, s := range c.stores { + stores[i] = s.String() + } + return fmt.Sprintf("cache %v", stores) +} + +func (c *cache) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { + readOpts := store.ReadOptions{} + for _, o := range opts { + o(&readOpts) + } + + if readOpts.Prefix || readOpts.Suffix { + // List, then try cached gets for each key + var lOpts []store.ListOption + if readOpts.Prefix { + lOpts = append(lOpts, store.ListPrefix(key)) + } + if readOpts.Suffix { + lOpts = append(lOpts, store.ListSuffix(key)) + } + if readOpts.Limit > 0 { + lOpts = append(lOpts, store.ListLimit(readOpts.Limit)) + } + if readOpts.Offset > 0 { + lOpts = append(lOpts, store.ListOffset(readOpts.Offset)) + } + keys, err := c.List(lOpts...) + if err != nil { + return []*store.Record{}, errors.Wrap(err, "cache.List failed") + } + recs := make([]*store.Record, len(keys)) + for i, k := range keys { + r, err := c.readOne(k, opts...) + if err != nil { + return recs, errors.Wrap(err, "cache.readOne failed") + } + recs[i] = r + } + return recs, nil + } + + // Otherwise just try cached get + r, err := c.readOne(key, opts...) + if err != nil { + return []*store.Record{}, err // preserve store.ErrNotFound + } + return []*store.Record{r}, nil +} + +func (c *cache) readOne(key string, opts ...store.ReadOption) (*store.Record, error) { + for i, s := range c.stores { + // ReadOne ignores all options + r, err := s.Read(key) + if err == nil { + if len(r) > 1 { + return nil, errors.Wrapf(err, "read from L%d cache (%s) returned multiple records", i, c.stores[i].String()) + } + for j := i - 1; j >= 0; j-- { + err := c.stores[j].Write(r[0]) + if err != nil { + return nil, errors.Wrapf(err, "could not write to L%d cache (%s)", j, c.stores[j].String()) + } + } + return r[0], nil + } + } + return nil, store.ErrNotFound +} + +func (c *cache) Write(r *store.Record, opts ...store.WriteOption) error { + // Write to all layers in reverse + for i := len(c.stores) - 1; i >= 0; i-- { + if err := c.stores[i].Write(r, opts...); err != nil { + return errors.Wrapf(err, "could not write to L%d cache (%s)", i, c.stores[i].String()) + } + } + return nil +} + +func (c *cache) Delete(key string, opts ...store.DeleteOption) error { + for i, s := range c.stores { + if err := s.Delete(key, opts...); err != nil { + return errors.Wrapf(err, "could not delete from L%d cache (%s)", i, c.stores[i].String()) + } + } + return nil +} + +func (c *cache) List(opts ...store.ListOption) ([]string, error) { + // List only makes sense from the top level + return c.stores[len(c.stores)-1].List(opts...) +} diff --git a/store/cache/cache_test.go b/store/cache/cache_test.go new file mode 100644 index 00000000..2af10698 --- /dev/null +++ b/store/cache/cache_test.go @@ -0,0 +1,97 @@ +package cache + +import ( + "sort" + "testing" + + "github.com/micro/go-micro/v2/store" + "github.com/micro/go-micro/v2/store/memory" + "github.com/stretchr/testify/assert" +) + +func TestCache(t *testing.T) { + l0, l1, l2 := memory.NewStore(store.Namespace("l0")), memory.NewStore(store.Prefix("l1")), memory.NewStore(store.Suffix("l2")) + _, _, _ = l0.Init(), l1.Init(), l2.Init() + + assert := assert.New(t) + + nonCache := NewCache(l0) + assert.NotNil(nonCache.Init(), "Expected a cache initialised with just 1 store to fail") + + // Basic functionality + cachedStore := NewCache(l0, l1, l2) + assert.Nil(cachedStore.Init(), "Init should not error") + assert.Equal(cachedStore.Options(), store.Options{}, "Options on store/cache are nonsensical") + expectedString := "cache [memory memory memory]" + assert.Equal(cachedStore.String(), expectedString, "Cache couldn't describe itself as expected") + + // Read/Write tests + _, err := cachedStore.Read("test") + assert.Equal(store.ErrNotFound, err, "Read non existant key") + r1 := &store.Record{ + Key: "aaa", + Value: []byte("bbb"), + } + r2 := &store.Record{ + Key: "aaaa", + Value: []byte("bbbb"), + } + r3 := &store.Record{ + Key: "aaaaa", + Value: []byte("bbbbb"), + } + // Write 3 records directly to l2 + l2.Write(r1) + l2.Write(r2) + l2.Write(r3) + // Ensure it's not in l0 + assert.Equal(store.ErrNotFound, func() error { _, err := l0.Read(r1.Key); return err }()) + // Read from cache, ensure it's in all 3 stores + results, err := cachedStore.Read(r1.Key) + assert.Nil(err, "cachedStore.Read() returned error") + assert.Len(results, 1, "cachedStore.Read() should only return 1 result") + assert.Equal(r1, results[0], "Cached read didn't return the record that was put in") + results, err = l0.Read(r1.Key) + assert.Nil(err) + assert.Equal(r1, results[0], "l0 not coherent") + results, err = l1.Read(r1.Key) + assert.Nil(err) + assert.Equal(r1, results[0], "l1 not coherent") + results, err = l2.Read(r1.Key) + assert.Nil(err) + assert.Equal(r1, results[0], "l2 not coherent") + // Multiple read + results, err = cachedStore.Read("aa", store.ReadPrefix()) + assert.Nil(err, "Cachedstore multiple read errored") + assert.Len(results, 3, "ReadPrefix should have read all records") + // l1 should now have all 3 records + l1results, err := l1.Read("aa", store.ReadPrefix()) + assert.Nil(err, "l1.Read failed") + assert.Len(l1results, 3, "l1 didn't contain a full cache") + sort.Slice(results, func(i, j int) bool { return results[i].Key < results[j].Key }) + sort.Slice(l1results, func(i, j int) bool { return l1results[i].Key < l1results[j].Key }) + assert.Equal(results[0], l1results[0], "l1 cache not coherent") + assert.Equal(results[1], l1results[1], "l1 cache not coherent") + assert.Equal(results[2], l1results[2], "l1 cache not coherent") + + // Test List and Delete + keys, err := cachedStore.List(store.ListPrefix("a")) + assert.Nil(err, "List should not error") + assert.Len(keys, 3, "List should return 3 keys") + for _, k := range keys { + err := cachedStore.Delete(k) + assert.Nil(err, "Delete should not error") + _, err = cachedStore.Read(k) + // N.B. - this may not pass on stores that are eventually consistent + assert.Equal(store.ErrNotFound, err, "record should be gone") + } + + // Test Write + err = cachedStore.Write(r1) + assert.Nil(err, "Write shouldn't fail") + l2result, err := l2.Read(r1.Key) + assert.Nil(err) + assert.Len(l2result, 1) + assert.Equal(r1, l2result[0], "Write didn't make it all the way through to l2") + +} diff --git a/store/memory/memory.go b/store/memory/memory.go index d9bdf1b3..07e73ddc 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -106,7 +106,9 @@ func (m *memoryStore) get(k string) (*store.Record, error) { newRecord.Key = storedRecord.key newRecord.Value = make([]byte, len(storedRecord.value)) copy(newRecord.Value, storedRecord.value) - newRecord.Expiry = time.Until(storedRecord.expiresAt) + if !storedRecord.expiresAt.IsZero() { + newRecord.Expiry = time.Until(storedRecord.expiresAt) + } return newRecord, nil } From e49be1da42ec659bbc2550ef2c18eb52c8a5e42d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 19 Mar 2020 22:38:37 +0000 Subject: [PATCH 409/788] fix local runtime (#1383) --- runtime/default.go | 4 ++-- runtime/service.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index d1eaba54..c9b381be 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -184,8 +184,8 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error { } if len(options.Command) == 0 { - options.Command = []string{"go", "run"} - options.Args = []string{"."} + options.Command = []string{"go"} + options.Args = []string{"run", "."} } // create new service diff --git a/runtime/service.go b/runtime/service.go index 8f1dd6ab..4b20ff65 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -72,7 +72,7 @@ func (s *service) shouldStart() bool { if s.running { return false } - return s.maxRetries <= s.retries + return s.retries <= s.maxRetries } func (s *service) ShouldStart() bool { From d2f153d7954f2a65ad837fe22c1b8a1d037622f4 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 20 Mar 2020 12:48:12 +0000 Subject: [PATCH 410/788] Add type of service (#1385) --- runtime/kubernetes/kubernetes.go | 2 ++ runtime/service.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index a6b301f3..9515878a 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -84,6 +84,8 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { address := kservice.Spec.ClusterIP port := kservice.Spec.Ports[0] srv.Service.Metadata["address"] = fmt.Sprintf("%s:%d", address, port.Port) + // set the type of service + srv.Service.Metadata["type"] = kservice.Metadata.Labels["micro"] // copy annotations metadata into service metadata for k, v := range kservice.Metadata.Annotations { diff --git a/runtime/service.go b/runtime/service.go index 4b20ff65..9c6bdc16 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -125,6 +125,8 @@ func (s *service) Start() error { s.running = true // set status s.Metadata["status"] = "running" + // set started + s.Metadata["started"] = time.Now().Format(time.RFC3339) if s.output != nil { s.streamOutput() From 95015122192c0b9df93484f61b9aa3fbb054f2b7 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Fri, 20 Mar 2020 16:23:12 +0100 Subject: [PATCH 411/788] Auth util func RequestToContext (#1386) --- util/http/http.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/util/http/http.go b/util/http/http.go index 3b743c2a..2f4dc636 100644 --- a/util/http/http.go +++ b/util/http/http.go @@ -1,12 +1,15 @@ package http import ( + "context" "encoding/json" "fmt" "log" "net/http" + "strings" "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" ) @@ -56,3 +59,14 @@ func NewRoundTripper(opts ...Option) http.RoundTripper { opts: options, } } + +// RequestToContext puts the `Authorization` header bearer token into context +// so calls to services will be authorized. +func RequestToContext(r *http.Request) context.Context { + ctx := context.Background() + md := make(metadata.Metadata) + for k, v := range r.Header { + md[k] = strings.Join(v, ",") + } + return metadata.NewContext(ctx, md) +} From d559587807c0f6f4e258140342a6d085839bdb9a Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 21 Mar 2020 12:40:58 +0300 Subject: [PATCH 412/788] client/grpc: remove json-iterator usage (#1387) * minimize external deps and binary size * if user wants json-iterator codec it must be used in server and client code. so best to use it via go-plugins Signed-off-by: Vasiliy Tolstov --- client/grpc/codec.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/client/grpc/codec.go b/client/grpc/codec.go index 9f89647a..a7ee99fc 100644 --- a/client/grpc/codec.go +++ b/client/grpc/codec.go @@ -1,6 +1,7 @@ package grpc import ( + "encoding/json" "fmt" "strings" @@ -8,7 +9,6 @@ import ( "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" - jsoniter "github.com/json-iterator/go" "github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/codec/bytes" "google.golang.org/grpc" @@ -21,6 +21,7 @@ type bytesCodec struct{} type wrapCodec struct{ encoding.Codec } var jsonpbMarshaler = &jsonpb.Marshaler{} +var useNumber bool var ( defaultGRPCCodecs = map[string]encoding.Codec{ @@ -33,18 +34,11 @@ var ( "application/grpc+proto": protoCodec{}, "application/grpc+bytes": bytesCodec{}, } - - json = jsoniter.ConfigCompatibleWithStandardLibrary ) // UseNumber fix unmarshal Number(8234567890123456789) to interface(8.234567890123457e+18) func UseNumber() { - json = jsoniter.Config{ - UseNumber: true, - EscapeHTML: true, - SortMapKeys: true, - ValidateJsonRawMessage: true, - }.Froze() + useNumber = true } func (w wrapCodec) String() string { @@ -134,7 +128,12 @@ func (jsonCodec) Unmarshal(data []byte, v interface{}) error { if pb, ok := v.(proto.Message); ok { return jsonpb.Unmarshal(b.NewReader(data), pb) } - return json.Unmarshal(data, v) + + dec := json.NewDecoder(b.NewReader(data)) + if useNumber { + dec.UseNumber() + } + return dec.Decode(v) } func (jsonCodec) Name() string { From 87617be22718e81757b7428f84d851f52dd658da Mon Sep 17 00:00:00 2001 From: 0987363 <0987363@gmail.com> Date: Sun, 22 Mar 2020 07:25:23 +0800 Subject: [PATCH 413/788] Add client header to rpcRequest header; issue #957 (#1378) Co-authored-by: Asim Aslam --- server/rpc_router.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/rpc_router.go b/server/rpc_router.go index d292880c..cd5d64df 100644 --- a/server/rpc_router.go +++ b/server/rpc_router.go @@ -211,6 +211,7 @@ func (s *service) call(ctx context.Context, router *router, sending *sync.Mutex, method: req.msg.Method, endpoint: req.msg.Endpoint, body: req.msg.Body, + header: req.msg.Header, } // only set if not nil From 9826ddbd64a9bb271bdda70c3f7b30f68d4c021e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 23 Mar 2020 10:31:35 +0300 Subject: [PATCH 414/788] api/handler/rpc: log errors (#1390) Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 5804dbc8..a246d996 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -19,6 +19,7 @@ import ( "github.com/micro/go-micro/v2/codec/jsonrpc" "github.com/micro/go-micro/v2/codec/protorpc" "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/ctx" ) @@ -90,7 +91,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // only allow post when we have the router if r.Method != "GET" && (h.opts.Router != nil && r.Method != "POST") { - http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + writeError(w, r, errors.MethodNotAllowed("go.micro.api", "method not allowed")) return } @@ -296,7 +297,12 @@ func writeError(w http.ResponseWriter, r *http.Request, err error) { w.Header().Set("grpc-message", ce.Detail) } - w.Write([]byte(ce.Error())) + _, werr := w.Write([]byte(ce.Error())) + if err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(werr) + } + } } func writeResponse(w http.ResponseWriter, r *http.Request, rsp []byte) { @@ -312,7 +318,13 @@ func writeResponse(w http.ResponseWriter, r *http.Request, rsp []byte) { } // write response - w.Write(rsp) + _, err := w.Write(rsp) + if err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } + } + } func NewHandler(opts ...handler.Option) handler.Handler { From e0e77f398323184924d5032c542b51eaf1b315d1 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 23 Mar 2020 16:19:30 +0000 Subject: [PATCH 415/788] Updated auth interface (#1384) * Updated auth interface * Add Rule * Remove Rule * Return token from Renew * Renew => Refresh * Implement Tokens & Default Auth Implementation * Change default auth to noop * Change default auth to noop * Move token.Token to auth.Token * Remove Token from Account * Auth service implementation * Decode JWT locally * Cookie for secret * Move string to bottom of interface definition * Depricate auth_exclude * Update auth wrappers * Update go.sum Co-authored-by: Ben Toogood --- api/server/auth/auth.go | 50 ++- auth/auth.go | 89 ++-- auth/default.go | 134 ++----- auth/jwt/jwt.go | 133 ------ auth/options.go | 72 +++- auth/service/proto/auth.pb.go | 601 +++++++++++++++++++++------- auth/service/proto/auth.pb.micro.go | 53 ++- auth/service/proto/auth.proto | 66 ++- auth/service/service.go | 173 +++++--- auth/store/rules.go | 72 ++++ auth/store/store.go | 209 +++++----- auth/store/store_test.go | 287 +++++++++++++ auth/token/basic/basic.go | 95 +++++ auth/token/basic/basic_test.go | 80 ++++ auth/token/jwt/jwt.go | 111 +++++ auth/token/jwt/jwt_test.go | 90 +++++ auth/token/jwt/test/sample_key | 1 + auth/token/jwt/test/sample_key.pub | 1 + auth/token/options.go | 96 +++++ auth/token/token.go | 23 ++ config/cmd/cmd.go | 21 +- service.go | 2 +- util/wrapper/wrapper.go | 32 +- 23 files changed, 1842 insertions(+), 649 deletions(-) delete mode 100644 auth/jwt/jwt.go create mode 100644 auth/store/rules.go create mode 100644 auth/store/store_test.go create mode 100644 auth/token/basic/basic.go create mode 100644 auth/token/basic/basic_test.go create mode 100644 auth/token/jwt/jwt.go create mode 100644 auth/token/jwt/jwt_test.go create mode 100644 auth/token/jwt/test/sample_key create mode 100644 auth/token/jwt/test/sample_key.pub create mode 100644 auth/token/options.go create mode 100644 auth/token/token.go diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index e89f0233..d7018f4c 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -43,44 +43,42 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } else { // Get the token out the cookies if not provided in headers if c, err := req.Cookie("micro-token"); err == nil && c != nil { - token = strings.TrimPrefix(c.Value, auth.CookieName+"=") + token = strings.TrimPrefix(c.Value, auth.TokenCookieName+"=") req.Header.Set("Authorization", BearerScheme+token) } } - // Return if the user disabled auth on this endpoint - excludes := h.auth.Options().Exclude - excludes = append(excludes, DefaultExcludes...) - - loginURL := h.auth.Options().LoginURL - if len(loginURL) > 0 { - excludes = append(excludes, loginURL) + // Get the account using the token, fallback to a blank account + // since some endpoints can be unauthenticated, so the lack of an + // account doesn't necesserially mean a forbidden request + acc, err := h.auth.Inspect(token) + if err != nil { + acc = &auth.Account{} } + err = h.auth.Verify(acc, &auth.Resource{ + Type: "service", + Name: "go.micro.web", + Endpoint: req.URL.Path, + }) - for _, e := range excludes { - // is a standard exclude, e.g. /rpc - if e == req.URL.Path { - h.handler.ServeHTTP(w, req) - return - } - - // is a wildcard exclude, e.g. /services/* - wildcard := strings.Replace(e, "*", "", 1) - if strings.HasSuffix(e, "*") && strings.HasPrefix(req.URL.Path, wildcard) { - h.handler.ServeHTTP(w, req) - return - } - } - - // If the token is valid, allow the request - if _, err := h.auth.Verify(token); err == nil { + // The account has the necessary permissions to access the + // resource + if err == nil { h.handler.ServeHTTP(w, req) return } + // The account is set, but they don't have enough permissions, + // hence we 403. + if len(acc.ID) > 0 { + w.WriteHeader(http.StatusForbidden) + return + } + // If there is no auth login url set, 401 + loginURL := h.auth.Options().LoginURL if loginURL == "" { - w.WriteHeader(401) + w.WriteHeader(http.StatusUnauthorized) return } diff --git a/auth/auth.go b/auth/auth.go index 36ee3f4c..5c5d7ba1 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -4,24 +4,44 @@ package auth import ( "context" "encoding/json" + "errors" "time" "github.com/micro/go-micro/v2/metadata" ) +var ( + // ErrNotFound is returned when a resouce cannot be found + ErrNotFound = errors.New("not found") + // ErrEncodingToken is returned when the service encounters an error during encoding + ErrEncodingToken = errors.New("error encoding the token") + // ErrInvalidToken is returned when the token provided is not valid + ErrInvalidToken = errors.New("invalid token provided") + // ErrInvalidRole is returned when the role provided was invalid + ErrInvalidRole = errors.New("invalid role") + // ErrForbidden is returned when a user does not have the necessary roles to access a resource + ErrForbidden = errors.New("resource forbidden") +) + // Auth providers authentication and authorization type Auth interface { - // Init the auth package - Init(opts ...Option) error - // Options returns the options set + // Init the auth + Init(opts ...Option) + // Options set for auth Options() Options - // Generate a new auth Account + // Generate a new account Generate(id string, opts ...GenerateOption) (*Account, error) - // Revoke an authorization Account - Revoke(token string) error - // Verify an account token - Verify(token string) (*Account, error) - // String returns the implementation + // Grant access to a resource + Grant(role string, res *Resource) error + // Revoke access to a resource + Revoke(role string, res *Resource) error + // Verify an account has access to a resource + Verify(acc *Account, res *Resource) error + // Inspect a token + Inspect(token string) (*Account, error) + // Refresh an account using a secret + Refresh(secret string, opts ...RefreshOption) (*Token, error) + // String returns the name of the implementation String() string } @@ -31,40 +51,47 @@ type Resource struct { Name string // Type of resource, e.g. Type string -} - -// Role an account has -type Role struct { - // Name of the role - Name string - // The resource it has access - // TODO: potentially remove - Resource *Resource + // Endpoint resource e.g NotesService.Create + Endpoint string } // Account provided by an auth provider type Account struct { // ID of the account (UUIDV4, email or username) - Id string `json:"id"` - // Token used to authenticate - Token string `json:"token"` - // Time of Account creation - Created time.Time `json:"created"` - // Time of Account expiry - Expiry time.Time `json:"expiry"` + ID string `json:"id"` + // Secret used to renew the account + Secret *Token `json:"secret"` // Roles associated with the Account - Roles []*Role `json:"roles"` + Roles []string `json:"roles"` // Any other associated metadata Metadata map[string]string `json:"metadata"` } +// Token can be short or long lived +type Token struct { + // The token itself + Token string `json:"token"` + // Type of token, e.g. JWT + Type string `json:"type"` + // Time of token creation + Created time.Time `json:"created"` + // Time of token expiry + Expiry time.Time `json:"expiry"` + // Subject of the token, e.g. the account ID + Subject string `json:"subject"` + // Roles granted to the token + Roles []string `json:"roles"` + // Metadata embedded in the token + Metadata map[string]string `json:"metadata"` +} + const ( - // MetadataKey is the key used when storing the account - // in metadata + // MetadataKey is the key used when storing the account in metadata MetadataKey = "auth-account" - // CookieName is the name of the cookie which stores the - // auth token - CookieName = "micro-token" + // TokenCookieName is the name of the cookie which stores the auth token + TokenCookieName = "micro-token" + // SecretCookieName is the name of the cookie which stores the auth secret + SecretCookieName = "micro-secret" ) // AccountFromContext gets the account from the context, which diff --git a/auth/default.go b/auth/default.go index 740437f1..15bb1757 100644 --- a/auth/default.go +++ b/auth/default.go @@ -1,122 +1,70 @@ package auth import ( - "encoding/base32" - "sync" - "time" + "github.com/google/uuid" ) var ( DefaultAuth = NewAuth() ) -func genAccount(id string) *Account { - // return a pseudo account - return &Account{ - Id: id, - Token: base32.StdEncoding.EncodeToString([]byte(id)), - Created: time.Now(), - Expiry: time.Now().Add(time.Hour * 24), - Metadata: make(map[string]string), - } -} - -// NewAuth returns a new default registry which is memory func NewAuth(opts ...Option) Auth { - var options Options - for _, o := range opts { - o(&options) - } - - return &memory{ - accounts: make(map[string]*Account), - opts: options, - } + return &noop{} } -// TODO: replace with https://github.com/nats-io/nkeys -// We'll then register public key in registry to use -type memory struct { +type noop struct { opts Options - // accounts - sync.RWMutex - accounts map[string]*Account } -func (n *memory) Init(opts ...Option) error { +// String returns the name of the implementation +func (n *noop) String() string { + return "noop" +} + +// Init the auth +func (n *noop) Init(opts ...Option) { for _, o := range opts { o(&n.opts) } - return nil } -func (n *memory) Options() Options { +// Options set for auth +func (n *noop) Options() Options { return n.opts } -func (n *memory) Generate(id string, opts ...GenerateOption) (*Account, error) { - var options GenerateOptions - for _, o := range opts { - o(&options) - } +// Generate a new account +func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) { + options := NewGenerateOptions(opts...) - // return a pseudo account - acc := genAccount(id) - - // set opts - if len(options.Roles) > 0 { - acc.Roles = options.Roles - } - if options.Metadata != nil { - acc.Metadata = options.Metadata - } - - // TODO: don't overwrite - n.Lock() - // maybe save by account id? - n.accounts[acc.Token] = acc - n.Unlock() - - return acc, nil -} - -func (n *memory) Revoke(token string) error { - n.Lock() - delete(n.accounts, token) - n.Unlock() - return nil -} - -func (n *memory) Verify(token string) (*Account, error) { - n.RLock() - defer n.RUnlock() - - if len(token) == 0 { - // pseudo account? - return genAccount(""), nil - } - - // try get the local account if it exists - if acc, ok := n.accounts[token]; ok { - return acc, nil - } - - // decode the token otherwise - b, err := base32.StdEncoding.DecodeString(token) - if err != nil { - return genAccount(""), nil - } - - // return a pseudo account based on token/id return &Account{ - Id: string(b), - Token: token, - Created: time.Now(), - Expiry: time.Now().Add(time.Hour * 24), - Metadata: make(map[string]string), + ID: id, + Roles: options.Roles, + Metadata: options.Metadata, }, nil } -func (n *memory) String() string { - return "memory" +// Grant access to a resource +func (n *noop) Grant(role string, res *Resource) error { + return nil +} + +// Revoke access to a resource +func (n *noop) Revoke(role string, res *Resource) error { + return nil +} + +// Verify an account has access to a resource +func (n *noop) Verify(acc *Account, res *Resource) error { + return nil +} + +// Inspect a token +func (n *noop) Inspect(token string) (*Account, error) { + return &Account{ID: uuid.New().String()}, nil +} + +// Refresh an account using a secret +func (n *noop) Refresh(secret string, opts ...RefreshOption) (*Token, error) { + return &Token{}, nil } diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go deleted file mode 100644 index 4db68d61..00000000 --- a/auth/jwt/jwt.go +++ /dev/null @@ -1,133 +0,0 @@ -package jwt - -import ( - "encoding/base64" - "errors" - - "github.com/dgrijalva/jwt-go" - "github.com/micro/go-micro/v2/auth" -) - -var ( - // ErrInvalidPrivateKey is returned when the service provided an invalid private key - ErrInvalidPrivateKey = errors.New("An invalid private key was provided") - - // ErrEncodingToken is returned when the service encounters an error during encoding - ErrEncodingToken = errors.New("An error occured while encoding the JWT") - - // ErrInvalidToken is returned when the token provided is not valid - ErrInvalidToken = errors.New("An invalid token was provided") - - // ErrMissingToken is returned when no token is provided - ErrMissingToken = errors.New("A valid JWT is required") -) - -// NewAuth returns a new instance of the Auth service -func NewAuth(opts ...auth.Option) auth.Auth { - svc := new(svc) - svc.Init(opts...) - return svc -} - -// svc is the JWT implementation of the Auth interface -type svc struct { - options auth.Options -} - -func (s *svc) String() string { - return "jwt" -} - -func (s *svc) Options() auth.Options { - return s.options -} - -func (s *svc) Init(opts ...auth.Option) error { - for _, o := range opts { - o(&s.options) - } - - return nil -} - -// AuthClaims to be encoded in the JWT -type AuthClaims struct { - Roles []*auth.Role `json:"roles"` - Metadata map[string]string `json:"metadata"` - - jwt.StandardClaims -} - -// Generate a new JWT -func (s *svc) Generate(id string, ops ...auth.GenerateOption) (*auth.Account, error) { - // decode the private key - priv, err := base64.StdEncoding.DecodeString(s.options.PrivateKey) - if err != nil { - return nil, err - } - - key, err := jwt.ParseRSAPrivateKeyFromPEM(priv) - if err != nil { - return nil, ErrEncodingToken - } - - options := auth.NewGenerateOptions(ops...) - account := jwt.NewWithClaims(jwt.SigningMethodRS256, AuthClaims{ - options.Roles, options.Metadata, jwt.StandardClaims{ - Subject: id, - ExpiresAt: options.Expiry.Unix(), - }, - }) - - token, err := account.SignedString(key) - if err != nil { - return nil, err - } - - return &auth.Account{ - Id: id, - Token: token, - Roles: options.Roles, - Metadata: options.Metadata, - }, nil -} - -// Revoke an authorization account -func (s *svc) Revoke(token string) error { - return nil -} - -// Verify a JWT -func (s *svc) Verify(token string) (*auth.Account, error) { - if token == "" { - return nil, ErrMissingToken - } - - // decode the public key - pub, err := base64.StdEncoding.DecodeString(s.options.PublicKey) - if err != nil { - return nil, err - } - - res, err := jwt.ParseWithClaims(token, &AuthClaims{}, func(token *jwt.Token) (interface{}, error) { - return jwt.ParseRSAPublicKeyFromPEM(pub) - }) - if err != nil { - return nil, err - } - - if !res.Valid { - return nil, ErrInvalidToken - } - - claims, ok := res.Claims.(*AuthClaims) - if !ok { - return nil, ErrInvalidToken - } - - return &auth.Account{ - Id: claims.Subject, - Metadata: claims.Metadata, - Roles: claims.Roles, - }, nil -} diff --git a/auth/options.go b/auth/options.go index 68b357b7..6a49af2e 100644 --- a/auth/options.go +++ b/auth/options.go @@ -4,6 +4,7 @@ import ( "time" "github.com/micro/go-micro/v2/auth/provider" + "github.com/micro/go-micro/v2/store" ) type Options struct { @@ -13,20 +14,20 @@ type Options struct { PublicKey string // Private key base64 encoded PrivateKey string - // Endpoints to exclude - Exclude []string // Provider is an auth provider Provider provider.Provider // LoginURL is the relative url path where a user can login LoginURL string + // Store to back auth + Store store.Store } type Option func(o *Options) -// Exclude ecludes a set of endpoints from authorization -func Exclude(e ...string) Option { +// Store to back auth +func Store(s store.Store) Option { return func(o *Options) { - o.Exclude = e + o.Store = s } } @@ -44,8 +45,8 @@ func PrivateKey(key string) Option { } } -// Token sets an auth token -func Token(t string) Option { +// ServiceToken sets an auth token +func ServiceToken(t string) Option { return func(o *Options) { o.Token = t } @@ -69,31 +70,31 @@ type GenerateOptions struct { // Metadata associated with the account Metadata map[string]string // Roles/scopes associated with the account - Roles []*Role - //Expiry of the token - Expiry time.Time + Roles []string + // SecretExpiry is the time the secret should live for + SecretExpiry time.Duration } type GenerateOption func(o *GenerateOptions) -// Metadata for the generated account -func Metadata(md map[string]string) func(o *GenerateOptions) { +// WithMetadata for the generated account +func WithMetadata(md map[string]string) GenerateOption { return func(o *GenerateOptions) { o.Metadata = md } } -// Roles for the generated account -func Roles(rs []*Role) func(o *GenerateOptions) { +// WithRoles for the generated account +func WithRoles(rs []string) GenerateOption { return func(o *GenerateOptions) { o.Roles = rs } } -// Expiry for the generated account's token expires -func Expiry(ex time.Time) func(o *GenerateOptions) { +// WithSecretExpiry for the generated account's secret expires +func WithSecretExpiry(ex time.Duration) GenerateOption { return func(o *GenerateOptions) { - o.Expiry = ex + o.SecretExpiry = ex } } @@ -103,9 +104,40 @@ func NewGenerateOptions(opts ...GenerateOption) GenerateOptions { for _, o := range opts { o(&options) } - //set defualt expiry of token - if options.Expiry.IsZero() { - options.Expiry = time.Now().Add(time.Hour * 24) + + // set defualt expiry of secret + if options.SecretExpiry == 0 { + options.SecretExpiry = time.Hour * 24 * 7 } + + return options +} + +type RefreshOptions struct { + // TokenExpiry is the time the token should live for + TokenExpiry time.Duration +} + +type RefreshOption func(o *RefreshOptions) + +// WithTokenExpiry for the token +func WithTokenExpiry(ex time.Duration) RefreshOption { + return func(o *RefreshOptions) { + o.TokenExpiry = ex + } +} + +// NewRefreshOptions from a slice of options +func NewRefreshOptions(opts ...RefreshOption) RefreshOptions { + var options RefreshOptions + for _, o := range opts { + o(&options) + } + + // set defualt expiry of token + if options.TokenExpiry == 0 { + options.TokenExpiry = time.Minute + } + return options } diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index b57f3cc5..b06f9b7c 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: micro/go-micro/auth/service/proto/auth.proto +// source: auth/service/proto/auth.proto package go_micro_auth @@ -20,13 +20,98 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package -type Account struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Token string `protobuf:"bytes,2,opt,name=token,proto3" json:"token,omitempty"` +type Token struct { + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` Created int64 `protobuf:"varint,3,opt,name=created,proto3" json:"created,omitempty"` Expiry int64 `protobuf:"varint,4,opt,name=expiry,proto3" json:"expiry,omitempty"` - Roles []*Role `protobuf:"bytes,5,rep,name=roles,proto3" json:"roles,omitempty"` - Metadata map[string]string `protobuf:"bytes,6,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Subject string `protobuf:"bytes,5,opt,name=subject,proto3" json:"subject,omitempty"` + Roles []string `protobuf:"bytes,6,rep,name=roles,proto3" json:"roles,omitempty"` + Metadata map[string]string `protobuf:"bytes,7,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Token) Reset() { *m = Token{} } +func (m *Token) String() string { return proto.CompactTextString(m) } +func (*Token) ProtoMessage() {} +func (*Token) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{0} +} + +func (m *Token) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Token.Unmarshal(m, b) +} +func (m *Token) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Token.Marshal(b, m, deterministic) +} +func (m *Token) XXX_Merge(src proto.Message) { + xxx_messageInfo_Token.Merge(m, src) +} +func (m *Token) XXX_Size() int { + return xxx_messageInfo_Token.Size(m) +} +func (m *Token) XXX_DiscardUnknown() { + xxx_messageInfo_Token.DiscardUnknown(m) +} + +var xxx_messageInfo_Token proto.InternalMessageInfo + +func (m *Token) GetToken() string { + if m != nil { + return m.Token + } + return "" +} + +func (m *Token) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *Token) GetCreated() int64 { + if m != nil { + return m.Created + } + return 0 +} + +func (m *Token) GetExpiry() int64 { + if m != nil { + return m.Expiry + } + return 0 +} + +func (m *Token) GetSubject() string { + if m != nil { + return m.Subject + } + return "" +} + +func (m *Token) GetRoles() []string { + if m != nil { + return m.Roles + } + return nil +} + +func (m *Token) GetMetadata() map[string]string { + if m != nil { + return m.Metadata + } + return nil +} + +type Account struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Secret *Token `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty"` + Roles []string `protobuf:"bytes,3,rep,name=roles,proto3" json:"roles,omitempty"` + Metadata map[string]string `protobuf:"bytes,4,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -36,7 +121,7 @@ func (m *Account) Reset() { *m = Account{} } func (m *Account) String() string { return proto.CompactTextString(m) } func (*Account) ProtoMessage() {} func (*Account) Descriptor() ([]byte, []int) { - return fileDescriptor_de609d4872dacc78, []int{0} + return fileDescriptor_21300bfacc51fc2a, []int{1} } func (m *Account) XXX_Unmarshal(b []byte) error { @@ -64,28 +149,14 @@ func (m *Account) GetId() string { return "" } -func (m *Account) GetToken() string { +func (m *Account) GetSecret() *Token { if m != nil { - return m.Token + return m.Secret } - return "" + return nil } -func (m *Account) GetCreated() int64 { - if m != nil { - return m.Created - } - return 0 -} - -func (m *Account) GetExpiry() int64 { - if m != nil { - return m.Expiry - } - return 0 -} - -func (m *Account) GetRoles() []*Role { +func (m *Account) GetRoles() []string { if m != nil { return m.Roles } @@ -99,56 +170,10 @@ func (m *Account) GetMetadata() map[string]string { return nil } -type Role struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Role) Reset() { *m = Role{} } -func (m *Role) String() string { return proto.CompactTextString(m) } -func (*Role) ProtoMessage() {} -func (*Role) Descriptor() ([]byte, []int) { - return fileDescriptor_de609d4872dacc78, []int{1} -} - -func (m *Role) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Role.Unmarshal(m, b) -} -func (m *Role) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Role.Marshal(b, m, deterministic) -} -func (m *Role) XXX_Merge(src proto.Message) { - xxx_messageInfo_Role.Merge(m, src) -} -func (m *Role) XXX_Size() int { - return xxx_messageInfo_Role.Size(m) -} -func (m *Role) XXX_DiscardUnknown() { - xxx_messageInfo_Role.DiscardUnknown(m) -} - -var xxx_messageInfo_Role proto.InternalMessageInfo - -func (m *Role) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -func (m *Role) GetResource() *Resource { - if m != nil { - return m.Resource - } - return nil -} - type Resource struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` + Endpoint string `protobuf:"bytes,3,opt,name=endpoint,proto3" json:"endpoint,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -158,7 +183,7 @@ func (m *Resource) Reset() { *m = Resource{} } func (m *Resource) String() string { return proto.CompactTextString(m) } func (*Resource) ProtoMessage() {} func (*Resource) Descriptor() ([]byte, []int) { - return fileDescriptor_de609d4872dacc78, []int{2} + return fileDescriptor_21300bfacc51fc2a, []int{2} } func (m *Resource) XXX_Unmarshal(b []byte) error { @@ -193,18 +218,28 @@ func (m *Resource) GetType() string { return "" } +func (m *Resource) GetEndpoint() string { + if m != nil { + return m.Endpoint + } + return "" +} + type GenerateRequest struct { - Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Roles []string `protobuf:"bytes,2,rep,name=roles,proto3" json:"roles,omitempty"` + Metadata map[string]string `protobuf:"bytes,3,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + SecretExpiry int64 `protobuf:"varint,4,opt,name=secret_expiry,json=secretExpiry,proto3" json:"secret_expiry,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *GenerateRequest) Reset() { *m = GenerateRequest{} } func (m *GenerateRequest) String() string { return proto.CompactTextString(m) } func (*GenerateRequest) ProtoMessage() {} func (*GenerateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_de609d4872dacc78, []int{3} + return fileDescriptor_21300bfacc51fc2a, []int{3} } func (m *GenerateRequest) XXX_Unmarshal(b []byte) error { @@ -225,13 +260,34 @@ func (m *GenerateRequest) XXX_DiscardUnknown() { var xxx_messageInfo_GenerateRequest proto.InternalMessageInfo -func (m *GenerateRequest) GetAccount() *Account { +func (m *GenerateRequest) GetId() string { if m != nil { - return m.Account + return m.Id + } + return "" +} + +func (m *GenerateRequest) GetRoles() []string { + if m != nil { + return m.Roles } return nil } +func (m *GenerateRequest) GetMetadata() map[string]string { + if m != nil { + return m.Metadata + } + return nil +} + +func (m *GenerateRequest) GetSecretExpiry() int64 { + if m != nil { + return m.SecretExpiry + } + return 0 +} + type GenerateResponse struct { Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -243,7 +299,7 @@ func (m *GenerateResponse) Reset() { *m = GenerateResponse{} } func (m *GenerateResponse) String() string { return proto.CompactTextString(m) } func (*GenerateResponse) ProtoMessage() {} func (*GenerateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_de609d4872dacc78, []int{4} + return fileDescriptor_21300bfacc51fc2a, []int{4} } func (m *GenerateResponse) XXX_Unmarshal(b []byte) error { @@ -271,18 +327,97 @@ func (m *GenerateResponse) GetAccount() *Account { return nil } -type VerifyRequest struct { - Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` +type GrantRequest struct { + Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` + Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GrantRequest) Reset() { *m = GrantRequest{} } +func (m *GrantRequest) String() string { return proto.CompactTextString(m) } +func (*GrantRequest) ProtoMessage() {} +func (*GrantRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{5} +} + +func (m *GrantRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GrantRequest.Unmarshal(m, b) +} +func (m *GrantRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GrantRequest.Marshal(b, m, deterministic) +} +func (m *GrantRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GrantRequest.Merge(m, src) +} +func (m *GrantRequest) XXX_Size() int { + return xxx_messageInfo_GrantRequest.Size(m) +} +func (m *GrantRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GrantRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GrantRequest proto.InternalMessageInfo + +func (m *GrantRequest) GetRole() string { + if m != nil { + return m.Role + } + return "" +} + +func (m *GrantRequest) GetResource() *Resource { + if m != nil { + return m.Resource + } + return nil +} + +type GrantResponse struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } +func (m *GrantResponse) Reset() { *m = GrantResponse{} } +func (m *GrantResponse) String() string { return proto.CompactTextString(m) } +func (*GrantResponse) ProtoMessage() {} +func (*GrantResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{6} +} + +func (m *GrantResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GrantResponse.Unmarshal(m, b) +} +func (m *GrantResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GrantResponse.Marshal(b, m, deterministic) +} +func (m *GrantResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GrantResponse.Merge(m, src) +} +func (m *GrantResponse) XXX_Size() int { + return xxx_messageInfo_GrantResponse.Size(m) +} +func (m *GrantResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GrantResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GrantResponse proto.InternalMessageInfo + +type VerifyRequest struct { + Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` + Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + func (m *VerifyRequest) Reset() { *m = VerifyRequest{} } func (m *VerifyRequest) String() string { return proto.CompactTextString(m) } func (*VerifyRequest) ProtoMessage() {} func (*VerifyRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_de609d4872dacc78, []int{5} + return fileDescriptor_21300bfacc51fc2a, []int{7} } func (m *VerifyRequest) XXX_Unmarshal(b []byte) error { @@ -303,15 +438,21 @@ func (m *VerifyRequest) XXX_DiscardUnknown() { var xxx_messageInfo_VerifyRequest proto.InternalMessageInfo -func (m *VerifyRequest) GetToken() string { +func (m *VerifyRequest) GetAccount() *Account { if m != nil { - return m.Token + return m.Account } - return "" + return nil +} + +func (m *VerifyRequest) GetResource() *Resource { + if m != nil { + return m.Resource + } + return nil } type VerifyResponse struct { - Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -321,7 +462,7 @@ func (m *VerifyResponse) Reset() { *m = VerifyResponse{} } func (m *VerifyResponse) String() string { return proto.CompactTextString(m) } func (*VerifyResponse) ProtoMessage() {} func (*VerifyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_de609d4872dacc78, []int{6} + return fileDescriptor_21300bfacc51fc2a, []int{8} } func (m *VerifyResponse) XXX_Unmarshal(b []byte) error { @@ -342,25 +483,19 @@ func (m *VerifyResponse) XXX_DiscardUnknown() { var xxx_messageInfo_VerifyResponse proto.InternalMessageInfo -func (m *VerifyResponse) GetAccount() *Account { - if m != nil { - return m.Account - } - return nil -} - type RevokeRequest struct { - Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` + Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *RevokeRequest) Reset() { *m = RevokeRequest{} } func (m *RevokeRequest) String() string { return proto.CompactTextString(m) } func (*RevokeRequest) ProtoMessage() {} func (*RevokeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_de609d4872dacc78, []int{7} + return fileDescriptor_21300bfacc51fc2a, []int{9} } func (m *RevokeRequest) XXX_Unmarshal(b []byte) error { @@ -381,13 +516,20 @@ func (m *RevokeRequest) XXX_DiscardUnknown() { var xxx_messageInfo_RevokeRequest proto.InternalMessageInfo -func (m *RevokeRequest) GetToken() string { +func (m *RevokeRequest) GetRole() string { if m != nil { - return m.Token + return m.Role } return "" } +func (m *RevokeRequest) GetResource() *Resource { + if m != nil { + return m.Resource + } + return nil +} + type RevokeResponse struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -398,7 +540,7 @@ func (m *RevokeResponse) Reset() { *m = RevokeResponse{} } func (m *RevokeResponse) String() string { return proto.CompactTextString(m) } func (*RevokeResponse) ProtoMessage() {} func (*RevokeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_de609d4872dacc78, []int{8} + return fileDescriptor_21300bfacc51fc2a, []int{10} } func (m *RevokeResponse) XXX_Unmarshal(b []byte) error { @@ -419,50 +561,235 @@ func (m *RevokeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_RevokeResponse proto.InternalMessageInfo +type InspectRequest struct { + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *InspectRequest) Reset() { *m = InspectRequest{} } +func (m *InspectRequest) String() string { return proto.CompactTextString(m) } +func (*InspectRequest) ProtoMessage() {} +func (*InspectRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{11} +} + +func (m *InspectRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_InspectRequest.Unmarshal(m, b) +} +func (m *InspectRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_InspectRequest.Marshal(b, m, deterministic) +} +func (m *InspectRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_InspectRequest.Merge(m, src) +} +func (m *InspectRequest) XXX_Size() int { + return xxx_messageInfo_InspectRequest.Size(m) +} +func (m *InspectRequest) XXX_DiscardUnknown() { + xxx_messageInfo_InspectRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_InspectRequest proto.InternalMessageInfo + +func (m *InspectRequest) GetToken() string { + if m != nil { + return m.Token + } + return "" +} + +type InspectResponse struct { + Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *InspectResponse) Reset() { *m = InspectResponse{} } +func (m *InspectResponse) String() string { return proto.CompactTextString(m) } +func (*InspectResponse) ProtoMessage() {} +func (*InspectResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{12} +} + +func (m *InspectResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_InspectResponse.Unmarshal(m, b) +} +func (m *InspectResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_InspectResponse.Marshal(b, m, deterministic) +} +func (m *InspectResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_InspectResponse.Merge(m, src) +} +func (m *InspectResponse) XXX_Size() int { + return xxx_messageInfo_InspectResponse.Size(m) +} +func (m *InspectResponse) XXX_DiscardUnknown() { + xxx_messageInfo_InspectResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_InspectResponse proto.InternalMessageInfo + +func (m *InspectResponse) GetAccount() *Account { + if m != nil { + return m.Account + } + return nil +} + +type RefreshRequest struct { + Secret string `protobuf:"bytes,1,opt,name=secret,proto3" json:"secret,omitempty"` + TokenExpiry int64 `protobuf:"varint,2,opt,name=token_expiry,json=tokenExpiry,proto3" json:"token_expiry,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RefreshRequest) Reset() { *m = RefreshRequest{} } +func (m *RefreshRequest) String() string { return proto.CompactTextString(m) } +func (*RefreshRequest) ProtoMessage() {} +func (*RefreshRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{13} +} + +func (m *RefreshRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RefreshRequest.Unmarshal(m, b) +} +func (m *RefreshRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RefreshRequest.Marshal(b, m, deterministic) +} +func (m *RefreshRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_RefreshRequest.Merge(m, src) +} +func (m *RefreshRequest) XXX_Size() int { + return xxx_messageInfo_RefreshRequest.Size(m) +} +func (m *RefreshRequest) XXX_DiscardUnknown() { + xxx_messageInfo_RefreshRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_RefreshRequest proto.InternalMessageInfo + +func (m *RefreshRequest) GetSecret() string { + if m != nil { + return m.Secret + } + return "" +} + +func (m *RefreshRequest) GetTokenExpiry() int64 { + if m != nil { + return m.TokenExpiry + } + return 0 +} + +type RefreshResponse struct { + Token *Token `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *RefreshResponse) Reset() { *m = RefreshResponse{} } +func (m *RefreshResponse) String() string { return proto.CompactTextString(m) } +func (*RefreshResponse) ProtoMessage() {} +func (*RefreshResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{14} +} + +func (m *RefreshResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_RefreshResponse.Unmarshal(m, b) +} +func (m *RefreshResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_RefreshResponse.Marshal(b, m, deterministic) +} +func (m *RefreshResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_RefreshResponse.Merge(m, src) +} +func (m *RefreshResponse) XXX_Size() int { + return xxx_messageInfo_RefreshResponse.Size(m) +} +func (m *RefreshResponse) XXX_DiscardUnknown() { + xxx_messageInfo_RefreshResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_RefreshResponse proto.InternalMessageInfo + +func (m *RefreshResponse) GetToken() *Token { + if m != nil { + return m.Token + } + return nil +} + func init() { + proto.RegisterType((*Token)(nil), "go.micro.auth.Token") + proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.Token.MetadataEntry") proto.RegisterType((*Account)(nil), "go.micro.auth.Account") proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.Account.MetadataEntry") - proto.RegisterType((*Role)(nil), "go.micro.auth.Role") proto.RegisterType((*Resource)(nil), "go.micro.auth.Resource") proto.RegisterType((*GenerateRequest)(nil), "go.micro.auth.GenerateRequest") + proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.GenerateRequest.MetadataEntry") proto.RegisterType((*GenerateResponse)(nil), "go.micro.auth.GenerateResponse") + proto.RegisterType((*GrantRequest)(nil), "go.micro.auth.GrantRequest") + proto.RegisterType((*GrantResponse)(nil), "go.micro.auth.GrantResponse") proto.RegisterType((*VerifyRequest)(nil), "go.micro.auth.VerifyRequest") proto.RegisterType((*VerifyResponse)(nil), "go.micro.auth.VerifyResponse") proto.RegisterType((*RevokeRequest)(nil), "go.micro.auth.RevokeRequest") proto.RegisterType((*RevokeResponse)(nil), "go.micro.auth.RevokeResponse") + proto.RegisterType((*InspectRequest)(nil), "go.micro.auth.InspectRequest") + proto.RegisterType((*InspectResponse)(nil), "go.micro.auth.InspectResponse") + proto.RegisterType((*RefreshRequest)(nil), "go.micro.auth.RefreshRequest") + proto.RegisterType((*RefreshResponse)(nil), "go.micro.auth.RefreshResponse") } -func init() { - proto.RegisterFile("micro/go-micro/auth/service/proto/auth.proto", fileDescriptor_de609d4872dacc78) -} +func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } -var fileDescriptor_de609d4872dacc78 = []byte{ - // 432 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x53, 0x4b, 0x6f, 0xd3, 0x40, - 0x10, 0xae, 0x1d, 0xe7, 0xc1, 0x44, 0x09, 0xd1, 0x80, 0x8a, 0x15, 0xf1, 0x88, 0x56, 0x20, 0x05, - 0x09, 0x1c, 0xe4, 0x5e, 0x10, 0x5c, 0x28, 0x0f, 0xf5, 0x54, 0x21, 0xed, 0x81, 0xfb, 0xe2, 0x0c, - 0xad, 0x95, 0xc4, 0x6b, 0xd6, 0xeb, 0x08, 0xff, 0x06, 0x7e, 0x28, 0x7f, 0x03, 0x79, 0xd7, 0x1b, - 0x6a, 0xb7, 0xe5, 0x00, 0xb7, 0x79, 0x7c, 0xf3, 0xcd, 0xf7, 0x8d, 0x76, 0xe1, 0xc5, 0x2e, 0x4d, - 0x94, 0x5c, 0x5d, 0xc8, 0x97, 0x36, 0x10, 0xa5, 0xbe, 0x5c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xb2, 0x18, 0x46, 0xae, 0x7a, 0x23, 0x29, 0x42, 0xa0, 0xab, 0xdc, 0x29, 0x31, 0x31, 0xfb, 0x00, - 0x77, 0xcf, 0x28, 0x23, 0x25, 0x34, 0x71, 0xfa, 0x5e, 0x52, 0xa1, 0xf1, 0x15, 0x0c, 0x85, 0xf5, - 0x6d, 0xa6, 0xc7, 0xf1, 0xf1, 0xcd, 0x57, 0xe1, 0x0e, 0xc6, 0x3e, 0xc2, 0xec, 0x0f, 0x49, 0x91, - 0xcb, 0xac, 0xa0, 0x7f, 0x60, 0x79, 0x06, 0x93, 0x2f, 0xa4, 0xd2, 0x6f, 0x95, 0x13, 0x72, 0x78, - 0x12, 0xde, 0x95, 0x27, 0xc1, 0xde, 0xc3, 0xd4, 0xc1, 0xfe, 0x67, 0x15, 0xa7, 0xbd, 0xdc, 0xd0, - 0xdf, 0x57, 0xcd, 0x60, 0xea, 0x60, 0x76, 0x55, 0xfc, 0xcb, 0x83, 0xe0, 0xb4, 0xd4, 0x97, 0x78, - 0x0e, 0x23, 0x67, 0x19, 0x1f, 0x77, 0xd6, 0x75, 0x0e, 0x3a, 0x7f, 0x72, 0x6b, 0xdf, 0xb2, 0xb2, - 0x23, 0x3c, 0x83, 0x81, 0x35, 0x85, 0x0f, 0x3b, 0xe0, 0xd6, 0x49, 0xe6, 0x8f, 0x6e, 0xe9, 0x5e, - 0x25, 0xb2, 0x92, 0xaf, 0x11, 0xb5, 0x0c, 0x5f, 0x23, 0x6a, 0xfb, 0x64, 0x47, 0x5f, 0x07, 0xe6, - 0x07, 0x9f, 0xfc, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x34, 0xce, 0x17, 0xf1, 0x03, 0x00, 0x00, +var fileDescriptor_21300bfacc51fc2a = []byte{ + // 663 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xdd, 0x6e, 0xd3, 0x4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f, 0x4d, 0xf6, 0xcd, 0x95, 0x79, 0x29, 0xe7, 0x1a, 0x39, 0x82, 0xa6, 0xf0, + 0x15, 0xf9, 0xbf, 0x5e, 0x5b, 0xb2, 0xb1, 0x7d, 0x63, 0x79, 0xb2, 0x40, 0x39, 0x81, 0x56, 0x6e, + 0x0a, 0x52, 0xaf, 0xac, 0x78, 0xd4, 0xde, 0x5e, 0x91, 0x2d, 0x03, 0xe5, 0x1b, 0x5f, 0x00, 0xaa, + 0x58, 0x6c, 0x01, 0xa8, 0x66, 0x93, 0x35, 0xf2, 0x12, 0xda, 0xd2, 0x00, 0xa4, 0x5e, 0x5b, 0x35, + 0x90, 0xbd, 0xb3, 0x2a, 0x5d, 0xc6, 0x92, 0xab, 0x23, 0x8b, 0xbc, 0x65, 0x7f, 0x2c, 0x60, 0xd5, + 0x36, 0xee, 0xac, 0x9d, 0xb5, 0xc4, 0x9f, 0xf4, 0xc1, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb7, + 0xf8, 0x55, 0xb6, 0xc5, 0x07, 0x00, 0x00, } diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index 72b197fa..dccf46b8 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: micro/go-micro/auth/service/proto/auth.proto +// source: auth/service/proto/auth.proto package go_micro_auth @@ -35,8 +35,11 @@ var _ server.Option type AuthService interface { Generate(ctx context.Context, in *GenerateRequest, opts ...client.CallOption) (*GenerateResponse, error) + Grant(ctx context.Context, in *GrantRequest, opts ...client.CallOption) (*GrantResponse, error) Verify(ctx context.Context, in *VerifyRequest, opts ...client.CallOption) (*VerifyResponse, error) Revoke(ctx context.Context, in *RevokeRequest, opts ...client.CallOption) (*RevokeResponse, error) + Inspect(ctx context.Context, in *InspectRequest, opts ...client.CallOption) (*InspectResponse, error) + Refresh(ctx context.Context, in *RefreshRequest, opts ...client.CallOption) (*RefreshResponse, error) } type authService struct { @@ -61,6 +64,16 @@ func (c *authService) Generate(ctx context.Context, in *GenerateRequest, opts .. return out, nil } +func (c *authService) Grant(ctx context.Context, in *GrantRequest, opts ...client.CallOption) (*GrantResponse, error) { + req := c.c.NewRequest(c.name, "Auth.Grant", in) + out := new(GrantResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *authService) Verify(ctx context.Context, in *VerifyRequest, opts ...client.CallOption) (*VerifyResponse, error) { req := c.c.NewRequest(c.name, "Auth.Verify", in) out := new(VerifyResponse) @@ -81,19 +94,45 @@ func (c *authService) Revoke(ctx context.Context, in *RevokeRequest, opts ...cli return out, nil } +func (c *authService) Inspect(ctx context.Context, in *InspectRequest, opts ...client.CallOption) (*InspectResponse, error) { + req := c.c.NewRequest(c.name, "Auth.Inspect", in) + out := new(InspectResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authService) Refresh(ctx context.Context, in *RefreshRequest, opts ...client.CallOption) (*RefreshResponse, error) { + req := c.c.NewRequest(c.name, "Auth.Refresh", in) + out := new(RefreshResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for Auth service type AuthHandler interface { Generate(context.Context, *GenerateRequest, *GenerateResponse) error + Grant(context.Context, *GrantRequest, *GrantResponse) error Verify(context.Context, *VerifyRequest, *VerifyResponse) error Revoke(context.Context, *RevokeRequest, *RevokeResponse) error + Inspect(context.Context, *InspectRequest, *InspectResponse) error + Refresh(context.Context, *RefreshRequest, *RefreshResponse) error } func RegisterAuthHandler(s server.Server, hdlr AuthHandler, opts ...server.HandlerOption) error { type auth interface { Generate(ctx context.Context, in *GenerateRequest, out *GenerateResponse) error + Grant(ctx context.Context, in *GrantRequest, out *GrantResponse) error Verify(ctx context.Context, in *VerifyRequest, out *VerifyResponse) error Revoke(ctx context.Context, in *RevokeRequest, out *RevokeResponse) error + Inspect(ctx context.Context, in *InspectRequest, out *InspectResponse) error + Refresh(ctx context.Context, in *RefreshRequest, out *RefreshResponse) error } type Auth struct { auth @@ -110,6 +149,10 @@ func (h *authHandler) Generate(ctx context.Context, in *GenerateRequest, out *Ge return h.AuthHandler.Generate(ctx, in, out) } +func (h *authHandler) Grant(ctx context.Context, in *GrantRequest, out *GrantResponse) error { + return h.AuthHandler.Grant(ctx, in, out) +} + func (h *authHandler) Verify(ctx context.Context, in *VerifyRequest, out *VerifyResponse) error { return h.AuthHandler.Verify(ctx, in, out) } @@ -117,3 +160,11 @@ func (h *authHandler) Verify(ctx context.Context, in *VerifyRequest, out *Verify func (h *authHandler) Revoke(ctx context.Context, in *RevokeRequest, out *RevokeResponse) error { return h.AuthHandler.Revoke(ctx, in, out) } + +func (h *authHandler) Inspect(ctx context.Context, in *InspectRequest, out *InspectResponse) error { + return h.AuthHandler.Inspect(ctx, in, out) +} + +func (h *authHandler) Refresh(ctx context.Context, in *RefreshRequest, out *RefreshResponse) error { + return h.AuthHandler.Refresh(ctx, in, out) +} diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index 7f60f8bb..6b2587bb 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -3,48 +3,82 @@ syntax = "proto3"; package go.micro.auth; service Auth { - rpc Generate(GenerateRequest) returns (GenerateResponse) {}; - rpc Verify(VerifyRequest) returns (VerifyResponse) {}; - rpc Revoke(RevokeRequest) returns (RevokeResponse) {}; + rpc Generate(GenerateRequest) returns (GenerateResponse) {}; + rpc Grant(GrantRequest) returns (GrantResponse) {}; + rpc Verify(VerifyRequest) returns (VerifyResponse) {}; + rpc Revoke(RevokeRequest) returns (RevokeResponse) {}; + rpc Inspect(InspectRequest) returns (InspectResponse) {}; + rpc Refresh(RefreshRequest) returns (RefreshResponse) {}; } -message Account{ - string id = 1; - string token = 2; +message Token { + string token = 1; + string type = 2; int64 created = 3; int64 expiry = 4; - repeated Role roles = 5; - map metadata = 6; + string subject = 5; + repeated string roles = 6; + map metadata = 7; } -message Role { - string name = 1; - Resource resource = 2; +message Account { + string id = 1; + Token secret = 2; + repeated string roles = 3; + map metadata = 4; } message Resource{ string name = 1; string type = 2; + string endpoint = 3; } message GenerateRequest { - Account account = 1; + string id = 1; + repeated string roles = 2; + map metadata = 3; + int64 secret_expiry = 4; } message GenerateResponse { Account account = 1; } -message VerifyRequest { - string token = 1; +message GrantRequest { + string role = 1; + Resource resource = 2; } -message VerifyResponse { +message GrantResponse {} + +message VerifyRequest { Account account = 1; + Resource resource = 2; } +message VerifyResponse {} + message RevokeRequest { - string token = 1; + string role = 1; + Resource resource = 2; } message RevokeResponse {} + +message InspectRequest { + string token = 1; +} + +message InspectResponse { + Account account = 1; +} + +message RefreshRequest { + string secret = 1; + int64 token_expiry = 2; +} + +message RefreshResponse { + Token token = 1; +} \ No newline at end of file diff --git a/auth/service/service.go b/auth/service/service.go index 6131eda2..3f11848b 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -2,10 +2,13 @@ package service import ( "context" + "strings" "time" "github.com/micro/go-micro/v2/auth" pb "github.com/micro/go-micro/v2/auth/service/proto" + "github.com/micro/go-micro/v2/auth/token" + "github.com/micro/go-micro/v2/auth/token/jwt" "github.com/micro/go-micro/v2/client" ) @@ -20,13 +23,14 @@ func NewAuth(opts ...auth.Option) auth.Auth { type svc struct { options auth.Options auth pb.AuthService + jwt token.Provider } func (s *svc) String() string { return "service" } -func (s *svc) Init(opts ...auth.Option) error { +func (s *svc) Init(opts ...auth.Option) { for _, o := range opts { o(&s.options) } @@ -34,99 +38,140 @@ func (s *svc) Init(opts ...auth.Option) error { dc := client.DefaultClient s.auth = pb.NewAuthService("go.micro.auth", dc) - return nil + // if we have a JWT public key passed as an option, + // we can decode tokens with the type "JWT" locally + // and not have to make an RPC call + if key := s.options.PublicKey; len(key) > 0 { + s.jwt = jwt.NewTokenProvider(token.WithPublicKey(key)) + } } func (s *svc) Options() auth.Options { return s.options } -// Generate a new auth account +// Generate a new account func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { - // construct the request options := auth.NewGenerateOptions(opts...) - sa := &auth.Account{ - Id: id, - Roles: options.Roles, - Metadata: options.Metadata, - } - req := &pb.GenerateRequest{Account: serializeAccount(sa)} - // execute the request - resp, err := s.auth.Generate(context.Background(), req) + rsp, err := s.auth.Generate(context.TODO(), &pb.GenerateRequest{ + Id: id, + Roles: options.Roles, + Metadata: options.Metadata, + SecretExpiry: int64(options.SecretExpiry.Seconds()), + }) if err != nil { return nil, err } - // format the response - return deserializeAccount(resp.Account), nil + return serializeAccount(rsp.Account), nil } -// Revoke an authorization account -func (s *svc) Revoke(token string) error { - // contruct the request - req := &pb.RevokeRequest{Token: token} - - // execute the request - _, err := s.auth.Revoke(context.Background(), req) +// Grant access to a resource +func (s *svc) Grant(role string, res *auth.Resource) error { + _, err := s.auth.Grant(context.TODO(), &pb.GrantRequest{ + Role: role, + Resource: &pb.Resource{ + Type: res.Type, + Name: res.Name, + Endpoint: res.Endpoint, + }, + }) return err } -// Verify an account token -func (s *svc) Verify(token string) (*auth.Account, error) { - resp, err := s.auth.Verify(context.Background(), &pb.VerifyRequest{Token: token}) +// Revoke access to a resource +func (s *svc) Revoke(role string, res *auth.Resource) error { + _, err := s.auth.Revoke(context.TODO(), &pb.RevokeRequest{ + Role: role, + Resource: &pb.Resource{ + Type: res.Type, + Name: res.Name, + Endpoint: res.Endpoint, + }, + }) + return err +} + +// Verify an account has access to a resource +func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { + _, err := s.auth.Verify(context.TODO(), &pb.VerifyRequest{ + Account: &pb.Account{ + Id: acc.ID, + Roles: acc.Roles, + }, + Resource: &pb.Resource{ + Type: res.Type, + Name: res.Name, + Endpoint: res.Endpoint, + }, + }) + return err +} + +// Inspect a token +func (s *svc) Inspect(token string) (*auth.Account, error) { + // try to decode JWT locally and fall back to srv if an error + // occurs, TODO: find a better way of determining if the token + // is a JWT, possibly update the interface to take an auth.Token + // and not just the string + if len(strings.Split(token, ".")) == 3 && s.jwt != nil { + if tok, err := s.jwt.Inspect(token); err == nil { + return &auth.Account{ + ID: tok.Subject, + Roles: tok.Roles, + Metadata: tok.Metadata, + }, nil + } + } + + rsp, err := s.auth.Inspect(context.TODO(), &pb.InspectRequest{ + Token: token, + }) if err != nil { return nil, err } - return deserializeAccount(resp.Account), nil + return serializeAccount(rsp.Account), nil } -func serializeAccount(sa *auth.Account) *pb.Account { - roles := make([]*pb.Role, len(sa.Roles)) - for i, r := range sa.Roles { - roles[i] = &pb.Role{ - Name: r.Name, - } +// Refresh an account using a secret +func (s *svc) Refresh(secret string, opts ...auth.RefreshOption) (*auth.Token, error) { + options := auth.NewRefreshOptions(opts...) - if r.Resource != nil { - roles[i].Resource = &pb.Resource{ - Name: r.Resource.Name, - Type: r.Resource.Type, - } - } + rsp, err := s.auth.Refresh(context.Background(), &pb.RefreshRequest{ + Secret: secret, + TokenExpiry: int64(options.TokenExpiry.Seconds()), + }) + if err != nil { + return nil, err } - return &pb.Account{ - Id: sa.Id, - Roles: roles, - Metadata: sa.Metadata, + return serializeToken(rsp.Token), nil +} + +func serializeToken(t *pb.Token) *auth.Token { + return &auth.Token{ + Token: t.Token, + Type: t.Type, + Created: time.Unix(t.Created, 0), + Expiry: time.Unix(t.Expiry, 0), + Subject: t.Subject, + Roles: t.Roles, + Metadata: t.Metadata, } } -func deserializeAccount(a *pb.Account) *auth.Account { - // format the response - sa := &auth.Account{ - Id: a.Id, - Token: a.Token, - Created: time.Unix(a.Created, 0), - Expiry: time.Unix(a.Expiry, 0), +func serializeAccount(a *pb.Account) *auth.Account { + var secret *auth.Token + if a.Secret != nil { + secret = serializeToken(a.Secret) + } + + return &auth.Account{ + ID: a.Id, + Roles: a.Roles, Metadata: a.Metadata, + Secret: secret, } - - sa.Roles = make([]*auth.Role, len(a.Roles)) - for i, r := range a.Roles { - sa.Roles[i] = &auth.Role{ - Name: r.Name, - } - - if r.Resource != nil { - sa.Roles[i].Resource = &auth.Resource{ - Name: r.Resource.Name, - Type: r.Resource.Type, - } - } - } - - return sa } diff --git a/auth/store/rules.go b/auth/store/rules.go new file mode 100644 index 00000000..29270eeb --- /dev/null +++ b/auth/store/rules.go @@ -0,0 +1,72 @@ +package store + +import ( + "encoding/json" + "strings" + + "github.com/micro/go-micro/v2/auth" + "github.com/micro/go-micro/v2/store" +) + +// Rule is an access control rule +type Rule struct { + Role string `json:"rule"` + Resource *auth.Resource `json:"resource"` +} + +// Key to be used when written to the store +func (r *Rule) Key() string { + comps := []string{r.Resource.Type, r.Resource.Name, r.Resource.Endpoint, r.Role} + return strings.Join(comps, "/") +} + +// Bytes returns json encoded bytes +func (r *Rule) Bytes() []byte { + bytes, _ := json.Marshal(r) + return bytes +} + +// isValidRule returns a bool, indicating if a rule permits access to a +// resource for a given account +func isValidRule(rule Rule, acc *auth.Account, res *auth.Resource) bool { + if rule.Role == "*" { + return true + } + + for _, role := range acc.Roles { + if rule.Role == role { + return true + } + + // allow user.anything if role is user.* + if strings.HasSuffix(rule.Role, ".*") && strings.HasPrefix(rule.Role, role+".") { + return true + } + } + + return false +} + +// listRules gets all the rules from the store which have a key +// prefix matching the filters +func (s *Store) listRules(filters ...string) ([]Rule, error) { + // get the records from the store + prefix := strings.Join(filters, "/") + recs, err := s.opts.Store.Read(prefix, store.ReadPrefix()) + if err != nil { + return nil, err + } + + // unmarshal the records + rules := make([]Rule, 0, len(recs)) + for _, rec := range recs { + var r Rule + if err := json.Unmarshal(rec.Value, &r); err != nil { + return nil, err + } + rules = append(rules, r) + } + + // return the rules + return rules, nil +} diff --git a/auth/store/store.go b/auth/store/store.go index 3f3f4d42..de5d5e75 100644 --- a/auth/store/store.go +++ b/auth/store/store.go @@ -1,130 +1,159 @@ package store import ( - "bytes" - "encoding/gob" - "time" - - "github.com/google/uuid" "github.com/micro/go-micro/v2/auth" - "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/auth/token" + "github.com/micro/go-micro/v2/auth/token/basic" "github.com/micro/go-micro/v2/store" + memStore "github.com/micro/go-micro/v2/store/memory" ) -type Auth struct { - store store.Store - opts auth.Options -} - -// NewAuth returns an instance of store auth +// NewAuth returns a new default registry which is store func NewAuth(opts ...auth.Option) auth.Auth { - var options auth.Options + var s Store + s.Init(opts...) + return &s +} +// Store implementation of auth +type Store struct { + secretProvider token.Provider + tokenProvider token.Provider + opts auth.Options +} + +// String returns store +func (s *Store) String() string { + return "store" +} + +// Init the auth +func (s *Store) Init(opts ...auth.Option) { for _, o := range opts { - o(&options) + o(&s.opts) } - return &Auth{ - store: store.DefaultStore, - opts: options, + // use the default store as a fallback + if s.opts.Store == nil { + s.opts.Store = store.DefaultStore + } + + // noop will not work for auth + if s.opts.Store.String() == "noop" { + s.opts.Store = memStore.NewStore() + } + + if s.tokenProvider == nil { + s.tokenProvider = basic.NewTokenProvider(token.WithStore(s.opts.Store)) + } + if s.secretProvider == nil { + s.secretProvider = basic.NewTokenProvider(token.WithStore(s.opts.Store)) } } -// Init the auth package -func (a *Auth) Init(opts ...auth.Option) error { - for _, o := range opts { - o(&a.opts) - } - return nil +// Options returns the options +func (s *Store) Options() auth.Options { + return s.opts } -// Options returns the options set -func (a *Auth) Options() auth.Options { - return a.opts -} - -// Generate a new auth Account -func (a *Auth) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { - // generate the token - token, err := uuid.NewUUID() - if err != nil { - return nil, err - } - +// Generate a new account +func (s *Store) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { // parse the options options := auth.NewGenerateOptions(opts...) - // construct the account - sa := auth.Account{ - Id: id, - Token: token.String(), - Created: time.Now(), - Metadata: options.Metadata, - Roles: options.Roles, + // Generate a long-lived secret + secretOpts := []token.GenerateOption{ + token.WithExpiry(options.SecretExpiry), + token.WithMetadata(options.Metadata), + token.WithRoles(options.Roles), } - - // encode the data to bytes - // TODO: replace with json - buf := &bytes.Buffer{} - e := gob.NewEncoder(buf) - if err := e.Encode(sa); err != nil { - return nil, err - } - - // write to the store - err = a.store.Write(&store.Record{ - Key: token.String(), - Value: buf.Bytes(), - }) + secret, err := s.secretProvider.Generate(id, secretOpts...) if err != nil { return nil, err } - // return the result - return &sa, nil + // return the account + return &auth.Account{ + ID: id, + Roles: options.Roles, + Metadata: options.Metadata, + Secret: secret, + }, nil } -// Revoke an authorization Account -func (a *Auth) Revoke(token string) error { - records, err := a.store.Read(token, store.ReadSuffix()) - if err != nil { - return err - } - if len(records) == 0 { - return errors.BadRequest("go.micro.auth", "token not found") +// Grant access to a resource +func (s *Store) Grant(role string, res *auth.Resource) error { + r := Rule{role, res} + return s.opts.Store.Write(&store.Record{Key: r.Key(), Value: r.Bytes()}) +} + +// Revoke access to a resource +func (s *Store) Revoke(role string, res *auth.Resource) error { + r := Rule{role, res} + + err := s.opts.Store.Delete(r.Key()) + if err == store.ErrNotFound { + return auth.ErrNotFound } - for _, r := range records { - if err := a.store.Delete(r.Key); err != nil { - return errors.InternalServerError("go.micro.auth", "error deleting from store") + return err +} + +// Verify an account has access to a resource +func (s *Store) Verify(acc *auth.Account, res *auth.Resource) error { + queries := [][]string{ + {res.Type, "*"}, // check for wildcard resource type, e.g. service.* + {res.Type, res.Name, "*"}, // check for wildcard name, e.g. service.foo* + {res.Type, res.Name, res.Endpoint, "*"}, // check for wildcard endpoints, e.g. service.foo.ListFoo:* + {res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin + } + + for _, q := range queries { + rules, err := s.listRules(q...) + if err != nil { + return err + } + + for _, rule := range rules { + if isValidRule(rule, acc, res) { + return nil + } } } - return nil + return auth.ErrForbidden } -// Verify an account token -func (a *Auth) Verify(token string) (*auth.Account, error) { - // lookup the record by token - records, err := a.store.Read(token, store.ReadSuffix()) - if err == store.ErrNotFound || len(records) == 0 { - return nil, errors.Unauthorized("go.micro.auth", "invalid token") +// Inspect a token +func (s *Store) Inspect(t string) (*auth.Account, error) { + tok, err := s.tokenProvider.Inspect(t) + if err == token.ErrInvalidToken || err == token.ErrNotFound { + return nil, auth.ErrInvalidToken } else if err != nil { - return nil, errors.InternalServerError("go.micro.auth", "error reading store") + return nil, err } - // decode the result - // TODO: replace with json - b := bytes.NewBuffer(records[0].Value) - decoder := gob.NewDecoder(b) - var sa auth.Account - err = decoder.Decode(&sa) - - // return the result - return &sa, err + return &auth.Account{ + ID: tok.Subject, + Roles: tok.Roles, + Metadata: tok.Metadata, + }, nil } -// String returns the implementation -func (a *Auth) String() string { - return "store" +// Refresh an account using a secret +func (s *Store) Refresh(secret string, opts ...auth.RefreshOption) (*auth.Token, error) { + sec, err := s.secretProvider.Inspect(secret) + if err == token.ErrInvalidToken || err == token.ErrNotFound { + return nil, auth.ErrInvalidToken + } else if err != nil { + return nil, err + } + + options := auth.NewRefreshOptions(opts...) + + return s.tokenProvider.Generate(sec.Subject, + token.WithExpiry(options.TokenExpiry), + token.WithMetadata(sec.Metadata), + token.WithRoles(sec.Roles), + ) } diff --git a/auth/store/store_test.go b/auth/store/store_test.go new file mode 100644 index 00000000..03381e31 --- /dev/null +++ b/auth/store/store_test.go @@ -0,0 +1,287 @@ +package store + +import ( + "log" + "testing" + + "github.com/micro/go-micro/v2/auth" + memStore "github.com/micro/go-micro/v2/store/memory" +) + +func TestGenerate(t *testing.T) { + s := memStore.NewStore() + a := NewAuth(auth.Store(s)) + + id := "test" + roles := []string{"admin"} + metadata := map[string]string{"foo": "bar"} + + opts := []auth.GenerateOption{ + auth.WithRoles(roles), + auth.WithMetadata(metadata), + } + + // generate the account + acc, err := a.Generate(id, opts...) + if err != nil { + t.Fatalf("Generate returned an error: %v, expected nil", err) + } + // validate the account attributes were set correctly + if acc.ID != id { + t.Errorf("Generate returned %v as the ID, expected %v", acc.ID, id) + } + if len(acc.Roles) != len(roles) { + t.Errorf("Generate returned %v as the roles, expected %v", acc.Roles, roles) + } + if len(acc.Metadata) != len(metadata) { + t.Errorf("Generate returned %v as the metadata, expected %v", acc.Metadata, metadata) + } + + // validate the secret is valid + if _, err := a.Refresh(acc.Secret.Token); err != nil { + t.Errorf("Generate returned an invalid secret, error: %v", err) + } +} + +func TestGrant(t *testing.T) { + s := memStore.NewStore() + a := NewAuth(auth.Store(s)) + + res := &auth.Resource{Type: "service", Name: "Test", Endpoint: "Foo.Bar"} + if err := a.Grant("users.*", res); err != nil { + t.Fatalf("Grant returned an error: %v, expected nil", err) + } + + recs, err := s.List() + if err != nil { + t.Fatalf("Could not read from the store: %v", err) + } + if len(recs) != 1 { + t.Errorf("Expected Grant to write 1 record, actually wrote %v", len(recs)) + } +} + +func TestRevoke(t *testing.T) { + s := memStore.NewStore() + a := NewAuth(auth.Store(s)) + + res := &auth.Resource{Type: "service", Name: "Test", Endpoint: "Foo.Bar"} + if err := a.Grant("users.*", res); err != nil { + t.Fatalf("Grant returned an error: %v, expected nil", err) + } + + recs, err := s.List() + if err != nil { + t.Fatalf("Could not read from the store: %v", err) + } + if len(recs) != 1 { + t.Fatalf("Expected Grant to write 1 record, actually wrote %v", len(recs)) + } + + if err := a.Revoke("users.*", res); err != nil { + t.Fatalf("Revoke returned an error: %v, expected nil", err) + } + + recs, err = s.List() + if err != nil { + t.Fatalf("Could not read from the store: %v", err) + } + if len(recs) != 0 { + t.Fatalf("Expected Revoke to delete 1 record, actually deleted %v", 1-len(recs)) + } +} + +func TestInspect(t *testing.T) { + a := NewAuth() + + t.Run("Valid Token", func(t *testing.T) { + id := "test" + roles := []string{"admin"} + metadata := map[string]string{"foo": "bar"} + + opts := []auth.GenerateOption{ + auth.WithRoles(roles), + auth.WithMetadata(metadata), + } + + // generate and inspect the token + acc, err := a.Generate("test", opts...) + if err != nil { + log.Fatalf("Generate returned an error: %v, expected nil", err) + } + tok, err := a.Refresh(acc.Secret.Token) + if err != nil { + log.Fatalf("Refresh returned an error: %v, expected nil", err) + } + acc2, err := a.Inspect(tok.Token) + if err != nil { + log.Fatalf("Inspect returned an error: %v, expected nil", err) + } + + // validate the account attributes were retrieved correctly + if acc2.ID != id { + t.Errorf("Generate returned %v as the ID, expected %v", acc.ID, id) + } + if len(acc2.Roles) != len(roles) { + t.Errorf("Generate returned %v as the roles, expected %v", acc.Roles, roles) + } + if len(acc2.Metadata) != len(metadata) { + t.Errorf("Generate returned %v as the metadata, expected %v", acc.Metadata, metadata) + } + }) + + t.Run("Invalid Token", func(t *testing.T) { + _, err := a.Inspect("invalid token") + if err != auth.ErrInvalidToken { + t.Errorf("Inspect returned %v error, expected %v", err, auth.ErrInvalidToken) + } + }) +} + +func TestRefresh(t *testing.T) { + a := NewAuth() + + t.Run("Valid Secret", func(t *testing.T) { + roles := []string{"admin"} + metadata := map[string]string{"foo": "bar"} + + opts := []auth.GenerateOption{ + auth.WithRoles(roles), + auth.WithMetadata(metadata), + } + + // generate the account + acc, err := a.Generate("test", opts...) + if err != nil { + log.Fatalf("Generate returned an error: %v, expected nil", err) + } + + // refresh the token + tok, err := a.Refresh(acc.Secret.Token) + if err != nil { + log.Fatalf("Refresh returned an error: %v, expected nil", err) + } + + // validate the account attributes were set correctly + if acc.ID != tok.Subject { + t.Errorf("Refresh returned %v as the ID, expected %v", acc.ID, tok.Subject) + } + if len(acc.Roles) != len(tok.Roles) { + t.Errorf("Refresh returned %v as the roles, expected %v", acc.Roles, tok.Subject) + } + if len(acc.Metadata) != len(tok.Metadata) { + t.Errorf("Refresh returned %v as the metadata, expected %v", acc.Metadata, tok.Metadata) + } + }) + + t.Run("Invalid Secret", func(t *testing.T) { + _, err := a.Refresh("invalid secret") + if err != auth.ErrInvalidToken { + t.Errorf("Inspect returned %v error, expected %v", err, auth.ErrInvalidToken) + } + }) +} + +func TestVerify(t *testing.T) { + testRules := []struct { + Role string + Resource *auth.Resource + }{ + { + Role: "*", + Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.PublicList"}, + }, + { + Role: "user.*", + Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.List"}, + }, + { + Role: "user.developer", + Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Update"}, + }, + { + Role: "admin", + Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Delete"}, + }, + { + Role: "admin", + Resource: &auth.Resource{Type: "service", Name: "*", Endpoint: "*"}, + }, + } + + a := NewAuth() + for _, r := range testRules { + if err := a.Grant(r.Role, r.Resource); err != nil { + t.Fatalf("Grant returned an error: %v, expected nil", err) + } + } + + testTable := []struct { + Name string + Roles []string + Resource *auth.Resource + Error error + }{ + { + Name: "An account with no roles accessing a public endpoint", + Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.PublicList"}, + }, + { + Name: "An account with no roles accessing a private endpoint", + Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Update"}, + Error: auth.ErrForbidden, + }, + { + Name: "An account with the user role accessing a user* endpoint", + Roles: []string{"user"}, + Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.List"}, + }, + { + Name: "An account with the user role accessing a user.admin endpoint", + Roles: []string{"user"}, + Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Delete"}, + Error: auth.ErrForbidden, + }, + { + Name: "An account with the developer role accessing a user.developer endpoint", + Roles: []string{"user.developer"}, + Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Update"}, + }, + { + Name: "An account with the developer role accessing an admin endpoint", + Roles: []string{"user.developer"}, + Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Delete"}, + Error: auth.ErrForbidden, + }, + { + Name: "An admin account accessing an admin endpoint", + Roles: []string{"admin"}, + Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Delete"}, + }, + { + Name: "An admin account accessing a generic service endpoint", + Roles: []string{"admin"}, + Resource: &auth.Resource{Type: "service", Name: "go.micro.foo", Endpoint: "Foo.Bar"}, + }, + { + Name: "An admin account accessing an unauthorised endpoint", + Roles: []string{"admin"}, + Resource: &auth.Resource{Type: "infra", Name: "go.micro.foo", Endpoint: "Foo.Bar"}, + Error: auth.ErrForbidden, + }, + { + Name: "A account with no roles accessing an unauthorised endpoint", + Resource: &auth.Resource{Type: "infra", Name: "go.micro.foo", Endpoint: "Foo.Bar"}, + Error: auth.ErrForbidden, + }, + } + + for _, tc := range testTable { + t.Run(tc.Name, func(t *testing.T) { + acc := &auth.Account{Roles: tc.Roles} + if err := a.Verify(acc, tc.Resource); err != tc.Error { + t.Errorf("Verify returned %v error, expected %v", err, tc.Error) + } + }) + } +} diff --git a/auth/token/basic/basic.go b/auth/token/basic/basic.go new file mode 100644 index 00000000..edf5d2fb --- /dev/null +++ b/auth/token/basic/basic.go @@ -0,0 +1,95 @@ +package basic + +import ( + "encoding/json" + "time" + + "github.com/google/uuid" + "github.com/micro/go-micro/v2/auth" + "github.com/micro/go-micro/v2/auth/token" + "github.com/micro/go-micro/v2/store" +) + +// Basic implementation of token provider, backed by the store +type Basic struct { + store store.Store +} + +// NewTokenProvider returns an initialized basic provider +func NewTokenProvider(opts ...token.Option) token.Provider { + options := token.NewOptions(opts...) + + if options.Store == nil { + options.Store = store.DefaultStore + } + + return &Basic{ + store: options.Store, + } +} + +// Generate a token for an account +func (b *Basic) Generate(subject string, opts ...token.GenerateOption) (*auth.Token, error) { + options := token.NewGenerateOptions(opts...) + + // construct the token + token := auth.Token{ + Subject: subject, + Type: b.String(), + Token: uuid.New().String(), + Created: time.Now(), + Expiry: time.Now().Add(options.Expiry), + Metadata: options.Metadata, + Roles: options.Roles, + } + + // marshal the account to bytes + bytes, err := json.Marshal(token) + if err != nil { + return nil, err + } + + // write to the store + err = b.store.Write(&store.Record{ + Key: token.Token, + Value: bytes, + Expiry: options.Expiry, + }) + if err != nil { + return nil, err + } + + // return the token + return &token, nil +} + +// Inspect a token +func (b *Basic) Inspect(t string) (*auth.Token, error) { + // lookup the token in the store + recs, err := b.store.Read(t) + if err == store.ErrNotFound { + return nil, token.ErrInvalidToken + } else if err != nil { + return nil, err + } + bytes := recs[0].Value + + // unmarshal the bytes + var tok *auth.Token + if err := json.Unmarshal(bytes, &tok); err != nil { + return nil, err + } + + // ensure the token hasn't expired, the store should + // expire the token but we're checking again + if tok.Expiry.Unix() < time.Now().Unix() { + return nil, token.ErrInvalidToken + } + + return tok, err +} + +// String returns basic +func (b *Basic) String() string { + return "basic" +} diff --git a/auth/token/basic/basic_test.go b/auth/token/basic/basic_test.go new file mode 100644 index 00000000..159387a1 --- /dev/null +++ b/auth/token/basic/basic_test.go @@ -0,0 +1,80 @@ +package basic + +import ( + "testing" + "time" + + "github.com/micro/go-micro/v2/auth/token" + "github.com/micro/go-micro/v2/store/memory" +) + +func TestGenerate(t *testing.T) { + store := memory.NewStore() + b := NewTokenProvider(token.WithStore(store)) + + _, err := b.Generate("test") + if err != nil { + t.Fatalf("Generate returned %v error, expected nil", err) + } + + recs, err := store.List() + if err != nil { + t.Fatalf("Unable to read from store: %v", err) + } + if len(recs) != 1 { + t.Errorf("Generate didn't write to the store, expected 1 record, got %v", len(recs)) + } +} + +func TestInspect(t *testing.T) { + store := memory.NewStore() + b := NewTokenProvider(token.WithStore(store)) + + t.Run("Valid token", func(t *testing.T) { + md := map[string]string{"foo": "bar"} + roles := []string{"admin"} + subject := "test" + + opts := []token.GenerateOption{ + token.WithMetadata(md), + token.WithRoles(roles), + } + + tok, err := b.Generate(subject, opts...) + if err != nil { + t.Fatalf("Generate returned %v error, expected nil", err) + } + + tok2, err := b.Inspect(tok.Token) + if err != nil { + t.Fatalf("Inspect returned %v error, expected nil", err) + } + if tok2.Subject != subject { + t.Errorf("Inspect returned %v as the token subject, expected %v", tok2.Subject, subject) + } + if len(tok2.Roles) != len(roles) { + t.Errorf("Inspect returned %v roles, expected %v", len(tok2.Roles), len(roles)) + } + if len(tok2.Metadata) != len(md) { + t.Errorf("Inspect returned %v as the token metadata, expected %v", tok2.Metadata, md) + } + }) + + t.Run("Expired token", func(t *testing.T) { + tok, err := b.Generate("foo", token.WithExpiry(-10*time.Second)) + if err != nil { + t.Fatalf("Generate returned %v error, expected nil", err) + } + + if _, err = b.Inspect(tok.Token); err != token.ErrInvalidToken { + t.Fatalf("Inspect returned %v error, expected %v", err, token.ErrInvalidToken) + } + }) + + t.Run("Invalid token", func(t *testing.T) { + _, err := b.Inspect("Invalid token") + if err != token.ErrInvalidToken { + t.Fatalf("Inspect returned %v error, expected %v", err, token.ErrInvalidToken) + } + }) +} diff --git a/auth/token/jwt/jwt.go b/auth/token/jwt/jwt.go new file mode 100644 index 00000000..12504fbe --- /dev/null +++ b/auth/token/jwt/jwt.go @@ -0,0 +1,111 @@ +package jwt + +import ( + "encoding/base64" + "time" + + "github.com/dgrijalva/jwt-go" + "github.com/micro/go-micro/v2/auth" + "github.com/micro/go-micro/v2/auth/token" +) + +// authClaims to be encoded in the JWT +type authClaims struct { + Roles []string `json:"roles"` + Metadata map[string]string `json:"metadata"` + + jwt.StandardClaims +} + +// JWT implementation of token provider +type JWT struct { + opts token.Options +} + +// NewTokenProvider returns an initialized basic provider +func NewTokenProvider(opts ...token.Option) token.Provider { + return &JWT{ + opts: token.NewOptions(opts...), + } +} + +// Generate a new JWT +func (j *JWT) Generate(subject string, opts ...token.GenerateOption) (*auth.Token, error) { + // decode the private key + priv, err := base64.StdEncoding.DecodeString(j.opts.PrivateKey) + if err != nil { + return nil, err + } + + // parse the private key + key, err := jwt.ParseRSAPrivateKeyFromPEM(priv) + if err != nil { + return nil, token.ErrEncodingToken + } + + // parse the options + options := token.NewGenerateOptions(opts...) + + // generate the JWT + expiry := time.Now().Add(options.Expiry) + t := jwt.NewWithClaims(jwt.SigningMethodRS256, authClaims{ + options.Roles, options.Metadata, jwt.StandardClaims{ + Subject: subject, + ExpiresAt: expiry.Unix(), + }, + }) + tok, err := t.SignedString(key) + if err != nil { + return nil, err + } + + // return the token + return &auth.Token{ + Subject: subject, + Token: tok, + Type: j.String(), + Created: time.Now(), + Expiry: expiry, + Roles: options.Roles, + Metadata: options.Metadata, + }, nil +} + +// Inspect a JWT +func (j *JWT) Inspect(t string) (*auth.Token, error) { + // decode the public key + pub, err := base64.StdEncoding.DecodeString(j.opts.PublicKey) + if err != nil { + return nil, err + } + + // parse the public key + res, err := jwt.ParseWithClaims(t, &authClaims{}, func(token *jwt.Token) (interface{}, error) { + return jwt.ParseRSAPublicKeyFromPEM(pub) + }) + if err != nil { + return nil, token.ErrInvalidToken + } + + // validate the token + if !res.Valid { + return nil, token.ErrInvalidToken + } + claims, ok := res.Claims.(*authClaims) + if !ok { + return nil, token.ErrInvalidToken + } + + // return the token + return &auth.Token{ + Token: t, + Subject: claims.Subject, + Metadata: claims.Metadata, + Roles: claims.Roles, + }, nil +} + +// String returns JWT +func (j *JWT) String() string { + return "jwt" +} diff --git a/auth/token/jwt/jwt_test.go b/auth/token/jwt/jwt_test.go new file mode 100644 index 00000000..3a2c6237 --- /dev/null +++ b/auth/token/jwt/jwt_test.go @@ -0,0 +1,90 @@ +package jwt + +import ( + "io/ioutil" + "testing" + "time" + + "github.com/micro/go-micro/v2/auth/token" +) + +func TestGenerate(t *testing.T) { + privKey, err := ioutil.ReadFile("test/sample_key") + if err != nil { + t.Fatalf("Unable to read private key: %v", err) + } + + j := NewTokenProvider( + token.WithPrivateKey(string(privKey)), + ) + + _, err = j.Generate("test") + if err != nil { + t.Fatalf("Generate returned %v error, expected nil", err) + } +} + +func TestInspect(t *testing.T) { + pubKey, err := ioutil.ReadFile("test/sample_key.pub") + if err != nil { + t.Fatalf("Unable to read public key: %v", err) + } + privKey, err := ioutil.ReadFile("test/sample_key") + if err != nil { + t.Fatalf("Unable to read private key: %v", err) + } + + j := NewTokenProvider( + token.WithPublicKey(string(pubKey)), + token.WithPrivateKey(string(privKey)), + ) + + t.Run("Valid token", func(t *testing.T) { + md := map[string]string{"foo": "bar"} + roles := []string{"admin"} + subject := "test" + + opts := []token.GenerateOption{ + token.WithMetadata(md), + token.WithRoles(roles), + } + + tok, err := j.Generate(subject, opts...) + if err != nil { + t.Fatalf("Generate returned %v error, expected nil", err) + } + + tok2, err := j.Inspect(tok.Token) + if err != nil { + t.Fatalf("Inspect returned %v error, expected nil", err) + } + if tok2.Subject != subject { + t.Errorf("Inspect returned %v as the token subject, expected %v", tok2.Subject, subject) + } + if len(tok2.Roles) != len(roles) { + t.Errorf("Inspect returned %v roles, expected %v", len(tok2.Roles), len(roles)) + } + if len(tok2.Metadata) != len(md) { + t.Errorf("Inspect returned %v as the token metadata, expected %v", tok2.Metadata, md) + } + }) + + t.Run("Expired token", func(t *testing.T) { + tok, err := j.Generate("foo", token.WithExpiry(-10*time.Second)) + if err != nil { + t.Fatalf("Generate returned %v error, expected nil", err) + } + + if _, err = j.Inspect(tok.Token); err != token.ErrInvalidToken { + t.Fatalf("Inspect returned %v error, expected %v", err, token.ErrInvalidToken) + } + }) + + t.Run("Invalid token", func(t *testing.T) { + _, err := j.Inspect("Invalid token") + if err != token.ErrInvalidToken { + t.Fatalf("Inspect returned %v error, expected %v", err, token.ErrInvalidToken) + } + }) + +} diff --git a/auth/token/jwt/test/sample_key b/auth/token/jwt/test/sample_key new file mode 100644 index 00000000..25488667 --- /dev/null +++ b/auth/token/jwt/test/sample_key @@ -0,0 +1 @@ +LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlKS3dJQkFBS0NBZ0VBOFNiSlA1WGJFaWRSbTViMnNOcExHbzJlV2ZVNU9KZTBpemdySHdEOEg3RjZQa1BkCi9SbDkvMXBNVjdNaU8zTEh3dGhIQzJCUllxcisxd0Zkb1pDR0JZckxhWHVYRnFLMHZ1WmhQcUUzYXpqdUlIUXUKMEJIL2xYUU1xeUVxRjVNSTJ6ZWpDNHpNenIxNU9OK2dFNEpuaXBqcC9DZGpPUEFEbUpHK0JKOXFlRS9RUGVtLwptVWRJVC9MYUY3a1F4eVlLNVZLbitOZ09Xek1sektBQXBDbjdUVEtCVWU4RlpHNldTWDdMVjBlTEdIc29pYnhsCm85akRq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PUktZTUttSHg4M08zRWsKMWhvb0FwbTZabTIzMjRGME1iVU1ham5Idld2ZjhHZGJTNk5zcHd4L0dkbk1tYVMrdUJMVUhVMkNLbmc1bEIwVAp4OWJITmY0dXlPbTR0dXRmNzhCd1R5V3UreEdrVW0zZ2VZMnkvR1hqdDZyY2l1ajFGNzFDenZzcXFmZThTcDdJCnd6SHdxcTNzVHR5S2lCYTZuYUdEYWpNR1pKYSt4MVZJV204Q2dnRUJBT001ajFZR25Ba0pxR0czQWJSVDIvNUMKaVVxN0loYkswOGZsSGs5a2YwUlVjZWc0ZVlKY3dIRXJVaE4rdWQyLzE3MC81dDYra0JUdTVZOUg3bkpLREtESQpoeEg5SStyamNlVkR0RVNTRkluSXdDQ1lrOHhOUzZ0cHZMV1U5b0pibGFKMlZsalV2NGRFWGVQb0hkREh1Zk9ZClVLa0lsV2E3Uit1QzNEOHF5U1JrQnFLa3ZXZ1RxcFNmTVNkc1ZTeFIzU2Q4SVhFSHFjTDNUNEtMWGtYNEdEamYKMmZOSTFpZkx6ekhJMTN3Tk5IUTVRNU9SUC9pell2QzVzZkx4U2ZIUXJiMXJZVkpKWkI5ZjVBUjRmWFpHSVFsbApjMG8xd0JmZFlqMnZxVDlpR09IQnNSSTlSL2M2RzJQcUt3aFRpSzJVR2lmVFNEUVFuUkF6b2tpQVkrbE8vUjQ9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg== \ No newline at end of file diff --git a/auth/token/jwt/test/sample_key.pub b/auth/token/jwt/test/sample_key.pub new file mode 100644 index 00000000..77bd153d --- /dev/null +++ b/auth/token/jwt/test/sample_key.pub @@ -0,0 +1 @@ +LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQ0lqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FnOEFNSUlDQ2dLQ0FnRUE4U2JKUDVYYkVpZFJtNWIyc05wTApHbzJlV2ZVNU9KZTBpemdySHdEOEg3RjZQa1BkL1JsOS8xcE1WN01pTzNMSHd0aEhDMkJSWXFyKzF3RmRvWkNHCkJZckxhWHVYRnFLMHZ1WmhQcUUzYXpqdUlIUXUwQkgvbFhRTXF5RXFGNU1JMnplakM0ek16cjE1T04rZ0U0Sm4KaXBqcC9DZGpPUEFEbUpHK0JKOXFlRS9RUGVtL21VZElUL0xhRjdrUXh5WUs1VktuK05nT1d6TWx6S0FBcENuNwpUVEtCVWU4RlpHNldTWDdMVjBlTEdIc29pYnhsbzlqRGpsWTVvQk9jemZxZU5XSEs1R1hCN1F3cExOaDk0NlB6ClpucW9hcFdVZStZL1JPaUhpekpUY3I1Wk1TTDV3bEVxOGhOaG1obTVOTmUvTytHZ2pCRE5TZlVoMDYrcTRuZ20KYm1OWDVoODM4QmJqUmN5YzM2ZHd6NkpVK2R1b1J0UWhnaVk5MTBwUGY5YmF1WFdxd1VDVWE0cXNIempLUjBMLwpOMVhYQXlsQ0RqeWVnWnp6Y093MkNIOFNrZkZVcmdMclBiRUI5ZWdjR2szOCticEtzM1o2UnI1K3RuRDFCSVBJCkZHTGVJMFVPQzAreGlCdjBvenhJRE9GbldhOVVUR0R4VXg4b2o4VkllUm5XRHE2TWMxaUpwOFV5Y2lCSVRSdHcKNGRabzcweG1mbmVJV3pyM0tTTmFoU29nSmRSMGxhUXpBdVAzYWlXWElNcDJzYzhTYytCbCtMalhtQm94QnJhQgpIaDlLa0pKRWNnQUZ3czJib2pDbEpPWXhvRi9YZ0ZLU3NJbkhEckhWT3lXUEJlM2ZhZEVjNzdiK25iL2V4T3pyCjFFcnhoR2c5akZtcmtPK3M0eEdodjZNQ0F3RUFBUT09Ci0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQo= \ No newline at end of file diff --git a/auth/token/options.go b/auth/token/options.go new file mode 100644 index 00000000..d2e490b8 --- /dev/null +++ b/auth/token/options.go @@ -0,0 +1,96 @@ +package token + +import ( + "time" + + "github.com/micro/go-micro/v2/store" +) + +type Options struct { + // Store to persist the tokens + Store store.Store + // PublicKey base64 encoded, used by JWT + PublicKey string + // PrivateKey base64 encoded, used by JWT + PrivateKey string +} + +type Option func(o *Options) + +// WithStore sets the token providers store +func WithStore(s store.Store) Option { + return func(o *Options) { + o.Store = s + } +} + +// WithPublicKey sets the JWT public key +func WithPublicKey(key string) Option { + return func(o *Options) { + o.PublicKey = key + } +} + +// WithPrivateKey sets the JWT private key +func WithPrivateKey(key string) Option { + return func(o *Options) { + o.PrivateKey = key + } +} + +func NewOptions(opts ...Option) Options { + var options Options + for _, o := range opts { + o(&options) + } + //set default store + if options.Store == nil { + options.Store = store.DefaultStore + } + return options +} + +type GenerateOptions struct { + // Expiry for the token + Expiry time.Duration + // Metadata associated with the account + Metadata map[string]string + // Roles/scopes associated with the account + Roles []string +} + +type GenerateOption func(o *GenerateOptions) + +// WithExpiry for the generated account's token expires +func WithExpiry(d time.Duration) GenerateOption { + return func(o *GenerateOptions) { + o.Expiry = d + } +} + +// WithMetadata for the token +func WithMetadata(md map[string]string) func(o *GenerateOptions) { + return func(o *GenerateOptions) { + o.Metadata = md + } +} + +// WithRoles for the token +func WithRoles(rs []string) func(o *GenerateOptions) { + return func(o *GenerateOptions) { + o.Roles = rs + } +} + +// NewGenerateOptions from a slice of options +func NewGenerateOptions(opts ...GenerateOption) GenerateOptions { + var options GenerateOptions + for _, o := range opts { + o(&options) + } + //set default Expiry of token + if options.Expiry == 0 { + options.Expiry = time.Minute * 15 + } + return options +} diff --git a/auth/token/token.go b/auth/token/token.go new file mode 100644 index 00000000..da8409f1 --- /dev/null +++ b/auth/token/token.go @@ -0,0 +1,23 @@ +package token + +import ( + "errors" + + "github.com/micro/go-micro/v2/auth" +) + +var ( + // ErrNotFound is returned when a token cannot be found + ErrNotFound = errors.New("token not found") + // ErrEncodingToken is returned when the service encounters an error during encoding + ErrEncodingToken = errors.New("error encoding the token") + // ErrInvalidToken is returned when the token provided is not valid + ErrInvalidToken = errors.New("invalid token provided") +) + +// Provider generates and inspects tokens +type Provider interface { + Generate(subject string, opts ...GenerateOption) (*auth.Token, error) + Inspect(token string) (*auth.Token, error) + String() string +} diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index a43a4886..4ea999ca 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -70,8 +70,7 @@ import ( memTracer "github.com/micro/go-micro/v2/debug/trace/memory" // auth - jwtAuth "github.com/micro/go-micro/v2/auth/jwt" - sAuth "github.com/micro/go-micro/v2/auth/service" + svcAuth "github.com/micro/go-micro/v2/auth/service" storeAuth "github.com/micro/go-micro/v2/auth/store" // auth providers @@ -271,11 +270,6 @@ var ( EnvVars: []string{"MICRO_AUTH_PRIVATE_KEY"}, Usage: "Private key for JWT auth (base64 encoded PEM)", }, - &cli.StringSliceFlag{ - Name: "auth_exclude", - EnvVars: []string{"MICRO_AUTH_EXCLUDE"}, - Usage: "Comma-separated list of endpoints excluded from authentication, e.g. Users.ListUsers", - }, &cli.StringFlag{ Name: "auth_provider", EnvVars: []string{"MICRO_AUTH_PROVIDER"}, @@ -365,9 +359,8 @@ var ( } DefaultAuths = map[string]func(...auth.Option) auth.Auth{ - "service": sAuth.NewAuth, + "service": svcAuth.NewAuth, "store": storeAuth.NewAuth, - "jwt": jwtAuth.NewAuth, } DefaultAuthProviders = map[string]func(...provider.Option) provider.Provider{ @@ -665,7 +658,7 @@ func (c *cmd) Before(ctx *cli.Context) error { } if len(ctx.String("auth_token")) > 0 { - authOpts = append(authOpts, auth.Token(ctx.String("auth_token"))) + authOpts = append(authOpts, auth.ServiceToken(ctx.String("auth_token"))) } if len(ctx.String("auth_public_key")) > 0 { @@ -676,10 +669,6 @@ func (c *cmd) Before(ctx *cli.Context) error { authOpts = append(authOpts, auth.PrivateKey(ctx.String("auth_private_key"))) } - if len(ctx.StringSlice("auth_exclude")) > 0 { - authOpts = append(authOpts, auth.Exclude(ctx.StringSlice("auth_exclude")...)) - } - if name := ctx.String("auth_provider"); len(name) > 0 { p, ok := DefaultAuthProviders[name] if !ok { @@ -707,9 +696,7 @@ func (c *cmd) Before(ctx *cli.Context) error { } if len(authOpts) > 0 { - if err := (*c.opts.Auth).Init(authOpts...); err != nil { - logger.Fatalf("Error configuring auth: %v", err) - } + (*c.opts.Auth).Init(authOpts...) } if ctx.String("config") == "service" { diff --git a/service.go b/service.go index a47a38de..a693aa34 100644 --- a/service.go +++ b/service.go @@ -118,7 +118,7 @@ func (s *service) Init(opts ...Option) { // May need to re-read value on change // TODO: should be scoped to micro/auth/token if tk, _ := config.Get("token"); len(tk) > 0 { - s.opts.Auth.Init(auth.Token(tk)) + s.opts.Auth.Init(auth.ServiceToken(tk)) } }) } diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 80dc702b..cd4cc30c 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -164,6 +164,11 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { return h(ctx, req, rsp) } + // Check for auth service endpoints which should be excluded from auth + if strings.HasPrefix(req.Endpoint(), "Auth.") { + return h(ctx, req, rsp) + } + // Extract the token if present. Note: if noop is being used // then the token can be blank without erroring var token string @@ -177,28 +182,15 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { } // Verify the token - account, authErr := a.Verify(token) - - // If there is an account, set it in the context - if authErr == nil { - var err error - ctx, err = auth.ContextWithAccount(ctx, account) - - if err != nil { - return err - } + account, err := a.Inspect(token) + if err != nil { + return errors.Unauthorized("go.micro.auth", err.Error()) } - // Return if the user disabled auth on this endpoint - for _, e := range a.Options().Exclude { - if e == req.Endpoint() { - return h(ctx, req, rsp) - } - } - - // If the authErr is set, prevent the user from calling the endpoint - if authErr != nil { - return errors.Unauthorized("go.micro.auth", authErr.Error()) + // There is an account, set it in the context + ctx, err = auth.ContextWithAccount(ctx, account) + if err != nil { + return err } // The user is authorised, allow the call From c1978265abfa333aea2e1c942e1361ec67bb2560 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 24 Mar 2020 09:39:33 +0000 Subject: [PATCH 416/788] Auth Wildcard Endpoints (#1394) * Auth Wildcard Endpoints * Fix joinkey bug, improve tests * Change joinKey Co-authored-by: Ben Toogood --- auth/store/rules.go | 6 ++++-- auth/store/store.go | 12 ++++++++++++ auth/store/store_test.go | 21 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/auth/store/rules.go b/auth/store/rules.go index 29270eeb..c4bf0c49 100644 --- a/auth/store/rules.go +++ b/auth/store/rules.go @@ -14,10 +14,12 @@ type Rule struct { Resource *auth.Resource `json:"resource"` } +var joinKey = ":" + // Key to be used when written to the store func (r *Rule) Key() string { comps := []string{r.Resource.Type, r.Resource.Name, r.Resource.Endpoint, r.Role} - return strings.Join(comps, "/") + return strings.Join(comps, joinKey) } // Bytes returns json encoded bytes @@ -51,7 +53,7 @@ func isValidRule(rule Rule, acc *auth.Account, res *auth.Resource) bool { // prefix matching the filters func (s *Store) listRules(filters ...string) ([]Rule, error) { // get the records from the store - prefix := strings.Join(filters, "/") + prefix := strings.Join(filters, joinKey) recs, err := s.opts.Store.Read(prefix, store.ReadPrefix()) if err != nil { return nil, err diff --git a/auth/store/store.go b/auth/store/store.go index de5d5e75..dad0be00 100644 --- a/auth/store/store.go +++ b/auth/store/store.go @@ -1,6 +1,9 @@ package store import ( + "fmt" + "strings" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/auth/token" "github.com/micro/go-micro/v2/auth/token/basic" @@ -108,6 +111,15 @@ func (s *Store) Verify(acc *auth.Account, res *auth.Resource) error { {res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin } + // endpoint is a url which can have wildcard excludes, e.g. + // "/foo/*" will allow "/foo/bar" + if comps := strings.Split(res.Endpoint, "/"); len(comps) > 1 { + for i := 1; i < len(comps); i++ { + wildcard := fmt.Sprintf("%v/*", strings.Join(comps[0:i], "/")) + queries = append(queries, []string{res.Type, res.Name, wildcard}) + } + } + for _, q := range queries { rules, err := s.listRules(q...) if err != nil { diff --git a/auth/store/store_test.go b/auth/store/store_test.go index 03381e31..9b1ca0e9 100644 --- a/auth/store/store_test.go +++ b/auth/store/store_test.go @@ -191,6 +191,14 @@ func TestVerify(t *testing.T) { Role: "*", Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.PublicList"}, }, + { + Role: "*", + Resource: &auth.Resource{Type: "service", Name: "go.micro.web", Endpoint: "/foo"}, + }, + { + Role: "*", + Resource: &auth.Resource{Type: "service", Name: "go.micro.web", Endpoint: "/bar/*"}, + }, { Role: "user.*", Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.List"}, @@ -274,6 +282,19 @@ func TestVerify(t *testing.T) { Resource: &auth.Resource{Type: "infra", Name: "go.micro.foo", Endpoint: "Foo.Bar"}, Error: auth.ErrForbidden, }, + { + Name: "Accessing a public web path", + Resource: &auth.Resource{Type: "service", Name: "go.micro.web", Endpoint: "/foo"}, + }, + { + Name: "Accessing a public web path with an invalid wildcard endpoint", + Resource: &auth.Resource{Type: "service", Name: "go.micro.web", Endpoint: "/foo/foo"}, + Error: auth.ErrForbidden, + }, + { + Name: "Accessing a public web path with wildcard endpoint", + Resource: &auth.Resource{Type: "service", Name: "go.micro.web", Endpoint: "/bar/foo"}, + }, } for _, tc := range testTable { From 86272a306446bb103fc21a394cf3f9a07429ab79 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 24 Mar 2020 10:18:34 +0000 Subject: [PATCH 417/788] WithRoles variadic args (#1395) Co-authored-by: Ben Toogood --- auth/options.go | 2 +- auth/store/store.go | 4 ++-- auth/store/store_test.go | 6 +++--- auth/token/basic/basic_test.go | 2 +- auth/token/jwt/jwt_test.go | 2 +- auth/token/options.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/auth/options.go b/auth/options.go index 6a49af2e..f7408335 100644 --- a/auth/options.go +++ b/auth/options.go @@ -85,7 +85,7 @@ func WithMetadata(md map[string]string) GenerateOption { } // WithRoles for the generated account -func WithRoles(rs []string) GenerateOption { +func WithRoles(rs ...string) GenerateOption { return func(o *GenerateOptions) { o.Roles = rs } diff --git a/auth/store/store.go b/auth/store/store.go index dad0be00..fe3693c9 100644 --- a/auth/store/store.go +++ b/auth/store/store.go @@ -68,7 +68,7 @@ func (s *Store) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, secretOpts := []token.GenerateOption{ token.WithExpiry(options.SecretExpiry), token.WithMetadata(options.Metadata), - token.WithRoles(options.Roles), + token.WithRoles(options.Roles...), } secret, err := s.secretProvider.Generate(id, secretOpts...) if err != nil { @@ -166,6 +166,6 @@ func (s *Store) Refresh(secret string, opts ...auth.RefreshOption) (*auth.Token, return s.tokenProvider.Generate(sec.Subject, token.WithExpiry(options.TokenExpiry), token.WithMetadata(sec.Metadata), - token.WithRoles(sec.Roles), + token.WithRoles(sec.Roles...), ) } diff --git a/auth/store/store_test.go b/auth/store/store_test.go index 9b1ca0e9..d7dfd0c0 100644 --- a/auth/store/store_test.go +++ b/auth/store/store_test.go @@ -17,7 +17,7 @@ func TestGenerate(t *testing.T) { metadata := map[string]string{"foo": "bar"} opts := []auth.GenerateOption{ - auth.WithRoles(roles), + auth.WithRoles(roles...), auth.WithMetadata(metadata), } @@ -100,7 +100,7 @@ func TestInspect(t *testing.T) { metadata := map[string]string{"foo": "bar"} opts := []auth.GenerateOption{ - auth.WithRoles(roles), + auth.WithRoles(roles...), auth.WithMetadata(metadata), } @@ -146,7 +146,7 @@ func TestRefresh(t *testing.T) { metadata := map[string]string{"foo": "bar"} opts := []auth.GenerateOption{ - auth.WithRoles(roles), + auth.WithRoles(roles...), auth.WithMetadata(metadata), } diff --git a/auth/token/basic/basic_test.go b/auth/token/basic/basic_test.go index 159387a1..4498db3c 100644 --- a/auth/token/basic/basic_test.go +++ b/auth/token/basic/basic_test.go @@ -37,7 +37,7 @@ func TestInspect(t *testing.T) { opts := []token.GenerateOption{ token.WithMetadata(md), - token.WithRoles(roles), + token.WithRoles(roles...), } tok, err := b.Generate(subject, opts...) diff --git a/auth/token/jwt/jwt_test.go b/auth/token/jwt/jwt_test.go index 3a2c6237..576a1e2e 100644 --- a/auth/token/jwt/jwt_test.go +++ b/auth/token/jwt/jwt_test.go @@ -46,7 +46,7 @@ func TestInspect(t *testing.T) { opts := []token.GenerateOption{ token.WithMetadata(md), - token.WithRoles(roles), + token.WithRoles(roles...), } tok, err := j.Generate(subject, opts...) diff --git a/auth/token/options.go b/auth/token/options.go index d2e490b8..29e166e1 100644 --- a/auth/token/options.go +++ b/auth/token/options.go @@ -76,7 +76,7 @@ func WithMetadata(md map[string]string) func(o *GenerateOptions) { } // WithRoles for the token -func WithRoles(rs []string) func(o *GenerateOptions) { +func WithRoles(rs ...string) func(o *GenerateOptions) { return func(o *GenerateOptions) { o.Roles = rs } From fd664f43923d381181b61b7ecf48c0f611f14a74 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 24 Mar 2020 13:48:37 +0000 Subject: [PATCH 418/788] Auth load rules (#1397) * WithRoles variadic args * Load Rules * Timer => Ticker Co-authored-by: Ben Toogood --- auth/service/proto/auth.pb.go | 322 ++++++++++++++++------------ auth/service/proto/auth.pb.micro.go | 34 +-- auth/service/proto/auth.proto | 24 ++- auth/service/service.go | 106 +++++++-- auth/store/rules.go | 74 ------- auth/store/store.go | 171 --------------- auth/store/store_test.go | 308 -------------------------- config/cmd/cmd.go | 2 - 8 files changed, 312 insertions(+), 729 deletions(-) delete mode 100644 auth/store/rules.go delete mode 100644 auth/store/store.go delete mode 100644 auth/store/store_test.go diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index b06f9b7c..5ca611a8 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -20,6 +20,61 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +type Rule struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` + Resource *Resource `protobuf:"bytes,3,opt,name=resource,proto3" json:"resource,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Rule) Reset() { *m = Rule{} } +func (m *Rule) String() string { return proto.CompactTextString(m) } +func (*Rule) ProtoMessage() {} +func (*Rule) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{0} +} + +func (m *Rule) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Rule.Unmarshal(m, b) +} +func (m *Rule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Rule.Marshal(b, m, deterministic) +} +func (m *Rule) XXX_Merge(src proto.Message) { + xxx_messageInfo_Rule.Merge(m, src) +} +func (m *Rule) XXX_Size() int { + return xxx_messageInfo_Rule.Size(m) +} +func (m *Rule) XXX_DiscardUnknown() { + xxx_messageInfo_Rule.DiscardUnknown(m) +} + +var xxx_messageInfo_Rule proto.InternalMessageInfo + +func (m *Rule) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *Rule) GetRole() string { + if m != nil { + return m.Role + } + return "" +} + +func (m *Rule) GetResource() *Resource { + if m != nil { + return m.Resource + } + return nil +} + type Token struct { Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` @@ -37,7 +92,7 @@ func (m *Token) Reset() { *m = Token{} } func (m *Token) String() string { return proto.CompactTextString(m) } func (*Token) ProtoMessage() {} func (*Token) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{0} + return fileDescriptor_21300bfacc51fc2a, []int{1} } func (m *Token) XXX_Unmarshal(b []byte) error { @@ -121,7 +176,7 @@ func (m *Account) Reset() { *m = Account{} } func (m *Account) String() string { return proto.CompactTextString(m) } func (*Account) ProtoMessage() {} func (*Account) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{1} + return fileDescriptor_21300bfacc51fc2a, []int{2} } func (m *Account) XXX_Unmarshal(b []byte) error { @@ -183,7 +238,7 @@ func (m *Resource) Reset() { *m = Resource{} } func (m *Resource) String() string { return proto.CompactTextString(m) } func (*Resource) ProtoMessage() {} func (*Resource) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{2} + return fileDescriptor_21300bfacc51fc2a, []int{3} } func (m *Resource) XXX_Unmarshal(b []byte) error { @@ -239,7 +294,7 @@ func (m *GenerateRequest) Reset() { *m = GenerateRequest{} } func (m *GenerateRequest) String() string { return proto.CompactTextString(m) } func (*GenerateRequest) ProtoMessage() {} func (*GenerateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{3} + return fileDescriptor_21300bfacc51fc2a, []int{4} } func (m *GenerateRequest) XXX_Unmarshal(b []byte) error { @@ -299,7 +354,7 @@ func (m *GenerateResponse) Reset() { *m = GenerateResponse{} } func (m *GenerateResponse) String() string { return proto.CompactTextString(m) } func (*GenerateResponse) ProtoMessage() {} func (*GenerateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{4} + return fileDescriptor_21300bfacc51fc2a, []int{5} } func (m *GenerateResponse) XXX_Unmarshal(b []byte) error { @@ -339,7 +394,7 @@ func (m *GrantRequest) Reset() { *m = GrantRequest{} } func (m *GrantRequest) String() string { return proto.CompactTextString(m) } func (*GrantRequest) ProtoMessage() {} func (*GrantRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{5} + return fileDescriptor_21300bfacc51fc2a, []int{6} } func (m *GrantRequest) XXX_Unmarshal(b []byte) error { @@ -384,7 +439,7 @@ func (m *GrantResponse) Reset() { *m = GrantResponse{} } func (m *GrantResponse) String() string { return proto.CompactTextString(m) } func (*GrantResponse) ProtoMessage() {} func (*GrantResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{6} + return fileDescriptor_21300bfacc51fc2a, []int{7} } func (m *GrantResponse) XXX_Unmarshal(b []byte) error { @@ -405,84 +460,6 @@ func (m *GrantResponse) XXX_DiscardUnknown() { var xxx_messageInfo_GrantResponse proto.InternalMessageInfo -type VerifyRequest struct { - Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` - Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *VerifyRequest) Reset() { *m = VerifyRequest{} } -func (m *VerifyRequest) String() string { return proto.CompactTextString(m) } -func (*VerifyRequest) ProtoMessage() {} -func (*VerifyRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{7} -} - -func (m *VerifyRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_VerifyRequest.Unmarshal(m, b) -} -func (m *VerifyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_VerifyRequest.Marshal(b, m, deterministic) -} -func (m *VerifyRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_VerifyRequest.Merge(m, src) -} -func (m *VerifyRequest) XXX_Size() int { - return xxx_messageInfo_VerifyRequest.Size(m) -} -func (m *VerifyRequest) XXX_DiscardUnknown() { - xxx_messageInfo_VerifyRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_VerifyRequest proto.InternalMessageInfo - -func (m *VerifyRequest) GetAccount() *Account { - if m != nil { - return m.Account - } - return nil -} - -func (m *VerifyRequest) GetResource() *Resource { - if m != nil { - return m.Resource - } - return nil -} - -type VerifyResponse struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *VerifyResponse) Reset() { *m = VerifyResponse{} } -func (m *VerifyResponse) String() string { return proto.CompactTextString(m) } -func (*VerifyResponse) ProtoMessage() {} -func (*VerifyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{8} -} - -func (m *VerifyResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_VerifyResponse.Unmarshal(m, b) -} -func (m *VerifyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_VerifyResponse.Marshal(b, m, deterministic) -} -func (m *VerifyResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_VerifyResponse.Merge(m, src) -} -func (m *VerifyResponse) XXX_Size() int { - return xxx_messageInfo_VerifyResponse.Size(m) -} -func (m *VerifyResponse) XXX_DiscardUnknown() { - xxx_messageInfo_VerifyResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_VerifyResponse proto.InternalMessageInfo - type RevokeRequest struct { Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` @@ -495,7 +472,7 @@ func (m *RevokeRequest) Reset() { *m = RevokeRequest{} } func (m *RevokeRequest) String() string { return proto.CompactTextString(m) } func (*RevokeRequest) ProtoMessage() {} func (*RevokeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{9} + return fileDescriptor_21300bfacc51fc2a, []int{8} } func (m *RevokeRequest) XXX_Unmarshal(b []byte) error { @@ -540,7 +517,7 @@ func (m *RevokeResponse) Reset() { *m = RevokeResponse{} } func (m *RevokeResponse) String() string { return proto.CompactTextString(m) } func (*RevokeResponse) ProtoMessage() {} func (*RevokeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{10} + return fileDescriptor_21300bfacc51fc2a, []int{9} } func (m *RevokeResponse) XXX_Unmarshal(b []byte) error { @@ -572,7 +549,7 @@ func (m *InspectRequest) Reset() { *m = InspectRequest{} } func (m *InspectRequest) String() string { return proto.CompactTextString(m) } func (*InspectRequest) ProtoMessage() {} func (*InspectRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{11} + return fileDescriptor_21300bfacc51fc2a, []int{10} } func (m *InspectRequest) XXX_Unmarshal(b []byte) error { @@ -611,7 +588,7 @@ func (m *InspectResponse) Reset() { *m = InspectResponse{} } func (m *InspectResponse) String() string { return proto.CompactTextString(m) } func (*InspectResponse) ProtoMessage() {} func (*InspectResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{12} + return fileDescriptor_21300bfacc51fc2a, []int{11} } func (m *InspectResponse) XXX_Unmarshal(b []byte) error { @@ -651,7 +628,7 @@ func (m *RefreshRequest) Reset() { *m = RefreshRequest{} } func (m *RefreshRequest) String() string { return proto.CompactTextString(m) } func (*RefreshRequest) ProtoMessage() {} func (*RefreshRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{13} + return fileDescriptor_21300bfacc51fc2a, []int{12} } func (m *RefreshRequest) XXX_Unmarshal(b []byte) error { @@ -697,7 +674,7 @@ func (m *RefreshResponse) Reset() { *m = RefreshResponse{} } func (m *RefreshResponse) String() string { return proto.CompactTextString(m) } func (*RefreshResponse) ProtoMessage() {} func (*RefreshResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{14} + return fileDescriptor_21300bfacc51fc2a, []int{13} } func (m *RefreshResponse) XXX_Unmarshal(b []byte) error { @@ -725,7 +702,78 @@ func (m *RefreshResponse) GetToken() *Token { return nil } +type ListRulesRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListRulesRequest) Reset() { *m = ListRulesRequest{} } +func (m *ListRulesRequest) String() string { return proto.CompactTextString(m) } +func (*ListRulesRequest) ProtoMessage() {} +func (*ListRulesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{14} +} + +func (m *ListRulesRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListRulesRequest.Unmarshal(m, b) +} +func (m *ListRulesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListRulesRequest.Marshal(b, m, deterministic) +} +func (m *ListRulesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListRulesRequest.Merge(m, src) +} +func (m *ListRulesRequest) XXX_Size() int { + return xxx_messageInfo_ListRulesRequest.Size(m) +} +func (m *ListRulesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ListRulesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ListRulesRequest proto.InternalMessageInfo + +type ListRulesResponse struct { + Rules []*Rule `protobuf:"bytes,1,rep,name=rules,proto3" json:"rules,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListRulesResponse) Reset() { *m = ListRulesResponse{} } +func (m *ListRulesResponse) String() string { return proto.CompactTextString(m) } +func (*ListRulesResponse) ProtoMessage() {} +func (*ListRulesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_21300bfacc51fc2a, []int{15} +} + +func (m *ListRulesResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListRulesResponse.Unmarshal(m, b) +} +func (m *ListRulesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListRulesResponse.Marshal(b, m, deterministic) +} +func (m *ListRulesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListRulesResponse.Merge(m, src) +} +func (m *ListRulesResponse) XXX_Size() int { + return xxx_messageInfo_ListRulesResponse.Size(m) +} +func (m *ListRulesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListRulesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ListRulesResponse proto.InternalMessageInfo + +func (m *ListRulesResponse) GetRules() []*Rule { + if m != nil { + return m.Rules + } + return nil +} + func init() { + proto.RegisterType((*Rule)(nil), "go.micro.auth.Rule") proto.RegisterType((*Token)(nil), "go.micro.auth.Token") proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.Token.MetadataEntry") proto.RegisterType((*Account)(nil), "go.micro.auth.Account") @@ -736,60 +784,62 @@ func init() { proto.RegisterType((*GenerateResponse)(nil), "go.micro.auth.GenerateResponse") proto.RegisterType((*GrantRequest)(nil), "go.micro.auth.GrantRequest") proto.RegisterType((*GrantResponse)(nil), "go.micro.auth.GrantResponse") - proto.RegisterType((*VerifyRequest)(nil), "go.micro.auth.VerifyRequest") - proto.RegisterType((*VerifyResponse)(nil), "go.micro.auth.VerifyResponse") proto.RegisterType((*RevokeRequest)(nil), "go.micro.auth.RevokeRequest") proto.RegisterType((*RevokeResponse)(nil), "go.micro.auth.RevokeResponse") proto.RegisterType((*InspectRequest)(nil), "go.micro.auth.InspectRequest") proto.RegisterType((*InspectResponse)(nil), "go.micro.auth.InspectResponse") proto.RegisterType((*RefreshRequest)(nil), "go.micro.auth.RefreshRequest") proto.RegisterType((*RefreshResponse)(nil), "go.micro.auth.RefreshResponse") + proto.RegisterType((*ListRulesRequest)(nil), "go.micro.auth.ListRulesRequest") + proto.RegisterType((*ListRulesResponse)(nil), "go.micro.auth.ListRulesResponse") } func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } var fileDescriptor_21300bfacc51fc2a = []byte{ - // 663 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xdd, 0x6e, 0xd3, 0x4c, - 0x10, 0xad, 0xed, 0xfc, 0x75, 0x52, 0x27, 0xd1, 0xaa, 0xea, 0x67, 0xf9, 0xa3, 0x25, 0x18, 0x84, - 0x2a, 0x54, 0xb9, 0x28, 0xbd, 0x41, 0x20, 0x10, 0x15, 0xad, 0xca, 0x8f, 0xca, 0x85, 0x85, 0x80, - 0x3b, 0xe4, 0x3a, 0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0xde, 0x5e, 0x91, 0x2d, 0x03, 0xe5, 0x1b, 0x5f, 0x00, 0xaa, - 0x58, 0x6c, 0x01, 0xa8, 0x66, 0x93, 0x35, 0xf2, 0x12, 0xda, 0xd2, 0x00, 0xa4, 0x5e, 0x5b, 0x35, - 0x90, 0xbd, 0xb3, 0x2a, 0x5d, 0xc6, 0x92, 0xab, 0x23, 0x8b, 0xbc, 0x65, 0x7f, 0x2c, 0x60, 0xd5, - 0x36, 0xee, 0xac, 0x9d, 0xb5, 0xc4, 0x9f, 0xf4, 0xc1, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb7, - 0xf8, 0x55, 0xb6, 0xc5, 0x07, 0x00, 0x00, + // 696 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xdb, 0x6e, 0xd3, 0x40, + 0x10, 0xad, 0xed, 0xdc, 0x3a, 0x69, 0x9a, 0xb0, 0x54, 0xc5, 0x32, 0x6d, 0x09, 0x06, 0xa1, 0x82, + 0xaa, 0x14, 0xa5, 0x2f, 0x08, 0x44, 0x45, 0x45, 0xab, 0x72, 0x2b, 0x42, 0x16, 0x12, 0xbc, 0x55, + 0xae, 0x33, 0x50, 0xd3, 0xd4, 0x36, 0xeb, 0x75, 0x45, 0xfe, 0x82, 0x2f, 0xe3, 0x0b, 0x78, 0xe3, + 0x47, 0xd0, 0xae, 0x77, 0xb7, 0x8e, 0x13, 0x23, 0xc4, 0xe5, 0x6d, 0x77, 0x76, 0x7c, 0xce, 0xcc, + 0x99, 0x33, 0x09, 0xac, 0xfb, 0x19, 0x3b, 0xdd, 0x4e, 0x91, 0x5e, 0x84, 0x01, 0x6e, 0x27, 0x34, + 0x66, 0xf1, 0x36, 0x0f, 0x0d, 0xc4, 0x91, 0x74, 0x3e, 0xc6, 0x83, 0xf3, 0x30, 0xa0, 0xf1, 0x80, + 0x07, 0xdd, 0x63, 0xa8,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 0xf5, 0xf8, 0x48, 0x59, 0xd6, 0xf2, 0xb0, 0x9d, + 0x7e, 0x75, 0x82, 0x42, 0x3c, 0x69, 0x88, 0x3f, 0xf6, 0x9d, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, + 0x91, 0x77, 0xf2, 0xa6, 0xf9, 0x07, 0x00, 0x00, } diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index dccf46b8..0d162a71 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -36,10 +36,10 @@ var _ server.Option type AuthService interface { Generate(ctx context.Context, in *GenerateRequest, opts ...client.CallOption) (*GenerateResponse, error) Grant(ctx context.Context, in *GrantRequest, opts ...client.CallOption) (*GrantResponse, error) - Verify(ctx context.Context, in *VerifyRequest, opts ...client.CallOption) (*VerifyResponse, error) Revoke(ctx context.Context, in *RevokeRequest, opts ...client.CallOption) (*RevokeResponse, error) Inspect(ctx context.Context, in *InspectRequest, opts ...client.CallOption) (*InspectResponse, error) Refresh(ctx context.Context, in *RefreshRequest, opts ...client.CallOption) (*RefreshResponse, error) + ListRules(ctx context.Context, in *ListRulesRequest, opts ...client.CallOption) (*ListRulesResponse, error) } type authService struct { @@ -74,16 +74,6 @@ func (c *authService) Grant(ctx context.Context, in *GrantRequest, opts ...clien return out, nil } -func (c *authService) Verify(ctx context.Context, in *VerifyRequest, opts ...client.CallOption) (*VerifyResponse, error) { - req := c.c.NewRequest(c.name, "Auth.Verify", in) - out := new(VerifyResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *authService) Revoke(ctx context.Context, in *RevokeRequest, opts ...client.CallOption) (*RevokeResponse, error) { req := c.c.NewRequest(c.name, "Auth.Revoke", in) out := new(RevokeResponse) @@ -114,25 +104,35 @@ func (c *authService) Refresh(ctx context.Context, in *RefreshRequest, opts ...c return out, nil } +func (c *authService) ListRules(ctx context.Context, in *ListRulesRequest, opts ...client.CallOption) (*ListRulesResponse, error) { + req := c.c.NewRequest(c.name, "Auth.ListRules", in) + out := new(ListRulesResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for Auth service type AuthHandler interface { Generate(context.Context, *GenerateRequest, *GenerateResponse) error Grant(context.Context, *GrantRequest, *GrantResponse) error - Verify(context.Context, *VerifyRequest, *VerifyResponse) error Revoke(context.Context, *RevokeRequest, *RevokeResponse) error Inspect(context.Context, *InspectRequest, *InspectResponse) error Refresh(context.Context, *RefreshRequest, *RefreshResponse) error + ListRules(context.Context, *ListRulesRequest, *ListRulesResponse) error } func RegisterAuthHandler(s server.Server, hdlr AuthHandler, opts ...server.HandlerOption) error { type auth interface { Generate(ctx context.Context, in *GenerateRequest, out *GenerateResponse) error Grant(ctx context.Context, in *GrantRequest, out *GrantResponse) error - Verify(ctx context.Context, in *VerifyRequest, out *VerifyResponse) error Revoke(ctx context.Context, in *RevokeRequest, out *RevokeResponse) error Inspect(ctx context.Context, in *InspectRequest, out *InspectResponse) error Refresh(ctx context.Context, in *RefreshRequest, out *RefreshResponse) error + ListRules(ctx context.Context, in *ListRulesRequest, out *ListRulesResponse) error } type Auth struct { auth @@ -153,10 +153,6 @@ func (h *authHandler) Grant(ctx context.Context, in *GrantRequest, out *GrantRes return h.AuthHandler.Grant(ctx, in, out) } -func (h *authHandler) Verify(ctx context.Context, in *VerifyRequest, out *VerifyResponse) error { - return h.AuthHandler.Verify(ctx, in, out) -} - func (h *authHandler) Revoke(ctx context.Context, in *RevokeRequest, out *RevokeResponse) error { return h.AuthHandler.Revoke(ctx, in, out) } @@ -168,3 +164,7 @@ func (h *authHandler) Inspect(ctx context.Context, in *InspectRequest, out *Insp func (h *authHandler) Refresh(ctx context.Context, in *RefreshRequest, out *RefreshResponse) error { return h.AuthHandler.Refresh(ctx, in, out) } + +func (h *authHandler) ListRules(ctx context.Context, in *ListRulesRequest, out *ListRulesResponse) error { + return h.AuthHandler.ListRules(ctx, in, out) +} diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index 6b2587bb..8efb64a5 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -5,10 +5,16 @@ package go.micro.auth; service Auth { rpc Generate(GenerateRequest) returns (GenerateResponse) {}; rpc Grant(GrantRequest) returns (GrantResponse) {}; - rpc Verify(VerifyRequest) returns (VerifyResponse) {}; rpc Revoke(RevokeRequest) returns (RevokeResponse) {}; rpc Inspect(InspectRequest) returns (InspectResponse) {}; rpc Refresh(RefreshRequest) returns (RefreshResponse) {}; + rpc ListRules(ListRulesRequest) returns (ListRulesResponse) {}; +} + +message Rule { + string id = 1; + string role = 2; + Resource resource = 3; } message Token { @@ -52,13 +58,6 @@ message GrantRequest { message GrantResponse {} -message VerifyRequest { - Account account = 1; - Resource resource = 2; -} - -message VerifyResponse {} - message RevokeRequest { string role = 1; Resource resource = 2; @@ -81,4 +80,11 @@ message RefreshRequest { message RefreshResponse { Token token = 1; -} \ No newline at end of file +} + +message ListRulesRequest { +} + +message ListRulesResponse { + repeated Rule rules = 1; +} diff --git a/auth/service/service.go b/auth/service/service.go index 3f11848b..c483fe04 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -2,7 +2,9 @@ package service import ( "context" + "fmt" "strings" + "sync" "time" "github.com/micro/go-micro/v2/auth" @@ -10,6 +12,7 @@ import ( "github.com/micro/go-micro/v2/auth/token" "github.com/micro/go-micro/v2/auth/token/jwt" "github.com/micro/go-micro/v2/client" + log "github.com/micro/go-micro/v2/logger" ) // NewAuth returns a new instance of the Auth service @@ -24,6 +27,9 @@ type svc struct { options auth.Options auth pb.AuthService jwt token.Provider + rules []*pb.Rule + + sync.Mutex } func (s *svc) String() string { @@ -44,6 +50,13 @@ func (s *svc) Init(opts ...auth.Option) { if key := s.options.PublicKey; len(key) > 0 { s.jwt = jwt.NewTokenProvider(token.WithPublicKey(key)) } + + // load rules periodically from the auth service + timer := time.NewTicker(time.Second * 30) + go func() { + s.loadRules() + <-timer.C + }() } func (s *svc) Options() auth.Options { @@ -95,18 +108,31 @@ func (s *svc) Revoke(role string, res *auth.Resource) error { // Verify an account has access to a resource func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { - _, err := s.auth.Verify(context.TODO(), &pb.VerifyRequest{ - Account: &pb.Account{ - Id: acc.ID, - Roles: acc.Roles, - }, - Resource: &pb.Resource{ - Type: res.Type, - Name: res.Name, - Endpoint: res.Endpoint, - }, - }) - return err + queries := [][]string{ + {res.Type, "*"}, // check for wildcard resource type, e.g. service.* + {res.Type, res.Name, "*"}, // check for wildcard name, e.g. service.foo* + {res.Type, res.Name, res.Endpoint, "*"}, // check for wildcard endpoints, e.g. service.foo.ListFoo:* + {res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin + } + + // endpoint is a url which can have wildcard excludes, e.g. + // "/foo/*" will allow "/foo/bar" + if comps := strings.Split(res.Endpoint, "/"); len(comps) > 1 { + for i := 1; i < len(comps); i++ { + wildcard := fmt.Sprintf("%v/*", strings.Join(comps[0:i], "/")) + queries = append(queries, []string{res.Type, res.Name, wildcard}) + } + } + + for _, q := range queries { + for _, rule := range s.listRules(q...) { + if isValidRule(rule, acc, res) { + return nil + } + } + } + + return auth.ErrForbidden } // Inspect a token @@ -150,6 +176,62 @@ func (s *svc) Refresh(secret string, opts ...auth.RefreshOption) (*auth.Token, e return serializeToken(rsp.Token), nil } +var ruleJoinKey = ":" + +// isValidRule returns a bool, indicating if a rule permits access to a +// resource for a given account +func isValidRule(rule *pb.Rule, acc *auth.Account, res *auth.Resource) bool { + if rule.Role == "*" { + return true + } + + for _, role := range acc.Roles { + if rule.Role == role { + return true + } + + // allow user.anything if role is user.* + if strings.HasSuffix(rule.Role, ".*") && strings.HasPrefix(rule.Role, role+".") { + return true + } + } + + return false +} + +// listRules gets all the rules from the store which have an id +// prefix matching the filters +func (s *svc) listRules(filters ...string) []*pb.Rule { + s.Lock() + defer s.Unlock() + + prefix := strings.Join(filters, ruleJoinKey) + + var rules []*pb.Rule + for _, r := range s.rules { + if strings.HasPrefix(r.Id, prefix) { + rules = append(rules, r) + } + } + + return rules +} + +// loadRules retrieves the rules from the auth service +func (s *svc) loadRules() { + rsp, err := s.auth.ListRules(context.TODO(), &pb.ListRulesRequest{}, client.WithRetries(3)) + s.Lock() + defer s.Unlock() + + if err != nil { + log.Errorf("Error listing rules: %v", err) + s.rules = []*pb.Rule{} + return + } + + s.rules = rsp.Rules +} + func serializeToken(t *pb.Token) *auth.Token { return &auth.Token{ Token: t.Token, diff --git a/auth/store/rules.go b/auth/store/rules.go deleted file mode 100644 index c4bf0c49..00000000 --- a/auth/store/rules.go +++ /dev/null @@ -1,74 +0,0 @@ -package store - -import ( - "encoding/json" - "strings" - - "github.com/micro/go-micro/v2/auth" - "github.com/micro/go-micro/v2/store" -) - -// Rule is an access control rule -type Rule struct { - Role string `json:"rule"` - Resource *auth.Resource `json:"resource"` -} - -var joinKey = ":" - -// Key to be used when written to the store -func (r *Rule) Key() string { - comps := []string{r.Resource.Type, r.Resource.Name, r.Resource.Endpoint, r.Role} - return strings.Join(comps, joinKey) -} - -// Bytes returns json encoded bytes -func (r *Rule) Bytes() []byte { - bytes, _ := json.Marshal(r) - return bytes -} - -// isValidRule returns a bool, indicating if a rule permits access to a -// resource for a given account -func isValidRule(rule Rule, acc *auth.Account, res *auth.Resource) bool { - if rule.Role == "*" { - return true - } - - for _, role := range acc.Roles { - if rule.Role == role { - return true - } - - // allow user.anything if role is user.* - if strings.HasSuffix(rule.Role, ".*") && strings.HasPrefix(rule.Role, role+".") { - return true - } - } - - return false -} - -// listRules gets all the rules from the store which have a key -// prefix matching the filters -func (s *Store) listRules(filters ...string) ([]Rule, error) { - // get the records from the store - prefix := strings.Join(filters, joinKey) - recs, err := s.opts.Store.Read(prefix, store.ReadPrefix()) - if err != nil { - return nil, err - } - - // unmarshal the records - rules := make([]Rule, 0, len(recs)) - for _, rec := range recs { - var r Rule - if err := json.Unmarshal(rec.Value, &r); err != nil { - return nil, err - } - rules = append(rules, r) - } - - // return the rules - return rules, nil -} diff --git a/auth/store/store.go b/auth/store/store.go deleted file mode 100644 index fe3693c9..00000000 --- a/auth/store/store.go +++ /dev/null @@ -1,171 +0,0 @@ -package store - -import ( - "fmt" - "strings" - - "github.com/micro/go-micro/v2/auth" - "github.com/micro/go-micro/v2/auth/token" - "github.com/micro/go-micro/v2/auth/token/basic" - "github.com/micro/go-micro/v2/store" - memStore "github.com/micro/go-micro/v2/store/memory" -) - -// NewAuth returns a new default registry which is store -func NewAuth(opts ...auth.Option) auth.Auth { - var s Store - s.Init(opts...) - return &s -} - -// Store implementation of auth -type Store struct { - secretProvider token.Provider - tokenProvider token.Provider - opts auth.Options -} - -// String returns store -func (s *Store) String() string { - return "store" -} - -// Init the auth -func (s *Store) Init(opts ...auth.Option) { - for _, o := range opts { - o(&s.opts) - } - - // use the default store as a fallback - if s.opts.Store == nil { - s.opts.Store = store.DefaultStore - } - - // noop will not work for auth - if s.opts.Store.String() == "noop" { - s.opts.Store = memStore.NewStore() - } - - if s.tokenProvider == nil { - s.tokenProvider = basic.NewTokenProvider(token.WithStore(s.opts.Store)) - } - if s.secretProvider == nil { - s.secretProvider = basic.NewTokenProvider(token.WithStore(s.opts.Store)) - } -} - -// Options returns the options -func (s *Store) Options() auth.Options { - return s.opts -} - -// Generate a new account -func (s *Store) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { - // parse the options - options := auth.NewGenerateOptions(opts...) - - // Generate a long-lived secret - secretOpts := []token.GenerateOption{ - token.WithExpiry(options.SecretExpiry), - token.WithMetadata(options.Metadata), - token.WithRoles(options.Roles...), - } - secret, err := s.secretProvider.Generate(id, secretOpts...) - if err != nil { - return nil, err - } - - // return the account - return &auth.Account{ - ID: id, - Roles: options.Roles, - Metadata: options.Metadata, - Secret: secret, - }, nil -} - -// Grant access to a resource -func (s *Store) Grant(role string, res *auth.Resource) error { - r := Rule{role, res} - return s.opts.Store.Write(&store.Record{Key: r.Key(), Value: r.Bytes()}) -} - -// Revoke access to a resource -func (s *Store) Revoke(role string, res *auth.Resource) error { - r := Rule{role, res} - - err := s.opts.Store.Delete(r.Key()) - if err == store.ErrNotFound { - return auth.ErrNotFound - } - - return err -} - -// Verify an account has access to a resource -func (s *Store) Verify(acc *auth.Account, res *auth.Resource) error { - queries := [][]string{ - {res.Type, "*"}, // check for wildcard resource type, e.g. service.* - {res.Type, res.Name, "*"}, // check for wildcard name, e.g. service.foo* - {res.Type, res.Name, res.Endpoint, "*"}, // check for wildcard endpoints, e.g. service.foo.ListFoo:* - {res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin - } - - // endpoint is a url which can have wildcard excludes, e.g. - // "/foo/*" will allow "/foo/bar" - if comps := strings.Split(res.Endpoint, "/"); len(comps) > 1 { - for i := 1; i < len(comps); i++ { - wildcard := fmt.Sprintf("%v/*", strings.Join(comps[0:i], "/")) - queries = append(queries, []string{res.Type, res.Name, wildcard}) - } - } - - for _, q := range queries { - rules, err := s.listRules(q...) - if err != nil { - return err - } - - for _, rule := range rules { - if isValidRule(rule, acc, res) { - return nil - } - } - } - - return auth.ErrForbidden -} - -// Inspect a token -func (s *Store) Inspect(t string) (*auth.Account, error) { - tok, err := s.tokenProvider.Inspect(t) - if err == token.ErrInvalidToken || err == token.ErrNotFound { - return nil, auth.ErrInvalidToken - } else if err != nil { - return nil, err - } - - return &auth.Account{ - ID: tok.Subject, - Roles: tok.Roles, - Metadata: tok.Metadata, - }, nil -} - -// Refresh an account using a secret -func (s *Store) Refresh(secret string, opts ...auth.RefreshOption) (*auth.Token, error) { - sec, err := s.secretProvider.Inspect(secret) - if err == token.ErrInvalidToken || err == token.ErrNotFound { - return nil, auth.ErrInvalidToken - } else if err != nil { - return nil, err - } - - options := auth.NewRefreshOptions(opts...) - - return s.tokenProvider.Generate(sec.Subject, - token.WithExpiry(options.TokenExpiry), - token.WithMetadata(sec.Metadata), - token.WithRoles(sec.Roles...), - ) -} diff --git a/auth/store/store_test.go b/auth/store/store_test.go deleted file mode 100644 index d7dfd0c0..00000000 --- a/auth/store/store_test.go +++ /dev/null @@ -1,308 +0,0 @@ -package store - -import ( - "log" - "testing" - - "github.com/micro/go-micro/v2/auth" - memStore "github.com/micro/go-micro/v2/store/memory" -) - -func TestGenerate(t *testing.T) { - s := memStore.NewStore() - a := NewAuth(auth.Store(s)) - - id := "test" - roles := []string{"admin"} - metadata := map[string]string{"foo": "bar"} - - opts := []auth.GenerateOption{ - auth.WithRoles(roles...), - auth.WithMetadata(metadata), - } - - // generate the account - acc, err := a.Generate(id, opts...) - if err != nil { - t.Fatalf("Generate returned an error: %v, expected nil", err) - } - // validate the account attributes were set correctly - if acc.ID != id { - t.Errorf("Generate returned %v as the ID, expected %v", acc.ID, id) - } - if len(acc.Roles) != len(roles) { - t.Errorf("Generate returned %v as the roles, expected %v", acc.Roles, roles) - } - if len(acc.Metadata) != len(metadata) { - t.Errorf("Generate returned %v as the metadata, expected %v", acc.Metadata, metadata) - } - - // validate the secret is valid - if _, err := a.Refresh(acc.Secret.Token); err != nil { - t.Errorf("Generate returned an invalid secret, error: %v", err) - } -} - -func TestGrant(t *testing.T) { - s := memStore.NewStore() - a := NewAuth(auth.Store(s)) - - res := &auth.Resource{Type: "service", Name: "Test", Endpoint: "Foo.Bar"} - if err := a.Grant("users.*", res); err != nil { - t.Fatalf("Grant returned an error: %v, expected nil", err) - } - - recs, err := s.List() - if err != nil { - t.Fatalf("Could not read from the store: %v", err) - } - if len(recs) != 1 { - t.Errorf("Expected Grant to write 1 record, actually wrote %v", len(recs)) - } -} - -func TestRevoke(t *testing.T) { - s := memStore.NewStore() - a := NewAuth(auth.Store(s)) - - res := &auth.Resource{Type: "service", Name: "Test", Endpoint: "Foo.Bar"} - if err := a.Grant("users.*", res); err != nil { - t.Fatalf("Grant returned an error: %v, expected nil", err) - } - - recs, err := s.List() - if err != nil { - t.Fatalf("Could not read from the store: %v", err) - } - if len(recs) != 1 { - t.Fatalf("Expected Grant to write 1 record, actually wrote %v", len(recs)) - } - - if err := a.Revoke("users.*", res); err != nil { - t.Fatalf("Revoke returned an error: %v, expected nil", err) - } - - recs, err = s.List() - if err != nil { - t.Fatalf("Could not read from the store: %v", err) - } - if len(recs) != 0 { - t.Fatalf("Expected Revoke to delete 1 record, actually deleted %v", 1-len(recs)) - } -} - -func TestInspect(t *testing.T) { - a := NewAuth() - - t.Run("Valid Token", func(t *testing.T) { - id := "test" - roles := []string{"admin"} - metadata := map[string]string{"foo": "bar"} - - opts := []auth.GenerateOption{ - auth.WithRoles(roles...), - auth.WithMetadata(metadata), - } - - // generate and inspect the token - acc, err := a.Generate("test", opts...) - if err != nil { - log.Fatalf("Generate returned an error: %v, expected nil", err) - } - tok, err := a.Refresh(acc.Secret.Token) - if err != nil { - log.Fatalf("Refresh returned an error: %v, expected nil", err) - } - acc2, err := a.Inspect(tok.Token) - if err != nil { - log.Fatalf("Inspect returned an error: %v, expected nil", err) - } - - // validate the account attributes were retrieved correctly - if acc2.ID != id { - t.Errorf("Generate returned %v as the ID, expected %v", acc.ID, id) - } - if len(acc2.Roles) != len(roles) { - t.Errorf("Generate returned %v as the roles, expected %v", acc.Roles, roles) - } - if len(acc2.Metadata) != len(metadata) { - t.Errorf("Generate returned %v as the metadata, expected %v", acc.Metadata, metadata) - } - }) - - t.Run("Invalid Token", func(t *testing.T) { - _, err := a.Inspect("invalid token") - if err != auth.ErrInvalidToken { - t.Errorf("Inspect returned %v error, expected %v", err, auth.ErrInvalidToken) - } - }) -} - -func TestRefresh(t *testing.T) { - a := NewAuth() - - t.Run("Valid Secret", func(t *testing.T) { - roles := []string{"admin"} - metadata := map[string]string{"foo": "bar"} - - opts := []auth.GenerateOption{ - auth.WithRoles(roles...), - auth.WithMetadata(metadata), - } - - // generate the account - acc, err := a.Generate("test", opts...) - if err != nil { - log.Fatalf("Generate returned an error: %v, expected nil", err) - } - - // refresh the token - tok, err := a.Refresh(acc.Secret.Token) - if err != nil { - log.Fatalf("Refresh returned an error: %v, expected nil", err) - } - - // validate the account attributes were set correctly - if acc.ID != tok.Subject { - t.Errorf("Refresh returned %v as the ID, expected %v", acc.ID, tok.Subject) - } - if len(acc.Roles) != len(tok.Roles) { - t.Errorf("Refresh returned %v as the roles, expected %v", acc.Roles, tok.Subject) - } - if len(acc.Metadata) != len(tok.Metadata) { - t.Errorf("Refresh returned %v as the metadata, expected %v", acc.Metadata, tok.Metadata) - } - }) - - t.Run("Invalid Secret", func(t *testing.T) { - _, err := a.Refresh("invalid secret") - if err != auth.ErrInvalidToken { - t.Errorf("Inspect returned %v error, expected %v", err, auth.ErrInvalidToken) - } - }) -} - -func TestVerify(t *testing.T) { - testRules := []struct { - Role string - Resource *auth.Resource - }{ - { - Role: "*", - Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.PublicList"}, - }, - { - Role: "*", - Resource: &auth.Resource{Type: "service", Name: "go.micro.web", Endpoint: "/foo"}, - }, - { - Role: "*", - Resource: &auth.Resource{Type: "service", Name: "go.micro.web", Endpoint: "/bar/*"}, - }, - { - Role: "user.*", - Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.List"}, - }, - { - Role: "user.developer", - Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Update"}, - }, - { - Role: "admin", - Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Delete"}, - }, - { - Role: "admin", - Resource: &auth.Resource{Type: "service", Name: "*", Endpoint: "*"}, - }, - } - - a := NewAuth() - for _, r := range testRules { - if err := a.Grant(r.Role, r.Resource); err != nil { - t.Fatalf("Grant returned an error: %v, expected nil", err) - } - } - - testTable := []struct { - Name string - Roles []string - Resource *auth.Resource - Error error - }{ - { - Name: "An account with no roles accessing a public endpoint", - Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.PublicList"}, - }, - { - Name: "An account with no roles accessing a private endpoint", - Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Update"}, - Error: auth.ErrForbidden, - }, - { - Name: "An account with the user role accessing a user* endpoint", - Roles: []string{"user"}, - Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.List"}, - }, - { - Name: "An account with the user role accessing a user.admin endpoint", - Roles: []string{"user"}, - Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Delete"}, - Error: auth.ErrForbidden, - }, - { - Name: "An account with the developer role accessing a user.developer endpoint", - Roles: []string{"user.developer"}, - Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Update"}, - }, - { - Name: "An account with the developer role accessing an admin endpoint", - Roles: []string{"user.developer"}, - Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Delete"}, - Error: auth.ErrForbidden, - }, - { - Name: "An admin account accessing an admin endpoint", - Roles: []string{"admin"}, - Resource: &auth.Resource{Type: "service", Name: "go.micro.apps", Endpoint: "Apps.Delete"}, - }, - { - Name: "An admin account accessing a generic service endpoint", - Roles: []string{"admin"}, - Resource: &auth.Resource{Type: "service", Name: "go.micro.foo", Endpoint: "Foo.Bar"}, - }, - { - Name: "An admin account accessing an unauthorised endpoint", - Roles: []string{"admin"}, - Resource: &auth.Resource{Type: "infra", Name: "go.micro.foo", Endpoint: "Foo.Bar"}, - Error: auth.ErrForbidden, - }, - { - Name: "A account with no roles accessing an unauthorised endpoint", - Resource: &auth.Resource{Type: "infra", Name: "go.micro.foo", Endpoint: "Foo.Bar"}, - Error: auth.ErrForbidden, - }, - { - Name: "Accessing a public web path", - Resource: &auth.Resource{Type: "service", Name: "go.micro.web", Endpoint: "/foo"}, - }, - { - Name: "Accessing a public web path with an invalid wildcard endpoint", - Resource: &auth.Resource{Type: "service", Name: "go.micro.web", Endpoint: "/foo/foo"}, - Error: auth.ErrForbidden, - }, - { - Name: "Accessing a public web path with wildcard endpoint", - Resource: &auth.Resource{Type: "service", Name: "go.micro.web", Endpoint: "/bar/foo"}, - }, - } - - for _, tc := range testTable { - t.Run(tc.Name, func(t *testing.T) { - acc := &auth.Account{Roles: tc.Roles} - if err := a.Verify(acc, tc.Resource); err != tc.Error { - t.Errorf("Verify returned %v error, expected %v", err, tc.Error) - } - }) - } -} diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 4ea999ca..fe50ef62 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -71,7 +71,6 @@ import ( // auth svcAuth "github.com/micro/go-micro/v2/auth/service" - storeAuth "github.com/micro/go-micro/v2/auth/store" // auth providers "github.com/micro/go-micro/v2/auth/provider/basic" @@ -360,7 +359,6 @@ var ( DefaultAuths = map[string]func(...auth.Option) auth.Auth{ "service": svcAuth.NewAuth, - "store": storeAuth.NewAuth, } DefaultAuthProviders = map[string]func(...provider.Option) provider.Provider{ From 84b4eb54049d5716d54f89feb92d10ee6d69dd74 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 24 Mar 2020 14:16:57 +0000 Subject: [PATCH 419/788] Fix missing loop (#1398) * WithRoles variadic args * Load Rules * Timer => Ticker * Add missing for loop in auth service Co-authored-by: Ben Toogood --- auth/service/service.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/auth/service/service.go b/auth/service/service.go index c483fe04..e544e3f1 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -54,8 +54,10 @@ func (s *svc) Init(opts ...auth.Option) { // load rules periodically from the auth service timer := time.NewTicker(time.Second * 30) go func() { - s.loadRules() - <-timer.C + for { + s.loadRules() + <-timer.C + } }() } From 914340585c850920b74afa3bdfe371198078ed46 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 24 Mar 2020 14:51:43 +0000 Subject: [PATCH 420/788] Trim space from env variables (#1399) --- store/cloudflare/cloudflare.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index 046276fa..4b4b82d6 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -15,6 +15,7 @@ import ( "net/url" "os" "strconv" + "strings" "time" "github.com/micro/go-micro/v2/store" @@ -79,9 +80,9 @@ type apiMessage struct { // getOptions returns account id, token and namespace func getOptions() (string, string, string) { - accountID := os.Getenv("CF_ACCOUNT_ID") - apiToken := os.Getenv("CF_API_TOKEN") - namespace := os.Getenv("KV_NAMESPACE_ID") + accountID := strings.TrimSpace(os.Getenv("CF_ACCOUNT_ID")) + apiToken := strings.TrimSpace(os.Getenv("CF_API_TOKEN")) + namespace := strings.TrimSpace(os.Getenv("KV_NAMESPACE_ID")) return accountID, apiToken, namespace } From eb4d2ae6aa9a91a0225b6d0b71ea4d3f5e04d760 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 24 Mar 2020 15:37:30 +0000 Subject: [PATCH 421/788] Remove useless variable from cockroach store (#1400) --- go.mod | 2 +- store/cockroach/cockroach.go | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 0dd4fc51..e862c8bb 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,7 @@ require ( github.com/imdario/mergo v0.3.8 github.com/jonboulle/clockwork v0.1.0 // indirect github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 - github.com/json-iterator/go v1.1.9 + github.com/json-iterator/go v1.1.9 // indirect github.com/kr/pretty v0.1.0 github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.3.0 diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index d70b0c1c..74bca2a5 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -296,9 +296,8 @@ func (s *sqlStore) initDB() error { } func (s *sqlStore) configure() error { - nodes := s.options.Nodes - if len(nodes) == 0 { - nodes = []string{"localhost:26257"} + if len(s.options.Nodes) == 0 { + s.options.Nodes = []string{"localhost:26257"} } namespace := s.options.Namespace @@ -318,7 +317,7 @@ func (s *sqlStore) configure() error { } namespace = reg.ReplaceAllString(namespace, "_") - source := nodes[0] + source := s.options.Nodes[0] // check if it is a standard connection string eg: host=%s port=%d user=%s password=%s dbname=%s sslmode=disable // if err is nil which means it would be a URL like postgre://xxxx?yy=zz _, err = url.Parse(source) From 397a8638f4b8e8b171473916aff5e72324a2dbab Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 24 Mar 2020 17:16:38 +0000 Subject: [PATCH 422/788] Cockroach Store bugfix (#1401) --- config/cmd/cmd.go | 2 +- store/cockroach/cockroach.go | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index fe50ef62..49c8a359 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -616,7 +616,7 @@ func (c *cmd) Before(ctx *cli.Context) error { } if len(ctx.String("store_namespace")) > 0 { - if err := (*c.opts.Store).Init(store.Namespace(ctx.String("store_address"))); err != nil { + if err := (*c.opts.Store).Init(store.Namespace(ctx.String("store_namespace"))); err != nil { logger.Fatalf("Error configuring store: %v", err) } } diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 74bca2a5..50e214ee 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -10,7 +10,6 @@ import ( "time" "github.com/lib/pq" - "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/store" "github.com/pkg/errors" ) @@ -370,10 +369,8 @@ func NewStore(opts ...store.Option) store.Store { // set the options s.options = options - // configure the store - if err := s.configure(); err != nil { - logger.Fatal(err) - } + // best-effort configure the store + s.configure() // return store return s From 8100d26430764207ae3ae2b9c2369a81d4df9232 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 24 Mar 2020 23:45:11 +0300 Subject: [PATCH 423/788] api/router/registry: use logger (#1402) * api/router/registry: use logger Signed-off-by: Vasiliy Tolstov * api/server/acme: use logger Signed-off-by: Vasiliy Tolstov --- api/router/registry/registry.go | 23 +++++++++++++++++++---- api/server/acme/autocert/autocert.go | 6 ++++-- api/server/acme/certmagic/certmagic.go | 5 ++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/api/router/registry/registry.go b/api/router/registry/registry.go index 51cbd8fc..a8e96d41 100644 --- a/api/router/registry/registry.go +++ b/api/router/registry/registry.go @@ -4,7 +4,6 @@ package registry import ( "errors" "fmt" - "log" "net/http" "regexp" "strings" @@ -13,6 +12,7 @@ import ( "github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/api/router" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/registry/cache" ) @@ -68,7 +68,9 @@ func (r *registryRouter) refresh() { services, err := r.opts.Registry.ListServices() if err != nil { attempts++ - log.Println("Error listing endpoints", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("unable to list services: %v", err) + } time.Sleep(time.Duration(attempts) * time.Second) continue } @@ -83,6 +85,9 @@ func (r *registryRouter) refresh() { } service, err := r.rc.GetService(s.Name) if err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("unable to get service: %v", err) + } continue } r.store(service) @@ -107,6 +112,9 @@ func (r *registryRouter) process(res *registry.Result) { // get entry from cache service, err := r.rc.GetService(res.Service.Name) if err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("unable to get service: %v", err) + } return } @@ -136,6 +144,9 @@ func (r *registryRouter) store(services []*registry.Service) { // if we got nothing skip if err := api.Validate(end); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("endpoint validation failed: %v", err) + } continue } @@ -188,7 +199,9 @@ func (r *registryRouter) watch() { w, err := r.opts.Registry.Watch() if err != nil { attempts++ - log.Println("Error watching endpoints", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("error watching endpoints: %v", err) + } time.Sleep(time.Duration(attempts) * time.Second) continue } @@ -211,7 +224,9 @@ func (r *registryRouter) watch() { // process next event res, err := w.Next() if err != nil { - log.Println("Error getting next endpoint", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("error getting next endoint: %v", err) + } close(ch) break } diff --git a/api/server/acme/autocert/autocert.go b/api/server/acme/autocert/autocert.go index 3b190f05..579be51f 100644 --- a/api/server/acme/autocert/autocert.go +++ b/api/server/acme/autocert/autocert.go @@ -4,11 +4,11 @@ package autocert import ( "crypto/tls" - "log" "net" "os" "github.com/micro/go-micro/v2/api/server/acme" + "github.com/micro/go-micro/v2/logger" "golang.org/x/crypto/acme/autocert" ) @@ -31,7 +31,9 @@ func (a *autocertProvider) TLSConfig(hosts ...string) (*tls.Config, error) { } dir := cacheDir() if err := os.MkdirAll(dir, 0700); err != nil { - log.Printf("warning: autocert not using a cache: %v", err) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("warning: autocert not using a cache: %v", err) + } } else { m.Cache = autocert.DirCache(dir) } diff --git a/api/server/acme/certmagic/certmagic.go b/api/server/acme/certmagic/certmagic.go index 0c62e4c7..e9daf62e 100644 --- a/api/server/acme/certmagic/certmagic.go +++ b/api/server/acme/certmagic/certmagic.go @@ -3,14 +3,13 @@ package certmagic import ( "crypto/tls" - "log" "math/rand" "net" "time" "github.com/mholt/certmagic" - "github.com/micro/go-micro/v2/api/server/acme" + "github.com/micro/go-micro/v2/logger" ) type certmagicProvider struct { @@ -58,7 +57,7 @@ func NewProvider(options ...acme.Option) acme.Provider { if opts.Cache != nil { if _, ok := opts.Cache.(certmagic.Storage); !ok { - log.Fatal("ACME: cache provided doesn't implement certmagic's Storage interface") + logger.Fatal("ACME: cache provided doesn't implement certmagic's Storage interface") } } From dff98355be609d06ee297ab22dae27b7e82953fe Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 24 Mar 2020 23:49:09 +0000 Subject: [PATCH 424/788] Missing ; in SQL query --- store/cockroach/cockroach.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 50e214ee..b555c9c0 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -233,7 +233,7 @@ func (s *sqlStore) initDB() error { } // Create Index - _, err = s.db.Exec(fmt.Sprintf(`CREATE INDEX IF NOT EXISTS "%s" ON %s.%s USING btree ("key")`, "key_index_"+s.table, s.database, s.table)) + _, err = s.db.Exec(fmt.Sprintf(`CREATE INDEX IF NOT EXISTS "%s" ON %s.%s USING btree ("key");`, "key_index_"+s.table, s.database, s.table)) if err != nil { return err } From 0e563821076b32133df586a8ef6420cf4b43c718 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 25 Mar 2020 09:35:29 +0000 Subject: [PATCH 425/788] Fix service level auth, add improved error descriptions to aid with debugging (#1403) Co-authored-by: Ben Toogood --- service.go | 2 +- util/wrapper/wrapper.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/service.go b/service.go index a693aa34..af491f86 100644 --- a/service.go +++ b/service.go @@ -46,7 +46,7 @@ func newService(opts ...Option) Service { options.Server.Init( server.WrapHandler(wrapper.HandlerStats(stats.DefaultStats)), server.WrapHandler(wrapper.TraceHandler(trace.DefaultTracer)), - server.WrapHandler(wrapper.AuthHandler(authFn)), + server.WrapHandler(wrapper.AuthHandler(authFn, serviceName)), ) // set opts diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index cd4cc30c..55f3caf3 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -153,7 +153,7 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper { } // AuthHandler wraps a server handler to perform auth -func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { +func AuthHandler(fn func() auth.Auth, srvName string) server.HandlerWrapper { return func(h server.HandlerFunc) server.HandlerFunc { return func(ctx context.Context, req server.Request, rsp interface{}) error { // get the auth.Auth interface @@ -181,10 +181,16 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { token = header[len(BearerScheme):] } - // Verify the token + // Inspect the token and get the account account, err := a.Inspect(token) if err != nil { - return errors.Unauthorized("go.micro.auth", err.Error()) + return errors.Unauthorized("go.micro.auth", "Unauthorised call made to %v", req.Endpoint()) + } + + // Verify the caller has access to the resource + resource := &auth.Resource{Type: "service", Name: srvName, Endpoint: req.Endpoint()} + if err := a.Verify(account, resource); err != nil { + return errors.Forbidden("go.micro.auth", "Forbidden call made to %v %v by %v", srvName, req.Endpoint(), account.ID) } // There is an account, set it in the context From 35e2a68a988c90392427eaf7beb0c3f4b03cc313 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 25 Mar 2020 10:31:33 +0000 Subject: [PATCH 426/788] Fix auth bug restricting access to unauthorised endpoints (#1405) Co-authored-by: Ben Toogood --- util/wrapper/wrapper.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 55f3caf3..cab93d5c 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -184,13 +184,15 @@ func AuthHandler(fn func() auth.Auth, srvName string) server.HandlerWrapper { // Inspect the token and get the account account, err := a.Inspect(token) if err != nil { - return errors.Unauthorized("go.micro.auth", "Unauthorised call made to %v", req.Endpoint()) + account = &auth.Account{} } // Verify the caller has access to the resource - resource := &auth.Resource{Type: "service", Name: srvName, Endpoint: req.Endpoint()} - if err := a.Verify(account, resource); err != nil { - return errors.Forbidden("go.micro.auth", "Forbidden call made to %v %v by %v", srvName, req.Endpoint(), account.ID) + err = a.Verify(account, &auth.Resource{Type: "service", Name: srvName, Endpoint: req.Endpoint()}) + if err != nil && len(account.ID) > 0 { + return errors.Forbidden("go.micro.auth", "Forbidden call made to %v:%v by %v", srvName, req.Endpoint(), account.ID) + } else if err != nil { + return errors.Unauthorized("go.micro.auth", "Unauthorised call made to %v:%v", srvName, req.Endpoint()) } // There is an account, set it in the context From 1057ef6acb545f88813c109a223e9e38b064ee51 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 25 Mar 2020 11:20:53 +0000 Subject: [PATCH 427/788] Add ContextWithToken (#1407) * Add ContextWithToken * Tidying up BearerScheme Co-authored-by: Ben Toogood --- api/server/auth/auth.go | 16 +++------------- auth/auth.go | 8 ++++++++ client/grpc/grpc.go | 7 ++----- util/wrapper/wrapper.go | 7 +++---- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index d7018f4c..1bd60508 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -9,11 +9,6 @@ import ( "github.com/micro/go-micro/v2/auth" ) -var ( - // DefaultExcludes is the paths which are allowed by default - DefaultExcludes = []string{"/favicon.ico"} -) - // CombinedAuthHandler wraps a server and authenticates requests func CombinedAuthHandler(h http.Handler) http.Handler { return authHandler{ @@ -27,24 +22,19 @@ type authHandler struct { auth auth.Auth } -const ( - // BearerScheme is the prefix in the auth header - BearerScheme = "Bearer " -) - func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Extract the token from the request var token string if header := req.Header.Get("Authorization"); len(header) > 0 { // Extract the auth token from the request - if strings.HasPrefix(header, BearerScheme) { - token = header[len(BearerScheme):] + if strings.HasPrefix(header, auth.BearerScheme) { + token = header[len(auth.BearerScheme):] } } else { // Get the token out the cookies if not provided in headers if c, err := req.Cookie("micro-token"); err == nil && c != nil { token = strings.TrimPrefix(c.Value, auth.TokenCookieName+"=") - req.Header.Set("Authorization", BearerScheme+token) + req.Header.Set("Authorization", auth.BearerScheme+token) } } diff --git a/auth/auth.go b/auth/auth.go index 5c5d7ba1..268f29ba 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "time" "github.com/micro/go-micro/v2/metadata" @@ -21,6 +22,8 @@ var ( ErrInvalidRole = errors.New("invalid role") // ErrForbidden is returned when a user does not have the necessary roles to access a resource ErrForbidden = errors.New("resource forbidden") + // BearerScheme used for Authorization header + BearerScheme = "Bearer " ) // Auth providers authentication and authorization @@ -125,3 +128,8 @@ func ContextWithAccount(ctx context.Context, account *Account) (context.Context, // generate a new context with the MetadataKey set return metadata.Set(ctx, MetadataKey, string(bytes)), nil } + +// ContextWithToken sets the auth token in the context +func ContextWithToken(ctx context.Context, token string) (context.Context, error) { + return metadata.Set(ctx, "Authorization", fmt.Sprintf("%v%v", BearerScheme, token)), nil +} diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 432ef539..0357abc3 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -11,6 +11,7 @@ import ( "sync/atomic" "time" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" @@ -26,10 +27,6 @@ import ( gmetadata "google.golang.org/grpc/metadata" ) -var ( - BearerScheme = "Bearer " -) - type grpcClient struct { opts client.Options pool *pool @@ -137,7 +134,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R // set the authorization token if one is saved locally if len(header["authorization"]) == 0 { if token, err := config.Get("token"); err == nil && len(token) > 0 { - header["authorization"] = BearerScheme + token + header["authorization"] = auth.BearerScheme + token } } diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index cab93d5c..99897178 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -31,7 +31,6 @@ type traceWrapper struct { var ( HeaderPrefix = "Micro-" - BearerScheme = "Bearer " ) func (c *clientWrapper) setHeaders(ctx context.Context) context.Context { @@ -44,7 +43,7 @@ func (c *clientWrapper) setHeaders(ctx context.Context) context.Context { tk := a.Options().Token // if the token if exists and auth header isn't set then set it if len(tk) > 0 && len(md["Authorization"]) == 0 { - md["Authorization"] = BearerScheme + tk + md["Authorization"] = auth.BearerScheme + tk } } @@ -174,11 +173,11 @@ func AuthHandler(fn func() auth.Auth, srvName string) server.HandlerWrapper { var token string if header, ok := metadata.Get(ctx, "Authorization"); ok { // Ensure the correct scheme is being used - if !strings.HasPrefix(header, BearerScheme) { + if !strings.HasPrefix(header, auth.BearerScheme) { return errors.Unauthorized("go.micro.auth", "invalid authorization header. expected Bearer schema") } - token = header[len(BearerScheme):] + token = header[len(auth.BearerScheme):] } // Inspect the token and get the account From 511ebd8ec28734a3c6b5b8a916a7277164e7e886 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 25 Mar 2020 14:40:37 +0000 Subject: [PATCH 428/788] Fix Token Expiry Bug (#1408) Co-authored-by: Ben Toogood --- auth/service/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/service/service.go b/auth/service/service.go index e544e3f1..5feacb1b 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -73,7 +73,7 @@ func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e Id: id, Roles: options.Roles, Metadata: options.Metadata, - SecretExpiry: int64(options.SecretExpiry.Seconds()), + SecretExpiry: int64(options.SecretExpiry.Nanoseconds()), }) if err != nil { return nil, err From 56af82623065058c66de038737c1f7dd87c9dc6d Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 25 Mar 2020 17:03:45 +0000 Subject: [PATCH 429/788] Update auth to pass seconds and not nanoseconds (#1409) Co-authored-by: Ben Toogood --- auth/service/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/service/service.go b/auth/service/service.go index 5feacb1b..e544e3f1 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -73,7 +73,7 @@ func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e Id: id, Roles: options.Roles, Metadata: options.Metadata, - SecretExpiry: int64(options.SecretExpiry.Nanoseconds()), + SecretExpiry: int64(options.SecretExpiry.Seconds()), }) if err != nil { return nil, err From 378d03eb66cf9bae611eeb615c072378a613cfcd Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 25 Mar 2020 18:34:13 +0000 Subject: [PATCH 430/788] Tidying up auth (#1410) * Don't clear auth rules if request fails * Add jitter to auth service loading rules * Remove unused error from ContextWithToken result Co-authored-by: Ben Toogood --- auth/auth.go | 4 ++-- auth/service/service.go | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 268f29ba..837ace66 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -130,6 +130,6 @@ func ContextWithAccount(ctx context.Context, account *Account) (context.Context, } // ContextWithToken sets the auth token in the context -func ContextWithToken(ctx context.Context, token string) (context.Context, error) { - return metadata.Set(ctx, "Authorization", fmt.Sprintf("%v%v", BearerScheme, token)), nil +func ContextWithToken(ctx context.Context, token string) context.Context { + return metadata.Set(ctx, "Authorization", fmt.Sprintf("%v%v", BearerScheme, token)) } diff --git a/auth/service/service.go b/auth/service/service.go index e544e3f1..190551f9 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -13,6 +13,7 @@ import ( "github.com/micro/go-micro/v2/auth/token/jwt" "github.com/micro/go-micro/v2/client" log "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/util/jitter" ) // NewAuth returns a new instance of the Auth service @@ -54,9 +55,17 @@ func (s *svc) Init(opts ...auth.Option) { // load rules periodically from the auth service timer := time.NewTicker(time.Second * 30) go func() { + // load rules immediately on startup + s.loadRules() + for { - s.loadRules() <-timer.C + + // jitter for up to 5 seconds, this stops + // all the services calling the auth service + // at the exact same time + time.Sleep(jitter.Do(time.Second * 5)) + s.loadRules() } }() } @@ -227,7 +236,6 @@ func (s *svc) loadRules() { if err != nil { log.Errorf("Error listing rules: %v", err) - s.rules = []*pb.Rule{} return } From 8d0826a031b7b0a7cad70c3735a3a5c4f7f3e0a7 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 25 Mar 2020 19:32:41 +0000 Subject: [PATCH 431/788] Add check for k8s condition (#1412) --- runtime/kubernetes/kubernetes.go | 6 ++++++ util/kubernetes/client/types.go | 1 + 2 files changed, 7 insertions(+) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 9515878a..f8568dc1 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -129,6 +129,7 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { // parse out deployment status and inject into service metadata if len(kdep.Status.Conditions) > 0 { svc.Metadata["status"] = kdep.Status.Conditions[0].Type + svc.Metadata["started"] = kdep.Status.Conditions[0].LastUpdate delete(svc.Metadata, "error") } else { svc.Metadata["status"] = "n/a" @@ -154,6 +155,11 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { status = item.Status.Phase } + // skip if we can't get the container + if len(item.Status.Containers) == 0 { + continue + } + // now try get a deeper status state := item.Status.Containers[0].State diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index b8bcf383..deca24a0 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -39,6 +39,7 @@ type DeploymentSpec struct { // DeploymentCondition describes the state of deployment type DeploymentCondition struct { + LastUpdate string `json:lastUpdateTime` Type string `json:"type"` reason string `json:"reason,omitempty"` message string `json:"message,omitempty"` From 6efc5556e5ca8d25335f1a35b978bf11bc9dab26 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 25 Mar 2020 20:59:37 +0000 Subject: [PATCH 432/788] use requested service (#1413) --- service.go | 2 +- util/kubernetes/client/types.go | 6 +++--- util/wrapper/wrapper.go | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/service.go b/service.go index af491f86..a693aa34 100644 --- a/service.go +++ b/service.go @@ -46,7 +46,7 @@ func newService(opts ...Option) Service { options.Server.Init( server.WrapHandler(wrapper.HandlerStats(stats.DefaultStats)), server.WrapHandler(wrapper.TraceHandler(trace.DefaultTracer)), - server.WrapHandler(wrapper.AuthHandler(authFn, serviceName)), + server.WrapHandler(wrapper.AuthHandler(authFn)), ) // set opts diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index deca24a0..0c6ecc29 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -40,9 +40,9 @@ type DeploymentSpec struct { // DeploymentCondition describes the state of deployment type DeploymentCondition struct { LastUpdate string `json:lastUpdateTime` - Type string `json:"type"` - reason string `json:"reason,omitempty"` - message string `json:"message,omitempty"` + Type string `json:"type"` + reason string `json:"reason,omitempty"` + message string `json:"message,omitempty"` } // DeploymentStatus is returned when querying deployment diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 99897178..d28155c1 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -152,7 +152,7 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper { } // AuthHandler wraps a server handler to perform auth -func AuthHandler(fn func() auth.Auth, srvName string) server.HandlerWrapper { +func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { return func(h server.HandlerFunc) server.HandlerFunc { return func(ctx context.Context, req server.Request, rsp interface{}) error { // get the auth.Auth interface @@ -187,11 +187,11 @@ func AuthHandler(fn func() auth.Auth, srvName string) server.HandlerWrapper { } // Verify the caller has access to the resource - err = a.Verify(account, &auth.Resource{Type: "service", Name: srvName, Endpoint: req.Endpoint()}) + err = a.Verify(account, &auth.Resource{Type: "service", Name: req.Service(), Endpoint: req.Endpoint()}) if err != nil && len(account.ID) > 0 { - return errors.Forbidden("go.micro.auth", "Forbidden call made to %v:%v by %v", srvName, req.Endpoint(), account.ID) + return errors.Forbidden("go.micro.auth", "Forbidden call made to %v:%v by %v", req.Service(), req.Endpoint(), account.ID) } else if err != nil { - return errors.Unauthorized("go.micro.auth", "Unauthorised call made to %v:%v", srvName, req.Endpoint()) + return errors.Unauthorized("go.micro.auth", "Unauthorised call made to %v:%v", req.Service(), req.Endpoint()) } // There is an account, set it in the context From beaa434610931582223fad71dd4b5ca8614def09 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 26 Mar 2020 01:00:43 +0300 Subject: [PATCH 433/788] logger: fix reading env var (#1414) Signed-off-by: Vasiliy Tolstov --- logger/default.go | 9 +++++++++ logger/logger_test.go | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/logger/default.go b/logger/default.go index 4eb0e1b6..0b3a432a 100644 --- a/logger/default.go +++ b/logger/default.go @@ -11,6 +11,15 @@ import ( dlog "github.com/micro/go-micro/v2/debug/log" ) +func init() { + lvl, err := GetLevel(os.Getenv("MICRO_LOG_LEVEL")) + if err != nil { + lvl = InfoLevel + } + + DefaultLogger = NewHelper(NewLogger(WithLevel(lvl))) +} + type defaultLogger struct { sync.RWMutex opts Options diff --git a/logger/logger_test.go b/logger/logger_test.go index 70d559bb..846038eb 100644 --- a/logger/logger_test.go +++ b/logger/logger_test.go @@ -1,6 +1,8 @@ package logger -import "testing" +import ( + "testing" +) func TestLogger(t *testing.T) { l := NewLogger(WithLevel(TraceLevel)) From 776a7d6cd62016e0b868ece23d823a94520e49e0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 26 Mar 2020 08:05:00 +0000 Subject: [PATCH 434/788] Update filter comment for proxy (#1416) --- proxy/mucp/mucp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index f2acdc4c..4b8a1926 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -164,7 +164,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route } if logger.V(logger.TraceLevel, logger.DefaultLogger) { - logger.Tracef("Proxy filtered routes %+v\n", filteredRoutes) + logger.Tracef("Proxy filtered routes %+v", filteredRoutes) } return filteredRoutes @@ -357,7 +357,7 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server } if logger.V(logger.TraceLevel, logger.DefaultLogger) { - logger.Tracef("Proxy received request for %s", service) + logger.Tracef("Proxy received request for %s %s", service, endpoint) } // are we network routing or local routing From 02839cfba5d74b0fc4ac4d6b251987c6dbf5410b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 26 Mar 2020 14:29:28 +0300 Subject: [PATCH 435/788] api/handler: use http.MaxBytesReader and buffer pool (#1415) * api/handler: use http.MaxBytesReader protect api handlers from OOM cases Signed-off-by: Vasiliy Tolstov --- api/handler/api/api.go | 6 ++++ api/handler/api/util.go | 16 ++++++--- api/handler/broker/broker.go | 22 +++++++++--- api/handler/cloudevents/cloudevents.go | 15 +++++--- api/handler/cloudevents/event.go | 12 +++++-- api/handler/event/event.go | 29 ++++++++++----- api/handler/options.go | 22 ++++++++++-- api/handler/registry/registry.go | 49 ++++++++++++++++---------- api/handler/rpc/rpc.go | 26 ++++++++++---- 9 files changed, 146 insertions(+), 51 deletions(-) diff --git a/api/handler/api/api.go b/api/handler/api/api.go index 7a14fb4f..85c7be75 100644 --- a/api/handler/api/api.go +++ b/api/handler/api/api.go @@ -24,6 +24,12 @@ const ( // API handler is the default handler which takes api.Request and returns api.Response func (a *apiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + bsize := handler.DefaultMaxRecvSize + if a.opts.MaxRecvSize > 0 { + bsize = a.opts.MaxRecvSize + } + + r.Body = http.MaxBytesReader(w, r.Body, bsize) request, err := requestToProto(r) if err != nil { er := errors.InternalServerError("go.micro.api", err.Error()) diff --git a/api/handler/api/util.go b/api/handler/api/util.go index f66f611b..1caf0ca4 100644 --- a/api/handler/api/util.go +++ b/api/handler/api/util.go @@ -2,7 +2,6 @@ package api import ( "fmt" - "io/ioutil" "mime" "net" "net/http" @@ -11,6 +10,12 @@ import ( api "github.com/micro/go-micro/v2/api/proto" "github.com/micro/go-micro/v2/client/selector" "github.com/micro/go-micro/v2/registry" + "github.com/oxtoacart/bpool" +) + +var ( + // need to calculate later to specify useful defaults + bufferPool = bpool.NewSizedBufferPool(1024, 8) ) func requestToProto(r *http.Request) (*api.Request, error) { @@ -39,9 +44,12 @@ func requestToProto(r *http.Request) (*api.Request, error) { case "application/x-www-form-urlencoded": // expect form vals in Post data default: - - data, _ := ioutil.ReadAll(r.Body) - req.Body = string(data) + buf := bufferPool.Get() + defer bufferPool.Put(buf) + if _, err = buf.ReadFrom(r.Body); err != nil { + return nil, err + } + req.Body = buf.String() } } diff --git a/api/handler/broker/broker.go b/api/handler/broker/broker.go index 8f82446b..7c04c0aa 100644 --- a/api/handler/broker/broker.go +++ b/api/handler/broker/broker.go @@ -3,7 +3,6 @@ package broker import ( "encoding/json" - "io/ioutil" "net/http" "net/url" "strings" @@ -15,6 +14,11 @@ import ( "github.com/micro/go-micro/v2/api/handler" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/logger" + "github.com/oxtoacart/bpool" +) + +var ( + bufferPool = bpool.NewSizedBufferPool(1024, 8) ) const ( @@ -155,6 +159,13 @@ func (c *conn) writeLoop() { } func (b *brokerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + bsize := handler.DefaultMaxRecvSize + if b.opts.MaxRecvSize > 0 { + bsize = b.opts.MaxRecvSize + } + + r.Body = http.MaxBytesReader(w, r.Body, bsize) + br := b.opts.Service.Client().Options().Broker // Setup the broker @@ -191,14 +202,15 @@ func (b *brokerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // Read body - b, err := ioutil.ReadAll(r.Body) - if err != nil { + buf := bufferPool.Get() + defer bufferPool.Put(buf) + if _, err := buf.ReadFrom(r.Body); err != nil { http.Error(w, err.Error(), 500) return } - // Set body - msg.Body = b + msg.Body = buf.Bytes() + // Set body // Publish br.Publish(topic, msg) diff --git a/api/handler/cloudevents/cloudevents.go b/api/handler/cloudevents/cloudevents.go index 2eec44ef..630412da 100644 --- a/api/handler/cloudevents/cloudevents.go +++ b/api/handler/cloudevents/cloudevents.go @@ -12,7 +12,7 @@ import ( ) type event struct { - options handler.Options + opts handler.Options } var ( @@ -58,10 +58,17 @@ func evRoute(ns, p string) (string, string) { } func (e *event) ServeHTTP(w http.ResponseWriter, r *http.Request) { + bsize := handler.DefaultMaxRecvSize + if e.opts.MaxRecvSize > 0 { + bsize = e.opts.MaxRecvSize + } + + r.Body = http.MaxBytesReader(w, r.Body, bsize) + // request to topic:event // create event // publish to topic - topic, _ := evRoute(e.options.Namespace, r.URL.Path) + topic, _ := evRoute(e.opts.Namespace, r.URL.Path) // create event ev, err := FromRequest(r) @@ -71,7 +78,7 @@ func (e *event) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // get client - c := e.options.Service.Client() + c := e.opts.Service.Client() // create publication p := c.NewMessage(topic, ev) @@ -89,6 +96,6 @@ func (e *event) String() string { func NewHandler(opts ...handler.Option) handler.Handler { return &event{ - options: handler.NewOptions(opts...), + opts: handler.NewOptions(opts...), } } diff --git a/api/handler/cloudevents/event.go b/api/handler/cloudevents/event.go index 4869188b..0463792c 100644 --- a/api/handler/cloudevents/event.go +++ b/api/handler/cloudevents/event.go @@ -24,7 +24,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "mime" "net/http" "strings" @@ -32,9 +31,14 @@ import ( "unicode" "github.com/google/uuid" + "github.com/oxtoacart/bpool" validator "gopkg.in/go-playground/validator.v9" ) +var ( + bufferPool = bpool.NewSizedBufferPool(1024, 8) +) + const ( // TransformationVersion is indicative of the revision of how Event Gateway transforms a request into CloudEvents format. TransformationVersion = "0.1" @@ -97,10 +101,12 @@ func FromRequest(r *http.Request) (*Event, error) { // Read request body body := []byte{} if r.Body != nil { - body, err = ioutil.ReadAll(r.Body) - if err != nil { + buf := bufferPool.Get() + defer bufferPool.Put(buf) + if _, err := buf.ReadFrom(r.Body); err != nil { return nil, err } + body = buf.Bytes() } var event *Event diff --git a/api/handler/event/event.go b/api/handler/event/event.go index a819d947..27393165 100644 --- a/api/handler/event/event.go +++ b/api/handler/event/event.go @@ -4,7 +4,6 @@ package event import ( "encoding/json" "fmt" - "io/ioutil" "net/http" "path" "regexp" @@ -15,10 +14,15 @@ import ( "github.com/micro/go-micro/v2/api/handler" proto "github.com/micro/go-micro/v2/api/proto" "github.com/micro/go-micro/v2/util/ctx" + "github.com/oxtoacart/bpool" +) + +var ( + bufferPool = bpool.NewSizedBufferPool(1024, 8) ) type event struct { - options handler.Options + opts handler.Options } var ( @@ -64,11 +68,18 @@ func evRoute(ns, p string) (string, string) { } func (e *event) ServeHTTP(w http.ResponseWriter, r *http.Request) { + bsize := handler.DefaultMaxRecvSize + if e.opts.MaxRecvSize > 0 { + bsize = e.opts.MaxRecvSize + } + + r.Body = http.MaxBytesReader(w, r.Body, bsize) + // request to topic:event // create event // publish to topic - topic, action := evRoute(e.options.Namespace, r.URL.Path) + topic, action := evRoute(e.opts.Namespace, r.URL.Path) // create event ev := &proto.Event{ @@ -96,16 +107,18 @@ func (e *event) ServeHTTP(w http.ResponseWriter, r *http.Request) { bytes, _ := json.Marshal(r.URL.Query()) ev.Data = string(bytes) } else { - b, err := ioutil.ReadAll(r.Body) - if err != nil { + // Read body + buf := bufferPool.Get() + defer bufferPool.Put(buf) + if _, err := buf.ReadFrom(r.Body); err != nil { http.Error(w, err.Error(), 500) return } - ev.Data = string(b) + ev.Data = buf.String() } // get client - c := e.options.Service.Client() + c := e.opts.Service.Client() // create publication p := c.NewMessage(topic, ev) @@ -123,6 +136,6 @@ func (e *event) String() string { func NewHandler(opts ...handler.Option) handler.Handler { return &event{ - options: handler.NewOptions(opts...), + opts: handler.NewOptions(opts...), } } diff --git a/api/handler/options.go b/api/handler/options.go index d7403270..6feeec24 100644 --- a/api/handler/options.go +++ b/api/handler/options.go @@ -5,10 +5,15 @@ import ( "github.com/micro/go-micro/v2/api/router" ) +var ( + DefaultMaxRecvSize int64 = 1024 * 1024 * 10 // 10Mb +) + type Options struct { - Namespace string - Router router.Router - Service micro.Service + MaxRecvSize int64 + Namespace string + Router router.Router + Service micro.Service } type Option func(o *Options) @@ -30,6 +35,10 @@ func NewOptions(opts ...Option) Options { WithNamespace("go.micro.api")(&options) } + if options.MaxRecvSize == 0 { + options.MaxRecvSize = DefaultMaxRecvSize + } + return options } @@ -53,3 +62,10 @@ func WithService(s micro.Service) Option { o.Service = s } } + +// WithmaxRecvSize specifies max body size +func WithMaxRecvSize(size int64) Option { + return func(o *Options) { + o.MaxRecvSize = size + } +} diff --git a/api/handler/registry/registry.go b/api/handler/registry/registry.go index 4aca36da..b0eeaf5a 100644 --- a/api/handler/registry/registry.go +++ b/api/handler/registry/registry.go @@ -3,7 +3,6 @@ package registry import ( "encoding/json" - "io/ioutil" "net/http" "strconv" "time" @@ -11,6 +10,11 @@ import ( "github.com/gorilla/websocket" "github.com/micro/go-micro/v2/api/handler" "github.com/micro/go-micro/v2/registry" + "github.com/oxtoacart/bpool" +) + +var ( + bufferPool = bpool.NewSizedBufferPool(1024, 8) ) const ( @@ -29,12 +33,15 @@ type registryHandler struct { func (rh *registryHandler) add(w http.ResponseWriter, r *http.Request) { r.ParseForm() - b, err := ioutil.ReadAll(r.Body) - if err != nil { + defer r.Body.Close() + + // Read body + buf := bufferPool.Get() + defer bufferPool.Put(buf) + if _, err := buf.ReadFrom(r.Body); err != nil { http.Error(w, err.Error(), 500) return } - defer r.Body.Close() var opts []registry.RegisterOption @@ -47,13 +54,11 @@ func (rh *registryHandler) add(w http.ResponseWriter, r *http.Request) { } var service *registry.Service - err = json.Unmarshal(b, &service) - if err != nil { + if err := json.NewDecoder(buf).Decode(&service); err != nil { http.Error(w, err.Error(), 500) return } - err = rh.reg.Register(service, opts...) - if err != nil { + if err := rh.reg.Register(service, opts...); err != nil { http.Error(w, err.Error(), 500) return } @@ -61,21 +66,22 @@ func (rh *registryHandler) add(w http.ResponseWriter, r *http.Request) { func (rh *registryHandler) del(w http.ResponseWriter, r *http.Request) { r.ParseForm() - b, err := ioutil.ReadAll(r.Body) - if err != nil { - http.Error(w, err.Error(), 500) - return - } defer r.Body.Close() - var service *registry.Service - err = json.Unmarshal(b, &service) - if err != nil { + // Read body + buf := bufferPool.Get() + defer bufferPool.Put(buf) + if _, err := buf.ReadFrom(r.Body); err != nil { http.Error(w, err.Error(), 500) return } - err = rh.reg.Deregister(service) - if err != nil { + + var service *registry.Service + if err := json.NewDecoder(buf).Decode(&service); err != nil { + http.Error(w, err.Error(), 500) + return + } + if err := rh.reg.Deregister(service); err != nil { http.Error(w, err.Error(), 500) return } @@ -187,6 +193,13 @@ func watch(rw registry.Watcher, w http.ResponseWriter, r *http.Request) { } func (rh *registryHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + bsize := handler.DefaultMaxRecvSize + if rh.opts.MaxRecvSize > 0 { + bsize = rh.opts.MaxRecvSize + } + + r.Body = http.MaxBytesReader(w, r.Body, bsize) + switch r.Method { case "GET": rh.get(w, r) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index a246d996..3059207d 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -4,7 +4,6 @@ package rpc import ( "encoding/json" "io" - "io/ioutil" "net/http" "strconv" "strings" @@ -22,6 +21,7 @@ import ( "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/ctx" + "github.com/oxtoacart/bpool" ) const ( @@ -45,6 +45,8 @@ var ( "application/proto-rpc", "application/octet-stream", } + + bufferPool = bpool.NewSizedBufferPool(1024, 8) ) type rpcHandler struct { @@ -69,6 +71,13 @@ func strategy(services []*registry.Service) selector.Strategy { } func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + bsize := handler.DefaultMaxRecvSize + if h.opts.MaxRecvSize > 0 { + bsize = h.opts.MaxRecvSize + } + + r.Body = http.MaxBytesReader(w, r.Body, bsize) + defer r.Body.Close() var service *api.Service @@ -240,8 +249,8 @@ func requestPayload(r *http.Request) ([]byte, error) { if err := c.ReadBody(&raw); err != nil { return nil, err } - b, _ := raw.Marshal() - return b, nil + b, err := raw.Marshal() + return b, err case strings.Contains(ct, "application/www-x-form-urlencoded"): r.ParseForm() @@ -252,8 +261,8 @@ func requestPayload(r *http.Request) ([]byte, error) { } // marshal - b, _ := json.Marshal(vals) - return b, nil + b, err := json.Marshal(vals) + return b, err // TODO: application/grpc } @@ -265,7 +274,12 @@ func requestPayload(r *http.Request) ([]byte, error) { return qson.ToJSON(r.URL.RawQuery) } case "PATCH", "POST": - return ioutil.ReadAll(r.Body) + buf := bufferPool.Get() + defer bufferPool.Put(buf) + if _, err := buf.ReadFrom(r.Body); err != nil { + return nil, err + } + return buf.Bytes(), nil } return []byte{}, nil From 7182ca1fd075e6e98f96431cbb27449c0e702629 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 26 Mar 2020 13:08:06 +0000 Subject: [PATCH 436/788] fix server logging (#1417) --- server/grpc/grpc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index af71aa5e..2b0dc913 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -830,7 +830,7 @@ func (g *grpcServer) Start() error { // announce self to the world if err := g.Register(); err != nil { if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Errorf("Server register error: ", err) + logger.Errorf("Server register error: %v", err) } } @@ -838,7 +838,7 @@ func (g *grpcServer) Start() error { go func() { if err := g.srv.Serve(ts); err != nil { if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Errorf("gRPC Server start error: ", err) + logger.Errorf("gRPC Server start error: %v", err) } } }() From 844c456839ef82a5d7511b6d6ded5a0f27fa5a49 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 26 Mar 2020 13:12:43 +0000 Subject: [PATCH 437/788] Refactor Auth Service Protos, Add Access Rules (#1411) * Refactor auth/service into two protos * Accounts Proto * Store Prefixes * Misc * Tweak Protos Co-authored-by: Ben Toogood Co-authored-by: Asim Aslam --- auth/service/proto/accounts/accounts.pb.go | 117 +++++ .../proto/accounts/accounts.pb.micro.go | 86 ++++ auth/service/proto/accounts/accounts.proto | 16 + auth/service/proto/{ => auth}/auth.pb.go | 249 +++-------- .../service/proto/{ => auth}/auth.pb.micro.go | 53 +-- auth/service/proto/{ => auth}/auth.proto | 18 +- auth/service/proto/rules/rules.pb.go | 398 ++++++++++++++++++ auth/service/proto/rules/rules.pb.micro.go | 120 ++++++ auth/service/proto/rules/rules.proto | 47 +++ auth/service/service.go | 72 ++-- auth/token/basic/basic.go | 10 +- 11 files changed, 895 insertions(+), 291 deletions(-) create mode 100644 auth/service/proto/accounts/accounts.pb.go create mode 100644 auth/service/proto/accounts/accounts.pb.micro.go create mode 100644 auth/service/proto/accounts/accounts.proto rename auth/service/proto/{ => auth}/auth.pb.go (69%) rename auth/service/proto/{ => auth}/auth.pb.micro.go (62%) rename auth/service/proto/{ => auth}/auth.proto (78%) create mode 100644 auth/service/proto/rules/rules.pb.go create mode 100644 auth/service/proto/rules/rules.pb.micro.go create mode 100644 auth/service/proto/rules/rules.proto diff --git a/auth/service/proto/accounts/accounts.pb.go b/auth/service/proto/accounts/accounts.pb.go new file mode 100644 index 00000000..e776cb64 --- /dev/null +++ b/auth/service/proto/accounts/accounts.pb.go @@ -0,0 +1,117 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: github.com/micro/go-micro/auth/service/proto/accounts/accounts.proto + +package go_micro_auth + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + auth "github.com/micro/go-micro/v2/auth/service/proto/auth" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type ListAccountsRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListAccountsRequest) Reset() { *m = ListAccountsRequest{} } +func (m *ListAccountsRequest) String() string { return proto.CompactTextString(m) } +func (*ListAccountsRequest) ProtoMessage() {} +func (*ListAccountsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_25929ace37374fcc, []int{0} +} + +func (m *ListAccountsRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListAccountsRequest.Unmarshal(m, b) +} +func (m *ListAccountsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListAccountsRequest.Marshal(b, m, deterministic) +} +func (m *ListAccountsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListAccountsRequest.Merge(m, src) +} +func (m *ListAccountsRequest) XXX_Size() int { + return xxx_messageInfo_ListAccountsRequest.Size(m) +} +func (m *ListAccountsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ListAccountsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ListAccountsRequest proto.InternalMessageInfo + +type ListAccountsResponse struct { + Accounts []*auth.Account `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListAccountsResponse) Reset() { *m = ListAccountsResponse{} } +func (m *ListAccountsResponse) String() string { return proto.CompactTextString(m) } +func (*ListAccountsResponse) ProtoMessage() {} +func (*ListAccountsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_25929ace37374fcc, []int{1} +} + +func (m *ListAccountsResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListAccountsResponse.Unmarshal(m, b) +} +func (m *ListAccountsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListAccountsResponse.Marshal(b, m, deterministic) +} +func (m *ListAccountsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListAccountsResponse.Merge(m, src) +} +func (m *ListAccountsResponse) XXX_Size() int { + return xxx_messageInfo_ListAccountsResponse.Size(m) +} +func (m *ListAccountsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListAccountsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ListAccountsResponse proto.InternalMessageInfo + +func (m *ListAccountsResponse) GetAccounts() []*auth.Account { + if m != nil { + return m.Accounts + } + return nil +} + +func init() { + proto.RegisterType((*ListAccountsRequest)(nil), "go.micro.auth.ListAccountsRequest") + proto.RegisterType((*ListAccountsResponse)(nil), "go.micro.auth.ListAccountsResponse") +} + +func init() { + proto.RegisterFile("github.com/micro/go-micro/auth/service/proto/accounts/accounts.proto", fileDescriptor_25929ace37374fcc) +} + +var fileDescriptor_25929ace37374fcc = []byte{ + // 186 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x72, 0x49, 0xcf, 0x2c, 0xc9, + 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0xcf, 0xcd, 0x4c, 0x2e, 0xca, 0xd7, 0x4f, 0xcf, 0xd7, + 0x85, 0x30, 0x12, 0x4b, 0x4b, 0x32, 0xf4, 0x8b, 0x53, 0x8b, 0xca, 0x32, 0x93, 0x53, 0xf5, 0x0b, + 0x8a, 0xf2, 0x4b, 0xf2, 0xf5, 0x13, 0x93, 0x93, 0xf3, 0x4b, 0xf3, 0x4a, 0x8a, 0xe1, 0x0c, 0x3d, + 0xb0, 0xb8, 0x10, 0x6f, 0x7a, 0xbe, 0x1e, 0x58, 0x93, 0x1e, 0x48, 0x93, 0x94, 0x0d, 0x69, 0x86, + 0x82, 0x84, 0x40, 0x04, 0xc4, 0x30, 0x25, 0x51, 0x2e, 0x61, 0x9f, 0xcc, 0xe2, 0x12, 0x47, 0xa8, + 0x15, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x4a, 0x5e, 0x5c, 0x22, 0xa8, 0xc2, 0xc5, 0x05, + 0xf9, 0x79, 0xc5, 0xa9, 0x42, 0x46, 0x5c, 0x1c, 0x30, 0xd7, 0x48, 0x30, 0x2a, 0x30, 0x6b, 0x70, + 0x1b, 0x89, 0xe9, 0xa1, 0x38, 0x47, 0x0f, 0xaa, 0x25, 0x08, 0xae, 0xce, 0x28, 0x96, 0x8b, 0x03, + 0x66, 0x8e, 0x50, 0x20, 0x17, 0x0b, 0xc8, 0x5c, 0x21, 0x25, 0x34, 0x5d, 0x58, 0xdc, 0x20, 0xa5, + 0x8c, 0x57, 0x0d, 0xc4, 0x41, 0x4a, 0x0c, 0x49, 0x6c, 0x60, 0x8f, 0x18, 0x03, 0x02, 0x00, 0x00, + 0xff, 0xff, 0x23, 0x27, 0x81, 0xfe, 0x5d, 0x01, 0x00, 0x00, +} diff --git a/auth/service/proto/accounts/accounts.pb.micro.go b/auth/service/proto/accounts/accounts.pb.micro.go new file mode 100644 index 00000000..820b968d --- /dev/null +++ b/auth/service/proto/accounts/accounts.pb.micro.go @@ -0,0 +1,86 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: github.com/micro/go-micro/auth/service/proto/accounts/accounts.proto + +package go_micro_auth + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + _ "github.com/micro/go-micro/v2/auth/service/proto/auth" + math "math" +) + +import ( + context "context" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ client.Option +var _ server.Option + +// Client API for Accounts service + +type AccountsService interface { + List(ctx context.Context, in *ListAccountsRequest, opts ...client.CallOption) (*ListAccountsResponse, error) +} + +type accountsService struct { + c client.Client + name string +} + +func NewAccountsService(name string, c client.Client) AccountsService { + return &accountsService{ + c: c, + name: name, + } +} + +func (c *accountsService) List(ctx context.Context, in *ListAccountsRequest, opts ...client.CallOption) (*ListAccountsResponse, error) { + req := c.c.NewRequest(c.name, "Accounts.List", in) + out := new(ListAccountsResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Accounts service + +type AccountsHandler interface { + List(context.Context, *ListAccountsRequest, *ListAccountsResponse) error +} + +func RegisterAccountsHandler(s server.Server, hdlr AccountsHandler, opts ...server.HandlerOption) error { + type accounts interface { + List(ctx context.Context, in *ListAccountsRequest, out *ListAccountsResponse) error + } + type Accounts struct { + accounts + } + h := &accountsHandler{hdlr} + return s.Handle(s.NewHandler(&Accounts{h}, opts...)) +} + +type accountsHandler struct { + AccountsHandler +} + +func (h *accountsHandler) List(ctx context.Context, in *ListAccountsRequest, out *ListAccountsResponse) error { + return h.AccountsHandler.List(ctx, in, out) +} diff --git a/auth/service/proto/accounts/accounts.proto b/auth/service/proto/accounts/accounts.proto new file mode 100644 index 00000000..8f93aa23 --- /dev/null +++ b/auth/service/proto/accounts/accounts.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package go.micro.auth; + +import "github.com/micro/go-micro/auth/service/proto/auth/auth.proto"; + +service Accounts { + rpc List(ListAccountsRequest) returns (ListAccountsResponse) {}; +} + +message ListAccountsRequest { +} + +message ListAccountsResponse { + repeated Account accounts = 1; +} diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth/auth.pb.go similarity index 69% rename from auth/service/proto/auth.pb.go rename to auth/service/proto/auth/auth.pb.go index 5ca611a8..31c89570 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth/auth.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: auth/service/proto/auth.proto +// source: github.com/micro/go-micro/auth/service/proto/auth/auth.proto package go_micro_auth @@ -20,61 +20,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package -type Rule struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` - Resource *Resource `protobuf:"bytes,3,opt,name=resource,proto3" json:"resource,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Rule) Reset() { *m = Rule{} } -func (m *Rule) String() string { return proto.CompactTextString(m) } -func (*Rule) ProtoMessage() {} -func (*Rule) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{0} -} - -func (m *Rule) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Rule.Unmarshal(m, b) -} -func (m *Rule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Rule.Marshal(b, m, deterministic) -} -func (m *Rule) XXX_Merge(src proto.Message) { - xxx_messageInfo_Rule.Merge(m, src) -} -func (m *Rule) XXX_Size() int { - return xxx_messageInfo_Rule.Size(m) -} -func (m *Rule) XXX_DiscardUnknown() { - xxx_messageInfo_Rule.DiscardUnknown(m) -} - -var xxx_messageInfo_Rule proto.InternalMessageInfo - -func (m *Rule) GetId() string { - if m != nil { - return m.Id - } - return "" -} - -func (m *Rule) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -func (m *Rule) GetResource() *Resource { - if m != nil { - return m.Resource - } - return nil -} - type Token struct { Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` @@ -92,7 +37,7 @@ func (m *Token) Reset() { *m = Token{} } func (m *Token) String() string { return proto.CompactTextString(m) } func (*Token) ProtoMessage() {} func (*Token) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{1} + return fileDescriptor_b246cecfa8195ff3, []int{0} } func (m *Token) XXX_Unmarshal(b []byte) error { @@ -176,7 +121,7 @@ func (m *Account) Reset() { *m = Account{} } func (m *Account) String() string { return proto.CompactTextString(m) } func (*Account) ProtoMessage() {} func (*Account) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{2} + return fileDescriptor_b246cecfa8195ff3, []int{1} } func (m *Account) XXX_Unmarshal(b []byte) error { @@ -238,7 +183,7 @@ func (m *Resource) Reset() { *m = Resource{} } func (m *Resource) String() string { return proto.CompactTextString(m) } func (*Resource) ProtoMessage() {} func (*Resource) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{3} + return fileDescriptor_b246cecfa8195ff3, []int{2} } func (m *Resource) XXX_Unmarshal(b []byte) error { @@ -294,7 +239,7 @@ func (m *GenerateRequest) Reset() { *m = GenerateRequest{} } func (m *GenerateRequest) String() string { return proto.CompactTextString(m) } func (*GenerateRequest) ProtoMessage() {} func (*GenerateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{4} + return fileDescriptor_b246cecfa8195ff3, []int{3} } func (m *GenerateRequest) XXX_Unmarshal(b []byte) error { @@ -354,7 +299,7 @@ func (m *GenerateResponse) Reset() { *m = GenerateResponse{} } func (m *GenerateResponse) String() string { return proto.CompactTextString(m) } func (*GenerateResponse) ProtoMessage() {} func (*GenerateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{5} + return fileDescriptor_b246cecfa8195ff3, []int{4} } func (m *GenerateResponse) XXX_Unmarshal(b []byte) error { @@ -394,7 +339,7 @@ func (m *GrantRequest) Reset() { *m = GrantRequest{} } func (m *GrantRequest) String() string { return proto.CompactTextString(m) } func (*GrantRequest) ProtoMessage() {} func (*GrantRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{6} + return fileDescriptor_b246cecfa8195ff3, []int{5} } func (m *GrantRequest) XXX_Unmarshal(b []byte) error { @@ -439,7 +384,7 @@ func (m *GrantResponse) Reset() { *m = GrantResponse{} } func (m *GrantResponse) String() string { return proto.CompactTextString(m) } func (*GrantResponse) ProtoMessage() {} func (*GrantResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{7} + return fileDescriptor_b246cecfa8195ff3, []int{6} } func (m *GrantResponse) XXX_Unmarshal(b []byte) error { @@ -472,7 +417,7 @@ func (m *RevokeRequest) Reset() { *m = RevokeRequest{} } func (m *RevokeRequest) String() string { return proto.CompactTextString(m) } func (*RevokeRequest) ProtoMessage() {} func (*RevokeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{8} + return fileDescriptor_b246cecfa8195ff3, []int{7} } func (m *RevokeRequest) XXX_Unmarshal(b []byte) error { @@ -517,7 +462,7 @@ func (m *RevokeResponse) Reset() { *m = RevokeResponse{} } func (m *RevokeResponse) String() string { return proto.CompactTextString(m) } func (*RevokeResponse) ProtoMessage() {} func (*RevokeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{9} + return fileDescriptor_b246cecfa8195ff3, []int{8} } func (m *RevokeResponse) XXX_Unmarshal(b []byte) error { @@ -549,7 +494,7 @@ func (m *InspectRequest) Reset() { *m = InspectRequest{} } func (m *InspectRequest) String() string { return proto.CompactTextString(m) } func (*InspectRequest) ProtoMessage() {} func (*InspectRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{10} + return fileDescriptor_b246cecfa8195ff3, []int{9} } func (m *InspectRequest) XXX_Unmarshal(b []byte) error { @@ -588,7 +533,7 @@ func (m *InspectResponse) Reset() { *m = InspectResponse{} } func (m *InspectResponse) String() string { return proto.CompactTextString(m) } func (*InspectResponse) ProtoMessage() {} func (*InspectResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{11} + return fileDescriptor_b246cecfa8195ff3, []int{10} } func (m *InspectResponse) XXX_Unmarshal(b []byte) error { @@ -628,7 +573,7 @@ func (m *RefreshRequest) Reset() { *m = RefreshRequest{} } func (m *RefreshRequest) String() string { return proto.CompactTextString(m) } func (*RefreshRequest) ProtoMessage() {} func (*RefreshRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{12} + return fileDescriptor_b246cecfa8195ff3, []int{11} } func (m *RefreshRequest) XXX_Unmarshal(b []byte) error { @@ -674,7 +619,7 @@ func (m *RefreshResponse) Reset() { *m = RefreshResponse{} } func (m *RefreshResponse) String() string { return proto.CompactTextString(m) } func (*RefreshResponse) ProtoMessage() {} func (*RefreshResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{13} + return fileDescriptor_b246cecfa8195ff3, []int{12} } func (m *RefreshResponse) XXX_Unmarshal(b []byte) error { @@ -702,78 +647,7 @@ func (m *RefreshResponse) GetToken() *Token { return nil } -type ListRulesRequest struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ListRulesRequest) Reset() { *m = ListRulesRequest{} } -func (m *ListRulesRequest) String() string { return proto.CompactTextString(m) } -func (*ListRulesRequest) ProtoMessage() {} -func (*ListRulesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{14} -} - -func (m *ListRulesRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ListRulesRequest.Unmarshal(m, b) -} -func (m *ListRulesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ListRulesRequest.Marshal(b, m, deterministic) -} -func (m *ListRulesRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ListRulesRequest.Merge(m, src) -} -func (m *ListRulesRequest) XXX_Size() int { - return xxx_messageInfo_ListRulesRequest.Size(m) -} -func (m *ListRulesRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ListRulesRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_ListRulesRequest proto.InternalMessageInfo - -type ListRulesResponse struct { - Rules []*Rule `protobuf:"bytes,1,rep,name=rules,proto3" json:"rules,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ListRulesResponse) Reset() { *m = ListRulesResponse{} } -func (m *ListRulesResponse) String() string { return proto.CompactTextString(m) } -func (*ListRulesResponse) ProtoMessage() {} -func (*ListRulesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{15} -} - -func (m *ListRulesResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ListRulesResponse.Unmarshal(m, b) -} -func (m *ListRulesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ListRulesResponse.Marshal(b, m, deterministic) -} -func (m *ListRulesResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_ListRulesResponse.Merge(m, src) -} -func (m *ListRulesResponse) XXX_Size() int { - return xxx_messageInfo_ListRulesResponse.Size(m) -} -func (m *ListRulesResponse) XXX_DiscardUnknown() { - xxx_messageInfo_ListRulesResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_ListRulesResponse proto.InternalMessageInfo - -func (m *ListRulesResponse) GetRules() []*Rule { - if m != nil { - return m.Rules - } - return nil -} - func init() { - proto.RegisterType((*Rule)(nil), "go.micro.auth.Rule") proto.RegisterType((*Token)(nil), "go.micro.auth.Token") proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.Token.MetadataEntry") proto.RegisterType((*Account)(nil), "go.micro.auth.Account") @@ -790,56 +664,51 @@ func init() { proto.RegisterType((*InspectResponse)(nil), "go.micro.auth.InspectResponse") proto.RegisterType((*RefreshRequest)(nil), "go.micro.auth.RefreshRequest") proto.RegisterType((*RefreshResponse)(nil), "go.micro.auth.RefreshResponse") - proto.RegisterType((*ListRulesRequest)(nil), "go.micro.auth.ListRulesRequest") - proto.RegisterType((*ListRulesResponse)(nil), "go.micro.auth.ListRulesResponse") } -func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } - -var fileDescriptor_21300bfacc51fc2a = []byte{ - // 696 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xdb, 0x6e, 0xd3, 0x40, - 0x10, 0xad, 0xed, 0xdc, 0x3a, 0x69, 0x9a, 0xb0, 0x54, 0xc5, 0x32, 0x6d, 0x09, 0x06, 0xa1, 0x82, - 0xaa, 0x14, 0xa5, 0x2f, 0x08, 0x44, 0x45, 0x45, 0xab, 0x72, 0x2b, 0x42, 0x16, 0x12, 0xbc, 0x55, - 0xae, 0x33, 0x50, 0xd3, 0xd4, 0x36, 0xeb, 0x75, 0x45, 0xfe, 0x82, 0x2f, 0xe3, 0x0b, 0x78, 0xe3, - 0x47, 0xd0, 0xae, 0x77, 0xb7, 0x8e, 0x13, 0x23, 0xc4, 0xe5, 0x6d, 0x77, 0x76, 0x7c, 0xce, 0xcc, - 0x99, 0x33, 0x09, 0xac, 0xfb, 0x19, 0x3b, 0xdd, 0x4e, 0x91, 0x5e, 0x84, 0x01, 0x6e, 0x27, 0x34, - 0x66, 0xf1, 0x36, 0x0f, 0x0d, 0xc4, 0x91, 0x74, 0x3e, 0xc6, 0x83, 0xf3, 0x30, 0xa0, 0xf1, 0x80, - 0x07, 0xdd, 0x63, 0xa8, 0x79, 0xd9, 0x18, 0xc9, 0x32, 0x98, 0xe1, 0xc8, 0x36, 0xfa, 0xc6, 0xe6, - 0xa2, 0x67, 0x86, 0x23, 0x42, 0xa0, 0x46, 0xe3, 0x31, 0xda, 0xa6, 0x88, 0x88, 0x33, 0xd9, 0x81, - 0x16, 0xc5, 0x34, 0xce, 0x68, 0x80, 0xb6, 0xd5, 0x37, 0x36, 0xdb, 0xc3, 0x6b, 0x83, 0x29, 0xb4, - 0x81, 0x27, 0x9f, 0x3d, 0x9d, 0xe8, 0x7e, 0x35, 0xa1, 0xfe, 0x36, 0x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d, 0x62, 0xe9, 0x55, 0x0b, 0x2e, 0x1b, 0x22, - 0xd0, 0x7b, 0x15, 0xa6, 0x8c, 0xff, 0x42, 0xa7, 0xb2, 0x1a, 0x77, 0x17, 0xae, 0x14, 0x62, 0x12, - 0xf4, 0x2e, 0xd4, 0x29, 0x0f, 0xd8, 0x86, 0xb0, 0xf9, 0xd5, 0xb2, 0xca, 0xd9, 0x18, 0xbd, 0x3c, - 0x63, 0xf8, 0xcd, 0x82, 0xda, 0x5e, 0xc6, 0x4e, 0xc9, 0x11, 0xb4, 0x94, 0xe3, 0xc8, 0xc6, 0xaf, - 0xf7, 0xc2, 0xb9, 0x51, 0xf9, 0x2e, 0x47, 0xb4, 0x40, 0xf6, 0xa1, 0x2e, 0x1c, 0x42, 0xae, 0x97, - 0x73, 0x0b, 0x86, 0x74, 0xd6, 0xe6, 0x3f, 0x6a, 0x94, 0x43, 0x68, 0xe4, 0xc3, 0x27, 0x6b, 0x33, - 0x4e, 0x29, 0xb8, 0xcd, 0x59, 0xaf, 0x78, 0xd5, 0x40, 0x2f, 0xa0, 0x29, 0xbd, 0x40, 0xca, 0xb9, - 0xd3, 0x5e, 0x72, 0x36, 0xaa, 0x9e, 0x8b, 0x58, 0x72, 0x8a, 0x64, 0x96, 0xb7, 0x68, 0x95, 0x19, - 0xac, 0xd2, 0xf0, 0xdd, 0x05, 0xf2, 0x06, 0x16, 0xf5, 0xf8, 0x48, 0x59, 0xd6, 0xf2, 0xb0, 0x9d, - 0x7e, 0x75, 0x82, 0x42, 0x3c, 0x69, 0x88, 0x3f, 0xf6, 0x9d, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, - 0x91, 0x77, 0xf2, 0xa6, 0xf9, 0x07, 0x00, 0x00, +func init() { + proto.RegisterFile("github.com/micro/go-micro/auth/service/proto/auth/auth.proto", fileDescriptor_b246cecfa8195ff3) +} + +var fileDescriptor_b246cecfa8195ff3 = []byte{ + // 612 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8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 0x40, 0x5d, 0x6f, 0x07, 0x39, 0xfa, 0xfd, 0x0e, 0x77, 0x6f, 0x6c, + 0x3d, 0x57, 0x72, 0xee, 0x90, 0xd7, 0x50, 0x53, 0x42, 0x91, 0xeb, 0xa5, 0xec, 0x55, 0xa1, 0xbb, + 0x47, 0xdb, 0x8e, 0x8b, 0x58, 0xaa, 0xc5, 0x35, 0xac, 0x55, 0x1d, 0xd7, 0xb0, 0x4a, 0xca, 0x38, + 0x3b, 0xa3, 0xaa, 0xfc, 0x84, 0x9c, 0xfc, 0x0a, 0x00, 0x00, 0xff, 0xff, 0xe9, 0x1b, 0x69, 0xa7, + 0x82, 0x06, 0x00, 0x00, } diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth/auth.pb.micro.go similarity index 62% rename from auth/service/proto/auth.pb.micro.go rename to auth/service/proto/auth/auth.pb.micro.go index 0d162a71..61107958 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth/auth.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: auth/service/proto/auth.proto +// source: github.com/micro/go-micro/auth/service/proto/auth/auth.proto package go_micro_auth @@ -35,11 +35,8 @@ var _ server.Option type AuthService interface { Generate(ctx context.Context, in *GenerateRequest, opts ...client.CallOption) (*GenerateResponse, error) - Grant(ctx context.Context, in *GrantRequest, opts ...client.CallOption) (*GrantResponse, error) - Revoke(ctx context.Context, in *RevokeRequest, opts ...client.CallOption) (*RevokeResponse, error) Inspect(ctx context.Context, in *InspectRequest, opts ...client.CallOption) (*InspectResponse, error) Refresh(ctx context.Context, in *RefreshRequest, opts ...client.CallOption) (*RefreshResponse, error) - ListRules(ctx context.Context, in *ListRulesRequest, opts ...client.CallOption) (*ListRulesResponse, error) } type authService struct { @@ -64,26 +61,6 @@ func (c *authService) Generate(ctx context.Context, in *GenerateRequest, opts .. return out, nil } -func (c *authService) Grant(ctx context.Context, in *GrantRequest, opts ...client.CallOption) (*GrantResponse, error) { - req := c.c.NewRequest(c.name, "Auth.Grant", in) - out := new(GrantResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authService) Revoke(ctx context.Context, in *RevokeRequest, opts ...client.CallOption) (*RevokeResponse, error) { - req := c.c.NewRequest(c.name, "Auth.Revoke", in) - out := new(RevokeResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *authService) Inspect(ctx context.Context, in *InspectRequest, opts ...client.CallOption) (*InspectResponse, error) { req := c.c.NewRequest(c.name, "Auth.Inspect", in) out := new(InspectResponse) @@ -104,35 +81,19 @@ func (c *authService) Refresh(ctx context.Context, in *RefreshRequest, opts ...c return out, nil } -func (c *authService) ListRules(ctx context.Context, in *ListRulesRequest, opts ...client.CallOption) (*ListRulesResponse, error) { - req := c.c.NewRequest(c.name, "Auth.ListRules", in) - out := new(ListRulesResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - // Server API for Auth service type AuthHandler interface { Generate(context.Context, *GenerateRequest, *GenerateResponse) error - Grant(context.Context, *GrantRequest, *GrantResponse) error - Revoke(context.Context, *RevokeRequest, *RevokeResponse) error Inspect(context.Context, *InspectRequest, *InspectResponse) error Refresh(context.Context, *RefreshRequest, *RefreshResponse) error - ListRules(context.Context, *ListRulesRequest, *ListRulesResponse) error } func RegisterAuthHandler(s server.Server, hdlr AuthHandler, opts ...server.HandlerOption) error { type auth interface { Generate(ctx context.Context, in *GenerateRequest, out *GenerateResponse) error - Grant(ctx context.Context, in *GrantRequest, out *GrantResponse) error - Revoke(ctx context.Context, in *RevokeRequest, out *RevokeResponse) error Inspect(ctx context.Context, in *InspectRequest, out *InspectResponse) error Refresh(ctx context.Context, in *RefreshRequest, out *RefreshResponse) error - ListRules(ctx context.Context, in *ListRulesRequest, out *ListRulesResponse) error } type Auth struct { auth @@ -149,14 +110,6 @@ func (h *authHandler) Generate(ctx context.Context, in *GenerateRequest, out *Ge return h.AuthHandler.Generate(ctx, in, out) } -func (h *authHandler) Grant(ctx context.Context, in *GrantRequest, out *GrantResponse) error { - return h.AuthHandler.Grant(ctx, in, out) -} - -func (h *authHandler) Revoke(ctx context.Context, in *RevokeRequest, out *RevokeResponse) error { - return h.AuthHandler.Revoke(ctx, in, out) -} - func (h *authHandler) Inspect(ctx context.Context, in *InspectRequest, out *InspectResponse) error { return h.AuthHandler.Inspect(ctx, in, out) } @@ -164,7 +117,3 @@ func (h *authHandler) Inspect(ctx context.Context, in *InspectRequest, out *Insp func (h *authHandler) Refresh(ctx context.Context, in *RefreshRequest, out *RefreshResponse) error { return h.AuthHandler.Refresh(ctx, in, out) } - -func (h *authHandler) ListRules(ctx context.Context, in *ListRulesRequest, out *ListRulesResponse) error { - return h.AuthHandler.ListRules(ctx, in, out) -} diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth/auth.proto similarity index 78% rename from auth/service/proto/auth.proto rename to auth/service/proto/auth/auth.proto index 8efb64a5..a31d6102 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth/auth.proto @@ -4,17 +4,8 @@ package go.micro.auth; service Auth { rpc Generate(GenerateRequest) returns (GenerateResponse) {}; - rpc Grant(GrantRequest) returns (GrantResponse) {}; - rpc Revoke(RevokeRequest) returns (RevokeResponse) {}; rpc Inspect(InspectRequest) returns (InspectResponse) {}; rpc Refresh(RefreshRequest) returns (RefreshResponse) {}; - rpc ListRules(ListRulesRequest) returns (ListRulesResponse) {}; -} - -message Rule { - string id = 1; - string role = 2; - Resource resource = 3; } message Token { @@ -80,11 +71,4 @@ message RefreshRequest { message RefreshResponse { Token token = 1; -} - -message ListRulesRequest { -} - -message ListRulesResponse { - repeated Rule rules = 1; -} +} \ No newline at end of file diff --git a/auth/service/proto/rules/rules.pb.go b/auth/service/proto/rules/rules.pb.go new file mode 100644 index 00000000..d9efd3a9 --- /dev/null +++ b/auth/service/proto/rules/rules.pb.go @@ -0,0 +1,398 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: github.com/micro/go-micro/auth/service/proto/rules/rules.proto + +package go_micro_auth + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + auth "github.com/micro/go-micro/v2/auth/service/proto/auth" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type Access int32 + +const ( + Access_UNKNOWN Access = 0 + Access_GRANTED Access = 1 + Access_DENIED Access = 2 +) + +var Access_name = map[int32]string{ + 0: "UNKNOWN", + 1: "GRANTED", + 2: "DENIED", +} + +var Access_value = map[string]int32{ + "UNKNOWN": 0, + "GRANTED": 1, + "DENIED": 2, +} + +func (x Access) String() string { + return proto.EnumName(Access_name, int32(x)) +} + +func (Access) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_d5bb7c98c32bdd99, []int{0} +} + +type Rule struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` + Resource *auth.Resource `protobuf:"bytes,3,opt,name=resource,proto3" json:"resource,omitempty"` + Access Access `protobuf:"varint,4,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Rule) Reset() { *m = Rule{} } +func (m *Rule) String() string { return proto.CompactTextString(m) } +func (*Rule) ProtoMessage() {} +func (*Rule) Descriptor() ([]byte, []int) { + return fileDescriptor_d5bb7c98c32bdd99, []int{0} +} + +func (m *Rule) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Rule.Unmarshal(m, b) +} +func (m *Rule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Rule.Marshal(b, m, deterministic) +} +func (m *Rule) XXX_Merge(src proto.Message) { + xxx_messageInfo_Rule.Merge(m, src) +} +func (m *Rule) XXX_Size() int { + return xxx_messageInfo_Rule.Size(m) +} +func (m *Rule) XXX_DiscardUnknown() { + xxx_messageInfo_Rule.DiscardUnknown(m) +} + +var xxx_messageInfo_Rule proto.InternalMessageInfo + +func (m *Rule) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *Rule) GetRole() string { + if m != nil { + return m.Role + } + return "" +} + +func (m *Rule) GetResource() *auth.Resource { + if m != nil { + return m.Resource + } + return nil +} + +func (m *Rule) GetAccess() Access { + if m != nil { + return m.Access + } + return Access_UNKNOWN +} + +type CreateRequest struct { + Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` + Resource *auth.Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` + Access Access `protobuf:"varint,3,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateRequest) Reset() { *m = CreateRequest{} } +func (m *CreateRequest) String() string { return proto.CompactTextString(m) } +func (*CreateRequest) ProtoMessage() {} +func (*CreateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d5bb7c98c32bdd99, []int{1} +} + +func (m *CreateRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateRequest.Unmarshal(m, b) +} +func (m *CreateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateRequest.Marshal(b, m, deterministic) +} +func (m *CreateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateRequest.Merge(m, src) +} +func (m *CreateRequest) XXX_Size() int { + return xxx_messageInfo_CreateRequest.Size(m) +} +func (m *CreateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CreateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateRequest proto.InternalMessageInfo + +func (m *CreateRequest) GetRole() string { + if m != nil { + return m.Role + } + return "" +} + +func (m *CreateRequest) GetResource() *auth.Resource { + if m != nil { + return m.Resource + } + return nil +} + +func (m *CreateRequest) GetAccess() Access { + if m != nil { + return m.Access + } + return Access_UNKNOWN +} + +type CreateResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateResponse) Reset() { *m = CreateResponse{} } +func (m *CreateResponse) String() string { return proto.CompactTextString(m) } +func (*CreateResponse) ProtoMessage() {} +func (*CreateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d5bb7c98c32bdd99, []int{2} +} + +func (m *CreateResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateResponse.Unmarshal(m, b) +} +func (m *CreateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateResponse.Marshal(b, m, deterministic) +} +func (m *CreateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateResponse.Merge(m, src) +} +func (m *CreateResponse) XXX_Size() int { + return xxx_messageInfo_CreateResponse.Size(m) +} +func (m *CreateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CreateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateResponse proto.InternalMessageInfo + +type DeleteRequest struct { + Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` + Resource *auth.Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` + Access Access `protobuf:"varint,3,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } +func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } +func (*DeleteRequest) ProtoMessage() {} +func (*DeleteRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d5bb7c98c32bdd99, []int{3} +} + +func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteRequest.Unmarshal(m, b) +} +func (m *DeleteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteRequest.Marshal(b, m, deterministic) +} +func (m *DeleteRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteRequest.Merge(m, src) +} +func (m *DeleteRequest) XXX_Size() int { + return xxx_messageInfo_DeleteRequest.Size(m) +} +func (m *DeleteRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteRequest proto.InternalMessageInfo + +func (m *DeleteRequest) GetRole() string { + if m != nil { + return m.Role + } + return "" +} + +func (m *DeleteRequest) GetResource() *auth.Resource { + if m != nil { + return m.Resource + } + return nil +} + +func (m *DeleteRequest) GetAccess() Access { + if m != nil { + return m.Access + } + return Access_UNKNOWN +} + +type DeleteResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } +func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } +func (*DeleteResponse) ProtoMessage() {} +func (*DeleteResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d5bb7c98c32bdd99, []int{4} +} + +func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteResponse.Unmarshal(m, b) +} +func (m *DeleteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteResponse.Marshal(b, m, deterministic) +} +func (m *DeleteResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteResponse.Merge(m, src) +} +func (m *DeleteResponse) XXX_Size() int { + return xxx_messageInfo_DeleteResponse.Size(m) +} +func (m *DeleteResponse) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo + +type ListRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListRequest) Reset() { *m = ListRequest{} } +func (m *ListRequest) String() string { return proto.CompactTextString(m) } +func (*ListRequest) ProtoMessage() {} +func (*ListRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d5bb7c98c32bdd99, []int{5} +} + +func (m *ListRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListRequest.Unmarshal(m, b) +} +func (m *ListRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListRequest.Marshal(b, m, deterministic) +} +func (m *ListRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListRequest.Merge(m, src) +} +func (m *ListRequest) XXX_Size() int { + return xxx_messageInfo_ListRequest.Size(m) +} +func (m *ListRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ListRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ListRequest proto.InternalMessageInfo + +type ListResponse struct { + Rules []*Rule `protobuf:"bytes,1,rep,name=rules,proto3" json:"rules,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListResponse) Reset() { *m = ListResponse{} } +func (m *ListResponse) String() string { return proto.CompactTextString(m) } +func (*ListResponse) ProtoMessage() {} +func (*ListResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d5bb7c98c32bdd99, []int{6} +} + +func (m *ListResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListResponse.Unmarshal(m, b) +} +func (m *ListResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListResponse.Marshal(b, m, deterministic) +} +func (m *ListResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListResponse.Merge(m, src) +} +func (m *ListResponse) XXX_Size() int { + return xxx_messageInfo_ListResponse.Size(m) +} +func (m *ListResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ListResponse proto.InternalMessageInfo + +func (m *ListResponse) GetRules() []*Rule { + if m != nil { + return m.Rules + } + return nil +} + +func init() { + proto.RegisterEnum("go.micro.auth.Access", Access_name, Access_value) + proto.RegisterType((*Rule)(nil), "go.micro.auth.Rule") + proto.RegisterType((*CreateRequest)(nil), "go.micro.auth.CreateRequest") + proto.RegisterType((*CreateResponse)(nil), "go.micro.auth.CreateResponse") + proto.RegisterType((*DeleteRequest)(nil), "go.micro.auth.DeleteRequest") + proto.RegisterType((*DeleteResponse)(nil), "go.micro.auth.DeleteResponse") + proto.RegisterType((*ListRequest)(nil), "go.micro.auth.ListRequest") + proto.RegisterType((*ListResponse)(nil), "go.micro.auth.ListResponse") +} + +func init() { + proto.RegisterFile("github.com/micro/go-micro/auth/service/proto/rules/rules.proto", fileDescriptor_d5bb7c98c32bdd99) +} + +var fileDescriptor_d5bb7c98c32bdd99 = []byte{ + // 384 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x93, 0x41, 0x6b, 0xdb, 0x30, + 0x1c, 0xc5, 0x23, 0xc7, 0xf1, 0xb6, 0xbf, 0x97, 0x60, 0x34, 0xc6, 0x8c, 0xb7, 0x81, 0xc9, 0xc9, + 0x1b, 0xc4, 0x06, 0xe7, 0x34, 0x18, 0x83, 0x30, 0x87, 0x30, 0x36, 0x3c, 0x10, 0x2d, 0x3d, 0x27, + 0xce, 0x9f, 0xc4, 0xe0, 0x54, 0xa9, 0x64, 0xf7, 0x2b, 0xf4, 0xd6, 0x4f, 0xd8, 0x0f, 0x53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03, 0x69, 0xd8, 0xfa, 0x60, 0xff, 0xcb, 0x65, 0xd9, 0x80, 0x0d, 0x7f, + 0xc0, 0x7b, 0xbd, 0xd4, 0x32, 0xfd, 0x06, 0x3d, 0xf5, 0x0d, 0xb9, 0xc4, 0xef, 0x06, 0x76, 0xfc, + 0xa1, 0x4d, 0x54, 0x15, 0xc8, 0xb4, 0xe3, 0x7b, 0x08, 0x96, 0x7e, 0x1a, 0xb5, 0xe1, 0xcd, 0x65, + 0xfa, 0x37, 0xfd, 0x7f, 0x95, 0x3a, 0x9d, 0x7a, 0x31, 0x63, 0x93, 0xf4, 0x62, 0x9a, 0x38, 0x84, + 0x02, 0x58, 0xc9, 0x34, 0xfd, 0x33, 0x4d, 0x1c, 0x23, 0x7e, 0x20, 0xd0, 0xab, 0xcf, 0x4b, 0x3a, + 0x03, 0x4b, 0x37, 0x46, 0xbf, 0xb4, 0xf2, 0x0f, 0xde, 0xa8, 0xf7, 0xf5, 0x84, 0xda, 0x5c, 0xa5, + 0x53, 0x07, 0xe9, 0xeb, 0x1d, 0x05, 0x1d, 0xd4, 0x7f, 0x14, 0xd4, 0xea, 0xa4, 0x43, 0x27, 0x60, + 0xd6, 0x35, 0x50, 0xaf, 0x65, 0x7c, 0x52, 0x95, 0xf7, 0xf9, 0x59, 0x6d, 0x17, 0xb1, 0xb0, 0xd4, + 0x8f, 0x32, 0x7e, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x85, 0x65, 0x07, 0x9d, 0xb7, 0x03, 0x00, 0x00, +} diff --git a/auth/service/proto/rules/rules.pb.micro.go b/auth/service/proto/rules/rules.pb.micro.go new file mode 100644 index 00000000..ee3a7f24 --- /dev/null +++ b/auth/service/proto/rules/rules.pb.micro.go @@ -0,0 +1,120 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: github.com/micro/go-micro/auth/service/proto/rules/rules.proto + +package go_micro_auth + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + _ "github.com/micro/go-micro/v2/auth/service/proto/auth" + math "math" +) + +import ( + context "context" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ client.Option +var _ server.Option + +// Client API for Rules service + +type RulesService interface { + Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) + List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) +} + +type rulesService struct { + c client.Client + name string +} + +func NewRulesService(name string, c client.Client) RulesService { + return &rulesService{ + c: c, + name: name, + } +} + +func (c *rulesService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { + req := c.c.NewRequest(c.name, "Rules.Create", in) + out := new(CreateResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *rulesService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { + req := c.c.NewRequest(c.name, "Rules.Delete", in) + out := new(DeleteResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *rulesService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { + req := c.c.NewRequest(c.name, "Rules.List", in) + out := new(ListResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Rules service + +type RulesHandler interface { + Create(context.Context, *CreateRequest, *CreateResponse) error + Delete(context.Context, *DeleteRequest, *DeleteResponse) error + List(context.Context, *ListRequest, *ListResponse) error +} + +func RegisterRulesHandler(s server.Server, hdlr RulesHandler, opts ...server.HandlerOption) error { + type rules interface { + Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error + Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error + List(ctx context.Context, in *ListRequest, out *ListResponse) error + } + type Rules struct { + rules + } + h := &rulesHandler{hdlr} + return s.Handle(s.NewHandler(&Rules{h}, opts...)) +} + +type rulesHandler struct { + RulesHandler +} + +func (h *rulesHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { + return h.RulesHandler.Create(ctx, in, out) +} + +func (h *rulesHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { + return h.RulesHandler.Delete(ctx, in, out) +} + +func (h *rulesHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { + return h.RulesHandler.List(ctx, in, out) +} diff --git a/auth/service/proto/rules/rules.proto b/auth/service/proto/rules/rules.proto new file mode 100644 index 00000000..d4937b51 --- /dev/null +++ b/auth/service/proto/rules/rules.proto @@ -0,0 +1,47 @@ +syntax = "proto3"; + +package go.micro.auth; + +import "github.com/micro/go-micro/auth/service/proto/auth/auth.proto"; + +service Rules { + rpc Create(CreateRequest) returns (CreateResponse) {}; + rpc Delete(DeleteRequest) returns (DeleteResponse) {}; + rpc List(ListRequest) returns (ListResponse) {}; +} + +enum Access { + UNKNOWN = 0; + GRANTED = 1; + DENIED = 2; +} + +message Rule { + string id = 1; + string role = 2; + Resource resource = 3; + Access access = 4; +} + +message CreateRequest { + string role = 1; + Resource resource = 2; + Access access = 3; +} + +message CreateResponse {} + +message DeleteRequest { + string role = 1; + Resource resource = 2; + Access access = 3; +} + +message DeleteResponse {} + +message ListRequest { +} + +message ListResponse { + repeated Rule rules = 1; +} diff --git a/auth/service/service.go b/auth/service/service.go index 190551f9..d3d8d388 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -8,7 +8,8 @@ import ( "time" "github.com/micro/go-micro/v2/auth" - pb "github.com/micro/go-micro/v2/auth/service/proto" + authPb "github.com/micro/go-micro/v2/auth/service/proto/auth" + rulePb "github.com/micro/go-micro/v2/auth/service/proto/rules" "github.com/micro/go-micro/v2/auth/token" "github.com/micro/go-micro/v2/auth/token/jwt" "github.com/micro/go-micro/v2/client" @@ -26,10 +27,11 @@ func NewAuth(opts ...auth.Option) auth.Auth { // svc is the service implementation of the Auth interface type svc struct { options auth.Options - auth pb.AuthService + auth authPb.AuthService + rule rulePb.RulesService jwt token.Provider - rules []*pb.Rule + rules []*rulePb.Rule sync.Mutex } @@ -43,7 +45,8 @@ func (s *svc) Init(opts ...auth.Option) { } dc := client.DefaultClient - s.auth = pb.NewAuthService("go.micro.auth", dc) + s.auth = authPb.NewAuthService("go.micro.auth", dc) + s.rule = rulePb.NewRulesService("go.micro.auth", dc) // if we have a JWT public key passed as an option, // we can decode tokens with the type "JWT" locally @@ -78,7 +81,7 @@ func (s *svc) Options() auth.Options { func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { options := auth.NewGenerateOptions(opts...) - rsp, err := s.auth.Generate(context.TODO(), &pb.GenerateRequest{ + rsp, err := s.auth.Generate(context.TODO(), &authPb.GenerateRequest{ Id: id, Roles: options.Roles, Metadata: options.Metadata, @@ -93,9 +96,10 @@ func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e // Grant access to a resource func (s *svc) Grant(role string, res *auth.Resource) error { - _, err := s.auth.Grant(context.TODO(), &pb.GrantRequest{ - Role: role, - Resource: &pb.Resource{ + _, err := s.rule.Create(context.TODO(), &rulePb.CreateRequest{ + Role: role, + Access: rulePb.Access_GRANTED, + Resource: &authPb.Resource{ Type: res.Type, Name: res.Name, Endpoint: res.Endpoint, @@ -106,9 +110,10 @@ func (s *svc) Grant(role string, res *auth.Resource) error { // Revoke access to a resource func (s *svc) Revoke(role string, res *auth.Resource) error { - _, err := s.auth.Revoke(context.TODO(), &pb.RevokeRequest{ - Role: role, - Resource: &pb.Resource{ + _, err := s.rule.Delete(context.TODO(), &rulePb.DeleteRequest{ + Role: role, + Access: rulePb.Access_GRANTED, + Resource: &authPb.Resource{ Type: res.Type, Name: res.Name, Endpoint: res.Endpoint, @@ -120,10 +125,11 @@ func (s *svc) Revoke(role string, res *auth.Resource) error { // Verify an account has access to a resource func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { queries := [][]string{ - {res.Type, "*"}, // check for wildcard resource type, e.g. service.* - {res.Type, res.Name, "*"}, // check for wildcard name, e.g. service.foo* - {res.Type, res.Name, res.Endpoint, "*"}, // check for wildcard endpoints, e.g. service.foo.ListFoo:* - {res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin + {res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin (role is checked in accessForRule) + {res.Type, res.Name, res.Endpoint, "*"}, // check for wildcard role, e.g. service.foo.ListFoo:* + {res.Type, res.Name, "*"}, // check for wildcard endpoint, e.g. service.foo* + {res.Type, "*"}, // check for wildcard name, e.g. service.* + {"*"}, // check for wildcard type, e.g. * } // endpoint is a url which can have wildcard excludes, e.g. @@ -137,12 +143,18 @@ func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { for _, q := range queries { for _, rule := range s.listRules(q...) { - if isValidRule(rule, acc, res) { - return nil + switch accessForRule(rule, acc, res) { + case rulePb.Access_UNKNOWN: + continue // rule did not specify access, check the next rule + case rulePb.Access_GRANTED: + return nil // rule grants the account access to the resource + case rulePb.Access_DENIED: + return auth.ErrForbidden // reule denies access to the resource } } } + // no rules were found for the resource, default to denying access return auth.ErrForbidden } @@ -162,7 +174,7 @@ func (s *svc) Inspect(token string) (*auth.Account, error) { } } - rsp, err := s.auth.Inspect(context.TODO(), &pb.InspectRequest{ + rsp, err := s.auth.Inspect(context.TODO(), &authPb.InspectRequest{ Token: token, }) if err != nil { @@ -176,7 +188,7 @@ func (s *svc) Inspect(token string) (*auth.Account, error) { func (s *svc) Refresh(secret string, opts ...auth.RefreshOption) (*auth.Token, error) { options := auth.NewRefreshOptions(opts...) - rsp, err := s.auth.Refresh(context.Background(), &pb.RefreshRequest{ + rsp, err := s.auth.Refresh(context.Background(), &authPb.RefreshRequest{ Secret: secret, TokenExpiry: int64(options.TokenExpiry.Seconds()), }) @@ -189,36 +201,36 @@ func (s *svc) Refresh(secret string, opts ...auth.RefreshOption) (*auth.Token, e var ruleJoinKey = ":" -// isValidRule returns a bool, indicating if a rule permits access to a +// accessForRule returns a rule status, indicating if a rule permits access to a // resource for a given account -func isValidRule(rule *pb.Rule, acc *auth.Account, res *auth.Resource) bool { +func accessForRule(rule *rulePb.Rule, acc *auth.Account, res *auth.Resource) rulePb.Access { if rule.Role == "*" { - return true + return rule.Access } for _, role := range acc.Roles { if rule.Role == role { - return true + return rule.Access } // allow user.anything if role is user.* if strings.HasSuffix(rule.Role, ".*") && strings.HasPrefix(rule.Role, role+".") { - return true + return rule.Access } } - return false + return rulePb.Access_DENIED } // listRules gets all the rules from the store which have an id // prefix matching the filters -func (s *svc) listRules(filters ...string) []*pb.Rule { +func (s *svc) listRules(filters ...string) []*rulePb.Rule { s.Lock() defer s.Unlock() prefix := strings.Join(filters, ruleJoinKey) - var rules []*pb.Rule + var rules []*rulePb.Rule for _, r := range s.rules { if strings.HasPrefix(r.Id, prefix) { rules = append(rules, r) @@ -230,7 +242,7 @@ func (s *svc) listRules(filters ...string) []*pb.Rule { // loadRules retrieves the rules from the auth service func (s *svc) loadRules() { - rsp, err := s.auth.ListRules(context.TODO(), &pb.ListRulesRequest{}, client.WithRetries(3)) + rsp, err := s.rule.List(context.TODO(), &rulePb.ListRequest{}) s.Lock() defer s.Unlock() @@ -242,7 +254,7 @@ func (s *svc) loadRules() { s.rules = rsp.Rules } -func serializeToken(t *pb.Token) *auth.Token { +func serializeToken(t *authPb.Token) *auth.Token { return &auth.Token{ Token: t.Token, Type: t.Type, @@ -254,7 +266,7 @@ func serializeToken(t *pb.Token) *auth.Token { } } -func serializeAccount(a *pb.Account) *auth.Account { +func serializeAccount(a *authPb.Account) *auth.Account { var secret *auth.Token if a.Secret != nil { secret = serializeToken(a.Secret) diff --git a/auth/token/basic/basic.go b/auth/token/basic/basic.go index edf5d2fb..87469127 100644 --- a/auth/token/basic/basic.go +++ b/auth/token/basic/basic.go @@ -2,6 +2,7 @@ package basic import ( "encoding/json" + "fmt" "time" "github.com/google/uuid" @@ -15,6 +16,11 @@ type Basic struct { store store.Store } +var ( + // StorePrefix to isolate tokens + StorePrefix = "tokens/" +) + // NewTokenProvider returns an initialized basic provider func NewTokenProvider(opts ...token.Option) token.Provider { options := token.NewOptions(opts...) @@ -51,7 +57,7 @@ func (b *Basic) Generate(subject string, opts ...token.GenerateOption) (*auth.To // write to the store err = b.store.Write(&store.Record{ - Key: token.Token, + Key: fmt.Sprintf("%v%v", StorePrefix, token.Token), Value: bytes, Expiry: options.Expiry, }) @@ -66,7 +72,7 @@ func (b *Basic) Generate(subject string, opts ...token.GenerateOption) (*auth.To // Inspect a token func (b *Basic) Inspect(t string) (*auth.Token, error) { // lookup the token in the store - recs, err := b.store.Read(t) + recs, err := b.store.Read(StorePrefix + t) if err == store.ErrNotFound { return nil, token.ErrInvalidToken } else if err != nil { From 42b6bf5bbf1f1948cdbca7b0029883745df4e7d5 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 26 Mar 2020 15:52:48 +0000 Subject: [PATCH 438/788] Fix auth multi-rule edgecase (#1418) Co-authored-by: Ben Toogood --- auth/service/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/service/service.go b/auth/service/service.go index d3d8d388..e6a4447b 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -219,7 +219,7 @@ func accessForRule(rule *rulePb.Rule, acc *auth.Account, res *auth.Resource) rul } } - return rulePb.Access_DENIED + return rulePb.Access_UNKNOWN } // listRules gets all the rules from the store which have an id From 00e7804f965a4ad51413b11b6400a7ed4770f296 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 26 Mar 2020 16:30:31 +0000 Subject: [PATCH 439/788] Auth - Add debugging to loading rules (#1420) * Fix auth multi-rule edgecase * Add logging to auth rules Co-authored-by: Ben Toogood --- auth/service/service.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/auth/service/service.go b/auth/service/service.go index e6a4447b..7e9e77c9 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -125,11 +125,10 @@ func (s *svc) Revoke(role string, res *auth.Resource) error { // Verify an account has access to a resource func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { queries := [][]string{ - {res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin (role is checked in accessForRule) - {res.Type, res.Name, res.Endpoint, "*"}, // check for wildcard role, e.g. service.foo.ListFoo:* - {res.Type, res.Name, "*"}, // check for wildcard endpoint, e.g. service.foo* - {res.Type, "*"}, // check for wildcard name, e.g. service.* - {"*"}, // check for wildcard type, e.g. * + {res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin (role is checked in accessForRule) + {res.Type, res.Name, "*"}, // check for wildcard endpoint, e.g. service.foo* + {res.Type, "*"}, // check for wildcard name, e.g. service.* + {"*"}, // check for wildcard type, e.g. * } // endpoint is a url which can have wildcard excludes, e.g. @@ -242,6 +241,7 @@ func (s *svc) listRules(filters ...string) []*rulePb.Rule { // loadRules retrieves the rules from the auth service func (s *svc) loadRules() { + log.Infof("Loading rules from auth service\n") rsp, err := s.rule.List(context.TODO(), &rulePb.ListRequest{}) s.Lock() defer s.Unlock() @@ -251,6 +251,7 @@ func (s *svc) loadRules() { return } + log.Infof("Loaded %v rules from the auth service\n", len(rsp.Rules)) s.rules = rsp.Rules } From 62f9a054a47b20148df60f1bb01b7fd578a7d40c Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 26 Mar 2020 16:57:31 +0000 Subject: [PATCH 440/788] 100mb (#1421) --- api/handler/options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/handler/options.go b/api/handler/options.go index 6feeec24..43401167 100644 --- a/api/handler/options.go +++ b/api/handler/options.go @@ -6,7 +6,7 @@ import ( ) var ( - DefaultMaxRecvSize int64 = 1024 * 1024 * 10 // 10Mb + DefaultMaxRecvSize int64 = 1024 * 1024 * 100 // 10Mb ) type Options struct { From c905df3be68a459c71c44acb54cce6a15b2b0f0d Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 26 Mar 2020 17:35:28 +0000 Subject: [PATCH 441/788] Log auth verify requests (#1422) * More auth debugging * More auth debugging Co-authored-by: Ben Toogood --- auth/service/service.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/auth/service/service.go b/auth/service/service.go index 7e9e77c9..af121998 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -124,6 +124,8 @@ func (s *svc) Revoke(role string, res *auth.Resource) error { // Verify an account has access to a resource func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { + log.Infof("%v requesting access to %v:%v:%v", acc.ID, res.Type, res.Name, res.Endpoint) + queries := [][]string{ {res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin (role is checked in accessForRule) {res.Type, res.Name, "*"}, // check for wildcard endpoint, e.g. service.foo* @@ -146,14 +148,17 @@ func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { case rulePb.Access_UNKNOWN: continue // rule did not specify access, check the next rule case rulePb.Access_GRANTED: + log.Infof("%v granted access to %v:%v:%v by rule %v", acc.ID, res.Type, res.Name, res.Endpoint, rule.Id) return nil // rule grants the account access to the resource case rulePb.Access_DENIED: - return auth.ErrForbidden // reule denies access to the resource + log.Infof("%v denied access to %v:%v:%v by rule %v", acc.ID, res.Type, res.Name, res.Endpoint, rule.Id) + return auth.ErrForbidden // rule denies access to the resource } } } // no rules were found for the resource, default to denying access + log.Infof("%v denied access to %v:%v:%v by lack of rule", acc.ID, res.Type, res.Name, res.Endpoint) return auth.ErrForbidden } @@ -241,7 +246,7 @@ func (s *svc) listRules(filters ...string) []*rulePb.Rule { // loadRules retrieves the rules from the auth service func (s *svc) loadRules() { - log.Infof("Loading rules from auth service\n") + log.Infof("Loading rules from auth service") rsp, err := s.rule.List(context.TODO(), &rulePb.ListRequest{}) s.Lock() defer s.Unlock() @@ -251,7 +256,7 @@ func (s *svc) loadRules() { return } - log.Infof("Loaded %v rules from the auth service\n", len(rsp.Rules)) + log.Infof("Loaded %v rules from the auth service", len(rsp.Rules)) s.rules = rsp.Rules } From 4648fd0d097c47c8a4dd5949a6e22968f6d600b3 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 26 Mar 2020 17:55:35 +0000 Subject: [PATCH 442/788] Auth debugging (#1423) * More auth debugging * More auth debugging * Increase auth debugging Co-authored-by: Ben Toogood --- auth/service/service.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/auth/service/service.go b/auth/service/service.go index af121998..8cbf7d47 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -144,6 +144,8 @@ func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { for _, q := range queries { for _, rule := range s.listRules(q...) { + log.Infof("Checking rule: %v for resource: %v:%v:%v", rule.Id, res.Type, res.Name, res.Endpoint) + switch accessForRule(rule, acc, res) { case rulePb.Access_UNKNOWN: continue // rule did not specify access, check the next rule @@ -158,7 +160,7 @@ func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { } // no rules were found for the resource, default to denying access - log.Infof("%v denied access to %v:%v:%v by lack of rule", acc.ID, res.Type, res.Name, res.Endpoint) + log.Infof("%v denied access to %v:%v:%v by lack of rule (%v rules found)", acc.ID, res.Type, res.Name, res.Endpoint, len(s.rules)) return auth.ErrForbidden } From 329bd09f93ecbcdd10a973d8017a7d162cce6ecc Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 26 Mar 2020 18:09:51 +0000 Subject: [PATCH 443/788] Fix Auth Init bug (#1424) Co-authored-by: Ben Toogood --- config/cmd/cmd.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 49c8a359..287c085e 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -692,10 +692,7 @@ func (c *cmd) Before(ctx *cli.Context) error { authOpts = append(authOpts, auth.Provider(p(provOpts...))) } - - if len(authOpts) > 0 { - (*c.opts.Auth).Init(authOpts...) - } + (*c.opts.Auth).Init(authOpts...) if ctx.String("config") == "service" { opt := config.WithSource(configSrv.NewSource()) From e204f3e2e802ac34161643e3606128740b44e436 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 26 Mar 2020 18:50:00 +0000 Subject: [PATCH 444/788] Add metadata Get method (#1425) --- metadata/metadata.go | 12 ++++++++++++ proxy/mucp/mucp.go | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/metadata/metadata.go b/metadata/metadata.go index c41aa284..63402fa9 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -13,6 +13,18 @@ type metaKey struct{} // from Transport headers. type Metadata map[string]string +func (md Metadata) Get(key string) (string, bool) { + // attempt to get as is + val, ok := md[key] + if ok { + return val, ok + } + + // attempt to get lower case + val, ok = md[strings.Title(key)] + return val, ok +} + // Copy makes a copy of the metadata func Copy(md Metadata) Metadata { cmd := make(Metadata) diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index 4b8a1926..da901c13 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -120,7 +120,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route // filter the routes based on our headers for _, route := range routes { // process only routes for this id - if id := md["Micro-Router"]; len(id) > 0 { + if id, ok := md.Get("Micro-Router"); ok && len(id) > 0 { if route.Router != id { // skip routes that don't mwatch continue @@ -128,7 +128,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route } // only process routes with this network - if net := md["Micro-Network"]; len(net) > 0 { + if net, ok := md.Get("Micro-Network"); ok && len(net) > 0 { if route.Network != net { // skip routes that don't mwatch continue @@ -136,7 +136,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route } // process only this gateway - if gw := md["Micro-Gateway"]; len(gw) > 0 { + if gw, ok := md.Get("Micro-Gateway"); ok && len(gw) > 0 { // if the gateway matches our address // special case, take the routes with no gateway // TODO: should we strip the gateway from the context? From 1a53307a781ab48ef51352b474255add179fe371 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 26 Mar 2020 19:00:24 +0000 Subject: [PATCH 445/788] Remove debug auth logs (#1426) Co-authored-by: Ben Toogood --- auth/service/service.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/auth/service/service.go b/auth/service/service.go index 8cbf7d47..32da7571 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -124,8 +124,6 @@ func (s *svc) Revoke(role string, res *auth.Resource) error { // Verify an account has access to a resource func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { - log.Infof("%v requesting access to %v:%v:%v", acc.ID, res.Type, res.Name, res.Endpoint) - queries := [][]string{ {res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin (role is checked in accessForRule) {res.Type, res.Name, "*"}, // check for wildcard endpoint, e.g. service.foo* @@ -144,8 +142,6 @@ func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { for _, q := range queries { for _, rule := range s.listRules(q...) { - log.Infof("Checking rule: %v for resource: %v:%v:%v", rule.Id, res.Type, res.Name, res.Endpoint) - switch accessForRule(rule, acc, res) { case rulePb.Access_UNKNOWN: continue // rule did not specify access, check the next rule @@ -248,7 +244,6 @@ func (s *svc) listRules(filters ...string) []*rulePb.Rule { // loadRules retrieves the rules from the auth service func (s *svc) loadRules() { - log.Infof("Loading rules from auth service") rsp, err := s.rule.List(context.TODO(), &rulePb.ListRequest{}) s.Lock() defer s.Unlock() @@ -258,7 +253,6 @@ func (s *svc) loadRules() { return } - log.Infof("Loaded %v rules from the auth service", len(rsp.Rules)) s.rules = rsp.Rules } From b38da6ced02bc8830ff609e4228d108ba9c85c45 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 27 Mar 2020 10:59:31 +0300 Subject: [PATCH 446/788] api/handler/rpc: process all methods and merge url params to json body (#1427) * api/handler/rpc: process all methods and merge url params to json body Signed-off-by: Vasiliy Tolstov * add merge json test Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 22 +++++++++++++++++++++- api/handler/rpc/rpc_test.go | 17 +++++++++++++++++ go.mod | 1 + go.sum | 2 ++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 3059207d..13c42070 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -8,6 +8,7 @@ import ( "strconv" "strings" + jsonpatch "github.com/evanphx/json-patch/v5" "github.com/joncalhoun/qson" "github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/api/handler" @@ -273,13 +274,32 @@ func requestPayload(r *http.Request) ([]byte, error) { if len(r.URL.RawQuery) > 0 { return qson.ToJSON(r.URL.RawQuery) } - case "PATCH", "POST": + case "PATCH", "POST", "PUT", "DELETE": + urlParams := []byte("{}") + bodyParams := []byte("{}") + var err error + if len(r.URL.RawQuery) > 0 { + if urlParams, err = qson.ToJSON(r.URL.RawQuery); err != nil { + return nil, err + } + } + buf := bufferPool.Get() defer bufferPool.Put(buf) if _, err := buf.ReadFrom(r.Body); err != nil { return nil, err } + if b := buf.Bytes(); len(b) > 0 { + bodyParams = b + } + + if out, err := jsonpatch.MergeMergePatches(urlParams, bodyParams); err == nil { + return out, nil + } + + //fallback to previous unknown behaviour return buf.Bytes(), nil + } return []byte{}, nil diff --git a/api/handler/rpc/rpc_test.go b/api/handler/rpc/rpc_test.go index ba943a4d..1b602f84 100644 --- a/api/handler/rpc/rpc_test.go +++ b/api/handler/rpc/rpc_test.go @@ -27,6 +27,23 @@ func TestRequestPayloadFromRequest(t *testing.T) { t.Fatal("Failed to marshal proto to JSON ", err) } + jsonUrlBytes := []byte(`{"key1":"val1","key2":"val2","name":"Test"}`) + + t.Run("extracting a json from a POST request with url params", func(t *testing.T) { + r, err := http.NewRequest("POST", "http://localhost/my/path?key1=val1&key2=val2", bytes.NewReader(jsonBytes)) + if err != nil { + t.Fatalf("Failed to created http.Request: %v", err) + } + + extByte, err := requestPayload(r) + if err != nil { + t.Fatalf("Failed to extract payload from request: %v", err) + } + if string(extByte) != string(jsonUrlBytes) { + t.Fatalf("Expected %v and %v to match", string(extByte), jsonUrlBytes) + } + }) + t.Run("extracting a proto from a POST request", func(t *testing.T) { r, err := http.NewRequest("POST", "http://localhost/my/path", bytes.NewReader(protoBytes)) if err != nil { diff --git a/go.mod b/go.mod index e862c8bb..88d291a8 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 + github.com/evanphx/json-patch/v5 v5.0.0 github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c github.com/fsnotify/fsnotify v1.4.7 github.com/fsouza/go-dockerclient v1.6.0 diff --git a/go.sum b/go.sum index 557728a2..07d12b66 100644 --- a/go.sum +++ b/go.sum @@ -129,6 +129,8 @@ github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/evanphx/json-patch/v5 v5.0.0 h1:dKTrUeykyQwKb/kx7Z+4ukDs6l+4L41HqG1XHnhX7WE= +github.com/evanphx/json-patch/v5 v5.0.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= From 47c7181d412aaf6cde44a5229a7a9ed3f2dd97dd Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Fri, 27 Mar 2020 09:46:17 +0000 Subject: [PATCH 447/788] Default Auth: Add blank secret to account to prevent nil errors (#1429) * Remove debug auth logs * Default auth, return account secret on Inspect Co-authored-by: Ben Toogood --- auth/default.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/auth/default.go b/auth/default.go index 15bb1757..038f22bf 100644 --- a/auth/default.go +++ b/auth/default.go @@ -61,7 +61,10 @@ func (n *noop) Verify(acc *Account, res *Resource) error { // Inspect a token func (n *noop) Inspect(token string) (*Account, error) { - return &Account{ID: uuid.New().String()}, nil + return &Account{ + ID: uuid.New().String(), + Secret: &Token{}, + }, nil } // Refresh an account using a secret From 6723d17b228705406fe0516c08460d58da7dfd36 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Fri, 27 Mar 2020 09:54:29 +0000 Subject: [PATCH 448/788] Default auth, return account secret on Inspect (#1430) Co-authored-by: Ben Toogood --- auth/default.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth/default.go b/auth/default.go index 038f22bf..300bb41c 100644 --- a/auth/default.go +++ b/auth/default.go @@ -41,6 +41,7 @@ func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) { ID: id, Roles: options.Roles, Metadata: options.Metadata, + Secret: &Token{}, }, nil } @@ -62,8 +63,7 @@ func (n *noop) Verify(acc *Account, res *Resource) error { // Inspect a token func (n *noop) Inspect(token string) (*Account, error) { return &Account{ - ID: uuid.New().String(), - Secret: &Token{}, + ID: uuid.New().String(), }, nil } From 011a783a9e30bcf0fd6ac754b728b4690d9a2233 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Fri, 27 Mar 2020 03:15:37 -0700 Subject: [PATCH 449/788] store/cockroach: fix dropped test errors (#1419) Co-authored-by: Asim Aslam --- store/cockroach/cockroach_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/store/cockroach/cockroach_test.go b/store/cockroach/cockroach_test.go index d9a95c1b..304078c8 100644 --- a/store/cockroach/cockroach_test.go +++ b/store/cockroach/cockroach_test.go @@ -108,11 +108,17 @@ func TestSQL(t *testing.T) { sqlStore.Write(&store.Record{Key: "aaaa", Value: []byte("bbb"), Expiry: 5 * time.Second}) sqlStore.Write(&store.Record{Key: "aaaaa", Value: []byte("bbb"), Expiry: 5 * time.Second}) results, err := sqlStore.Read("a", store.ReadPrefix()) + if err != nil { + t.Error(err) + } if len(results) != 3 { t.Fatal("Results should have returned 3 records") } time.Sleep(6 * time.Second) results, err = sqlStore.Read("a", store.ReadPrefix()) + if err != nil { + t.Error(err) + } if len(results) != 0 { t.Fatal("Results should have returned 0 records") } From b60fde0e6418f78358601a14c7765f18c4ec0375 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 27 Mar 2020 11:37:12 +0000 Subject: [PATCH 450/788] Pass through source and metadata in Update and Delete calls to runtime (#1431) --- runtime/service/service.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/runtime/service/service.go b/runtime/service/service.go index 96f3ebbd..5cb30805 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -105,8 +105,10 @@ func (s *svc) Update(svc *runtime.Service) error { // runtime service create request req := &pb.UpdateRequest{ Service: &pb.Service{ - Name: svc.Name, - Version: svc.Version, + Name: svc.Name, + Version: svc.Version, + Source: svc.Source, + Metadata: svc.Metadata, }, } @@ -122,8 +124,10 @@ func (s *svc) Delete(svc *runtime.Service) error { // runtime service create request req := &pb.DeleteRequest{ Service: &pb.Service{ - Name: svc.Name, - Version: svc.Version, + Name: svc.Name, + Version: svc.Version, + Source: svc.Source, + Metadata: svc.Metadata, }, } From 45ee5e9ad18bb993cb6ff7963744e908f4a50e15 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 27 Mar 2020 14:01:47 +0000 Subject: [PATCH 451/788] Move error for api validation to trace level (#1432) * remove error on endpoint validation * trace level --- api/router/registry/registry.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/router/registry/registry.go b/api/router/registry/registry.go index a8e96d41..5b61fca4 100644 --- a/api/router/registry/registry.go +++ b/api/router/registry/registry.go @@ -144,8 +144,8 @@ func (r *registryRouter) store(services []*registry.Service) { // if we got nothing skip if err := api.Validate(end); err != nil { - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Errorf("endpoint validation failed: %v", err) + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("endpoint validation failed: %v", err) } continue } From e4acc63d5f92c6b99ef568694f9fd39983a54665 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 27 Mar 2020 22:33:49 +0300 Subject: [PATCH 452/788] add mdns registry debug (#1434) Signed-off-by: Vasiliy Tolstov --- registry/mdns_registry.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/registry/mdns_registry.go b/registry/mdns_registry.go index 7be88162..9dbca6de 100644 --- a/registry/mdns_registry.go +++ b/registry/mdns_registry.go @@ -156,6 +156,9 @@ func (m *mdnsRegistry) Register(service *Service, opts ...RegisterOption) error } port, _ := strconv.Atoi(pt) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("[mdns] registry create new service with ip: %s for: %s", net.ParseIP(host).String(), host) + } // we got here, new node s, err := mdns.NewMDNSService( node.Id, From 8282e781e46062c98c9cf8feaf1c015d4259d026 Mon Sep 17 00:00:00 2001 From: Socket <30768657+Socketsj@users.noreply.github.com> Date: Sat, 28 Mar 2020 16:48:25 +0800 Subject: [PATCH 453/788] grpc pool should check state (#1435) Co-authored-by: huangshaojie --- client/grpc/grpc_pool.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/client/grpc/grpc_pool.go b/client/grpc/grpc_pool.go index 340aecce..0eec4698 100644 --- a/client/grpc/grpc_pool.go +++ b/client/grpc/grpc_pool.go @@ -5,6 +5,7 @@ import ( "time" "google.golang.org/grpc" + "google.golang.org/grpc/connectivity" ) type pool struct { @@ -77,6 +78,32 @@ func (p *pool) getConn(addr string, opts ...grpc.DialOption) (*poolConn, error) // otherwise we'll create a new conn conn := sp.head.next for conn != nil { + // check conn state + // https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md + switch conn.GetState() { + case connectivity.Connecting: + conn = conn.next + continue + case connectivity.Shutdown: + next := conn.next + if conn.streams == 0 { + removeConn(conn) + sp.idle-- + } + conn = next + continue + case connectivity.TransientFailure: + next := conn.next + if conn.streams == 0 { + removeConn(conn) + conn.ClientConn.Close() + sp.idle-- + } + conn = next + continue + case connectivity.Ready: + case connectivity.Idle: + } // a old conn if now-conn.created > p.ttl { next := conn.next From 3d7d5ce6b4e58be092bb6c09f88c5d598f45410a Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 30 Mar 2020 11:04:59 +0300 Subject: [PATCH 454/788] api: add static router and improve path parser in rpc handler (#1437) * api: add static router and improve path parser in rpc handler Signed-off-by: Vasiliy Tolstov * expose metadata context key to be able to get unmodified map keys Signed-off-by: Vasiliy Tolstov * server/grpc: fix jsonpb codec for protobuf msg Signed-off-by: Vasiliy Tolstov * api/handler/rpc: write 204 status code when rsp is nil Signed-off-by: Vasiliy Tolstov * api/handler/rpc: add check for nil response for non javascript Signed-off-by: Vasiliy Tolstov --- api/api.go | 16 ++ api/grpc_test.go | 132 +++++++++++++ api/handler/rpc/rpc.go | 121 +++++++++--- api/router/registry/registry.go | 8 + api/router/router.go | 4 + api/router/static/static.go | 304 ++++++++++++++++++++++++++++++ api/service/proto/api.pb.go | 149 +++++++++++++++ api/service/proto/api.pb.micro.go | 102 ++++++++++ api/service/proto/api.proto | 18 ++ go.mod | 2 +- metadata/metadata.go | 12 +- server/grpc/codec.go | 6 +- 12 files changed, 839 insertions(+), 35 deletions(-) create mode 100644 api/grpc_test.go create mode 100644 api/router/static/static.go create mode 100644 api/service/proto/api.pb.go create mode 100644 api/service/proto/api.pb.micro.go create mode 100644 api/service/proto/api.proto diff --git a/api/api.go b/api/api.go index f04d67e0..1e81b184 100644 --- a/api/api.go +++ b/api/api.go @@ -9,6 +9,20 @@ import ( "github.com/micro/go-micro/v2/server" ) +type Api interface { + // Register a http handler + Register(*Endpoint) error + // Register a route + Deregister(*Endpoint) error + // Init initialises the command line. + // It also parses further options. + //Init(...Option) error + // Options + //Options() Options + // String + String() string +} + // Endpoint is a mapping between an RPC method and HTTP endpoint type Endpoint struct { // RPC Method e.g. Greeter.Hello @@ -23,6 +37,8 @@ type Endpoint struct { Method []string // HTTP Path e.g /greeter. Expect POSIX regex Path []string + // Stream flag + Stream bool } // Service represents an API service diff --git a/api/grpc_test.go b/api/grpc_test.go new file mode 100644 index 00000000..f40734c3 --- /dev/null +++ b/api/grpc_test.go @@ -0,0 +1,132 @@ +package api_test + +import ( + "context" + "fmt" + "io/ioutil" + "log" + "net/http" + "testing" + "time" + + "github.com/micro/go-micro/v2" + "github.com/micro/go-micro/v2/api" + ahandler "github.com/micro/go-micro/v2/api/handler" + apirpc "github.com/micro/go-micro/v2/api/handler/rpc" + "github.com/micro/go-micro/v2/api/router" + rstatic "github.com/micro/go-micro/v2/api/router/static" + bmemory "github.com/micro/go-micro/v2/broker/memory" + "github.com/micro/go-micro/v2/client" + gcli "github.com/micro/go-micro/v2/client/grpc" + rmemory "github.com/micro/go-micro/v2/registry/memory" + "github.com/micro/go-micro/v2/server" + gsrv "github.com/micro/go-micro/v2/server/grpc" + tgrpc "github.com/micro/go-micro/v2/transport/grpc" + + pb "github.com/micro/go-micro/v2/server/grpc/proto" +) + +// server is used to implement helloworld.GreeterServer. +type testServer struct { + msgCount int +} + +// TestHello implements helloworld.GreeterServer +func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error { + rsp.Msg = "Hello " + req.Name + return nil +} + +func TestApiAndGRPC(t *testing.T) { + r := rmemory.NewRegistry() + b := bmemory.NewBroker() + tr := tgrpc.NewTransport() + s := gsrv.NewServer( + server.Broker(b), + server.Name("foo"), + server.Registry(r), + server.Transport(tr), + ) + c := gcli.NewClient( + client.Registry(r), + client.Broker(b), + client.Transport(tr), + ) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + svc := micro.NewService( + micro.Server(s), + micro.Client(c), + micro.Broker(b), + micro.Registry(r), + micro.Transport(tr), + micro.Context(ctx)) + h := &testServer{} + pb.RegisterTestHandler(s, h) + + go func() { + if err := svc.Run(); err != nil { + t.Fatalf("failed to start: %v", err) + } + }() + time.Sleep(1 * time.Second) + // check registration + services, err := r.GetService("foo") + if err != nil || len(services) == 0 { + t.Fatalf("failed to get service: %v # %d", err, len(services)) + } + + router := rstatic.NewRouter( + router.WithHandler(apirpc.Handler), + router.WithRegistry(svc.Server().Options().Registry), + ) + err = router.Register(&api.Endpoint{ + Name: "foo.Test.Call", + Method: []string{"GET"}, + Path: []string{"/api/v0/test/call/{name}"}, + Handler: "rpc", + }) + if err != nil { + t.Fatal(err) + } + + hrpc := apirpc.NewHandler( + ahandler.WithService(svc), + ahandler.WithRouter(router), + ) + + hsrv := &http.Server{ + Handler: hrpc, + Addr: "127.0.0.1:6543", + WriteTimeout: 15 * time.Second, + ReadTimeout: 15 * time.Second, + IdleTimeout: 20 * time.Second, + MaxHeaderBytes: 1024 * 1024 * 1, // 1Mb + } + + go func() { + log.Println(hsrv.ListenAndServe()) + }() + + time.Sleep(1 * time.Second) + rsp, err := http.Get(fmt.Sprintf("http://%s/api/v0/test/call/TEST", hsrv.Addr)) + if err != nil { + t.Fatalf("Failed to created http.Request: %v", err) + } + defer rsp.Body.Close() + buf, err := ioutil.ReadAll(rsp.Body) + if err != nil { + t.Fatal(err) + } + + jsonMsg := `{"msg":"Hello TEST"}` + if string(buf) != jsonMsg { + t.Fatalf("invalid message received, parsing error %s != %s", buf, jsonMsg) + } + select { + case <-ctx.Done(): + return + } + +} diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 13c42070..c6bd6daf 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -12,7 +12,7 @@ import ( "github.com/joncalhoun/qson" "github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/api/handler" - proto "github.com/micro/go-micro/v2/api/internal/proto" + "github.com/micro/go-micro/v2/api/internal/proto" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" "github.com/micro/go-micro/v2/codec" @@ -20,6 +20,7 @@ import ( "github.com/micro/go-micro/v2/codec/protorpc" "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/ctx" "github.com/oxtoacart/bpool" @@ -128,7 +129,6 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { so := selector.WithStrategy(strategy(service.Services)) // walk the standard call path - // get payload br, err := requestPayload(r) if err != nil { @@ -164,7 +164,12 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // marshall response - rsp, _ = response.Marshal() + rsp, err = response.Marshal() + if err != nil { + writeError(w, r, err) + return + } + default: // if json codec is not present set to json if !hasCodec(ct, jsonCodecs) { @@ -195,7 +200,11 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // marshall response - rsp, _ = response.MarshalJSON() + rsp, err = response.MarshalJSON() + if err != nil { + writeError(w, r, err) + return + } } // write the response @@ -219,8 +228,11 @@ func hasCodec(ct string, codecs []string) bool { // If the request is a GET the query string parameters are extracted and marshaled to JSON and the raw bytes are returned. // If the request method is a POST the request body is read and returned func requestPayload(r *http.Request) ([]byte, error) { + var err error + // we have to decode json-rpc and proto-rpc because we suck // well actually because there's no proxy codec right now + ct := r.Header.Get("Content-Type") switch { case strings.Contains(ct, "application/json-rpc"): @@ -229,11 +241,11 @@ func requestPayload(r *http.Request) ([]byte, error) { Header: make(map[string]string), } c := jsonrpc.NewCodec(&buffer{r.Body}) - if err := c.ReadHeader(&msg, codec.Request); err != nil { + if err = c.ReadHeader(&msg, codec.Request); err != nil { return nil, err } var raw json.RawMessage - if err := c.ReadBody(&raw); err != nil { + if err = c.ReadBody(&raw); err != nil { return nil, err } return ([]byte)(raw), nil @@ -243,15 +255,14 @@ func requestPayload(r *http.Request) ([]byte, error) { Header: make(map[string]string), } c := protorpc.NewCodec(&buffer{r.Body}) - if err := c.ReadHeader(&msg, codec.Request); err != nil { + if err = c.ReadHeader(&msg, codec.Request); err != nil { return nil, err } var raw proto.Message - if err := c.ReadBody(&raw); err != nil { + if err = c.ReadBody(&raw); err != nil { return nil, err } - b, err := raw.Marshal() - return b, err + return raw.Marshal() case strings.Contains(ct, "application/www-x-form-urlencoded"): r.ParseForm() @@ -262,43 +273,94 @@ func requestPayload(r *http.Request) ([]byte, error) { } // marshal - b, err := json.Marshal(vals) - return b, err + return json.Marshal(vals) // TODO: application/grpc } // otherwise as per usual + ctx := r.Context() + // dont user meadata.FromContext as it mangles names + md, ok := ctx.Value(metadata.MetadataKey{}).(metadata.Metadata) + if !ok { + md = make(map[string]string) + } + // allocate maximum + matches := make(map[string]string, len(md)) + for k, v := range md { + if strings.HasPrefix(k, "x-api-field-") { + matches[strings.TrimPrefix(k, "x-api-field-")] = v + } + delete(md, k) + } + + // restore context without fields + ctx = metadata.NewContext(ctx, md) + *r = *r.WithContext(ctx) + req := make(map[string]interface{}, len(md)) + for k, v := range matches { + ps := strings.Split(k, ".") + if len(ps) == 1 { + req[k] = v + continue + } + + em := make(map[string]interface{}) + em[ps[len(ps)-1]] = v + for i := len(ps) - 2; i > 0; i-- { + nm := make(map[string]interface{}) + nm[ps[i]] = em + em = nm + } + req[ps[0]] = em + } + pathbuf := []byte("{}") + if len(req) > 0 { + pathbuf, err = json.Marshal(req) + if err != nil { + return nil, err + } + } + urlbuf := []byte("{}") + if len(r.URL.RawQuery) > 0 { + urlbuf, err = qson.ToJSON(r.URL.RawQuery) + if err != nil { + return nil, err + } + } + + out, err := jsonpatch.MergeMergePatches(urlbuf, pathbuf) + if err != nil { + return nil, err + } switch r.Method { case "GET": - if len(r.URL.RawQuery) > 0 { - return qson.ToJSON(r.URL.RawQuery) + // empty response + if strings.Contains(ct, "application/json") && string(out) == "{}" { + return out, nil + } else if string(out) == "{}" && !strings.Contains(ct, "application/json") { + return []byte{}, nil } + return out, nil case "PATCH", "POST", "PUT", "DELETE": - urlParams := []byte("{}") - bodyParams := []byte("{}") - var err error - if len(r.URL.RawQuery) > 0 { - if urlParams, err = qson.ToJSON(r.URL.RawQuery); err != nil { - return nil, err - } - } - + bodybuf := []byte("{}") buf := bufferPool.Get() defer bufferPool.Put(buf) if _, err := buf.ReadFrom(r.Body); err != nil { return nil, err } if b := buf.Bytes(); len(b) > 0 { - bodyParams = b + bodybuf = b + } else { + return []byte{}, nil } - if out, err := jsonpatch.MergeMergePatches(urlParams, bodyParams); err == nil { + if out, err = jsonpatch.MergeMergePatches(out, bodybuf); err == nil { return out, nil } //fallback to previous unknown behaviour - return buf.Bytes(), nil + return bodybuf, nil } @@ -332,7 +394,7 @@ func writeError(w http.ResponseWriter, r *http.Request, err error) { } _, werr := w.Write([]byte(ce.Error())) - if err != nil { + if werr != nil { if logger.V(logger.ErrorLevel, logger.DefaultLogger) { logger.Error(werr) } @@ -351,6 +413,11 @@ func writeResponse(w http.ResponseWriter, r *http.Request, rsp []byte) { w.Header().Set("grpc-message", "") } + // write 204 status if rsp is nil + if len(rsp) == 0 { + w.WriteHeader(http.StatusNoContent) + } + // write response _, err := w.Write(rsp) if err != nil { diff --git a/api/router/registry/registry.go b/api/router/registry/registry.go index 5b61fca4..375aa7d0 100644 --- a/api/router/registry/registry.go +++ b/api/router/registry/registry.go @@ -250,6 +250,14 @@ func (r *registryRouter) Close() error { return nil } +func (r *registryRouter) Register(ep *api.Endpoint) error { + return nil +} + +func (r *registryRouter) Deregister(ep *api.Endpoint) error { + return nil +} + func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) { if r.isClosed() { return nil, errors.New("router closed") diff --git a/api/router/router.go b/api/router/router.go index 7a2dc24a..18311804 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -15,6 +15,10 @@ type Router interface { Close() error // Endpoint returns an api.Service endpoint or an error if it does not exist Endpoint(r *http.Request) (*api.Service, error) + // Register endpoint in router + Register(ep *api.Endpoint) error + // Deregister endpoint from router + Deregister(ep *api.Endpoint) error // Route returns an api.Service route Route(r *http.Request) (*api.Service, error) } diff --git a/api/router/static/static.go b/api/router/static/static.go new file mode 100644 index 00000000..2f8a0962 --- /dev/null +++ b/api/router/static/static.go @@ -0,0 +1,304 @@ +package static + +import ( + "context" + "errors" + "fmt" + "net/http" + "regexp" + "strings" + "sync" + + "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/micro/go-micro/v2/api" + "github.com/micro/go-micro/v2/api/router" + "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/metadata" +) + +type endpoint struct { + apiep *api.Endpoint + hostregs []*regexp.Regexp + pathregs []runtime.Pattern +} + +// router is the default router +type staticRouter struct { + exit chan bool + opts router.Options + sync.RWMutex + eps map[string]*endpoint +} + +func (r *staticRouter) isClosed() bool { + select { + case <-r.exit: + return true + default: + return false + } +} + +/* +// watch for endpoint changes +func (r *staticRouter) watch() { + var attempts int + + for { + if r.isClosed() { + return + } + + // watch for changes + w, err := r.opts.Registry.Watch() + if err != nil { + attempts++ + log.Println("Error watching endpoints", err) + time.Sleep(time.Duration(attempts) * time.Second) + continue + } + + ch := make(chan bool) + + go func() { + select { + case <-ch: + w.Stop() + case <-r.exit: + w.Stop() + } + }() + + // reset if we get here + attempts = 0 + + for { + // process next event + res, err := w.Next() + if err != nil { + log.Println("Error getting next endpoint", err) + close(ch) + break + } + r.process(res) + } + } +} +*/ + +func (r *staticRouter) Register(ep *api.Endpoint) error { + if err := api.Validate(ep); err != nil { + return err + } + + var pathregs []runtime.Pattern + var hostregs []*regexp.Regexp + + for _, h := range ep.Host { + if h == "" || h == "*" { + continue + } + hostreg, err := regexp.CompilePOSIX(h) + if err != nil { + return err + } + hostregs = append(hostregs, hostreg) + } + + for _, p := range ep.Path { + rule, err := httprule.Parse(p) + if err != nil { + return err + } + tpl := rule.Compile() + pathreg, err := runtime.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "") + if err != nil { + return err + } + pathregs = append(pathregs, pathreg) + } + + r.Lock() + r.eps[ep.Name] = &endpoint{apiep: ep, pathregs: pathregs, hostregs: hostregs} + r.Unlock() + return nil +} + +func (r *staticRouter) Deregister(ep *api.Endpoint) error { + if err := api.Validate(ep); err != nil { + return err + } + r.Lock() + delete(r.eps, ep.Name) + r.Unlock() + return nil +} + +func (r *staticRouter) Options() router.Options { + return r.opts +} + +func (r *staticRouter) Close() error { + select { + case <-r.exit: + return nil + default: + close(r.exit) + } + return nil +} + +func (r *staticRouter) Endpoint(req *http.Request) (*api.Service, error) { + ep, err := r.endpoint(req) + if err != nil { + return nil, err + } + + epf := strings.Split(ep.apiep.Name, ".") + services, err := r.opts.Registry.GetService(epf[0]) + if err != nil { + return nil, err + } + + // hack for stream endpoint + if ep.apiep.Stream { + for _, svc := range services { + for _, e := range svc.Endpoints { + e.Name = strings.Join(epf[1:], ".") + e.Metadata = make(map[string]string) + e.Metadata["stream"] = "true" + } + } + } + + svc := &api.Service{ + Name: epf[0], + Endpoint: &api.Endpoint{ + Name: strings.Join(epf[1:], "."), + Handler: "rpc", + Host: ep.apiep.Host, + Method: ep.apiep.Method, + Path: ep.apiep.Path, + }, + Services: services, + } + + return svc, nil +} + +func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { + if r.isClosed() { + return nil, errors.New("router closed") + } + + r.RLock() + defer r.RUnlock() + + var idx int + if len(req.URL.Path) > 0 && req.URL.Path != "/" { + idx = 1 + } + path := strings.Split(req.URL.Path[idx:], "/") + // use the first match + // TODO: weighted matching + + for _, ep := range r.eps { + var mMatch, hMatch, pMatch bool + + // 1. try method + methodLoop: + for _, m := range ep.apiep.Method { + if m == req.Method { + mMatch = true + break methodLoop + } + } + if !mMatch { + continue + } + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api method match %s", req.Method) + } + + // 2. try host + if len(ep.apiep.Host) == 0 { + hMatch = true + } else { + hostLoop: + for idx, h := range ep.apiep.Host { + if h == "" || h == "*" { + hMatch = true + break hostLoop + } else { + if ep.hostregs[idx].MatchString(req.URL.Host) { + hMatch = true + break hostLoop + } + } + } + } + if !hMatch { + continue + } + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api host match %s", req.URL.Host) + } + + // 3. try path + pathLoop: + for _, pathreg := range ep.pathregs { + matches, err := pathreg.Match(path, "") + if err != nil { + // TODO: log error + continue + } + pMatch = true + ctx := req.Context() + md, ok := metadata.FromContext(ctx) + if !ok { + md = make(metadata.Metadata) + } + for k, v := range matches { + md[fmt.Sprintf("x-api-field-%s", k)] = v + } + *req = *req.WithContext(context.WithValue(ctx, metadata.MetadataKey{}, md)) + break pathLoop + } + if !pMatch { + continue + } + // TODO: Percentage traffic + + // we got here, so its a match + return ep, nil + } + // no match + return nil, fmt.Errorf("endpoint not found for %v", req) +} + +func (r *staticRouter) Route(req *http.Request) (*api.Service, error) { + if r.isClosed() { + return nil, errors.New("router closed") + } + + // try get an endpoint + ep, err := r.Endpoint(req) + if err != nil { + return nil, err + } + + return ep, nil +} + +func NewRouter(opts ...router.Option) *staticRouter { + options := router.NewOptions(opts...) + r := &staticRouter{ + exit: make(chan bool), + opts: options, + eps: make(map[string]*endpoint), + } + //go r.watch() + //go r.refresh() + return r +} diff --git a/api/service/proto/api.pb.go b/api/service/proto/api.pb.go new file mode 100644 index 00000000..b643fd79 --- /dev/null +++ b/api/service/proto/api.pb.go @@ -0,0 +1,149 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: api.proto + +package go_micro_api + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type Endpoint struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Host []string `protobuf:"bytes,2,rep,name=host,proto3" json:"host,omitempty"` + Path []string `protobuf:"bytes,3,rep,name=path,proto3" json:"path,omitempty"` + Method []string `protobuf:"bytes,4,rep,name=method,proto3" json:"method,omitempty"` + Stream bool `protobuf:"varint,5,opt,name=stream,proto3" json:"stream,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Endpoint) Reset() { *m = Endpoint{} } +func (m *Endpoint) String() string { return proto.CompactTextString(m) } +func (*Endpoint) ProtoMessage() {} +func (*Endpoint) Descriptor() ([]byte, []int) { + return fileDescriptor_00212fb1f9d3bf1c, []int{0} +} + +func (m *Endpoint) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Endpoint.Unmarshal(m, b) +} +func (m *Endpoint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Endpoint.Marshal(b, m, deterministic) +} +func (m *Endpoint) XXX_Merge(src proto.Message) { + xxx_messageInfo_Endpoint.Merge(m, src) +} +func (m *Endpoint) XXX_Size() int { + return xxx_messageInfo_Endpoint.Size(m) +} +func (m *Endpoint) XXX_DiscardUnknown() { + xxx_messageInfo_Endpoint.DiscardUnknown(m) +} + +var xxx_messageInfo_Endpoint proto.InternalMessageInfo + +func (m *Endpoint) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *Endpoint) GetHost() []string { + if m != nil { + return m.Host + } + return nil +} + +func (m *Endpoint) GetPath() []string { + if m != nil { + return m.Path + } + return nil +} + +func (m *Endpoint) GetMethod() []string { + if m != nil { + return m.Method + } + return nil +} + +func (m *Endpoint) GetStream() bool { + if m != nil { + return m.Stream + } + return false +} + +type EmptyResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *EmptyResponse) Reset() { *m = EmptyResponse{} } +func (m *EmptyResponse) String() string { return proto.CompactTextString(m) } +func (*EmptyResponse) ProtoMessage() {} +func (*EmptyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_00212fb1f9d3bf1c, []int{1} +} + +func (m *EmptyResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_EmptyResponse.Unmarshal(m, b) +} +func (m *EmptyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_EmptyResponse.Marshal(b, m, deterministic) +} +func (m *EmptyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_EmptyResponse.Merge(m, src) +} +func (m *EmptyResponse) XXX_Size() int { + return xxx_messageInfo_EmptyResponse.Size(m) +} +func (m *EmptyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_EmptyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_EmptyResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Endpoint)(nil), "go.micro.api.Endpoint") + proto.RegisterType((*EmptyResponse)(nil), "go.micro.api.EmptyResponse") +} + +func init() { + proto.RegisterFile("api.proto", fileDescriptor_00212fb1f9d3bf1c) +} + +var fileDescriptor_00212fb1f9d3bf1c = []byte{ + // 201 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0xd0, 0x41, 0x4a, 0xc5, 0x30, + 0x10, 0x06, 0x60, 0x63, 0x9f, 0x8f, 0xbe, 0x41, 0x11, 0xb2, 0x78, 0x04, 0xdd, 0x94, 0xae, 0xde, + 0x2a, 0x0b, 0x3d, 0x41, 0xd1, 0x5e, 0x20, 0x37, 0x88, 0x76, 0x68, 0xb3, 0x48, 0x66, 0x48, 0x06, + 0xc1, 0x43, 0x78, 0x67, 0x49, 0xad, 0x50, 0xdc, 0xba, 0xfb, 0xe7, 0x5b, 0xfc, 0xfc, 0x0c, 0x9c, + 0x3c, 0x07, 0xcb, 0x99, 0x84, 0xf4, 0xed, 0x4c, 0x36, 0x86, 0xf7, 0x4c, 0xd6, 0x73, 0xe8, 0x3f, + 0xa0, 0x1d, 0xd3, 0xc4, 0x14, 0x92, 0x68, 0x0d, 0x87, 0xe4, 0x23, 0x1a, 0xd5, 0xa9, 0xcb, 0xc9, + 0xad, 0xb9, 0xda, 0x42, 0x45, 0xcc, 0x75, 0xd7, 0x54, 0xab, 0xb9, 0x1a, 0x7b, 0x59, 0x4c, 0xf3, + 0x63, 0x35, 0xeb, 0x33, 0x1c, 0x23, 0xca, 0x42, 0x93, 0x39, 0xac, 0xba, 0x5d, 0xd5, 0x8b, 0x64, + 0xf4, 0xd1, 0xdc, 0x74, 0xea, 0xd2, 0xba, 0xed, 0xea, 0xef, 0xe1, 0x6e, 0x8c, 0x2c, 0x9f, 0x0e, + 0x0b, 0x53, 0x2a, 0xf8, 0xf4, 0xa5, 0xa0, 0x19, 0x38, 0xe8, 0x01, 0x5a, 0x87, 0x73, 0x28, 0x82, + 0x59, 0x9f, 0xed, 0x7e, 0xab, 0xfd, 0x1d, 0xfa, 0xf0, 0xf8, 0xc7, 0xf7, 0x45, 0xfd, 0x95, 0x7e, + 0x01, 0x78, 0xc5, 0xfc, 0xbf, 0x92, 0xb7, 0xe3, 0xfa, 0xad, 0xe7, 0xef, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x1f, 0xf0, 0xd9, 0x19, 0x3a, 0x01, 0x00, 0x00, +} diff --git a/api/service/proto/api.pb.micro.go b/api/service/proto/api.pb.micro.go new file mode 100644 index 00000000..6754bcca --- /dev/null +++ b/api/service/proto/api.pb.micro.go @@ -0,0 +1,102 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: api.proto + +package go_micro_api + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +import ( + context "context" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ client.Option +var _ server.Option + +// Client API for Api service + +type ApiService interface { + Register(ctx context.Context, in *Endpoint, opts ...client.CallOption) (*EmptyResponse, error) + Deregister(ctx context.Context, in *Endpoint, opts ...client.CallOption) (*EmptyResponse, error) +} + +type apiService struct { + c client.Client + name string +} + +func NewApiService(name string, c client.Client) ApiService { + return &apiService{ + c: c, + name: name, + } +} + +func (c *apiService) Register(ctx context.Context, in *Endpoint, opts ...client.CallOption) (*EmptyResponse, error) { + req := c.c.NewRequest(c.name, "Api.Register", in) + out := new(EmptyResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *apiService) Deregister(ctx context.Context, in *Endpoint, opts ...client.CallOption) (*EmptyResponse, error) { + req := c.c.NewRequest(c.name, "Api.Deregister", in) + out := new(EmptyResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Api service + +type ApiHandler interface { + Register(context.Context, *Endpoint, *EmptyResponse) error + Deregister(context.Context, *Endpoint, *EmptyResponse) error +} + +func RegisterApiHandler(s server.Server, hdlr ApiHandler, opts ...server.HandlerOption) error { + type api interface { + Register(ctx context.Context, in *Endpoint, out *EmptyResponse) error + Deregister(ctx context.Context, in *Endpoint, out *EmptyResponse) error + } + type Api struct { + api + } + h := &apiHandler{hdlr} + return s.Handle(s.NewHandler(&Api{h}, opts...)) +} + +type apiHandler struct { + ApiHandler +} + +func (h *apiHandler) Register(ctx context.Context, in *Endpoint, out *EmptyResponse) error { + return h.ApiHandler.Register(ctx, in, out) +} + +func (h *apiHandler) Deregister(ctx context.Context, in *Endpoint, out *EmptyResponse) error { + return h.ApiHandler.Deregister(ctx, in, out) +} diff --git a/api/service/proto/api.proto b/api/service/proto/api.proto new file mode 100644 index 00000000..c4317d12 --- /dev/null +++ b/api/service/proto/api.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package go.micro.api; + +service Api { + rpc Register(Endpoint) returns (EmptyResponse) {}; + rpc Deregister(Endpoint) returns (EmptyResponse) {}; +} + +message Endpoint { + string name = 1; + repeated string host = 2; + repeated string path = 3; + repeated string method = 4; + bool stream = 5; +} + +message EmptyResponse {} diff --git a/go.mod b/go.mod index 88d291a8..a0ce00d1 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/gorilla/websocket v1.4.1 github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect - github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect + github.com/grpc-ecosystem/grpc-gateway v1.9.5 github.com/hashicorp/hcl v1.0.0 github.com/imdario/mergo v0.3.8 github.com/jonboulle/clockwork v0.1.0 // indirect diff --git a/metadata/metadata.go b/metadata/metadata.go index 63402fa9..5ba0e4c0 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -6,7 +6,7 @@ import ( "strings" ) -type metaKey struct{} +type MetadataKey struct{} // Metadata is our way of representing request headers internally. // They're used at the RPC level and translate back and forth @@ -41,7 +41,7 @@ func Set(ctx context.Context, k, v string) context.Context { md = make(Metadata) } md[k] = v - return context.WithValue(ctx, metaKey{}, md) + return context.WithValue(ctx, MetadataKey{}, md) } // Get returns a single value from metadata in the context @@ -64,7 +64,7 @@ func Get(ctx context.Context, key string) (string, bool) { // FromContext returns metadata from the given context func FromContext(ctx context.Context) (Metadata, bool) { - md, ok := ctx.Value(metaKey{}).(Metadata) + md, ok := ctx.Value(MetadataKey{}).(Metadata) if !ok { return nil, ok } @@ -80,7 +80,7 @@ func FromContext(ctx context.Context) (Metadata, bool) { // NewContext creates a new context with the given metadata func NewContext(ctx context.Context, md Metadata) context.Context { - return context.WithValue(ctx, metaKey{}, md) + return context.WithValue(ctx, MetadataKey{}, md) } // MergeContext merges metadata to existing metadata, overwriting if specified @@ -88,7 +88,7 @@ func MergeContext(ctx context.Context, patchMd Metadata, overwrite bool) context if ctx == nil { ctx = context.Background() } - md, _ := ctx.Value(metaKey{}).(Metadata) + md, _ := ctx.Value(MetadataKey{}).(Metadata) cmd := make(Metadata) for k, v := range md { cmd[k] = v @@ -100,5 +100,5 @@ func MergeContext(ctx context.Context, patchMd Metadata, overwrite bool) context cmd[k] = v } } - return context.WithValue(ctx, metaKey{}, cmd) + return context.WithValue(ctx, MetadataKey{}, cmd) } diff --git a/server/grpc/codec.go b/server/grpc/codec.go index db9706d0..55287f6b 100644 --- a/server/grpc/codec.go +++ b/server/grpc/codec.go @@ -20,7 +20,11 @@ type bytesCodec struct{} type protoCodec struct{} type wrapCodec struct{ encoding.Codec } -var jsonpbMarshaler = &jsonpb.Marshaler{} +var jsonpbMarshaler = &jsonpb.Marshaler{ + EnumsAsInts: false, + EmitDefaults: false, + OrigName: true, +} var ( defaultGRPCCodecs = map[string]encoding.Codec{ From 4db2f5e79dbe894ee39f7159fb20e7317bf64fb1 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 30 Mar 2020 09:51:37 +0100 Subject: [PATCH 455/788] Add Namespace to Auth (#1438) Co-authored-by: Ben Toogood --- auth/auth.go | 4 ++ auth/options.go | 9 +++ auth/service/proto/auth/auth.pb.go | 103 ++++++++++++++++++----------- auth/service/proto/auth/auth.proto | 3 + auth/service/service.go | 10 +-- auth/token/basic/basic.go | 15 +++-- auth/token/jwt/jwt.go | 31 +++++---- auth/token/options.go | 9 +++ 8 files changed, 120 insertions(+), 64 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 837ace66..155ffebc 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -68,6 +68,8 @@ type Account struct { Roles []string `json:"roles"` // Any other associated metadata Metadata map[string]string `json:"metadata"` + // Namespace the account belongs to, default blank + Namespace string `json:"namespace"` } // Token can be short or long lived @@ -86,6 +88,8 @@ type Token struct { Roles []string `json:"roles"` // Metadata embedded in the token Metadata map[string]string `json:"metadata"` + // Namespace the token belongs to + Namespace string `json:"namespace"` } const ( diff --git a/auth/options.go b/auth/options.go index f7408335..95665f15 100644 --- a/auth/options.go +++ b/auth/options.go @@ -73,6 +73,8 @@ type GenerateOptions struct { Roles []string // SecretExpiry is the time the secret should live for SecretExpiry time.Duration + // Namespace the account belongs too + Namespace string } type GenerateOption func(o *GenerateOptions) @@ -91,6 +93,13 @@ func WithRoles(rs ...string) GenerateOption { } } +// WithNamespace for the generated account +func WithNamespace(n string) GenerateOption { + return func(o *GenerateOptions) { + o.Namespace = n + } +} + // WithSecretExpiry for the generated account's secret expires func WithSecretExpiry(ex time.Duration) GenerateOption { return func(o *GenerateOptions) { diff --git a/auth/service/proto/auth/auth.pb.go b/auth/service/proto/auth/auth.pb.go index 31c89570..10641f49 100644 --- a/auth/service/proto/auth/auth.pb.go +++ b/auth/service/proto/auth/auth.pb.go @@ -28,6 +28,7 @@ type Token struct { Subject string `protobuf:"bytes,5,opt,name=subject,proto3" json:"subject,omitempty"` Roles []string `protobuf:"bytes,6,rep,name=roles,proto3" json:"roles,omitempty"` Metadata map[string]string `protobuf:"bytes,7,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Namespace string `protobuf:"bytes,8,opt,name=namespace,proto3" json:"namespace,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -107,11 +108,19 @@ func (m *Token) GetMetadata() map[string]string { return nil } +func (m *Token) GetNamespace() string { + if m != nil { + return m.Namespace + } + return "" +} + type Account struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Secret *Token `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty"` Roles []string `protobuf:"bytes,3,rep,name=roles,proto3" json:"roles,omitempty"` Metadata map[string]string `protobuf:"bytes,4,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Namespace string `protobuf:"bytes,5,opt,name=namespace,proto3" json:"namespace,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -170,6 +179,13 @@ func (m *Account) GetMetadata() map[string]string { return nil } +func (m *Account) GetNamespace() string { + if m != nil { + return m.Namespace + } + return "" +} + type Resource struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` @@ -230,6 +246,7 @@ type GenerateRequest struct { Roles []string `protobuf:"bytes,2,rep,name=roles,proto3" json:"roles,omitempty"` Metadata map[string]string `protobuf:"bytes,3,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` SecretExpiry int64 `protobuf:"varint,4,opt,name=secret_expiry,json=secretExpiry,proto3" json:"secret_expiry,omitempty"` + Namespace string `protobuf:"bytes,5,opt,name=namespace,proto3" json:"namespace,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -288,6 +305,13 @@ func (m *GenerateRequest) GetSecretExpiry() int64 { return 0 } +func (m *GenerateRequest) GetNamespace() string { + if m != nil { + return m.Namespace + } + return "" +} + type GenerateResponse struct { Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -671,44 +695,45 @@ func init() { } var fileDescriptor_b246cecfa8195ff3 = []byte{ - // 612 bytes of a gzipped FileDescriptorProto + // 630 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0xae, 0xed, 0x34, 0x49, 0x27, 0x4d, 0x13, 0xad, 0xaa, 0x60, 0x45, 0xa2, 0x04, 0x83, 0x50, - 0x84, 0x8a, 0x83, 0xd2, 0x0b, 0xe2, 0x4f, 0x54, 0x50, 0x95, 0x1f, 0x95, 0x83, 0x85, 0x04, 0x37, - 0xe4, 0x38, 0x43, 0x62, 0xd2, 0x78, 0xcd, 0x7a, 0x1d, 0x91, 0xb7, 0xe0, 0x01, 0xb9, 0x71, 0xe6, - 0x1d, 0xd0, 0xae, 0x77, 0x5d, 0xc7, 0x49, 0x38, 0xf0, 0x73, 0x89, 0x66, 0x66, 0x67, 0xbf, 0x6f, - 0xe6, 0x9b, 0xd9, 0x18, 0x1e, 0x4f, 0x42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34, 0x15, 0x51, 0xe4, 0x46, 0x25, 0x7b, 0x91, + 0xe8, 0xee, 0xfe, 0xba, 0xc7, 0x65, 0x2c, 0xb5, 0xe2, 0x12, 0xd6, 0x22, 0x8f, 0x4b, 0x58, 0x15, + 0x66, 0xdc, 0x8d, 0xf3, 0x86, 0xfc, 0x73, 0x3a, 0xfa, 0x1d, 0x00, 0x00, 0xff, 0xff, 0xb6, 0x18, + 0xd0, 0x5a, 0xdc, 0x06, 0x00, 0x00, } diff --git a/auth/service/proto/auth/auth.proto b/auth/service/proto/auth/auth.proto index a31d6102..7d681de0 100644 --- a/auth/service/proto/auth/auth.proto +++ b/auth/service/proto/auth/auth.proto @@ -16,6 +16,7 @@ message Token { string subject = 5; repeated string roles = 6; map metadata = 7; + string namespace = 8; } message Account { @@ -23,6 +24,7 @@ message Account { Token secret = 2; repeated string roles = 3; map metadata = 4; + string namespace = 5; } message Resource{ @@ -36,6 +38,7 @@ message GenerateRequest { repeated string roles = 2; map metadata = 3; int64 secret_expiry = 4; + string namespace = 5; } message GenerateResponse { diff --git a/auth/service/service.go b/auth/service/service.go index 32da7571..a30e3498 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -85,6 +85,7 @@ func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e Id: id, Roles: options.Roles, Metadata: options.Metadata, + Namespace: options.Namespace, SecretExpiry: int64(options.SecretExpiry.Seconds()), }) if err != nil { @@ -275,9 +276,10 @@ func serializeAccount(a *authPb.Account) *auth.Account { } return &auth.Account{ - ID: a.Id, - Roles: a.Roles, - Metadata: a.Metadata, - Secret: secret, + ID: a.Id, + Roles: a.Roles, + Metadata: a.Metadata, + Namespace: a.Namespace, + Secret: secret, } } diff --git a/auth/token/basic/basic.go b/auth/token/basic/basic.go index 87469127..34b79f92 100644 --- a/auth/token/basic/basic.go +++ b/auth/token/basic/basic.go @@ -40,13 +40,14 @@ func (b *Basic) Generate(subject string, opts ...token.GenerateOption) (*auth.To // construct the token token := auth.Token{ - Subject: subject, - Type: b.String(), - Token: uuid.New().String(), - Created: time.Now(), - Expiry: time.Now().Add(options.Expiry), - Metadata: options.Metadata, - Roles: options.Roles, + Subject: subject, + Type: b.String(), + Token: uuid.New().String(), + Created: time.Now(), + Expiry: time.Now().Add(options.Expiry), + Metadata: options.Metadata, + Roles: options.Roles, + Namespace: options.Namespace, } // marshal the account to bytes diff --git a/auth/token/jwt/jwt.go b/auth/token/jwt/jwt.go index 12504fbe..e35ac5e7 100644 --- a/auth/token/jwt/jwt.go +++ b/auth/token/jwt/jwt.go @@ -11,8 +11,9 @@ import ( // authClaims to be encoded in the JWT type authClaims struct { - Roles []string `json:"roles"` - Metadata map[string]string `json:"metadata"` + Roles []string `json:"roles"` + Metadata map[string]string `json:"metadata"` + Namespace string `json:"namespace"` jwt.StandardClaims } @@ -49,7 +50,7 @@ func (j *JWT) Generate(subject string, opts ...token.GenerateOption) (*auth.Toke // generate the JWT expiry := time.Now().Add(options.Expiry) t := jwt.NewWithClaims(jwt.SigningMethodRS256, authClaims{ - options.Roles, options.Metadata, jwt.StandardClaims{ + options.Roles, options.Metadata, options.Namespace, jwt.StandardClaims{ Subject: subject, ExpiresAt: expiry.Unix(), }, @@ -61,13 +62,14 @@ func (j *JWT) Generate(subject string, opts ...token.GenerateOption) (*auth.Toke // return the token return &auth.Token{ - Subject: subject, - Token: tok, - Type: j.String(), - Created: time.Now(), - Expiry: expiry, - Roles: options.Roles, - Metadata: options.Metadata, + Subject: subject, + Token: tok, + Type: j.String(), + Created: time.Now(), + Expiry: expiry, + Roles: options.Roles, + Metadata: options.Metadata, + Namespace: options.Namespace, }, nil } @@ -98,10 +100,11 @@ func (j *JWT) Inspect(t string) (*auth.Token, error) { // return the token return &auth.Token{ - Token: t, - Subject: claims.Subject, - Metadata: claims.Metadata, - Roles: claims.Roles, + Token: t, + Subject: claims.Subject, + Metadata: claims.Metadata, + Roles: claims.Roles, + Namespace: claims.Namespace, }, nil } diff --git a/auth/token/options.go b/auth/token/options.go index 29e166e1..2e8d3bbd 100644 --- a/auth/token/options.go +++ b/auth/token/options.go @@ -57,6 +57,8 @@ type GenerateOptions struct { Metadata map[string]string // Roles/scopes associated with the account Roles []string + // Namespace the account belongs too + Namespace string } type GenerateOption func(o *GenerateOptions) @@ -82,6 +84,13 @@ func WithRoles(rs ...string) func(o *GenerateOptions) { } } +// WithNamespace for the token +func WithNamespace(n string) func(o *GenerateOptions) { + return func(o *GenerateOptions) { + o.Namespace = n + } +} + // NewGenerateOptions from a slice of options func NewGenerateOptions(opts ...GenerateOption) GenerateOptions { var options GenerateOptions From 756b346672fd6125b95a2e9740641e24ab0cff7f Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 30 Mar 2020 18:23:00 +0300 Subject: [PATCH 456/788] auth/service: move all proto files to single dir (#1439) Signed-off-by: Vasiliy Tolstov --- .../proto/{accounts => }/accounts.pb.go | 45 ++++--- .../proto/{accounts => }/accounts.pb.micro.go | 3 +- .../proto/{accounts => }/accounts.proto | 2 +- auth/service/proto/{auth => }/auth.pb.go | 112 +++++++++-------- .../service/proto/{auth => }/auth.pb.micro.go | 2 +- auth/service/proto/{auth => }/auth.proto | 0 auth/service/proto/{rules => }/rules.pb.go | 115 +++++++++--------- .../proto/{rules => }/rules.pb.micro.go | 3 +- auth/service/proto/{rules => }/rules.proto | 2 +- auth/service/service.go | 51 ++++---- 10 files changed, 162 insertions(+), 173 deletions(-) rename auth/service/proto/{accounts => }/accounts.pb.go (62%) rename auth/service/proto/{accounts => }/accounts.pb.micro.go (94%) rename auth/service/proto/{accounts => }/accounts.proto (76%) rename auth/service/proto/{auth => }/auth.pb.go (82%) rename auth/service/proto/{auth => }/auth.pb.micro.go (98%) rename auth/service/proto/{auth => }/auth.proto (100%) rename auth/service/proto/{rules => }/rules.pb.go (66%) rename auth/service/proto/{rules => }/rules.pb.micro.go (96%) rename auth/service/proto/{rules => }/rules.proto (90%) diff --git a/auth/service/proto/accounts/accounts.pb.go b/auth/service/proto/accounts.pb.go similarity index 62% rename from auth/service/proto/accounts/accounts.pb.go rename to auth/service/proto/accounts.pb.go index e776cb64..f389386c 100644 --- a/auth/service/proto/accounts/accounts.pb.go +++ b/auth/service/proto/accounts.pb.go @@ -1,12 +1,11 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/auth/service/proto/accounts/accounts.proto +// source: accounts.proto package go_micro_auth import ( fmt "fmt" proto "github.com/golang/protobuf/proto" - auth "github.com/micro/go-micro/v2/auth/service/proto/auth" math "math" ) @@ -31,7 +30,7 @@ func (m *ListAccountsRequest) Reset() { *m = ListAccountsRequest{} } func (m *ListAccountsRequest) String() string { return proto.CompactTextString(m) } func (*ListAccountsRequest) ProtoMessage() {} func (*ListAccountsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_25929ace37374fcc, []int{0} + return fileDescriptor_e1e7723af4c007b7, []int{0} } func (m *ListAccountsRequest) XXX_Unmarshal(b []byte) error { @@ -53,17 +52,17 @@ func (m *ListAccountsRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ListAccountsRequest proto.InternalMessageInfo type ListAccountsResponse struct { - Accounts []*auth.Account `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Accounts []*Account `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *ListAccountsResponse) Reset() { *m = ListAccountsResponse{} } func (m *ListAccountsResponse) String() string { return proto.CompactTextString(m) } func (*ListAccountsResponse) ProtoMessage() {} func (*ListAccountsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_25929ace37374fcc, []int{1} + return fileDescriptor_e1e7723af4c007b7, []int{1} } func (m *ListAccountsResponse) XXX_Unmarshal(b []byte) error { @@ -84,7 +83,7 @@ func (m *ListAccountsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_ListAccountsResponse proto.InternalMessageInfo -func (m *ListAccountsResponse) GetAccounts() []*auth.Account { +func (m *ListAccountsResponse) GetAccounts() []*Account { if m != nil { return m.Accounts } @@ -97,21 +96,19 @@ func init() { } func init() { - proto.RegisterFile("github.com/micro/go-micro/auth/service/proto/accounts/accounts.proto", fileDescriptor_25929ace37374fcc) + proto.RegisterFile("accounts.proto", fileDescriptor_e1e7723af4c007b7) } -var fileDescriptor_25929ace37374fcc = []byte{ - // 186 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x72, 0x49, 0xcf, 0x2c, 0xc9, - 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0xcf, 0xcd, 0x4c, 0x2e, 0xca, 0xd7, 0x4f, 0xcf, 0xd7, - 0x85, 0x30, 0x12, 0x4b, 0x4b, 0x32, 0xf4, 0x8b, 0x53, 0x8b, 0xca, 0x32, 0x93, 0x53, 0xf5, 0x0b, - 0x8a, 0xf2, 0x4b, 0xf2, 0xf5, 0x13, 0x93, 0x93, 0xf3, 0x4b, 0xf3, 0x4a, 0x8a, 0xe1, 0x0c, 0x3d, - 0xb0, 0xb8, 0x10, 0x6f, 0x7a, 0xbe, 0x1e, 0x58, 0x93, 0x1e, 0x48, 0x93, 0x94, 0x0d, 0x69, 0x86, - 0x82, 0x84, 0x40, 0x04, 0xc4, 0x30, 0x25, 0x51, 0x2e, 0x61, 0x9f, 0xcc, 0xe2, 0x12, 0x47, 0xa8, - 0x15, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x4a, 0x5e, 0x5c, 0x22, 0xa8, 0xc2, 0xc5, 0x05, - 0xf9, 0x79, 0xc5, 0xa9, 0x42, 0x46, 0x5c, 0x1c, 0x30, 0xd7, 0x48, 0x30, 0x2a, 0x30, 0x6b, 0x70, - 0x1b, 0x89, 0xe9, 0xa1, 0x38, 0x47, 0x0f, 0xaa, 0x25, 0x08, 0xae, 0xce, 0x28, 0x96, 0x8b, 0x03, - 0x66, 0x8e, 0x50, 0x20, 0x17, 0x0b, 0xc8, 0x5c, 0x21, 0x25, 0x34, 0x5d, 0x58, 0xdc, 0x20, 0xa5, - 0x8c, 0x57, 0x0d, 0xc4, 0x41, 0x4a, 0x0c, 0x49, 0x6c, 0x60, 0x8f, 0x18, 0x03, 0x02, 0x00, 0x00, - 0xff, 0xff, 0x23, 0x27, 0x81, 0xfe, 0x5d, 0x01, 0x00, 0x00, +var fileDescriptor_e1e7723af4c007b7 = []byte{ + // 147 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0x4c, 0x4e, 0xce, + 0x2f, 0xcd, 0x2b, 0x29, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x4d, 0xcf, 0xd7, 0xcb, + 0xcd, 0x4c, 0x2e, 0xca, 0xd7, 0x4b, 0x2c, 0x2d, 0xc9, 0x90, 0xe2, 0x02, 0x91, 0x10, 0x29, 0x25, + 0x51, 0x2e, 0x61, 0x9f, 0xcc, 0xe2, 0x12, 0x47, 0xa8, 0x86, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2, + 0x12, 0x25, 0x2f, 0x2e, 0x11, 0x54, 0xe1, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x21, 0x23, 0x2e, + 0x0e, 0x98, 0xd9, 0x12, 0x8c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0x62, 0x7a, 0x28, 0x86, 0xeb, 0x41, + 0xb5, 0x04, 0xc1, 0xd5, 0x19, 0xc5, 0x72, 0x71, 0xc0, 0xcc, 0x11, 0x0a, 0xe4, 0x62, 0x01, 0x99, + 0x2b, 0xa4, 0x84, 0xa6, 0x0b, 0x8b, 0x1b, 0xa4, 0x94, 0xf1, 0xaa, 0x81, 0x38, 0x48, 0x89, 0x21, + 0x89, 0x0d, 0xec, 0x11, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb4, 0xbb, 0xf1, 0x10, 0xf5, + 0x00, 0x00, 0x00, } diff --git a/auth/service/proto/accounts/accounts.pb.micro.go b/auth/service/proto/accounts.pb.micro.go similarity index 94% rename from auth/service/proto/accounts/accounts.pb.micro.go rename to auth/service/proto/accounts.pb.micro.go index 820b968d..56408164 100644 --- a/auth/service/proto/accounts/accounts.pb.micro.go +++ b/auth/service/proto/accounts.pb.micro.go @@ -1,12 +1,11 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/auth/service/proto/accounts/accounts.proto +// source: accounts.proto package go_micro_auth import ( fmt "fmt" proto "github.com/golang/protobuf/proto" - _ "github.com/micro/go-micro/v2/auth/service/proto/auth" math "math" ) diff --git a/auth/service/proto/accounts/accounts.proto b/auth/service/proto/accounts.proto similarity index 76% rename from auth/service/proto/accounts/accounts.proto rename to auth/service/proto/accounts.proto index 8f93aa23..47143693 100644 --- a/auth/service/proto/accounts/accounts.proto +++ b/auth/service/proto/accounts.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package go.micro.auth; -import "github.com/micro/go-micro/auth/service/proto/auth/auth.proto"; +import "auth.proto"; service Accounts { rpc List(ListAccountsRequest) returns (ListAccountsResponse) {}; diff --git a/auth/service/proto/auth/auth.pb.go b/auth/service/proto/auth.pb.go similarity index 82% rename from auth/service/proto/auth/auth.pb.go rename to auth/service/proto/auth.pb.go index 10641f49..df741fe8 100644 --- a/auth/service/proto/auth/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/auth/service/proto/auth/auth.proto +// source: auth.proto package go_micro_auth @@ -38,7 +38,7 @@ func (m *Token) Reset() { *m = Token{} } func (m *Token) String() string { return proto.CompactTextString(m) } func (*Token) ProtoMessage() {} func (*Token) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{0} + return fileDescriptor_8bbd6f3875b0e874, []int{0} } func (m *Token) XXX_Unmarshal(b []byte) error { @@ -130,7 +130,7 @@ func (m *Account) Reset() { *m = Account{} } func (m *Account) String() string { return proto.CompactTextString(m) } func (*Account) ProtoMessage() {} func (*Account) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{1} + return fileDescriptor_8bbd6f3875b0e874, []int{1} } func (m *Account) XXX_Unmarshal(b []byte) error { @@ -199,7 +199,7 @@ func (m *Resource) Reset() { *m = Resource{} } func (m *Resource) String() string { return proto.CompactTextString(m) } func (*Resource) ProtoMessage() {} func (*Resource) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{2} + return fileDescriptor_8bbd6f3875b0e874, []int{2} } func (m *Resource) XXX_Unmarshal(b []byte) error { @@ -256,7 +256,7 @@ func (m *GenerateRequest) Reset() { *m = GenerateRequest{} } func (m *GenerateRequest) String() string { return proto.CompactTextString(m) } func (*GenerateRequest) ProtoMessage() {} func (*GenerateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{3} + return fileDescriptor_8bbd6f3875b0e874, []int{3} } func (m *GenerateRequest) XXX_Unmarshal(b []byte) error { @@ -323,7 +323,7 @@ func (m *GenerateResponse) Reset() { *m = GenerateResponse{} } func (m *GenerateResponse) String() string { return proto.CompactTextString(m) } func (*GenerateResponse) ProtoMessage() {} func (*GenerateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{4} + return fileDescriptor_8bbd6f3875b0e874, []int{4} } func (m *GenerateResponse) XXX_Unmarshal(b []byte) error { @@ -363,7 +363,7 @@ func (m *GrantRequest) Reset() { *m = GrantRequest{} } func (m *GrantRequest) String() string { return proto.CompactTextString(m) } func (*GrantRequest) ProtoMessage() {} func (*GrantRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{5} + return fileDescriptor_8bbd6f3875b0e874, []int{5} } func (m *GrantRequest) XXX_Unmarshal(b []byte) error { @@ -408,7 +408,7 @@ func (m *GrantResponse) Reset() { *m = GrantResponse{} } func (m *GrantResponse) String() string { return proto.CompactTextString(m) } func (*GrantResponse) ProtoMessage() {} func (*GrantResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{6} + return fileDescriptor_8bbd6f3875b0e874, []int{6} } func (m *GrantResponse) XXX_Unmarshal(b []byte) error { @@ -441,7 +441,7 @@ func (m *RevokeRequest) Reset() { *m = RevokeRequest{} } func (m *RevokeRequest) String() string { return proto.CompactTextString(m) } func (*RevokeRequest) ProtoMessage() {} func (*RevokeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{7} + return fileDescriptor_8bbd6f3875b0e874, []int{7} } func (m *RevokeRequest) XXX_Unmarshal(b []byte) error { @@ -486,7 +486,7 @@ func (m *RevokeResponse) Reset() { *m = RevokeResponse{} } func (m *RevokeResponse) String() string { return proto.CompactTextString(m) } func (*RevokeResponse) ProtoMessage() {} func (*RevokeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{8} + return fileDescriptor_8bbd6f3875b0e874, []int{8} } func (m *RevokeResponse) XXX_Unmarshal(b []byte) error { @@ -518,7 +518,7 @@ func (m *InspectRequest) Reset() { *m = InspectRequest{} } func (m *InspectRequest) String() string { return proto.CompactTextString(m) } func (*InspectRequest) ProtoMessage() {} func (*InspectRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{9} + return fileDescriptor_8bbd6f3875b0e874, []int{9} } func (m *InspectRequest) XXX_Unmarshal(b []byte) error { @@ -557,7 +557,7 @@ func (m *InspectResponse) Reset() { *m = InspectResponse{} } func (m *InspectResponse) String() string { return proto.CompactTextString(m) } func (*InspectResponse) ProtoMessage() {} func (*InspectResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{10} + return fileDescriptor_8bbd6f3875b0e874, []int{10} } func (m *InspectResponse) XXX_Unmarshal(b []byte) error { @@ -597,7 +597,7 @@ func (m *RefreshRequest) Reset() { *m = RefreshRequest{} } func (m *RefreshRequest) String() string { return proto.CompactTextString(m) } func (*RefreshRequest) ProtoMessage() {} func (*RefreshRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{11} + return fileDescriptor_8bbd6f3875b0e874, []int{11} } func (m *RefreshRequest) XXX_Unmarshal(b []byte) error { @@ -643,7 +643,7 @@ func (m *RefreshResponse) Reset() { *m = RefreshResponse{} } func (m *RefreshResponse) String() string { return proto.CompactTextString(m) } func (*RefreshResponse) ProtoMessage() {} func (*RefreshResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_b246cecfa8195ff3, []int{12} + return fileDescriptor_8bbd6f3875b0e874, []int{12} } func (m *RefreshResponse) XXX_Unmarshal(b []byte) error { @@ -691,49 +691,47 @@ func init() { } func init() { - proto.RegisterFile("github.com/micro/go-micro/auth/service/proto/auth/auth.proto", fileDescriptor_b246cecfa8195ff3) + proto.RegisterFile("auth.proto", fileDescriptor_8bbd6f3875b0e874) } -var fileDescriptor_b246cecfa8195ff3 = []byte{ - // 630 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0xae, 0xed, 0xfc, 0xb8, 0x93, 0xa6, 0xa9, 0x56, 0x55, 0xb1, 0x22, 0x28, 0xc1, 0x20, 0x54, - 0xa1, 0xe2, 0xa0, 0xf4, 0x82, 0xf8, 0x13, 0x15, 0x54, 0xe5, 0x47, 0xe5, 0x60, 0x21, 0xc1, 0x0d, - 0xb9, 0xce, 0xd0, 0x98, 0x34, 0x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12, 0xd6, 0x22, 0x8f, 0x4b, 0x58, 0x15, - 0x66, 0xdc, 0x8d, 0xf3, 0x86, 0xfc, 0x73, 0x3a, 0xfa, 0x1d, 0x00, 0x00, 0xff, 0xff, 0xb6, 0x18, - 0xd0, 0x5a, 0xdc, 0x06, 0x00, 0x00, +var fileDescriptor_8bbd6f3875b0e874 = []byte{ + // 601 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0xad, 0xed, 0x7c, 0x38, 0x93, 0x4f, 0xad, 0xaa, 0x60, 0x45, 0x50, 0x82, 0x41, 0x28, 0x42, + 0x95, 0x85, 0xd2, 0x0b, 0x02, 0x81, 0xa8, 0xa0, 0x2a, 0x1f, 0x2a, 0x07, 0x0b, 0x09, 0x6e, 0xc8, + 0x75, 0x06, 0x12, 0xd2, 0x78, 0xcd, 0x7a, 0x5d, 0x91, 0x23, 0x7f, 0x88, 0x7f, 0xc6, 0x1f, 0xe0, + 0x84, 0x76, 0xbd, 0xeb, 0x38, 0x4e, 0x82, 0x10, 0x6a, 0x6f, 0x3b, 0xbb, 0x33, 0x6f, 0xe6, 0xbd, + 0x79, 0x71, 0x00, 0x82, 0x94, 0x4f, 0xbd, 0x98, 0x51, 0x4e, 0x49, 0xfb, 0x0b, 0xf5, 0x16, 0xb3, + 0x90, 0x51, 0x4f, 0x5c, 0xba, 0x3f, 0x4d, 0xa8, 0xbe, 0xa7, 0x73, 0x8c, 0xc8, 0x3e, 0x54, 0xb9, + 0x38, 0x38, 0xc6, 0xd0, 0x18, 0x35, 0xfc, 0x2c, 0x20, 0x04, 0x2a, 0x7c, 0x19, 0xa3, 0x63, 0xca, + 0x4b, 0x79, 0x26, 0x0e, 0xd4, 0x43, 0x86, 0x01, 0xc7, 0x89, 0x63, 0x0d, 0x8d, 0x91, 0xe5, 0xeb, + 0x90, 0xf4, 0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0xbc, + 0xcb, 0x0c, 0xe3, 0x3e, 0x85, 0x6e, 0x0e, 0xa6, 0x26, 0x7a, 0x50, 0x1c, 0x7d, 0xd7, 0xc7, 0x21, + 0x4b, 0x19, 0xff, 0x32, 0xa0, 0x72, 0x9c, 0xf2, 0x29, 0x39, 0x03, 0x5b, 0xbb, 0x83, 0x1c, 0xfc, + 0xdd, 0xe1, 0x83, 0xdb, 0x3b, 0xdf, 0x95, 0x9c, 0x7b, 0xe4, 0x0d, 0xd4, 0x95, 0x50, 0xe4, 0x56, + 0x29, 0x7b, 0x5d, 0xe8, 0xc1, 0xc1, 0xae, 0xe7, 0x22, 0x96, 0xa2, 0xb8, 0x81, 0xb5, 0xae, 0xe3, + 0x06, 0x56, 0x49, 0x19, 0x77, 0xef, 0xbc, 0x26, 0xff, 0x9c, 0x8e, 0xfe, 0x04, 0x00, 0x00, 0xff, + 0xff, 0x9a, 0xf4, 0x9d, 0x85, 0xaa, 0x06, 0x00, 0x00, } diff --git a/auth/service/proto/auth/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go similarity index 98% rename from auth/service/proto/auth/auth.pb.micro.go rename to auth/service/proto/auth.pb.micro.go index 61107958..f304e32b 100644 --- a/auth/service/proto/auth/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/auth/service/proto/auth/auth.proto +// source: auth.proto package go_micro_auth diff --git a/auth/service/proto/auth/auth.proto b/auth/service/proto/auth.proto similarity index 100% rename from auth/service/proto/auth/auth.proto rename to auth/service/proto/auth.proto diff --git a/auth/service/proto/rules/rules.pb.go b/auth/service/proto/rules.pb.go similarity index 66% rename from auth/service/proto/rules/rules.pb.go rename to auth/service/proto/rules.pb.go index d9efd3a9..04d02a75 100644 --- a/auth/service/proto/rules/rules.pb.go +++ b/auth/service/proto/rules.pb.go @@ -1,12 +1,11 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/auth/service/proto/rules/rules.proto +// source: rules.proto package go_micro_auth import ( fmt "fmt" proto "github.com/golang/protobuf/proto" - auth "github.com/micro/go-micro/v2/auth/service/proto/auth" math "math" ) @@ -46,24 +45,24 @@ func (x Access) String() string { } func (Access) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_d5bb7c98c32bdd99, []int{0} + return fileDescriptor_8e722d3e922f0937, []int{0} } type Rule struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` - Resource *auth.Resource `protobuf:"bytes,3,opt,name=resource,proto3" json:"resource,omitempty"` - Access Access `protobuf:"varint,4,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` + Resource *Resource `protobuf:"bytes,3,opt,name=resource,proto3" json:"resource,omitempty"` + Access Access `protobuf:"varint,4,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Rule) Reset() { *m = Rule{} } func (m *Rule) String() string { return proto.CompactTextString(m) } func (*Rule) ProtoMessage() {} func (*Rule) Descriptor() ([]byte, []int) { - return fileDescriptor_d5bb7c98c32bdd99, []int{0} + return fileDescriptor_8e722d3e922f0937, []int{0} } func (m *Rule) XXX_Unmarshal(b []byte) error { @@ -98,7 +97,7 @@ func (m *Rule) GetRole() string { return "" } -func (m *Rule) GetResource() *auth.Resource { +func (m *Rule) GetResource() *Resource { if m != nil { return m.Resource } @@ -113,19 +112,19 @@ func (m *Rule) GetAccess() Access { } type CreateRequest struct { - Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` - Resource *auth.Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` - Access Access `protobuf:"varint,3,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` + Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` + Access Access `protobuf:"varint,3,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_d5bb7c98c32bdd99, []int{1} + return fileDescriptor_8e722d3e922f0937, []int{1} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -153,7 +152,7 @@ func (m *CreateRequest) GetRole() string { return "" } -func (m *CreateRequest) GetResource() *auth.Resource { +func (m *CreateRequest) GetResource() *Resource { if m != nil { return m.Resource } @@ -177,7 +176,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d5bb7c98c32bdd99, []int{2} + return fileDescriptor_8e722d3e922f0937, []int{2} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -199,19 +198,19 @@ func (m *CreateResponse) XXX_DiscardUnknown() { var xxx_messageInfo_CreateResponse proto.InternalMessageInfo type DeleteRequest struct { - Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` - Resource *auth.Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` - Access Access `protobuf:"varint,3,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` + Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` + Access Access `protobuf:"varint,3,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_d5bb7c98c32bdd99, []int{3} + return fileDescriptor_8e722d3e922f0937, []int{3} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -239,7 +238,7 @@ func (m *DeleteRequest) GetRole() string { return "" } -func (m *DeleteRequest) GetResource() *auth.Resource { +func (m *DeleteRequest) GetResource() *Resource { if m != nil { return m.Resource } @@ -263,7 +262,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d5bb7c98c32bdd99, []int{4} + return fileDescriptor_8e722d3e922f0937, []int{4} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -294,7 +293,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_d5bb7c98c32bdd99, []int{5} + return fileDescriptor_8e722d3e922f0937, []int{5} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -326,7 +325,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d5bb7c98c32bdd99, []int{6} + return fileDescriptor_8e722d3e922f0937, []int{6} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -366,33 +365,31 @@ func init() { } func init() { - proto.RegisterFile("github.com/micro/go-micro/auth/service/proto/rules/rules.proto", fileDescriptor_d5bb7c98c32bdd99) + proto.RegisterFile("rules.proto", fileDescriptor_8e722d3e922f0937) } -var fileDescriptor_d5bb7c98c32bdd99 = []byte{ - // 384 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x93, 0x41, 0x6b, 0xdb, 0x30, - 0x1c, 0xc5, 0x23, 0xc7, 0xf1, 0xb6, 0xbf, 0x97, 0x60, 0x34, 0xc6, 0x8c, 0xb7, 0x81, 0xc9, 0xc9, - 0x1b, 0xc4, 0x06, 0xe7, 0x34, 0x18, 0x83, 0x30, 0x87, 0x30, 0x36, 0x3c, 0x10, 0x2d, 0x3d, 0x27, - 0xce, 0x9f, 0xc4, 0xe0, 0x54, 0xa9, 0x64, 0xf7, 0x2b, 0xf4, 0xd6, 0x4f, 0xd8, 0x0f, 0x53, 0x2c, - 0x39, 0xa1, 0x71, 0x1a, 0x68, 0x6e, 0xbd, 0x08, 0x49, 0xef, 0xe9, 0xf9, 0xa7, 0x67, 0x1b, 0x7e, - 0xad, 0xf2, 0x72, 0x5d, 0x2d, 0xc2, 0x8c, 0x6f, 0xa2, 0x4d, 0x9e, 0x09, 0x1e, 0xad, 0xf8, 0x48, - 0x4f, 0xe6, 0x55, 0xb9, 0x8e, 0x24, 0x8a, 0xdb, 0x3c, 0xc3, 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0xfa, 0x37, 0xfd, 0x7f, 0x95, 0x3a, 0x9d, 0x7a, 0x31, 0x63, 0x93, 0xf4, 0x62, 0x9a, 0x38, 0x84, - 0x02, 0x58, 0xc9, 0x34, 0xfd, 0x33, 0x4d, 0x1c, 0x23, 0x7e, 0x20, 0xd0, 0xab, 0xcf, 0x4b, 0x3a, - 0x03, 0x4b, 0x37, 0x46, 0xbf, 0xb4, 0xf2, 0x0f, 0xde, 0xa8, 0xf7, 0xf5, 0x84, 0xda, 0x5c, 0xa5, - 0x53, 0x07, 0xe9, 0xeb, 0x1d, 0x05, 0x1d, 0xd4, 0x7f, 0x14, 0xd4, 0xea, 0xa4, 0x43, 0x27, 0x60, - 0xd6, 0x35, 0x50, 0xaf, 0x65, 0x7c, 0x52, 0x95, 0xf7, 0xf9, 0x59, 0x6d, 0x17, 0xb1, 0xb0, 0xd4, - 0x8f, 0x32, 0x7e, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x85, 0x65, 0x07, 0x9d, 0xb7, 0x03, 0x00, 0x00, +var fileDescriptor_8e722d3e922f0937 = []byte{ + // 346 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x93, 0xc1, 0x4e, 0xb3, 0x40, + 0x14, 0x85, 0x3b, 0x94, 0xf2, 0xff, 0x5e, 0x6c, 0x43, 0xae, 0x31, 0x12, 0xd4, 0x84, 0x74, 0x85, + 0x26, 0xb2, 0xa0, 0x2b, 0x97, 0x8d, 0x34, 0x8d, 0xd1, 0x60, 0x32, 0xd1, 0xb8, 0xae, 0xf4, 0x46, + 0x49, 0xd0, 0xa9, 0x33, 0xf0, 0x0c, 0xee, 0x7c, 0x42, 0x1f, 0xc6, 0xc0, 0xd0, 0xc6, 0x52, 0x9b, + 0xe8, 0xce, 0x0d, 0x61, 0x38, 0x67, 0x0e, 0xdf, 0x3d, 0x30, 0x60, 0xcb, 0x32, 0x27, 0x15, 0x2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0xe3, 0xe4, 0x76, 0x12, 0x3b, 0x0c, 0x01, 0xac, 0x78, 0x92, 0x5c, + 0x4e, 0x62, 0xc7, 0x88, 0x3e, 0x18, 0xf4, 0xaa, 0xfd, 0x0a, 0xa7, 0x60, 0xe9, 0xc6, 0xf0, 0xa8, + 0x95, 0xbf, 0xf6, 0x45, 0xbd, 0xe3, 0x2d, 0x6a, 0x33, 0x4a, 0xa7, 0x0a, 0xd2, 0xe3, 0x6d, 0x04, + 0xad, 0xd5, 0xbf, 0x11, 0xd4, 0xea, 0xa4, 0x83, 0x63, 0x30, 0xab, 0x1a, 0xd0, 0x6b, 0x19, 0xbf, + 0x54, 0xe5, 0x1d, 0x7e, 0xab, 0x2d, 0x23, 0x1e, 0xac, 0xfa, 0xa0, 0x8c, 0x3e, 0x03, 0x00, 0x00, + 0xff, 0xff, 0xb8, 0x06, 0xc3, 0x53, 0x52, 0x03, 0x00, 0x00, } diff --git a/auth/service/proto/rules/rules.pb.micro.go b/auth/service/proto/rules.pb.micro.go similarity index 96% rename from auth/service/proto/rules/rules.pb.micro.go rename to auth/service/proto/rules.pb.micro.go index ee3a7f24..fa25ba61 100644 --- a/auth/service/proto/rules/rules.pb.micro.go +++ b/auth/service/proto/rules.pb.micro.go @@ -1,12 +1,11 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/auth/service/proto/rules/rules.proto +// source: rules.proto package go_micro_auth import ( fmt "fmt" proto "github.com/golang/protobuf/proto" - _ "github.com/micro/go-micro/v2/auth/service/proto/auth" math "math" ) diff --git a/auth/service/proto/rules/rules.proto b/auth/service/proto/rules.proto similarity index 90% rename from auth/service/proto/rules/rules.proto rename to auth/service/proto/rules.proto index d4937b51..cc941952 100644 --- a/auth/service/proto/rules/rules.proto +++ b/auth/service/proto/rules.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package go.micro.auth; -import "github.com/micro/go-micro/auth/service/proto/auth/auth.proto"; +import "auth.proto"; service Rules { rpc Create(CreateRequest) returns (CreateResponse) {}; diff --git a/auth/service/service.go b/auth/service/service.go index a30e3498..21d918c7 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -8,8 +8,7 @@ import ( "time" "github.com/micro/go-micro/v2/auth" - authPb "github.com/micro/go-micro/v2/auth/service/proto/auth" - rulePb "github.com/micro/go-micro/v2/auth/service/proto/rules" + pb "github.com/micro/go-micro/v2/auth/service/proto" "github.com/micro/go-micro/v2/auth/token" "github.com/micro/go-micro/v2/auth/token/jwt" "github.com/micro/go-micro/v2/client" @@ -27,11 +26,11 @@ func NewAuth(opts ...auth.Option) auth.Auth { // svc is the service implementation of the Auth interface type svc struct { options auth.Options - auth authPb.AuthService - rule rulePb.RulesService + auth pb.AuthService + rule pb.RulesService jwt token.Provider - rules []*rulePb.Rule + rules []*pb.Rule sync.Mutex } @@ -45,8 +44,8 @@ func (s *svc) Init(opts ...auth.Option) { } dc := client.DefaultClient - s.auth = authPb.NewAuthService("go.micro.auth", dc) - s.rule = rulePb.NewRulesService("go.micro.auth", dc) + s.auth = pb.NewAuthService("go.micro.auth", dc) + s.rule = pb.NewRulesService("go.micro.auth", dc) // if we have a JWT public key passed as an option, // we can decode tokens with the type "JWT" locally @@ -81,7 +80,7 @@ func (s *svc) Options() auth.Options { func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { options := auth.NewGenerateOptions(opts...) - rsp, err := s.auth.Generate(context.TODO(), &authPb.GenerateRequest{ + rsp, err := s.auth.Generate(context.TODO(), &pb.GenerateRequest{ Id: id, Roles: options.Roles, Metadata: options.Metadata, @@ -97,10 +96,10 @@ func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e // Grant access to a resource func (s *svc) Grant(role string, res *auth.Resource) error { - _, err := s.rule.Create(context.TODO(), &rulePb.CreateRequest{ + _, err := s.rule.Create(context.TODO(), &pb.CreateRequest{ Role: role, - Access: rulePb.Access_GRANTED, - Resource: &authPb.Resource{ + Access: pb.Access_GRANTED, + Resource: &pb.Resource{ Type: res.Type, Name: res.Name, Endpoint: res.Endpoint, @@ -111,10 +110,10 @@ func (s *svc) Grant(role string, res *auth.Resource) error { // Revoke access to a resource func (s *svc) Revoke(role string, res *auth.Resource) error { - _, err := s.rule.Delete(context.TODO(), &rulePb.DeleteRequest{ + _, err := s.rule.Delete(context.TODO(), &pb.DeleteRequest{ Role: role, - Access: rulePb.Access_GRANTED, - Resource: &authPb.Resource{ + Access: pb.Access_GRANTED, + Resource: &pb.Resource{ Type: res.Type, Name: res.Name, Endpoint: res.Endpoint, @@ -144,12 +143,12 @@ func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { for _, q := range queries { for _, rule := range s.listRules(q...) { switch accessForRule(rule, acc, res) { - case rulePb.Access_UNKNOWN: + case pb.Access_UNKNOWN: continue // rule did not specify access, check the next rule - case rulePb.Access_GRANTED: + case pb.Access_GRANTED: log.Infof("%v granted access to %v:%v:%v by rule %v", acc.ID, res.Type, res.Name, res.Endpoint, rule.Id) return nil // rule grants the account access to the resource - case rulePb.Access_DENIED: + case pb.Access_DENIED: log.Infof("%v denied access to %v:%v:%v by rule %v", acc.ID, res.Type, res.Name, res.Endpoint, rule.Id) return auth.ErrForbidden // rule denies access to the resource } @@ -177,7 +176,7 @@ func (s *svc) Inspect(token string) (*auth.Account, error) { } } - rsp, err := s.auth.Inspect(context.TODO(), &authPb.InspectRequest{ + rsp, err := s.auth.Inspect(context.TODO(), &pb.InspectRequest{ Token: token, }) if err != nil { @@ -191,7 +190,7 @@ func (s *svc) Inspect(token string) (*auth.Account, error) { func (s *svc) Refresh(secret string, opts ...auth.RefreshOption) (*auth.Token, error) { options := auth.NewRefreshOptions(opts...) - rsp, err := s.auth.Refresh(context.Background(), &authPb.RefreshRequest{ + rsp, err := s.auth.Refresh(context.Background(), &pb.RefreshRequest{ Secret: secret, TokenExpiry: int64(options.TokenExpiry.Seconds()), }) @@ -206,7 +205,7 @@ var ruleJoinKey = ":" // accessForRule returns a rule status, indicating if a rule permits access to a // resource for a given account -func accessForRule(rule *rulePb.Rule, acc *auth.Account, res *auth.Resource) rulePb.Access { +func accessForRule(rule *pb.Rule, acc *auth.Account, res *auth.Resource) pb.Access { if rule.Role == "*" { return rule.Access } @@ -222,18 +221,18 @@ func accessForRule(rule *rulePb.Rule, acc *auth.Account, res *auth.Resource) rul } } - return rulePb.Access_UNKNOWN + return pb.Access_UNKNOWN } // listRules gets all the rules from the store which have an id // prefix matching the filters -func (s *svc) listRules(filters ...string) []*rulePb.Rule { +func (s *svc) listRules(filters ...string) []*pb.Rule { s.Lock() defer s.Unlock() prefix := strings.Join(filters, ruleJoinKey) - var rules []*rulePb.Rule + var rules []*pb.Rule for _, r := range s.rules { if strings.HasPrefix(r.Id, prefix) { rules = append(rules, r) @@ -245,7 +244,7 @@ func (s *svc) listRules(filters ...string) []*rulePb.Rule { // loadRules retrieves the rules from the auth service func (s *svc) loadRules() { - rsp, err := s.rule.List(context.TODO(), &rulePb.ListRequest{}) + rsp, err := s.rule.List(context.TODO(), &pb.ListRequest{}) s.Lock() defer s.Unlock() @@ -257,7 +256,7 @@ func (s *svc) loadRules() { s.rules = rsp.Rules } -func serializeToken(t *authPb.Token) *auth.Token { +func serializeToken(t *pb.Token) *auth.Token { return &auth.Token{ Token: t.Token, Type: t.Type, @@ -269,7 +268,7 @@ func serializeToken(t *authPb.Token) *auth.Token { } } -func serializeAccount(a *authPb.Account) *auth.Account { +func serializeAccount(a *pb.Account) *auth.Account { var secret *auth.Token if a.Secret != nil { secret = serializeToken(a.Secret) From 9e6db79860e77bee754d4fbbc57413608b3c2b2e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 30 Mar 2020 23:58:32 +0300 Subject: [PATCH 457/788] regenerate all proto (#1440) * regenerate all proto Signed-off-by: Vasiliy Tolstov * regenerate from proto Signed-off-by: Vasiliy Tolstov * regenerate from proto Signed-off-by: Vasiliy Tolstov --- .github/generate.sh | 9 + agent/proto/bot.pb.go | 167 ++++- agent/proto/bot.pb.micro.go | 8 +- api/proto/api.pb.go | 69 +- api/proto/api.pb.micro.go | 2 +- api/service/proto/api.pb.go | 159 ++++- api/service/proto/api.pb.micro.go | 2 +- auth/service/proto/accounts.pb.go | 117 +++- auth/service/proto/accounts.pb.micro.go | 2 +- auth/service/proto/accounts.proto | 2 +- auth/service/proto/auth.pb.go | 267 ++++++-- auth/service/proto/auth.pb.micro.go | 2 +- auth/service/proto/rules.pb.go | 225 +++++-- auth/service/proto/rules.pb.micro.go | 2 +- auth/service/proto/rules.proto | 2 +- broker/service/proto/broker.pb.go | 203 +++++- broker/service/proto/broker.pb.micro.go | 18 +- client/service/proto/client.pb.go | 244 ++++++- client/service/proto/client.pb.micro.go | 18 +- codec/protorpc/envelope.pb.go | 131 ++-- codec/protorpc/envelope.pb.micro.go | 21 + codec/protorpc/envelope.proto | 12 +- codec/protorpc/protorpc.go | 8 +- config/source/service/proto/service.pb.go | 387 ++++++++++-- .../source/service/proto/service.pb.micro.go | 2 +- debug/service/proto/debug.pb.go | 324 ++++++++-- debug/service/proto/debug.pb.micro.go | 2 +- errors/errors.pb.go | 26 +- errors/errors.pb.micro.go | 21 + generate.go | 3 + go.mod | 1 + go.sum | 4 + network/service/proto/network.pb.go | 413 ++++++++++-- network/service/proto/network.pb.micro.go | 8 +- network/service/proto/network.proto | 2 +- registry/service/proto/registry.pb.go | 374 +++++++++-- registry/service/proto/registry.pb.micro.go | 18 +- router/service/proto/router.pb.go | 593 ++++++++++++++++-- router/service/proto/router.pb.micro.go | 36 +- router/service/proto/router.proto | 115 ++-- runtime/service/proto/runtime.pb.go | 335 ++++++++-- runtime/service/proto/runtime.pb.micro.go | 2 +- server/grpc/proto/test.pb.go | 44 +- .../proto/{test.micro.go => test.pb.micro.go} | 8 +- server/proto/server.pb.go | 165 ++++- server/proto/server.pb.micro.go | 8 +- service/grpc/proto/test.pb.go | 44 +- .../proto/{test.micro.go => test.pb.micro.go} | 8 +- store/etcd/config.go | 2 +- store/service/proto/store.pb.go | 313 +++++++-- store/service/proto/store.pb.micro.go | 2 +- transport/grpc/proto/transport.pb.go | 60 +- ...ansport.micro.go => transport.pb.micro.go} | 20 +- transport/grpc/proto/transport.proto | 2 +- 54 files changed, 4106 insertions(+), 926 deletions(-) create mode 100755 .github/generate.sh create mode 100644 codec/protorpc/envelope.pb.micro.go create mode 100644 errors/errors.pb.micro.go create mode 100644 generate.go rename server/grpc/proto/{test.micro.go => test.pb.micro.go} (93%) rename service/grpc/proto/{test.micro.go => test.pb.micro.go} (93%) rename transport/grpc/proto/{transport.micro.go => transport.pb.micro.go} (92%) diff --git a/.github/generate.sh b/.github/generate.sh new file mode 100755 index 00000000..059277a9 --- /dev/null +++ b/.github/generate.sh @@ -0,0 +1,9 @@ +#!/bin/bash -e + +find . -type f -name '*.pb.*.go' -o -name '*.pb.go' -a ! -name 'message.pb.go' -delete +PROTOS=$(find . -type f -name '*.proto') + +for PROTO in $PROTOS; do + echo $PROTO + protoc -I./ -I$(dirname $PROTO) --go_out=plugins=grpc,paths=source_relative:. --micro_out=paths=source_relative:. $PROTO +done diff --git a/agent/proto/bot.pb.go b/agent/proto/bot.pb.go index db35f945..10fde8f6 100644 --- a/agent/proto/bot.pb.go +++ b/agent/proto/bot.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/v2/agent/proto/bot.proto +// source: agent/proto/bot.proto package go_micro_bot import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -30,7 +34,7 @@ func (m *HelpRequest) Reset() { *m = HelpRequest{} } func (m *HelpRequest) String() string { return proto.CompactTextString(m) } func (*HelpRequest) ProtoMessage() {} func (*HelpRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_018e8d5b14a89d12, []int{0} + return fileDescriptor_79b974b8c77805fa, []int{0} } func (m *HelpRequest) XXX_Unmarshal(b []byte) error { @@ -63,7 +67,7 @@ func (m *HelpResponse) Reset() { *m = HelpResponse{} } func (m *HelpResponse) String() string { return proto.CompactTextString(m) } func (*HelpResponse) ProtoMessage() {} func (*HelpResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_018e8d5b14a89d12, []int{1} + return fileDescriptor_79b974b8c77805fa, []int{1} } func (m *HelpResponse) XXX_Unmarshal(b []byte) error { @@ -109,7 +113,7 @@ func (m *ExecRequest) Reset() { *m = ExecRequest{} } func (m *ExecRequest) String() string { return proto.CompactTextString(m) } func (*ExecRequest) ProtoMessage() {} func (*ExecRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_018e8d5b14a89d12, []int{2} + return fileDescriptor_79b974b8c77805fa, []int{2} } func (m *ExecRequest) XXX_Unmarshal(b []byte) error { @@ -149,7 +153,7 @@ func (m *ExecResponse) Reset() { *m = ExecResponse{} } func (m *ExecResponse) String() string { return proto.CompactTextString(m) } func (*ExecResponse) ProtoMessage() {} func (*ExecResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_018e8d5b14a89d12, []int{3} + return fileDescriptor_79b974b8c77805fa, []int{3} } func (m *ExecResponse) XXX_Unmarshal(b []byte) error { @@ -191,26 +195,139 @@ func init() { proto.RegisterType((*ExecResponse)(nil), "go.micro.bot.ExecResponse") } -func init() { - proto.RegisterFile("github.com/micro/go-micro/v2/agent/proto/bot.proto", fileDescriptor_018e8d5b14a89d12) +func init() { proto.RegisterFile("agent/proto/bot.proto", fileDescriptor_79b974b8c77805fa) } + +var fileDescriptor_79b974b8c77805fa = []byte{ + // 234 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x3f, 0x4f, 0xc3, 0x30, + 0x10, 0xc5, 0x1b, 0x28, 0x45, 0xbd, 0x84, 0xc5, 0x02, 0x14, 0x3a, 0x05, 0x4f, 0x9d, 0x5c, 0x09, + 0x56, 0x24, 0x06, 0x04, 0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4e, 0xfb, 0xfa, 0x1f, 0x00, 0x00, + 0xff, 0xff, 0xe8, 0x08, 0x5e, 0xad, 0x73, 0x01, 0x00, 0x00, } -var fileDescriptor_018e8d5b14a89d12 = []byte{ - // 246 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x50, 0x4d, 0x4b, 0xc4, 0x30, - 0x10, 0xdd, 0xea, 0xba, 0xb2, 0xd3, 0x7a, 0x09, 0x22, 0x75, 0x4f, 0x35, 0xa7, 0xbd, 0x98, 0x80, - 0x5e, 0x05, 0x0f, 0xa2, 0x78, 0xee, 0x3f, 0x68, 0xbb, 0x43, 0x2c, 0x6c, 0x3b, 0x35, 0x99, 0x82, - 0xff, 0xc1, 0x3f, 0x2d, 0x4d, 0x72, 0x08, 0xc5, 0xdb, 0x7b, 0x79, 0xe1, 0x7d, 0x0c, 0x68, 0xd3, - 0xf3, 0xd7, 0xdc, 0xaa, 0x8e, 0x06, 0x3d, 0xf4, 0x9d, 0x25, 0x6d, 0xe8, 0x31, 0x80, 0xc6, 0xe0, - 0xc8, 0x7a, 0xb2, 0xc4, 0xa4, 0x5b, 0x62, 0xe5, 0x91, 0x28, 0x0c, 0x29, 0xaf, 0xab, 0x96, 0x58, - 0xde, 0x40, 0xfe, 0x89, 0xe7, 0xa9, 0xc6, 0xef, 0x19, 0x1d, 0xcb, 0x0f, 0x28, 0x02, 0x75, 0x13, - 0x8d, 0x0e, 0xc5, 0x2d, 0x5c, 0xcd, 0xae, 0x31, 0x58, 0x66, 0x55, 0x76, 0xdc, 0xd7, 0x81, 0x88, - 0x0a, 0xf2, 0x13, 0xba, 0xce, 0xf6, 0x13, 0xf7, 0x34, 0x96, 0x17, 0x5e, 0x4b, 0x9f, 0xe4, 0x03, - 0xe4, 0xef, 0x3f, 0xd8, 0x45, 0x5b, 0x21, 0x60, 0xdb, 0x58, 0xe3, 0xca, 0xac, 0xba, 0x3c, 0xee, - 0x6b, 0x8f, 0xe5, 0x0b, 0x14, 0xe1, 0x4b, 0x8c, 0xba, 0x83, 0x9d, 0x45, 0x37, 0x9f, 0xd9, 0x67, - 0x15, 0x75, 0x64, 0x4b, 0x05, 0xb4, 0x96, 0x6c, 0x8c, 0x09, 0xe4, 0xe9, 0x37, 0x83, 0xeb, 0x37, - 0x1a, 0x86, 0x66, 0x3c, 0x89, 0x57, 0xd8, 0x2e, 0xa5, 0xc5, 0xbd, 0x4a, 0xa7, 0xa9, 0x64, 0xd7, - 0xe1, 0xf0, 0x9f, 0x14, 0x82, 0xe5, 0x66, 0x31, 0x58, 0xaa, 0xac, 0x0d, 0x92, 0x05, 0x6b, 0x83, - 0xb4, 0xb9, 0xdc, 0xb4, 0x3b, 0x7f, 0xda, 0xe7, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x18, 0xbd, - 0x39, 0x29, 0x8d, 0x01, 0x00, 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// CommandClient is the client API for Command service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type CommandClient interface { + Help(ctx context.Context, in *HelpRequest, opts ...grpc.CallOption) (*HelpResponse, error) + Exec(ctx context.Context, in *ExecRequest, opts ...grpc.CallOption) (*ExecResponse, error) +} + +type commandClient struct { + cc *grpc.ClientConn +} + +func NewCommandClient(cc *grpc.ClientConn) CommandClient { + return &commandClient{cc} +} + +func (c *commandClient) Help(ctx context.Context, in *HelpRequest, opts ...grpc.CallOption) (*HelpResponse, error) { + out := new(HelpResponse) + err := c.cc.Invoke(ctx, "/go.micro.bot.Command/Help", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *commandClient) Exec(ctx context.Context, in *ExecRequest, opts ...grpc.CallOption) (*ExecResponse, error) { + out := new(ExecResponse) + err := c.cc.Invoke(ctx, "/go.micro.bot.Command/Exec", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// CommandServer is the server API for Command service. +type CommandServer interface { + Help(context.Context, *HelpRequest) (*HelpResponse, error) + Exec(context.Context, *ExecRequest) (*ExecResponse, error) +} + +// UnimplementedCommandServer can be embedded to have forward compatible implementations. +type UnimplementedCommandServer struct { +} + +func (*UnimplementedCommandServer) Help(ctx context.Context, req *HelpRequest) (*HelpResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Help not implemented") +} +func (*UnimplementedCommandServer) Exec(ctx context.Context, req *ExecRequest) (*ExecResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Exec not implemented") +} + +func RegisterCommandServer(s *grpc.Server, srv CommandServer) { + s.RegisterService(&_Command_serviceDesc, srv) +} + +func _Command_Help_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HelpRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommandServer).Help(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.bot.Command/Help", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommandServer).Help(ctx, req.(*HelpRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Command_Exec_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ExecRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommandServer).Exec(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.bot.Command/Exec", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommandServer).Exec(ctx, req.(*ExecRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Command_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.bot.Command", + HandlerType: (*CommandServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Help", + Handler: _Command_Help_Handler, + }, + { + MethodName: "Exec", + Handler: _Command_Exec_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "agent/proto/bot.proto", } diff --git a/agent/proto/bot.pb.micro.go b/agent/proto/bot.pb.micro.go index 61e678db..60338cda 100644 --- a/agent/proto/bot.pb.micro.go +++ b/agent/proto/bot.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/v2/agent/proto/bot.proto +// source: agent/proto/bot.proto package go_micro_bot @@ -44,12 +44,6 @@ type commandService struct { } func NewCommandService(name string, c client.Client) CommandService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "go.micro.bot" - } return &commandService{ c: c, name: name, diff --git a/api/proto/api.pb.go b/api/proto/api.pb.go index b9dba1fb..e5d88473 100644 --- a/api/proto/api.pb.go +++ b/api/proto/api.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/v2/api/proto/api.proto +// source: api/proto/api.proto package go_api @@ -32,7 +32,7 @@ func (m *Pair) Reset() { *m = Pair{} } func (m *Pair) String() string { return proto.CompactTextString(m) } func (*Pair) ProtoMessage() {} func (*Pair) Descriptor() ([]byte, []int) { - return fileDescriptor_7b6696ef87ec1943, []int{0} + return fileDescriptor_2df576b66d12087a, []int{0} } func (m *Pair) XXX_Unmarshal(b []byte) error { @@ -86,7 +86,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_7b6696ef87ec1943, []int{1} + return fileDescriptor_2df576b66d12087a, []int{1} } func (m *Request) XXX_Unmarshal(b []byte) error { @@ -171,7 +171,7 @@ func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_7b6696ef87ec1943, []int{2} + return fileDescriptor_2df576b66d12087a, []int{2} } func (m *Response) XXX_Unmarshal(b []byte) error { @@ -235,7 +235,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_7b6696ef87ec1943, []int{3} + return fileDescriptor_2df576b66d12087a, []int{3} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -303,36 +303,33 @@ func init() { proto.RegisterMapType((map[string]*Pair)(nil), "go.api.Event.HeaderEntry") } -func init() { - proto.RegisterFile("github.com/micro/go-micro/v2/api/proto/api.proto", fileDescriptor_7b6696ef87ec1943) -} +func init() { proto.RegisterFile("api/proto/api.proto", fileDescriptor_2df576b66d12087a) } -var fileDescriptor_7b6696ef87ec1943 = []byte{ - // 408 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0x4d, 0x8f, 0xd3, 0x30, - 0x10, 0x55, 0xe2, 0x24, 0xbb, 0x99, 0x22, 0x84, 0x7c, 0x40, 0x66, 0x59, 0xa1, 0x2a, 0xa7, 0x0a, - 0xa9, 0x29, 0xec, 0x72, 0x40, 0x5c, 0xa1, 0x5a, 0x8e, 0x2b, 0xff, 0x03, 0x77, 0x63, 0x25, 0x16, - 0x4d, 0x1c, 0x62, 0xa7, 0x52, 0x7f, 0x1c, 0x07, 0x7e, 0x06, 0xff, 0x06, 0x79, 0xec, 0x7e, 0x50, - 0x95, 0x0b, 0xf4, 0xf6, 0x62, 0xbf, 0x79, 0xf3, 0xe6, 0x8d, 0x03, 0xf3, 0x5a, 0xd9, 0x66, 0x5c, - 0x95, 0x4f, 0xba, 0x5d, 0xb4, 0xea, 0x69, 0xd0, 0x8b, 0x5a, 0xcf, 0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 0x9d, 0xdd, 0xff, 0x50, 0x59, 0x42, 0xbe, 0x9f, 0xe3, 0xdf, 0x65, 0x8a, 0x1f, - 0x11, 0x5c, 0x73, 0x69, 0x7a, 0xdd, 0x19, 0x49, 0xdf, 0x00, 0x18, 0x2b, 0xec, 0x68, 0x3e, 0xeb, - 0x4a, 0xa2, 0x5a, 0xca, 0x8f, 0x4e, 0xe8, 0x87, 0xfd, 0xe2, 0x62, 0x4c, 0xf6, 0xf6, 0x90, 0xac, - 0x57, 0x38, 0xbb, 0xb9, 0x5d, 0xbc, 0xe4, 0x10, 0xef, 0xc5, 0xc2, 0x2c, 0x7e, 0x45, 0x90, 0x2e, - 0x37, 0xb2, 0xc3, 0x2d, 0x76, 0xa2, 0x95, 0x41, 0x04, 0x31, 0x7d, 0x0e, 0xb1, 0xaa, 0xc2, 0xdb, - 0x8b, 0x55, 0x45, 0x6f, 0x21, 0xb7, 0xaa, 0x95, 0xc6, 0x8a, 0xb6, 0x47, 0x3f, 0x84, 0x1f, 0x0e, - 0xe8, 0xfb, 0xfd, 0x78, 0xc9, 0x9f, 0x0f, 0x07, 0x1b, 0xfc, 0x6d, 0xb6, 0x4a, 0x58, 0xc1, 0x52, - 0xdf, 0xd4, 0xe1, 0x8b, 0xcd, 0xb6, 0xca, 0xf0, 0x07, 0xbd, 0xff, 0x1d, 0x00, 0x00, 0xff, 0xff, - 0x97, 0xf3, 0x59, 0x6e, 0xd1, 0x03, 0x00, 0x00, +var fileDescriptor_2df576b66d12087a = []byte{ + // 393 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0xcd, 0xce, 0xd3, 0x30, + 0x10, 0x54, 0xe2, 0x24, 0x6d, 0xb6, 0x08, 0x21, 0x23, 0x21, 0x53, 0x2a, 0x54, 0xe5, 0x54, 0x21, + 0x91, 0x42, 0xcb, 0x01, 0x71, 0x85, 0xaa, 0x1c, 0x2b, 0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, + 0xd9, 0xb1, 0x5e, 0x97, 0x42, 0xdb, 0xec, 0x86, 0x4b, 0x18, 0x5c, 0xf8, 0xba, 0x11, 0x53, 0x06, + 0x31, 0x06, 0x83, 0xb3, 0x0e, 0x66, 0x2f, 0x8e, 0x6d, 0x5d, 0xaa, 0xbc, 0xbb, 0xfa, 0x16, 0x7e, + 0x0d, 0x86, 0x3f, 0xa0, 0x7f, 0xb4, 0xfb, 0x0c, 0x95, 0x05, 0xa4, 0xa7, 0x39, 0x9e, 0x2e, 0x93, + 0xfd, 0x09, 0xa0, 0xcf, 0xa5, 0xd1, 0xaa, 0x36, 0x92, 0xbe, 0x07, 0x30, 0x56, 0xd8, 0xd6, 0x7c, + 0x57, 0x85, 0x44, 0xb5, 0x98, 0x5f, 0x9c, 0xd0, 0x2f, 0xa7, 0xc5, 0x85, 0x98, 0xec, 0xe8, 0x9c, + 0x6c, 0xa7, 0x70, 0x73, 0x73, 0xc7, 0x78, 0xc9, 0x39, 0xde, 0xbb, 0x85, 0x99, 0xfd, 0x0b, 0x20, + 0x5e, 0xec, 0x65, 0x8d, 0x5b, 0xac, 0x45, 0x25, 0xbd, 0x08, 0x62, 0xfa, 0x12, 0xc2, 0xb2, 0xf0, + 0x6f, 0x2f, 0x2c, 0x0b, 0x3a, 0x82, 0xd4, 0x96, 0x95, 0x34, 0x56, 0x54, 0x1a, 0xfd, 0x10, 0x7e, + 0x3e, 0xa0, 0x9f, 0x4f, 0xe3, 0x45, 0x0f, 0x1f, 0x0e, 0x36, 0x78, 0x6c, 0xb6, 0x42, 0x58, 0xc1, + 0xe2, 0xae, 0xa9, 0xc3, 0x77, 0x9b, 0x6d, 0x9d, 0xe0, 0x0f, 0x3a, 0xff, 0x1f, 0x00, 0x00, 0xff, + 0xff, 0xd4, 0x6d, 0x70, 0x51, 0xb7, 0x03, 0x00, 0x00, } diff --git a/api/proto/api.pb.micro.go b/api/proto/api.pb.micro.go index 494a7ce5..9b91e09d 100644 --- a/api/proto/api.pb.micro.go +++ b/api/proto/api.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/v2/api/proto/api.proto +// source: api/proto/api.proto package go_api diff --git a/api/service/proto/api.pb.go b/api/service/proto/api.pb.go index b643fd79..7cdff499 100644 --- a/api/service/proto/api.pb.go +++ b/api/service/proto/api.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: api.proto +// source: api/service/proto/api.proto package go_micro_api import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -35,7 +39,7 @@ func (m *Endpoint) Reset() { *m = Endpoint{} } func (m *Endpoint) String() string { return proto.CompactTextString(m) } func (*Endpoint) ProtoMessage() {} func (*Endpoint) Descriptor() ([]byte, []int) { - return fileDescriptor_00212fb1f9d3bf1c, []int{0} + return fileDescriptor_c4a48b6b680b5c31, []int{0} } func (m *Endpoint) XXX_Unmarshal(b []byte) error { @@ -101,7 +105,7 @@ func (m *EmptyResponse) Reset() { *m = EmptyResponse{} } func (m *EmptyResponse) String() string { return proto.CompactTextString(m) } func (*EmptyResponse) ProtoMessage() {} func (*EmptyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_00212fb1f9d3bf1c, []int{1} + return fileDescriptor_c4a48b6b680b5c31, []int{1} } func (m *EmptyResponse) XXX_Unmarshal(b []byte) error { @@ -127,23 +131,138 @@ func init() { proto.RegisterType((*EmptyResponse)(nil), "go.micro.api.EmptyResponse") } -func init() { - proto.RegisterFile("api.proto", fileDescriptor_00212fb1f9d3bf1c) +func init() { proto.RegisterFile("api/service/proto/api.proto", fileDescriptor_c4a48b6b680b5c31) } + +var fileDescriptor_c4a48b6b680b5c31 = []byte{ + // 212 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff,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, + 0x92, 0x8f, 0x75, 0xfd, 0xd6, 0xeb, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x46, 0x62, 0x67, 0x30, + 0x4c, 0x01, 0x00, 0x00, } -var fileDescriptor_00212fb1f9d3bf1c = []byte{ - // 201 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0xd0, 0x41, 0x4a, 0xc5, 0x30, - 0x10, 0x06, 0x60, 0x63, 0x9f, 0x8f, 0xbe, 0x41, 0x11, 0xb2, 0x78, 0x04, 0xdd, 0x94, 0xae, 0xde, - 0x2a, 0x0b, 0x3d, 0x41, 0xd1, 0x5e, 0x20, 0x37, 0x88, 0x76, 0x68, 0xb3, 0x48, 0x66, 0x48, 0x06, - 0xc1, 0x43, 0x78, 0x67, 0x49, 0xad, 0x50, 0xdc, 0xba, 0xfb, 0xe7, 0x5b, 0xfc, 0xfc, 0x0c, 0x9c, - 0x3c, 0x07, 0xcb, 0x99, 0x84, 0xf4, 0xed, 0x4c, 0x36, 0x86, 0xf7, 0x4c, 0xd6, 0x73, 0xe8, 0x3f, - 0xa0, 0x1d, 0xd3, 0xc4, 0x14, 0x92, 0x68, 0x0d, 0x87, 0xe4, 0x23, 0x1a, 0xd5, 0xa9, 0xcb, 0xc9, - 0xad, 0xb9, 0xda, 0x42, 0x45, 0xcc, 0x75, 0xd7, 0x54, 0xab, 0xb9, 0x1a, 0x7b, 0x59, 0x4c, 0xf3, - 0x63, 0x35, 0xeb, 0x33, 0x1c, 0x23, 0xca, 0x42, 0x93, 0x39, 0xac, 0xba, 0x5d, 0xd5, 0x8b, 0x64, - 0xf4, 0xd1, 0xdc, 0x74, 0xea, 0xd2, 0xba, 0xed, 0xea, 0xef, 0xe1, 0x6e, 0x8c, 0x2c, 0x9f, 0x0e, - 0x0b, 0x53, 0x2a, 0xf8, 0xf4, 0xa5, 0xa0, 0x19, 0x38, 0xe8, 0x01, 0x5a, 0x87, 0x73, 0x28, 0x82, - 0x59, 0x9f, 0xed, 0x7e, 0xab, 0xfd, 0x1d, 0xfa, 0xf0, 0xf8, 0xc7, 0xf7, 0x45, 0xfd, 0x95, 0x7e, - 0x01, 0x78, 0xc5, 0xfc, 0xbf, 0x92, 0xb7, 0xe3, 0xfa, 0xad, 0xe7, 0xef, 0x00, 0x00, 0x00, 0xff, - 0xff, 0x1f, 0xf0, 0xd9, 0x19, 0x3a, 0x01, 0x00, 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// ApiClient is the client API for Api service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ApiClient interface { + Register(ctx context.Context, in *Endpoint, opts ...grpc.CallOption) (*EmptyResponse, error) + Deregister(ctx context.Context, in *Endpoint, opts ...grpc.CallOption) (*EmptyResponse, error) +} + +type apiClient struct { + cc *grpc.ClientConn +} + +func NewApiClient(cc *grpc.ClientConn) ApiClient { + return &apiClient{cc} +} + +func (c *apiClient) Register(ctx context.Context, in *Endpoint, opts ...grpc.CallOption) (*EmptyResponse, error) { + out := new(EmptyResponse) + err := c.cc.Invoke(ctx, "/go.micro.api.Api/Register", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *apiClient) Deregister(ctx context.Context, in *Endpoint, opts ...grpc.CallOption) (*EmptyResponse, error) { + out := new(EmptyResponse) + err := c.cc.Invoke(ctx, "/go.micro.api.Api/Deregister", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ApiServer is the server API for Api service. +type ApiServer interface { + Register(context.Context, *Endpoint) (*EmptyResponse, error) + Deregister(context.Context, *Endpoint) (*EmptyResponse, error) +} + +// UnimplementedApiServer can be embedded to have forward compatible implementations. +type UnimplementedApiServer struct { +} + +func (*UnimplementedApiServer) Register(ctx context.Context, req *Endpoint) (*EmptyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Register not implemented") +} +func (*UnimplementedApiServer) Deregister(ctx context.Context, req *Endpoint) (*EmptyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Deregister not implemented") +} + +func RegisterApiServer(s *grpc.Server, srv ApiServer) { + s.RegisterService(&_Api_serviceDesc, srv) +} + +func _Api_Register_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Endpoint) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ApiServer).Register(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.api.Api/Register", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ApiServer).Register(ctx, req.(*Endpoint)) + } + return interceptor(ctx, in, info, handler) +} + +func _Api_Deregister_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Endpoint) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ApiServer).Deregister(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.api.Api/Deregister", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ApiServer).Deregister(ctx, req.(*Endpoint)) + } + return interceptor(ctx, in, info, handler) +} + +var _Api_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.api.Api", + HandlerType: (*ApiServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Register", + Handler: _Api_Register_Handler, + }, + { + MethodName: "Deregister", + Handler: _Api_Deregister_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "api/service/proto/api.proto", } diff --git a/api/service/proto/api.pb.micro.go b/api/service/proto/api.pb.micro.go index 6754bcca..301b7c55 100644 --- a/api/service/proto/api.pb.micro.go +++ b/api/service/proto/api.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: api.proto +// source: api/service/proto/api.proto package go_micro_api diff --git a/auth/service/proto/accounts.pb.go b/auth/service/proto/accounts.pb.go index f389386c..5d7a415c 100644 --- a/auth/service/proto/accounts.pb.go +++ b/auth/service/proto/accounts.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: accounts.proto +// source: auth/service/proto/accounts.proto package go_micro_auth import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -30,7 +34,7 @@ func (m *ListAccountsRequest) Reset() { *m = ListAccountsRequest{} } func (m *ListAccountsRequest) String() string { return proto.CompactTextString(m) } func (*ListAccountsRequest) ProtoMessage() {} func (*ListAccountsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_e1e7723af4c007b7, []int{0} + return fileDescriptor_fdbfb9fc95541122, []int{0} } func (m *ListAccountsRequest) XXX_Unmarshal(b []byte) error { @@ -62,7 +66,7 @@ func (m *ListAccountsResponse) Reset() { *m = ListAccountsResponse{} } func (m *ListAccountsResponse) String() string { return proto.CompactTextString(m) } func (*ListAccountsResponse) ProtoMessage() {} func (*ListAccountsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_e1e7723af4c007b7, []int{1} + return fileDescriptor_fdbfb9fc95541122, []int{1} } func (m *ListAccountsResponse) XXX_Unmarshal(b []byte) error { @@ -95,20 +99,99 @@ func init() { proto.RegisterType((*ListAccountsResponse)(nil), "go.micro.auth.ListAccountsResponse") } -func init() { - proto.RegisterFile("accounts.proto", fileDescriptor_e1e7723af4c007b7) +func init() { proto.RegisterFile("auth/service/proto/accounts.proto", fileDescriptor_fdbfb9fc95541122) } + +var fileDescriptor_fdbfb9fc95541122 = []byte{ + // 164 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4c, 0x2c, 0x2d, 0xc9, + 0xd0, 0x2f, 0x4e, 0x2d, 0x2a, 0xcb, 0x4c, 0x4e, 0xd5, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x4f, + 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0x29, 0xd6, 0x03, 0x73, 0x85, 0x78, 0xd3, 0xf3, 0xf5, 0x72, + 0x33, 0x93, 0x8b, 0xf2, 0xf5, 0x40, 0x6a, 0xa5, 0x64, 0xb1, 0xe9, 0x28, 0x2d, 0xc9, 0x80, 0xa8, + 0x56, 0x12, 0xe5, 0x12, 0xf6, 0xc9, 0x2c, 0x2e, 0x71, 0x84, 0x9a, 0x11, 0x94, 0x5a, 0x58, 0x9a, + 0x5a, 0x5c, 0xa2, 0xe4, 0xc5, 0x25, 0x82, 0x2a, 0x5c, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x2a, 0x64, + 0xc4, 0xc5, 0x01, 0xb3, 0x4e, 0x82, 0x51, 0x81, 0x59, 0x83, 0xdb, 0x48, 0x4c, 0x0f, 0xc5, 0x3e, + 0x3d, 0xa8, 0x96, 0x20, 0xb8, 0x3a, 0xa3, 0x58, 0x2e, 0x0e, 0x98, 0x39, 0x42, 0x81, 0x5c, 0x2c, + 0x20, 0x73, 0x85, 0x94, 0xd0, 0x74, 0x61, 0x71, 0x83, 0x94, 0x32, 0x5e, 0x35, 0x10, 0x07, 0x29, + 0x31, 0x24, 0xb1, 0x81, 0x3d, 0x62, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x82, 0x00, 0x19, 0x2f, + 0x1b, 0x01, 0x00, 0x00, } -var fileDescriptor_e1e7723af4c007b7 = []byte{ - // 147 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0x4c, 0x4e, 0xce, - 0x2f, 0xcd, 0x2b, 0x29, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x4d, 0xcf, 0xd7, 0xcb, - 0xcd, 0x4c, 0x2e, 0xca, 0xd7, 0x4b, 0x2c, 0x2d, 0xc9, 0x90, 0xe2, 0x02, 0x91, 0x10, 0x29, 0x25, - 0x51, 0x2e, 0x61, 0x9f, 0xcc, 0xe2, 0x12, 0x47, 0xa8, 0x86, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2, - 0x12, 0x25, 0x2f, 0x2e, 0x11, 0x54, 0xe1, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x21, 0x23, 0x2e, - 0x0e, 0x98, 0xd9, 0x12, 0x8c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0x62, 0x7a, 0x28, 0x86, 0xeb, 0x41, - 0xb5, 0x04, 0xc1, 0xd5, 0x19, 0xc5, 0x72, 0x71, 0xc0, 0xcc, 0x11, 0x0a, 0xe4, 0x62, 0x01, 0x99, - 0x2b, 0xa4, 0x84, 0xa6, 0x0b, 0x8b, 0x1b, 0xa4, 0x94, 0xf1, 0xaa, 0x81, 0x38, 0x48, 0x89, 0x21, - 0x89, 0x0d, 0xec, 0x11, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb4, 0xbb, 0xf1, 0x10, 0xf5, - 0x00, 0x00, 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// AccountsClient is the client API for Accounts service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type AccountsClient interface { + List(ctx context.Context, in *ListAccountsRequest, opts ...grpc.CallOption) (*ListAccountsResponse, error) +} + +type accountsClient struct { + cc *grpc.ClientConn +} + +func NewAccountsClient(cc *grpc.ClientConn) AccountsClient { + return &accountsClient{cc} +} + +func (c *accountsClient) List(ctx context.Context, in *ListAccountsRequest, opts ...grpc.CallOption) (*ListAccountsResponse, error) { + out := new(ListAccountsResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Accounts/List", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// AccountsServer is the server API for Accounts service. +type AccountsServer interface { + List(context.Context, *ListAccountsRequest) (*ListAccountsResponse, error) +} + +// UnimplementedAccountsServer can be embedded to have forward compatible implementations. +type UnimplementedAccountsServer struct { +} + +func (*UnimplementedAccountsServer) List(ctx context.Context, req *ListAccountsRequest) (*ListAccountsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method List not implemented") +} + +func RegisterAccountsServer(s *grpc.Server, srv AccountsServer) { + s.RegisterService(&_Accounts_serviceDesc, srv) +} + +func _Accounts_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListAccountsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountsServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Accounts/List", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountsServer).List(ctx, req.(*ListAccountsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Accounts_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.auth.Accounts", + HandlerType: (*AccountsServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "List", + Handler: _Accounts_List_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "auth/service/proto/accounts.proto", } diff --git a/auth/service/proto/accounts.pb.micro.go b/auth/service/proto/accounts.pb.micro.go index 56408164..d83f2a9f 100644 --- a/auth/service/proto/accounts.pb.micro.go +++ b/auth/service/proto/accounts.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: accounts.proto +// source: auth/service/proto/accounts.proto package go_micro_auth diff --git a/auth/service/proto/accounts.proto b/auth/service/proto/accounts.proto index 47143693..77967b51 100644 --- a/auth/service/proto/accounts.proto +++ b/auth/service/proto/accounts.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package go.micro.auth; -import "auth.proto"; +import "auth/service/proto/auth.proto"; service Accounts { rpc List(ListAccountsRequest) returns (ListAccountsResponse) {}; diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index df741fe8..7d7d2ab5 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: auth.proto +// source: auth/service/proto/auth.proto package go_micro_auth import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -38,7 +42,7 @@ func (m *Token) Reset() { *m = Token{} } func (m *Token) String() string { return proto.CompactTextString(m) } func (*Token) ProtoMessage() {} func (*Token) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{0} + return fileDescriptor_21300bfacc51fc2a, []int{0} } func (m *Token) XXX_Unmarshal(b []byte) error { @@ -130,7 +134,7 @@ func (m *Account) Reset() { *m = Account{} } func (m *Account) String() string { return proto.CompactTextString(m) } func (*Account) ProtoMessage() {} func (*Account) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{1} + return fileDescriptor_21300bfacc51fc2a, []int{1} } func (m *Account) XXX_Unmarshal(b []byte) error { @@ -199,7 +203,7 @@ func (m *Resource) Reset() { *m = Resource{} } func (m *Resource) String() string { return proto.CompactTextString(m) } func (*Resource) ProtoMessage() {} func (*Resource) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{2} + return fileDescriptor_21300bfacc51fc2a, []int{2} } func (m *Resource) XXX_Unmarshal(b []byte) error { @@ -256,7 +260,7 @@ func (m *GenerateRequest) Reset() { *m = GenerateRequest{} } func (m *GenerateRequest) String() string { return proto.CompactTextString(m) } func (*GenerateRequest) ProtoMessage() {} func (*GenerateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{3} + return fileDescriptor_21300bfacc51fc2a, []int{3} } func (m *GenerateRequest) XXX_Unmarshal(b []byte) error { @@ -323,7 +327,7 @@ func (m *GenerateResponse) Reset() { *m = GenerateResponse{} } func (m *GenerateResponse) String() string { return proto.CompactTextString(m) } func (*GenerateResponse) ProtoMessage() {} func (*GenerateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{4} + return fileDescriptor_21300bfacc51fc2a, []int{4} } func (m *GenerateResponse) XXX_Unmarshal(b []byte) error { @@ -363,7 +367,7 @@ func (m *GrantRequest) Reset() { *m = GrantRequest{} } func (m *GrantRequest) String() string { return proto.CompactTextString(m) } func (*GrantRequest) ProtoMessage() {} func (*GrantRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{5} + return fileDescriptor_21300bfacc51fc2a, []int{5} } func (m *GrantRequest) XXX_Unmarshal(b []byte) error { @@ -408,7 +412,7 @@ func (m *GrantResponse) Reset() { *m = GrantResponse{} } func (m *GrantResponse) String() string { return proto.CompactTextString(m) } func (*GrantResponse) ProtoMessage() {} func (*GrantResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{6} + return fileDescriptor_21300bfacc51fc2a, []int{6} } func (m *GrantResponse) XXX_Unmarshal(b []byte) error { @@ -441,7 +445,7 @@ func (m *RevokeRequest) Reset() { *m = RevokeRequest{} } func (m *RevokeRequest) String() string { return proto.CompactTextString(m) } func (*RevokeRequest) ProtoMessage() {} func (*RevokeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{7} + return fileDescriptor_21300bfacc51fc2a, []int{7} } func (m *RevokeRequest) XXX_Unmarshal(b []byte) error { @@ -486,7 +490,7 @@ func (m *RevokeResponse) Reset() { *m = RevokeResponse{} } func (m *RevokeResponse) String() string { return proto.CompactTextString(m) } func (*RevokeResponse) ProtoMessage() {} func (*RevokeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{8} + return fileDescriptor_21300bfacc51fc2a, []int{8} } func (m *RevokeResponse) XXX_Unmarshal(b []byte) error { @@ -518,7 +522,7 @@ func (m *InspectRequest) Reset() { *m = InspectRequest{} } func (m *InspectRequest) String() string { return proto.CompactTextString(m) } func (*InspectRequest) ProtoMessage() {} func (*InspectRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{9} + return fileDescriptor_21300bfacc51fc2a, []int{9} } func (m *InspectRequest) XXX_Unmarshal(b []byte) error { @@ -557,7 +561,7 @@ func (m *InspectResponse) Reset() { *m = InspectResponse{} } func (m *InspectResponse) String() string { return proto.CompactTextString(m) } func (*InspectResponse) ProtoMessage() {} func (*InspectResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{10} + return fileDescriptor_21300bfacc51fc2a, []int{10} } func (m *InspectResponse) XXX_Unmarshal(b []byte) error { @@ -597,7 +601,7 @@ func (m *RefreshRequest) Reset() { *m = RefreshRequest{} } func (m *RefreshRequest) String() string { return proto.CompactTextString(m) } func (*RefreshRequest) ProtoMessage() {} func (*RefreshRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{11} + return fileDescriptor_21300bfacc51fc2a, []int{11} } func (m *RefreshRequest) XXX_Unmarshal(b []byte) error { @@ -643,7 +647,7 @@ func (m *RefreshResponse) Reset() { *m = RefreshResponse{} } func (m *RefreshResponse) String() string { return proto.CompactTextString(m) } func (*RefreshResponse) ProtoMessage() {} func (*RefreshResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8bbd6f3875b0e874, []int{12} + return fileDescriptor_21300bfacc51fc2a, []int{12} } func (m *RefreshResponse) XXX_Unmarshal(b []byte) error { @@ -690,48 +694,199 @@ func init() { proto.RegisterType((*RefreshResponse)(nil), "go.micro.auth.RefreshResponse") } -func init() { - proto.RegisterFile("auth.proto", fileDescriptor_8bbd6f3875b0e874) +func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } + +var fileDescriptor_21300bfacc51fc2a = []byte{ + // 612 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0xae, 0xed, 0xfc, 0xb8, 0x93, 0x5f, 0xad, 0xaa, 0x60, 0x45, 0xb4, 0x04, 0x83, 0x50, 0x84, + 0x2a, 0x07, 0xa5, 0x17, 0x04, 0x02, 0x51, 0x41, 0x55, 0x7e, 0x54, 0x0e, 0x16, 0x12, 0xdc, 0x90, + 0xeb, 0x0c, 0xc4, 0xa4, 0xb1, 0xcd, 0x7a, 0x1d, 0x91, 0x23, 0x2f, 0xc4, 0x9b, 0xf1, 0x02, 0x9c, + 0xd0, 0xae, 0x77, 0x1d, 0xc7, 0x49, 0x10, 0x42, 0xe5, 0x36, 0x33, 0x3b, 0xf3, 0xcd, 0xcc, 0x37, + 0x5f, 0x1c, 0x38, 0xf4, 0x52, 0x36, 0x1d, 0x25, 0x48, 0x17, 0x81, 0x8f, 0xa3, 0x98, 0x46, 0x2c, + 0x1a, 0xf1, 0x90, 0x23, 0x4c, 0xd2, 0xfa, 0x1c, 0x39, 0xf3, 0xc0, 0xa7, 0x91, 0xc3, 0x83, 0xf6, + 0x0f, 0x1d, 0xaa, 0xef, 0xa2, 0x19, 0x86, 0xe4, 0x00, 0xaa, 0x8c, 0x1b, 0x96, 0x36, 0xd0, 0x86, + 0xfb, 0x6e, 0xe6, 0x10, 0x02, 0x15, 0xb6, 0x8c, 0xd1, 0xd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0xc1, + 0x74, 0x31, 0x89, 0x52, 0xea, 0x23, 0x57, 0x06, 0x47, 0x95, 0x85, 0xc2, 0xde, 0xaa, 0x96, 0x3e, + 0x98, 0x18, 0x4e, 0xe2, 0x28, 0x08, 0x99, 0x90, 0xcb, 0xbe, 0x9b, 0xfb, 0xf6, 0x77, 0x1d, 0x3a, + 0xe7, 0x18, 0x22, 0xf5, 0x18, 0xba, 0xf8, 0x35, 0xc5, 0x64, 0x93, 0xd4, 0x9c, 0x26, 0xbd, 0x48, + 0xd3, 0xcb, 0x02, 0x4d, 0x86, 0xa0, 0xe9, 0xb8, 0x44, 0x53, 0x09, 0x77, 0x27, 0x5d, 0x77, 0xa0, + 0x95, 0x1d, 0xe4, 0xe3, 0x9a, 0x74, 0x9b, 0x59, 0xf0, 0x2c, 0x13, 0xf0, 0x7f, 0xe4, 0xf4, 0x05, + 0x74, 0x57, 0xa3, 0x26, 0x71, 0x14, 0x26, 0x48, 0x1e, 0x40, 0xdd, 0xcb, 0xae, 0x2c, 0x30, 0x1a, + 0xe3, 0xde, 0x76, 0x0d, 0xb8, 0x2a, 0xcd, 0x7e, 0x0f, 0xcd, 0x73, 0xea, 0x85, 0x4c, 0xb1, 0x48, + 0xa0, 0xc2, 0x89, 0x52, 0xd7, 0xe1, 0x36, 0x39, 0x01, 0x93, 0xca, 0xeb, 0x49, 0x81, 0xde, 0x28, + 0xc1, 0xaa, 0xe3, 0xba, 0x79, 0xa2, 0xdd, 0x81, 0x96, 0x04, 0xce, 0x66, 0xb3, 0x3f, 0x40, 0xcb, + 0xc5, 0x45, 0x34, 0xc3, 0x6b, 0x6f, 0xd5, 0x85, 0xb6, 0x42, 0x96, 0xbd, 0xee, 0x41, 0xfb, 0x55, + 0x98, 0xc4, 0xe8, 0xe7, 0x7b, 0x6d, 0xfd, 0x4a, 0xd9, 0xcf, 0xa1, 0x93, 0xe7, 0xfd, 0x33, 0x85, + 0x6f, 0x78, 0xfb, 0x4f, 0x14, 0x93, 0xa9, 0x6a, 0xd6, 0xcb, 0x7f, 0xcf, 0x59, 0x37, 0xf5, 0xcb, + 0xbd, 0x0d, 0x4d, 0xd1, 0x57, 0x29, 0x46, 0x17, 0x8a, 0x69, 0x88, 0x58, 0x26, 0x18, 0xfb, 0x09, + 0x74, 0x72, 0x30, 0x39, 0xd1, 0xfd, 0xe2, 0xe8, 0xbb, 0x3e, 0x0e, 0x59, 0xca, 0xf8, 0xa7, 0x06, + 0x95, 0xd3, 0x94, 0x4d, 0xc9, 0x05, 0x98, 0x4a, 0x1d, 0xe4, 0xe8, 0xcf, 0x0a, 0xef, 0xdf, 0xda, + 0xf9, 0x2e, 0xe9, 0xdc, 0x23, 0xaf, 0xa1, 0x2e, 0x89, 0x22, 0x87, 0xa5, 0xec, 0x75, 0xa2, 0xfb, + 0x47, 0xbb, 0x9e, 0x8b, 0x58, 0x72, 0xc5, 0x0d, 0xac, 0x75, 0x1e, 0x37, 0xb0, 0x4a, 0xcc, 0xd8, + 0x7b, 0x97, 0x35, 0xf1, 0xe7, 0x74, 0xf2, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xa8, 0xe4, 0x21, 0xa9, + 0xbd, 0x06, 0x00, 0x00, } -var fileDescriptor_8bbd6f3875b0e874 = []byte{ - // 601 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x4d, 0x6f, 0xd3, 0x40, - 0x10, 0xad, 0xed, 0x7c, 0x38, 0x93, 0x4f, 0xad, 0xaa, 0x60, 0x45, 0x50, 0x82, 0x41, 0x28, 0x42, - 0x95, 0x85, 0xd2, 0x0b, 0x02, 0x81, 0xa8, 0xa0, 0x2a, 0x1f, 0x2a, 0x07, 0x0b, 0x09, 0x6e, 0xc8, - 0x75, 0x06, 0x12, 0xd2, 0x78, 0xcd, 0x7a, 0x5d, 0x91, 0x23, 0x7f, 0x88, 0x7f, 0xc6, 0x1f, 0xe0, - 0x84, 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xb5, - 0x3d, 0x65, 0xd0, 0x1b, 0x25, 0x58, 0xbd, 0x5c, 0x3f, 0x4f, 0x74, 0xbb, 0xd0, 0x56, 0xc0, 0xd9, - 0x6c, 0xee, 0x47, 0x68, 0xfb, 0x78, 0x49, 0xe7, 0x78, 0xe5, 0xad, 0x7a, 0xd0, 0xd1, 0xc8, 0xaa, - 0xd7, 0x7d, 0xe8, 0xbc, 0x8e, 0x92, 0x18, 0xc3, 0x9c, 0xd7, 0xd6, 0xaf, 0x94, 0xfb, 0x02, 0xba, - 0x79, 0xde, 0x7f, 0x4b, 0xf8, 0x56, 0xb4, 0xff, 0xcc, 0x30, 0x99, 0xea, 0x66, 0xfd, 0xfc, 0xf7, - 0x9c, 0x75, 0xd3, 0xbf, 0xdc, 0x3b, 0xd0, 0x92, 0x7d, 0xb5, 0x63, 0x4c, 0xe9, 0x98, 0xa6, 0xbc, - 0xcb, 0x0c, 0xe3, 0x3e, 0x85, 0x6e, 0x0e, 0xa6, 0x26, 0x7a, 0x50, 0x1c, 0x7d, 0xd7, 0xc7, 0x21, - 0x4b, 0x19, 0xff, 0x32, 0xa0, 0x72, 0x9c, 0xf2, 0x29, 0x39, 0x03, 0x5b, 0xbb, 0x83, 0x1c, 0xfc, - 0xdd, 0xe1, 0x83, 0xdb, 0x3b, 0xdf, 0x95, 0x9c, 0x7b, 0xe4, 0x0d, 0xd4, 0x95, 0x50, 0xe4, 0x56, - 0x29, 0x7b, 0x5d, 0xe8, 0xc1, 0xc1, 0xae, 0xe7, 0x22, 0x96, 0xa2, 0xb8, 0x81, 0xb5, 0xae, 0xe3, - 0x06, 0x56, 0x49, 0x19, 0x77, 0xef, 0xbc, 0x26, 0xff, 0x9c, 0x8e, 0xfe, 0x04, 0x00, 0x00, 0xff, - 0xff, 0x9a, 0xf4, 0x9d, 0x85, 0xaa, 0x06, 0x00, 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// AuthClient is the client API for Auth service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type AuthClient interface { + Generate(ctx context.Context, in *GenerateRequest, opts ...grpc.CallOption) (*GenerateResponse, error) + Inspect(ctx context.Context, in *InspectRequest, opts ...grpc.CallOption) (*InspectResponse, error) + Refresh(ctx context.Context, in *RefreshRequest, opts ...grpc.CallOption) (*RefreshResponse, error) +} + +type authClient struct { + cc *grpc.ClientConn +} + +func NewAuthClient(cc *grpc.ClientConn) AuthClient { + return &authClient{cc} +} + +func (c *authClient) Generate(ctx context.Context, in *GenerateRequest, opts ...grpc.CallOption) (*GenerateResponse, error) { + out := new(GenerateResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Auth/Generate", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authClient) Inspect(ctx context.Context, in *InspectRequest, opts ...grpc.CallOption) (*InspectResponse, error) { + out := new(InspectResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Auth/Inspect", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authClient) Refresh(ctx context.Context, in *RefreshRequest, opts ...grpc.CallOption) (*RefreshResponse, error) { + out := new(RefreshResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Auth/Refresh", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// AuthServer is the server API for Auth service. +type AuthServer interface { + Generate(context.Context, *GenerateRequest) (*GenerateResponse, error) + Inspect(context.Context, *InspectRequest) (*InspectResponse, error) + Refresh(context.Context, *RefreshRequest) (*RefreshResponse, error) +} + +// UnimplementedAuthServer can be embedded to have forward compatible implementations. +type UnimplementedAuthServer struct { +} + +func (*UnimplementedAuthServer) Generate(ctx context.Context, req *GenerateRequest) (*GenerateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Generate not implemented") +} +func (*UnimplementedAuthServer) Inspect(ctx context.Context, req *InspectRequest) (*InspectResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Inspect not implemented") +} +func (*UnimplementedAuthServer) Refresh(ctx context.Context, req *RefreshRequest) (*RefreshResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Refresh not implemented") +} + +func RegisterAuthServer(s *grpc.Server, srv AuthServer) { + s.RegisterService(&_Auth_serviceDesc, srv) +} + +func _Auth_Generate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GenerateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthServer).Generate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Auth/Generate", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthServer).Generate(ctx, req.(*GenerateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Auth_Inspect_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(InspectRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthServer).Inspect(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Auth/Inspect", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthServer).Inspect(ctx, req.(*InspectRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Auth_Refresh_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RefreshRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthServer).Refresh(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Auth/Refresh", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthServer).Refresh(ctx, req.(*RefreshRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Auth_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.auth.Auth", + HandlerType: (*AuthServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Generate", + Handler: _Auth_Generate_Handler, + }, + { + MethodName: "Inspect", + Handler: _Auth_Inspect_Handler, + }, + { + MethodName: "Refresh", + Handler: _Auth_Refresh_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "auth/service/proto/auth.proto", } diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index f304e32b..db0d2a70 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: auth.proto +// source: auth/service/proto/auth.proto package go_micro_auth diff --git a/auth/service/proto/rules.pb.go b/auth/service/proto/rules.pb.go index 04d02a75..dc75ff0d 100644 --- a/auth/service/proto/rules.pb.go +++ b/auth/service/proto/rules.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: rules.proto +// source: auth/service/proto/rules.proto package go_micro_auth import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -45,7 +49,7 @@ func (x Access) String() string { } func (Access) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_8e722d3e922f0937, []int{0} + return fileDescriptor_ce1ef0aa40cdd6dc, []int{0} } type Rule struct { @@ -62,7 +66,7 @@ func (m *Rule) Reset() { *m = Rule{} } func (m *Rule) String() string { return proto.CompactTextString(m) } func (*Rule) ProtoMessage() {} func (*Rule) Descriptor() ([]byte, []int) { - return fileDescriptor_8e722d3e922f0937, []int{0} + return fileDescriptor_ce1ef0aa40cdd6dc, []int{0} } func (m *Rule) XXX_Unmarshal(b []byte) error { @@ -124,7 +128,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8e722d3e922f0937, []int{1} + return fileDescriptor_ce1ef0aa40cdd6dc, []int{1} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -176,7 +180,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8e722d3e922f0937, []int{2} + return fileDescriptor_ce1ef0aa40cdd6dc, []int{2} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -210,7 +214,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8e722d3e922f0937, []int{3} + return fileDescriptor_ce1ef0aa40cdd6dc, []int{3} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -262,7 +266,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8e722d3e922f0937, []int{4} + return fileDescriptor_ce1ef0aa40cdd6dc, []int{4} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -293,7 +297,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8e722d3e922f0937, []int{5} + return fileDescriptor_ce1ef0aa40cdd6dc, []int{5} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -325,7 +329,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8e722d3e922f0937, []int{6} + return fileDescriptor_ce1ef0aa40cdd6dc, []int{6} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -364,32 +368,183 @@ func init() { proto.RegisterType((*ListResponse)(nil), "go.micro.auth.ListResponse") } -func init() { - proto.RegisterFile("rules.proto", fileDescriptor_8e722d3e922f0937) +func init() { proto.RegisterFile("auth/service/proto/rules.proto", fileDescriptor_ce1ef0aa40cdd6dc) } + +var fileDescriptor_ce1ef0aa40cdd6dc = []byte{ + // 362 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x93, 0x51, 0x4b, 0xeb, 0x30, + 0x1c, 0xc5, 0x97, 0xae, 0xeb, 0xbd, 0xf7, 0xdf, 0xbb, 0x51, 0x72, 0xb9, 0x58, 0xaa, 0x93, 0xb2, + 0xa7, 0x2a, 0xd8, 0x41, 0xf7, 0xe4, 0xe3, 0xb0, 0x63, 0x88, 0x52, 0x21, 0x28, 0x3e, 0xcf, 0xee, + 0x8f, 0x16, 0xaa, 0x99, 0x49, 0xeb, 0x57, 0xf0, 0xcd, 0x4f, 0xe8, 0x87, 0x91, 0x26, 0xdd, 0x70, + 0xdd, 0x06, 0xfa, 0xe6, 0x5b, 0x92, 0x73, 0x72, 0xf2, 0xcb, 0x69, 0x03, 0x87, 0xb3, 0xb2, 0x78, + 0x18, 0x4a, 0x14, 0x2f, 0x59, 0x8a, 0xc3, 0x85, 0xe0, 0x05, 0x1f, 0x8a, 0x32, 0x47, 0x19, 0xaa, + 0x31, 0xed, 0xde, 0xf3, 0xf0, 0x31, 0x4b, 0x05, 0x0f, 0x2b, 0xa3, 0xd7, 0xdf, 0x62, 0xaf, 0x96, + 0xb4, 0x7b, 0xf0, 0x46, 0xc0, 0x64, 0x65, 0x8e, 0xb4, 0x07, 0x46, 0x36, 0x77, 0x89, 0x4f, 0x82, + 0x3f, 0xcc, 0xc8, 0xe6, 0x94, 0x82, 0x29, 0x78, 0x8e, 0xae, 0xa1, 0x56, 0xd4, 0x98, 0x8e, 0xe0, + 0xb7, 0x40, 0xc9, 0x4b, 0x91, 0xa2, 0xdb, 0xf6, 0x49, 0x60, 0x47, 0x7b, 0xe1, 0xda, 0x69, 0x21, + 0xab, 0x65, 0xb6, 0x32, 0xd2, 0x13, 0xb0, 0x66, 0x69, 0x8a, 0x52, 0xba, 0xa6, 0x4f, 0x82, 0x5e, + 0xf4, 0xbf, 0xb1, 0x65, 0xac, 0x44, 0x56, 0x9b, 0x06, 0xaf, 0x04, 0xba, 0x67, 0x02, 0x67, 0x05, + 0x32, 0x7c, 0x2e, 0x51, 0x16, 0x2b, 0x12, 0xb2, 0x83, 0xc4, 0xf8, 0x3e, 0x49, 0xfb, 0x2b, 0x24, + 0x0e, 0xf4, 0x96, 0x20, 0x72, 0xc1, 0x9f, 0x24, 0x2a, 0xb6, 0x18, 0x73, 0xfc, 0x11, 0x6c, 0x4b, + 0x90, 0x9a, 0xad, 0x0b, 0xf6, 0x65, 0x26, 0x8b, 0x1a, 0x6c, 0x70, 0x0a, 0x7f, 0xf5, 0x54, 0xcb, + 0xf4, 0x08, 0x3a, 0xea, 0x27, 0x71, 0x89, 0xdf, 0x0e, 0xec, 0xe8, 0x5f, 0x93, 0xa8, 0xcc, 0x91, + 0x69, 0xc7, 0x71, 0x08, 0x96, 0x3e, 0x8d, 0xda, 0xf0, 0xeb, 0x26, 0xb9, 0x48, 0xae, 0x6e, 0x13, + 0xa7, 0x55, 0x4d, 0xa6, 0x6c, 0x9c, 0x5c, 0x4f, 0x62, 0x87, 0x50, 0x00, 0x2b, 0x9e, 0x24, 0xe7, + 0x93, 0xd8, 0x31, 0xa2, 0x77, 0x02, 0x9d, 0x6a, 0xbf, 0xa4, 0x53, 0xb0, 0x74, 0x63, 0xf4, 0xa0, + 0x91, 0xbf, 0xf6, 0x45, 0xbd, 0xfe, 0x0e, 0xb5, 0xbe, 0x4a, 0xab, 0x0a, 0xd2, 0xd7, 0xdb, 0x08, + 0x5a, 0xab, 0x7f, 0x23, 0xa8, 0xd1, 0x49, 0x8b, 0x8e, 0xc1, 0xac, 0x6a, 0xa0, 0x5e, 0xc3, 0xf8, + 0xa9, 0x2a, 0x6f, 0x7f, 0xab, 0xb6, 0x8c, 0xb8, 0xb3, 0xd4, 0x43, 0x19, 0x7d, 0x04, 0x00, 0x00, + 0xff, 0xff, 0xd9, 0x7d, 0x25, 0xd9, 0x78, 0x03, 0x00, 0x00, } -var fileDescriptor_8e722d3e922f0937 = []byte{ - // 346 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x93, 0xc1, 0x4e, 0xb3, 0x40, - 0x14, 0x85, 0x3b, 0x94, 0xf2, 0xff, 0x5e, 0x6c, 0x43, 0xae, 0x31, 0x12, 0xd4, 0x84, 0x74, 0x85, - 0x26, 0xb2, 0xa0, 0x2b, 0x97, 0x8d, 0x34, 0x8d, 0xd1, 0x60, 0x32, 0xd1, 0xb8, 0xae, 0xf4, 0x46, - 0x49, 0xd0, 0xa9, 0x33, 0xf0, 0x0c, 0xee, 0x7c, 0x42, 0x1f, 0xc6, 0xc0, 0xd0, 0xc6, 0x52, 0x9b, - 0xe8, 0xce, 0x0d, 0x61, 0x38, 0x67, 0x0e, 0xdf, 0x3d, 0x30, 0x60, 0xcb, 0x32, 0x27, 0x15, 0x2e, - 0xa4, 0x28, 0x04, 0xf6, 0x1f, 0x45, 0xf8, 0x9c, 0xa5, 0x52, 0x84, 0xb3, 0xb2, 0x78, 0xf2, 0xa0, - 0xba, 0x6a, 0x69, 0xf8, 0xce, 0xc0, 0xe4, 0x65, 0x4e, 0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 0xa8, - 0x95, 0xbf, 0xf6, 0x45, 0xbd, 0xe3, 0x2d, 0x6a, 0x33, 0x4a, 0xa7, 0x0a, 0xd2, 0xe3, 0x6d, 0x04, - 0xad, 0xd5, 0xbf, 0x11, 0xd4, 0xea, 0xa4, 0x83, 0x63, 0x30, 0xab, 0x1a, 0xd0, 0x6b, 0x19, 0xbf, - 0x54, 0xe5, 0x1d, 0x7e, 0xab, 0x2d, 0x23, 0x1e, 0xac, 0xfa, 0xa0, 0x8c, 0x3e, 0x03, 0x00, 0x00, - 0xff, 0xff, 0xb8, 0x06, 0xc3, 0x53, 0x52, 0x03, 0x00, 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// RulesClient is the client API for Rules service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type RulesClient interface { + Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) + List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) +} + +type rulesClient struct { + cc *grpc.ClientConn +} + +func NewRulesClient(cc *grpc.ClientConn) RulesClient { + return &rulesClient{cc} +} + +func (c *rulesClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { + out := new(CreateResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Rules/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *rulesClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { + out := new(DeleteResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Rules/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *rulesClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) { + out := new(ListResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Rules/List", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// RulesServer is the server API for Rules service. +type RulesServer interface { + Create(context.Context, *CreateRequest) (*CreateResponse, error) + Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) + List(context.Context, *ListRequest) (*ListResponse, error) +} + +// UnimplementedRulesServer can be embedded to have forward compatible implementations. +type UnimplementedRulesServer struct { +} + +func (*UnimplementedRulesServer) Create(ctx context.Context, req *CreateRequest) (*CreateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") +} +func (*UnimplementedRulesServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} +func (*UnimplementedRulesServer) List(ctx context.Context, req *ListRequest) (*ListResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method List not implemented") +} + +func RegisterRulesServer(s *grpc.Server, srv RulesServer) { + s.RegisterService(&_Rules_serviceDesc, srv) +} + +func _Rules_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RulesServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Rules/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RulesServer).Create(ctx, req.(*CreateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Rules_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RulesServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Rules/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RulesServer).Delete(ctx, req.(*DeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Rules_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RulesServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Rules/List", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RulesServer).List(ctx, req.(*ListRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Rules_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.auth.Rules", + HandlerType: (*RulesServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _Rules_Create_Handler, + }, + { + MethodName: "Delete", + Handler: _Rules_Delete_Handler, + }, + { + MethodName: "List", + Handler: _Rules_List_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "auth/service/proto/rules.proto", } diff --git a/auth/service/proto/rules.pb.micro.go b/auth/service/proto/rules.pb.micro.go index fa25ba61..9e24fe06 100644 --- a/auth/service/proto/rules.pb.micro.go +++ b/auth/service/proto/rules.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: rules.proto +// source: auth/service/proto/rules.proto package go_micro_auth diff --git a/auth/service/proto/rules.proto b/auth/service/proto/rules.proto index cc941952..35355e5a 100644 --- a/auth/service/proto/rules.proto +++ b/auth/service/proto/rules.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package go.micro.auth; -import "auth.proto"; +import "auth/service/proto/auth.proto"; service Rules { rpc Create(CreateRequest) returns (CreateResponse) {}; diff --git a/broker/service/proto/broker.pb.go b/broker/service/proto/broker.pb.go index e602e4b1..cb561cc9 100644 --- a/broker/service/proto/broker.pb.go +++ b/broker/service/proto/broker.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: micro/go-micro/broker/service/proto/broker.proto +// source: broker/service/proto/broker.proto package go_micro_broker import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -30,7 +34,7 @@ func (m *Empty) Reset() { *m = Empty{} } func (m *Empty) String() string { return proto.CompactTextString(m) } func (*Empty) ProtoMessage() {} func (*Empty) Descriptor() ([]byte, []int) { - return fileDescriptor_178fdc60944ff5e5, []int{0} + return fileDescriptor_df4d8f04292cf3fe, []int{0} } func (m *Empty) XXX_Unmarshal(b []byte) error { @@ -63,7 +67,7 @@ func (m *PublishRequest) Reset() { *m = PublishRequest{} } func (m *PublishRequest) String() string { return proto.CompactTextString(m) } func (*PublishRequest) ProtoMessage() {} func (*PublishRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_178fdc60944ff5e5, []int{1} + return fileDescriptor_df4d8f04292cf3fe, []int{1} } func (m *PublishRequest) XXX_Unmarshal(b []byte) error { @@ -110,7 +114,7 @@ func (m *SubscribeRequest) Reset() { *m = SubscribeRequest{} } func (m *SubscribeRequest) String() string { return proto.CompactTextString(m) } func (*SubscribeRequest) ProtoMessage() {} func (*SubscribeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_178fdc60944ff5e5, []int{2} + return fileDescriptor_df4d8f04292cf3fe, []int{2} } func (m *SubscribeRequest) XXX_Unmarshal(b []byte) error { @@ -157,7 +161,7 @@ func (m *Message) Reset() { *m = Message{} } func (m *Message) String() string { return proto.CompactTextString(m) } func (*Message) ProtoMessage() {} func (*Message) Descriptor() ([]byte, []int) { - return fileDescriptor_178fdc60944ff5e5, []int{3} + return fileDescriptor_df4d8f04292cf3fe, []int{3} } func (m *Message) XXX_Unmarshal(b []byte) error { @@ -200,30 +204,171 @@ func init() { proto.RegisterMapType((map[string]string)(nil), "go.micro.broker.Message.HeaderEntry") } -func init() { - proto.RegisterFile("micro/go-micro/broker/service/proto/broker.proto", fileDescriptor_178fdc60944ff5e5) +func init() { proto.RegisterFile("broker/service/proto/broker.proto", fileDescriptor_df4d8f04292cf3fe) } + +var fileDescriptor_df4d8f04292cf3fe = []byte{ + // 299 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x51, 0x4d, 0x4b, 0xc3, 0x40, + 0x14, 0xec, 0xb6, 0xb6, 0xa1, 0xaf, 0xa2, 0x65, 0x29, 0x12, 0x7a, 0x31, 0x0d, 0x1e, 0x72, 0xda, + 0x48, 0xbc, 0xa8, 0x88, 0x07, 0xb1, 0xe0, 0x41, 0x41, 0xd6, 0x9b, 0xb7, 0x6c, 0xfa, 0x68, 0x43, + 0x1b, 0x37, 0xdd, 0x4d, 0x0a, 0xf9, 0x23, 0x9e, 0xfc, 0xb1, 0xd2, 0xdd, 0xf8, 0xd5, 0x50, 0x6f, + 0x6f, 0xde, 0xce, 0xce, 0x1b, 0x66, 0x60, 0x22, 0x94, 0x5c, 0xa2, 0x0a, 0x35, 0xaa, 0x4d, 0x9a, + 0x60, 0x98, 0x2b, 0x59, 0xc8, 0xd0, 0x2e, 0x99, 0x01, 0xf4, 0x78, 0x2e, 0x59, 0x96, 0x26, 0x4a, + 0x32, 0xbb, 0xf6, 0x1d, 0xe8, 0x4e, 0xb3, 0xbc, 0xa8, 0xfc, 0x57, 0x38, 0x7a, 0x2e, 0xc5, 0x2a, + 0xd5, 0x0b, 0x8e, 0xeb, 0x12, 0x75, 0x41, 0x47, 0xd0, 0x2d, 0x64, 0x9e, 0x26, 0x2e, 0xf1, 0x48, + 0xd0, 0xe7, 0x16, 0xd0, 0x08, 0x9c, 0x0c, 0xb5, 0x8e, 0xe7, 0xe8, 0xb6, 0x3d, 0x12, 0x0c, 0x22, + 0x97, 0xed, 0x68, 0xb2, 0x27, 0xfb, 0xce, 0xbf, 0x88, 0xfe, 0x2d, 0x0c, 0x5f, 0x4a, 0xa1, 0x13, + 0x95, 0x0a, 0xfc, 0x5f, 0x7d, 0x04, 0xdd, 0x75, 0x89, 0xa5, 0xd5, 0xee, 0x73, 0x0b, 0xfc, 0x77, + 0x02, 0x4e, 0x2d, 0x4a, 0x6f, 0xa0, 0xb7, 0xc0, 0x78, 0x86, 0xca, 0x25, 0x5e, 0x27, 0x18, 0x44, + 0x67, 0xfb, 0xce, 0xb3, 0x07, 0x43, 0x9b, 0xbe, 0x15, 0xaa, 0xe2, 0xf5, 0x1f, 0x4a, 0xe1, 0x40, + 0xc8, 0x59, 0x65, 0xe4, 0x0f, 0xb9, 0x99, 0xc7, 0x57, 0x30, 0xf8, 0x45, 0xa5, 0x43, 0xe8, 0x2c, + 0xb1, 0xaa, 0x6d, 0x6d, 0xc7, 0xad, 0xa9, 0x4d, 0xbc, 0xfa, 0x31, 0x65, 0xc0, 0x75, 0xfb, 0x92, + 0x44, 0x1f, 0x04, 0x7a, 0x77, 0xe6, 0x2a, 0xbd, 0x07, 0xa7, 0xce, 0x8f, 0x9e, 0x36, 0x2c, 0xfd, + 0x4d, 0x76, 0x7c, 0xd2, 0x20, 0xd8, 0x0e, 0x5a, 0xf4, 0x11, 0xfa, 0xdf, 0x49, 0xd1, 0x49, 0x83, + 0xb6, 0x9b, 0xe2, 0x78, 0x6f, 0xf8, 0x7e, 0xeb, 0x9c, 0x88, 0x9e, 0x29, 0xfd, 0xe2, 0x33, 0x00, + 0x00, 0xff, 0xff, 0x19, 0x9f, 0x10, 0x75, 0x19, 0x02, 0x00, 0x00, } -var fileDescriptor_178fdc60944ff5e5 = []byte{ - // 305 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x51, 0x4d, 0x4f, 0xc2, 0x40, - 0x14, 0x64, 0x41, 0x68, 0x78, 0x18, 0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8, 0xa6, 0xef, 0xb9, 0x2a, - 0x79, 0xf5, 0x87, 0x52, 0x38, 0x10, 0x72, 0x56, 0x1a, 0xfb, 0x43, 0x6e, 0xf0, 0xf0, 0x1a, 0x7a, - 0xbf, 0xa4, 0xb4, 0x0f, 0xad, 0x05, 0x96, 0x55, 0xac, 0x0d, 0xdc, 0x84, 0x5a, 0x87, 0xcb, 0x9f, - 0x50, 0x86, 0xdc, 0x34, 0xaf, 0x48, 0xf0, 0x49, 0xa0, 0x73, 0x6f, 0xb6, 0xd2, 0x07, 0x70, 0xaa, - 0xfe, 0xe8, 0x69, 0x2d, 0xd2, 0xdf, 0x66, 0x87, 0x27, 0x35, 0x81, 0xbd, 0x41, 0x83, 0x3e, 0x41, - 0xf7, 0xbb, 0x29, 0x7a, 0x56, 0x93, 0xed, 0xb6, 0x38, 0xdc, 0x5b, 0xbe, 0xd7, 0x98, 0x10, 0xd1, - 0x31, 0x47, 0xbf, 0xfc, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x60, 0x8c, 0x40, 0xd5, 0x28, 0x02, 0x00, - 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// BrokerClient is the client API for Broker service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type BrokerClient interface { + Publish(ctx context.Context, in *PublishRequest, opts ...grpc.CallOption) (*Empty, error) + Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (Broker_SubscribeClient, error) +} + +type brokerClient struct { + cc *grpc.ClientConn +} + +func NewBrokerClient(cc *grpc.ClientConn) BrokerClient { + return &brokerClient{cc} +} + +func (c *brokerClient) Publish(ctx context.Context, in *PublishRequest, opts ...grpc.CallOption) (*Empty, error) { + out := new(Empty) + err := c.cc.Invoke(ctx, "/go.micro.broker.Broker/Publish", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *brokerClient) Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (Broker_SubscribeClient, error) { + stream, err := c.cc.NewStream(ctx, &_Broker_serviceDesc.Streams[0], "/go.micro.broker.Broker/Subscribe", opts...) + if err != nil { + return nil, err + } + x := &brokerSubscribeClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Broker_SubscribeClient interface { + Recv() (*Message, error) + grpc.ClientStream +} + +type brokerSubscribeClient struct { + grpc.ClientStream +} + +func (x *brokerSubscribeClient) Recv() (*Message, error) { + m := new(Message) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// BrokerServer is the server API for Broker service. +type BrokerServer interface { + Publish(context.Context, *PublishRequest) (*Empty, error) + Subscribe(*SubscribeRequest, Broker_SubscribeServer) error +} + +// UnimplementedBrokerServer can be embedded to have forward compatible implementations. +type UnimplementedBrokerServer struct { +} + +func (*UnimplementedBrokerServer) Publish(ctx context.Context, req *PublishRequest) (*Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method Publish not implemented") +} +func (*UnimplementedBrokerServer) Subscribe(req *SubscribeRequest, srv Broker_SubscribeServer) error { + return status.Errorf(codes.Unimplemented, "method Subscribe not implemented") +} + +func RegisterBrokerServer(s *grpc.Server, srv BrokerServer) { + s.RegisterService(&_Broker_serviceDesc, srv) +} + +func _Broker_Publish_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(PublishRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BrokerServer).Publish(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.broker.Broker/Publish", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BrokerServer).Publish(ctx, req.(*PublishRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Broker_Subscribe_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(SubscribeRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(BrokerServer).Subscribe(m, &brokerSubscribeServer{stream}) +} + +type Broker_SubscribeServer interface { + Send(*Message) error + grpc.ServerStream +} + +type brokerSubscribeServer struct { + grpc.ServerStream +} + +func (x *brokerSubscribeServer) Send(m *Message) error { + return x.ServerStream.SendMsg(m) +} + +var _Broker_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.broker.Broker", + HandlerType: (*BrokerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Publish", + Handler: _Broker_Publish_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "Subscribe", + Handler: _Broker_Subscribe_Handler, + ServerStreams: true, + }, + }, + Metadata: "broker/service/proto/broker.proto", } diff --git a/broker/service/proto/broker.pb.micro.go b/broker/service/proto/broker.pb.micro.go index 4ce6cd52..384f66f6 100644 --- a/broker/service/proto/broker.pb.micro.go +++ b/broker/service/proto/broker.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: micro/go-micro/broker/service/proto/broker.proto +// source: broker/service/proto/broker.proto package go_micro_broker @@ -44,12 +44,6 @@ type brokerService struct { } func NewBrokerService(name string, c client.Client) BrokerService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "go.micro.broker" - } return &brokerService{ c: c, name: name, @@ -79,6 +73,7 @@ func (c *brokerService) Subscribe(ctx context.Context, in *SubscribeRequest, opt } type Broker_SubscribeService interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -93,6 +88,10 @@ func (x *brokerServiceSubscribe) Close() error { return x.stream.Close() } +func (x *brokerServiceSubscribe) Context() context.Context { + return x.stream.Context() +} + func (x *brokerServiceSubscribe) SendMsg(m interface{}) error { return x.stream.Send(m) } @@ -146,6 +145,7 @@ func (h *brokerHandler) Subscribe(ctx context.Context, stream server.Stream) err } type Broker_SubscribeStream interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -160,6 +160,10 @@ func (x *brokerSubscribeStream) Close() error { return x.stream.Close() } +func (x *brokerSubscribeStream) Context() context.Context { + return x.stream.Context() +} + func (x *brokerSubscribeStream) SendMsg(m interface{}) error { return x.stream.Send(m) } diff --git a/client/service/proto/client.pb.go b/client/service/proto/client.pb.go index 071c1c16..8d82354e 100644 --- a/client/service/proto/client.pb.go +++ b/client/service/proto/client.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/v2/client/proto/client.proto +// source: client/service/proto/client.proto package go_micro_client import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -34,7 +38,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_d418333f021a3308, []int{0} + return fileDescriptor_27c3d425ddd1a066, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { @@ -94,7 +98,7 @@ func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_d418333f021a3308, []int{1} + return fileDescriptor_27c3d425ddd1a066, []int{1} } func (m *Response) XXX_Unmarshal(b []byte) error { @@ -135,7 +139,7 @@ func (m *Message) Reset() { *m = Message{} } func (m *Message) String() string { return proto.CompactTextString(m) } func (*Message) ProtoMessage() {} func (*Message) Descriptor() ([]byte, []int) { - return fileDescriptor_d418333f021a3308, []int{2} + return fileDescriptor_27c3d425ddd1a066, []int{2} } func (m *Message) XXX_Unmarshal(b []byte) error { @@ -183,28 +187,216 @@ func init() { proto.RegisterType((*Message)(nil), "go.micro.client.Message") } -func init() { - proto.RegisterFile("github.com/micro/go-micro/v2/client/proto/client.proto", fileDescriptor_d418333f021a3308) +func init() { proto.RegisterFile("client/service/proto/client.proto", fileDescriptor_27c3d425ddd1a066) } + +var fileDescriptor_27c3d425ddd1a066 = []byte{ + // 267 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x91, 0xc1, 0x4b, 0xc3, 0x30, + 0x14, 0xc6, 0x97, 0x6d, 0xb6, 0xf3, 0x39, 0x10, 0x1e, 0x1e, 0x62, 0x0f, 0xb2, 0xf5, 0xd4, 0x53, + 0x2b, 0x7a, 0x16, 0x0f, 0x3d, 0x0b, 0x52, 0xc5, 0xab, 0xb4, 0xd9, 0x63, 0x06, 0xba, 0x24, 0x36, + 0xd9, 0xa0, 0x7f, 0xa4, 0xff, 0x93, 0x90, 0x46, 0x27, 0xba, 0x5d, 0xbc, 0xe5, 0xfb, 0x7e, 0xe4, + 0x7b, 0x2f, 0x5f, 0x60, 0x29, 0x5a, 0x49, 0xca, 0x15, 0x96, 0xba, 0x9d, 0x14, 0x54, 0x98, 0x4e, + 0x3b, 0x5d, 0x0c, 0x66, 0xee, 0x05, 0x9e, 0xaf, 0x75, 0xbe, 0x91, 0xa2, 0xd3, 0xf9, 0x60, 0xa7, + 0x3b, 0x88, 0x2b, 0x7a, 0xdf, 0x92, 0x75, 0xc8, 0x21, 0x0e, 0x37, 0x39, 0x5b, 0xb0, 0xec, 0xb4, + 0xfa, 0x92, 0x98, 0xc0, 0x8c, 0xd4, 0xca, 0x68, 0xa9, 0x1c, 0x1f, 0x7b, 0xf4, 0xad, 0x71, 0x09, + 0x73, 0xa1, 0x95, 0x23, 0xe5, 0x5e, 0x5d, 0x6f, 0x88, 0x4f, 0x3c, 0x3f, 0x0b, 0xde, 0x73, 0x6f, + 0x08, 0x11, 0xa6, 0x8d, 0x5e, 0xf5, 0x7c, 0xba, 0x60, 0xd9, 0xbc, 0xf2, 0xe7, 0xf4, 0x0a, 0x66, + 0x15, 0x59, 0xa3, 0x95, 0xdd, 0x73, 0xf6, 0x83, 0xbf, 0x40, 0xfc, 0x40, 0xd6, 0xd6, 0x6b, 0xc2, + 0x0b, 0x38, 0x71, 0xda, 0x48, 0x11, 0xb6, 0x1a, 0xc4, 0x9f, 0xb9, 0xe3, 0xe3, 0x73, 0x27, 0xfb, + 0xdc, 0x9b, 0x0f, 0x06, 0x51, 0xe9, 0x9f, 0x8e, 0x77, 0x30, 0x2d, 0xeb, 0xb6, 0x45, 0x9e, 0xff, + 0x2a, 0x25, 0x0f, 0x8d, 0x24, 0x97, 0x07, 0xc8, 0xb0, 0x73, 0x3a, 0xc2, 0x12, 0xa2, 0x27, 0xd7, + 0x51, 0xbd, 0xf9, 0x67, 0x40, 0xc6, 0xae, 0x19, 0xde, 0x43, 0xfc, 0xb8, 0x6d, 0x5a, 0x69, 0xdf, + 0x0e, 0xa4, 0x84, 0x02, 0x92, 0xa3, 0x24, 0x1d, 0x35, 0x91, 0xff, 0xd7, 0xdb, 0xcf, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xd6, 0x3f, 0xc3, 0xa1, 0xfc, 0x01, 0x00, 0x00, } -var fileDescriptor_d418333f021a3308 = []byte{ - // 279 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x91, 0x31, 0x4f, 0xfb, 0x30, - 0x10, 0xc5, 0xeb, 0xb6, 0xff, 0xa4, 0xff, 0xa3, 0x12, 0x92, 0xc5, 0x60, 0x32, 0xa0, 0x92, 0x29, - 0x0b, 0x0e, 0xa2, 0x33, 0x62, 0xc8, 0x8c, 0x84, 0x02, 0x62, 0x45, 0x89, 0x7b, 0x4a, 0x2d, 0x25, - 0xb6, 0x89, 0x9d, 0x4a, 0xf9, 0x90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x62, 0xd1, 0xfc, - 0xd1, 0x20, 0x21, 0xb7, 0x84, 0x3e, 0x40, 0xf8, 0xd4, 0x95, 0xb5, 0xb4, 0xdb, 0x23, 0x2e, 0x63, - 0x00, 0xd1, 0x49, 0x12, 0x4f, 0xca, 0xc0, 0xdf, 0x75, 0xfd, 0x19, 0x00, 0x00, 0xff, 0xff, 0xb6, - 0x4d, 0x6e, 0xd5, 0x0e, 0x02, 0x00, 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// ClientClient is the client API for Client service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ClientClient interface { + // Call allows a single request to be made + Call(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) + // Stream is a bidirectional stream + Stream(ctx context.Context, opts ...grpc.CallOption) (Client_StreamClient, error) + // Publish publishes a message and returns an empty Message + Publish(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error) +} + +type clientClient struct { + cc *grpc.ClientConn +} + +func NewClientClient(cc *grpc.ClientConn) ClientClient { + return &clientClient{cc} +} + +func (c *clientClient) Call(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) { + out := new(Response) + err := c.cc.Invoke(ctx, "/go.micro.client.Client/Call", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *clientClient) Stream(ctx context.Context, opts ...grpc.CallOption) (Client_StreamClient, error) { + stream, err := c.cc.NewStream(ctx, &_Client_serviceDesc.Streams[0], "/go.micro.client.Client/Stream", opts...) + if err != nil { + return nil, err + } + x := &clientStreamClient{stream} + return x, nil +} + +type Client_StreamClient interface { + Send(*Request) error + Recv() (*Response, error) + grpc.ClientStream +} + +type clientStreamClient struct { + grpc.ClientStream +} + +func (x *clientStreamClient) Send(m *Request) error { + return x.ClientStream.SendMsg(m) +} + +func (x *clientStreamClient) Recv() (*Response, error) { + m := new(Response) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *clientClient) Publish(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error) { + out := new(Message) + err := c.cc.Invoke(ctx, "/go.micro.client.Client/Publish", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ClientServer is the server API for Client service. +type ClientServer interface { + // Call allows a single request to be made + Call(context.Context, *Request) (*Response, error) + // Stream is a bidirectional stream + Stream(Client_StreamServer) error + // Publish publishes a message and returns an empty Message + Publish(context.Context, *Message) (*Message, error) +} + +// UnimplementedClientServer can be embedded to have forward compatible implementations. +type UnimplementedClientServer struct { +} + +func (*UnimplementedClientServer) Call(ctx context.Context, req *Request) (*Response, error) { + return nil, status.Errorf(codes.Unimplemented, "method Call not implemented") +} +func (*UnimplementedClientServer) Stream(srv Client_StreamServer) error { + return status.Errorf(codes.Unimplemented, "method Stream not implemented") +} +func (*UnimplementedClientServer) Publish(ctx context.Context, req *Message) (*Message, error) { + return nil, status.Errorf(codes.Unimplemented, "method Publish not implemented") +} + +func RegisterClientServer(s *grpc.Server, srv ClientServer) { + s.RegisterService(&_Client_serviceDesc, srv) +} + +func _Client_Call_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Request) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ClientServer).Call(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.client.Client/Call", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ClientServer).Call(ctx, req.(*Request)) + } + return interceptor(ctx, in, info, handler) +} + +func _Client_Stream_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(ClientServer).Stream(&clientStreamServer{stream}) +} + +type Client_StreamServer interface { + Send(*Response) error + Recv() (*Request, error) + grpc.ServerStream +} + +type clientStreamServer struct { + grpc.ServerStream +} + +func (x *clientStreamServer) Send(m *Response) error { + return x.ServerStream.SendMsg(m) +} + +func (x *clientStreamServer) Recv() (*Request, error) { + m := new(Request) + if err := x.ServerStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func _Client_Publish_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Message) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ClientServer).Publish(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.client.Client/Publish", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ClientServer).Publish(ctx, req.(*Message)) + } + return interceptor(ctx, in, info, handler) +} + +var _Client_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.client.Client", + HandlerType: (*ClientServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Call", + Handler: _Client_Call_Handler, + }, + { + MethodName: "Publish", + Handler: _Client_Publish_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "Stream", + Handler: _Client_Stream_Handler, + ServerStreams: true, + ClientStreams: true, + }, + }, + Metadata: "client/service/proto/client.proto", } diff --git a/client/service/proto/client.pb.micro.go b/client/service/proto/client.pb.micro.go index 029a6c73..671e5021 100644 --- a/client/service/proto/client.pb.micro.go +++ b/client/service/proto/client.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/v2/client/proto/client.proto +// source: client/service/proto/client.proto package go_micro_client @@ -48,12 +48,6 @@ type clientService struct { } func NewClientService(name string, c client.Client) ClientService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "go.micro.client" - } return &clientService{ c: c, name: name, @@ -80,6 +74,7 @@ func (c *clientService) Stream(ctx context.Context, opts ...client.CallOption) ( } type Client_StreamService interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -95,6 +90,10 @@ func (x *clientServiceStream) Close() error { return x.stream.Close() } +func (x *clientServiceStream) Context() context.Context { + return x.stream.Context() +} + func (x *clientServiceStream) SendMsg(m interface{}) error { return x.stream.Send(m) } @@ -163,6 +162,7 @@ func (h *clientHandler) Stream(ctx context.Context, stream server.Stream) error } type Client_StreamStream interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -178,6 +178,10 @@ func (x *clientStreamStream) Close() error { return x.stream.Close() } +func (x *clientStreamStream) Context() context.Context { + return x.stream.Context() +} + func (x *clientStreamStream) SendMsg(m interface{}) error { return x.stream.Send(m) } diff --git a/codec/protorpc/envelope.pb.go b/codec/protorpc/envelope.pb.go index 9af273e0..b0e88066 100644 --- a/codec/protorpc/envelope.pb.go +++ b/codec/protorpc/envelope.pb.go @@ -1,83 +1,144 @@ -// Code generated by protoc-gen-go. -// source: envelope.proto -// DO NOT EDIT! +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: codec/protorpc/envelope.proto -/* -Package proto is a generated protocol buffer package. - -It is generated from these files: - envelope.proto - -It has these top-level messages: - Request - Response -*/ package protorpc -import proto "github.com/golang/protobuf/proto" -import json "encoding/json" -import math "math" +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) -// Reference proto, json, and math imports to suppress error if they are not otherwise used. +// Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal -var _ = &json.SyntaxError{} +var _ = fmt.Errorf var _ = math.Inf +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + type Request struct { - ServiceMethod *string `protobuf:"bytes,1,opt,name=service_method" json:"service_method,omitempty"` - Seq *uint64 `protobuf:"fixed64,2,opt,name=seq" json:"seq,omitempty"` - XXX_unrecognized []byte `json:"-"` + ServiceMethod string `protobuf:"bytes,1,opt,name=service_method,json=serviceMethod,proto3" json:"service_method,omitempty"` + Seq uint64 `protobuf:"fixed64,2,opt,name=seq,proto3" json:"seq,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} +func (*Request) Descriptor() ([]byte, []int) { + return fileDescriptor_12fd17ed7ee86a33, []int{0} +} + +func (m *Request) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Request.Unmarshal(m, b) +} +func (m *Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Request.Marshal(b, m, deterministic) +} +func (m *Request) XXX_Merge(src proto.Message) { + xxx_messageInfo_Request.Merge(m, src) +} +func (m *Request) XXX_Size() int { + return xxx_messageInfo_Request.Size(m) +} +func (m *Request) XXX_DiscardUnknown() { + xxx_messageInfo_Request.DiscardUnknown(m) +} + +var xxx_messageInfo_Request proto.InternalMessageInfo func (m *Request) GetServiceMethod() string { - if m != nil && m.ServiceMethod != nil { - return *m.ServiceMethod + if m != nil { + return m.ServiceMethod } return "" } func (m *Request) GetSeq() uint64 { - if m != nil && m.Seq != nil { - return *m.Seq + if m != nil { + return m.Seq } return 0 } type Response struct { - ServiceMethod *string `protobuf:"bytes,1,opt,name=service_method" json:"service_method,omitempty"` - Seq *uint64 `protobuf:"fixed64,2,opt,name=seq" json:"seq,omitempty"` - Error *string `protobuf:"bytes,3,opt,name=error" json:"error,omitempty"` - XXX_unrecognized []byte `json:"-"` + ServiceMethod string `protobuf:"bytes,1,opt,name=service_method,json=serviceMethod,proto3" json:"service_method,omitempty"` + Seq uint64 `protobuf:"fixed64,2,opt,name=seq,proto3" json:"seq,omitempty"` + Error string `protobuf:"bytes,3,opt,name=error,proto3" json:"error,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} +func (*Response) Descriptor() ([]byte, []int) { + return fileDescriptor_12fd17ed7ee86a33, []int{1} +} + +func (m *Response) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Response.Unmarshal(m, b) +} +func (m *Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Response.Marshal(b, m, deterministic) +} +func (m *Response) XXX_Merge(src proto.Message) { + xxx_messageInfo_Response.Merge(m, src) +} +func (m *Response) XXX_Size() int { + return xxx_messageInfo_Response.Size(m) +} +func (m *Response) XXX_DiscardUnknown() { + xxx_messageInfo_Response.DiscardUnknown(m) +} + +var xxx_messageInfo_Response proto.InternalMessageInfo func (m *Response) GetServiceMethod() string { - if m != nil && m.ServiceMethod != nil { - return *m.ServiceMethod + if m != nil { + return m.ServiceMethod } return "" } func (m *Response) GetSeq() uint64 { - if m != nil && m.Seq != nil { - return *m.Seq + if m != nil { + return m.Seq } return 0 } func (m *Response) GetError() string { - if m != nil && m.Error != nil { - return *m.Error + if m != nil { + return m.Error } return "" } func init() { + proto.RegisterType((*Request)(nil), "protorpc.Request") + proto.RegisterType((*Response)(nil), "protorpc.Response") +} + +func init() { proto.RegisterFile("codec/protorpc/envelope.proto", fileDescriptor_12fd17ed7ee86a33) } + +var fileDescriptor_12fd17ed7ee86a33 = []byte{ + // 148 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4d, 0xce, 0x4f, 0x49, + 0x4d, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0x2f, 0x2a, 0x48, 0xd6, 0x4f, 0xcd, 0x2b, 0x4b, 0xcd, + 0xc9, 0x2f, 0x48, 0xd5, 0x03, 0x8b, 0x08, 0x71, 0xc0, 0x24, 0x94, 0x9c, 0xb8, 0xd8, 0x83, 0x52, + 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x54, 0xb9, 0xf8, 0x8a, 0x53, 0x8b, 0xca, 0x32, 0x93, 0x53, + 0xe3, 0x73, 0x53, 0x4b, 0x32, 0xf2, 0x53, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x78, 0xa1, + 0xa2, 0xbe, 0x60, 0x41, 0x21, 0x01, 0x2e, 0xe6, 0xe2, 0xd4, 0x42, 0x09, 0x26, 0x05, 0x46, 0x0d, + 0xb6, 0x20, 0x10, 0x53, 0x29, 0x92, 0x8b, 0x23, 0x28, 0xb5, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x95, + 0x6c, 0x43, 0x84, 0x44, 0xb8, 0x58, 0x53, 0x8b, 0x8a, 0xf2, 0x8b, 0x24, 0x98, 0xc1, 0xea, 0x21, + 0x9c, 0x24, 0x36, 0xb0, 0x43, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe4, 0x73, 0x3a, 0x4b, + 0xd0, 0x00, 0x00, 0x00, } diff --git a/codec/protorpc/envelope.pb.micro.go b/codec/protorpc/envelope.pb.micro.go new file mode 100644 index 00000000..fcaa757c --- /dev/null +++ b/codec/protorpc/envelope.pb.micro.go @@ -0,0 +1,21 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: codec/protorpc/envelope.proto + +package protorpc + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package diff --git a/codec/protorpc/envelope.proto b/codec/protorpc/envelope.proto index 9c4fd19d..5b2f9599 100644 --- a/codec/protorpc/envelope.proto +++ b/codec/protorpc/envelope.proto @@ -1,12 +1,14 @@ +syntax = "proto3"; + package protorpc; message Request { - optional string service_method = 1; - optional fixed64 seq = 2; + string service_method = 1; + fixed64 seq = 2; } message Response { - optional string service_method = 1; - optional fixed64 seq = 2; - optional string error = 3; + string service_method = 1; + fixed64 seq = 2; + string error = 3; } diff --git a/codec/protorpc/protorpc.go b/codec/protorpc/protorpc.go index 41f52fff..ce945693 100644 --- a/codec/protorpc/protorpc.go +++ b/codec/protorpc/protorpc.go @@ -32,13 +32,13 @@ func (c *protoCodec) String() string { return "proto-rpc" } -func id(id string) *uint64 { +func id(id string) uint64 { p, err := strconv.ParseInt(id, 10, 64) if err != nil { p = 0 } i := uint64(p) - return &i + return i } func (c *protoCodec) Write(m *codec.Message, b interface{}) error { @@ -47,7 +47,7 @@ func (c *protoCodec) Write(m *codec.Message, b interface{}) error { c.Lock() defer c.Unlock() // This is protobuf, of course we copy it. - pbr := &Request{ServiceMethod: &m.Method, Seq: id(m.Id)} + pbr := &Request{ServiceMethod: m.Method, Seq: id(m.Id)} data, err := proto.Marshal(pbr) if err != nil { return err @@ -77,7 +77,7 @@ func (c *protoCodec) Write(m *codec.Message, b interface{}) error { case codec.Response, codec.Error: c.Lock() defer c.Unlock() - rtmp := &Response{ServiceMethod: &m.Method, Seq: id(m.Id), Error: &m.Error} + rtmp := &Response{ServiceMethod: m.Method, Seq: id(m.Id), Error: m.Error} data, err := proto.Marshal(rtmp) if err != nil { return err diff --git a/config/source/service/proto/service.pb.go b/config/source/service/proto/service.pb.go index deef8a75..45e62cdf 100644 --- a/config/source/service/proto/service.pb.go +++ b/config/source/service/proto/service.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: service.proto +// source: config/source/service/proto/service.proto package service import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -35,7 +39,7 @@ func (m *ChangeSet) Reset() { *m = ChangeSet{} } func (m *ChangeSet) String() string { return proto.CompactTextString(m) } func (*ChangeSet) ProtoMessage() {} func (*ChangeSet) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{0} + return fileDescriptor_e67338fe1f659d14, []int{0} } func (m *ChangeSet) XXX_Unmarshal(b []byte) error { @@ -104,7 +108,7 @@ func (m *Change) Reset() { *m = Change{} } func (m *Change) String() string { return proto.CompactTextString(m) } func (*Change) ProtoMessage() {} func (*Change) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{1} + return fileDescriptor_e67338fe1f659d14, []int{1} } func (m *Change) XXX_Unmarshal(b []byte) error { @@ -157,7 +161,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{2} + return fileDescriptor_e67338fe1f659d14, []int{2} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -195,7 +199,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{3} + return fileDescriptor_e67338fe1f659d14, []int{3} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -227,7 +231,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{4} + return fileDescriptor_e67338fe1f659d14, []int{4} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -265,7 +269,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{5} + return fileDescriptor_e67338fe1f659d14, []int{5} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -297,7 +301,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{6} + return fileDescriptor_e67338fe1f659d14, []int{6} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -335,7 +339,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{7} + return fileDescriptor_e67338fe1f659d14, []int{7} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -366,7 +370,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{8} + return fileDescriptor_e67338fe1f659d14, []int{8} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -398,7 +402,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{9} + return fileDescriptor_e67338fe1f659d14, []int{9} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -438,7 +442,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{10} + return fileDescriptor_e67338fe1f659d14, []int{10} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -484,7 +488,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{11} + return fileDescriptor_e67338fe1f659d14, []int{11} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -524,7 +528,7 @@ func (m *WatchRequest) Reset() { *m = WatchRequest{} } func (m *WatchRequest) String() string { return proto.CompactTextString(m) } func (*WatchRequest) ProtoMessage() {} func (*WatchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{12} + return fileDescriptor_e67338fe1f659d14, []int{12} } func (m *WatchRequest) XXX_Unmarshal(b []byte) error { @@ -571,7 +575,7 @@ func (m *WatchResponse) Reset() { *m = WatchResponse{} } func (m *WatchResponse) String() string { return proto.CompactTextString(m) } func (*WatchResponse) ProtoMessage() {} func (*WatchResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_a0b84a42fa06f626, []int{13} + return fileDescriptor_e67338fe1f659d14, []int{13} } func (m *WatchResponse) XXX_Unmarshal(b []byte) error { @@ -623,35 +627,326 @@ func init() { proto.RegisterType((*WatchResponse)(nil), "WatchResponse") } -func init() { proto.RegisterFile("service.proto", fileDescriptor_a0b84a42fa06f626) } - -var fileDescriptor_a0b84a42fa06f626 = []byte{ - // 424 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xcd, 0x6a, 0xdb, 0x40, - 0x10, 0xc7, 0x2d, 0xdb, 0x51, 0xeb, 0xb1, 0x24, 0x97, 0x39, 0x14, 0x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, 0xe6, 0xe1, 0x30, 0xe4, 0x53, 0x04, 0x49, 0xc4, 0x67, - 0xef, 0xc9, 0x16, 0xb7, 0xde, 0x6f, 0xdf, 0xfc, 0x1d, 0xbe, 0xfc, 0x0b, 0x00, 0x00, 0xff, 0xff, - 0x1c, 0x3e, 0x57, 0xb0, 0x2e, 0x04, 0x00, 0x00, +func init() { + proto.RegisterFile("config/source/service/proto/service.proto", fileDescriptor_e67338fe1f659d14) +} + +var fileDescriptor_e67338fe1f659d14 = []byte{ + // 434 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xcd, 0x8e, 0xd3, 0x30, + 0x10, 0xc7, 0x9b, 0xb6, 0x1b, 0xe8, 0xb4, 0x49, 0xd1, 0x1c, 0x50, 0x14, 0x21, 0x51, 0x59, 0x42, + 0x2a, 0x20, 0xb9, 0xab, 0xf2, 0x00, 0x20, 0x95, 0x23, 0xa7, 0x20, 0xb4, 0x67, 0xe3, 0xce, 0x6e, + 0x23, 0x36, 0x1f, 0xc4, 0xce, 0xbe, 0xc3, 0xbe, 0x35, 0xf2, 0x47, 0x36, 0x49, 0x0f, 0x95, 0xca, + 0xcd, 0xf3, 0xf5, 0x9f, 0xb1, 0x7f, 0x93, 0xc0, 0x47, 0x59, 0x95, 0xf7, 0xf9, 0xc3, 0x4e, 0x55, + 0x6d, 0x23, 0x69, 0xa7, 0xa8, 0x79, 0xca, 0x25, 0xed, 0xea, 0xa6, 0xd2, 0x55, 0x67, 0x71, 0x6b, + 0xb1, 0xe7, 0x00, 0x16, 0x87, 0x93, 0x28, 0x1f, 0xe8, 0x27, 0x69, 0x44, 0x98, 0x1f, 0x85, 0x16, + 0x49, 0xb0, 0x09, 0xb6, 0x8b, 0xcc, 0x9e, 0x31, 0x85, 0xd7, 0xf2, 0x44, 0xf2, 0x8f, 0x6a, 0x8b, + 0x64, 0x6a, 0xfd, 0x2f, 0x36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0x41, 0xe4, 0x15, 0x7c, 0xcf, 0xcb, 0x12, + 0xa3, 0xc5, 0x98, 0x5e, 0x58, 0x8c, 0xfd, 0xf3, 0x14, 0xc2, 0x83, 0xfd, 0x70, 0xf0, 0x33, 0x84, + 0x8e, 0x38, 0xc6, 0x7c, 0xb4, 0x2c, 0xe9, 0x9a, 0x9f, 0xad, 0xc2, 0xc4, 0x24, 0x3b, 0xb4, 0x18, + 0xf3, 0xd1, 0x56, 0xa4, 0x6b, 0x7e, 0xc6, 0xdc, 0x26, 0x3b, 0x86, 0x18, 0xf3, 0x11, 0xfe, 0x74, + 0xcd, 0xcf, 0xe0, 0x4e, 0xf0, 0x03, 0xcc, 0x0d, 0x4f, 0x5c, 0xf1, 0x01, 0xe5, 0x34, 0xe2, 0x43, + 0xc8, 0x2e, 0xcd, 0x40, 0xc0, 0x15, 0x1f, 0xc0, 0x4c, 0x23, 0x3e, 0x24, 0xc3, 0x26, 0xf8, 0x09, + 0x6e, 0xec, 0xc3, 0x61, 0xc4, 0x87, 0x08, 0xd2, 0x98, 0x8f, 0xde, 0x93, 0x4d, 0x6e, 0x83, 0xdf, + 0xa1, 0xfd, 0x3b, 0x7c, 0xf9, 0x17, 0x00, 0x00, 0xff, 0xff, 0x05, 0xbb, 0xfd, 0xc1, 0x4a, 0x04, + 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// ConfigClient is the client API for Config service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ConfigClient interface { + Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) + Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) + List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) + Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) + Watch(ctx context.Context, in *WatchRequest, opts ...grpc.CallOption) (Config_WatchClient, error) +} + +type configClient struct { + cc *grpc.ClientConn +} + +func NewConfigClient(cc *grpc.ClientConn) ConfigClient { + return &configClient{cc} +} + +func (c *configClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { + out := new(CreateResponse) + err := c.cc.Invoke(ctx, "/Config/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *configClient) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) { + out := new(UpdateResponse) + err := c.cc.Invoke(ctx, "/Config/Update", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *configClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { + out := new(DeleteResponse) + err := c.cc.Invoke(ctx, "/Config/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *configClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) { + out := new(ListResponse) + err := c.cc.Invoke(ctx, "/Config/List", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *configClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { + out := new(ReadResponse) + err := c.cc.Invoke(ctx, "/Config/Read", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *configClient) Watch(ctx context.Context, in *WatchRequest, opts ...grpc.CallOption) (Config_WatchClient, error) { + stream, err := c.cc.NewStream(ctx, &_Config_serviceDesc.Streams[0], "/Config/Watch", opts...) + if err != nil { + return nil, err + } + x := &configWatchClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Config_WatchClient interface { + Recv() (*WatchResponse, error) + grpc.ClientStream +} + +type configWatchClient struct { + grpc.ClientStream +} + +func (x *configWatchClient) Recv() (*WatchResponse, error) { + m := new(WatchResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// ConfigServer is the server API for Config service. +type ConfigServer interface { + Create(context.Context, *CreateRequest) (*CreateResponse, error) + Update(context.Context, *UpdateRequest) (*UpdateResponse, error) + Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) + List(context.Context, *ListRequest) (*ListResponse, error) + Read(context.Context, *ReadRequest) (*ReadResponse, error) + Watch(*WatchRequest, Config_WatchServer) error +} + +// UnimplementedConfigServer can be embedded to have forward compatible implementations. +type UnimplementedConfigServer struct { +} + +func (*UnimplementedConfigServer) Create(ctx context.Context, req *CreateRequest) (*CreateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") +} +func (*UnimplementedConfigServer) Update(ctx context.Context, req *UpdateRequest) (*UpdateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Update not implemented") +} +func (*UnimplementedConfigServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} +func (*UnimplementedConfigServer) List(ctx context.Context, req *ListRequest) (*ListResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method List not implemented") +} +func (*UnimplementedConfigServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") +} +func (*UnimplementedConfigServer) Watch(req *WatchRequest, srv Config_WatchServer) error { + return status.Errorf(codes.Unimplemented, "method Watch not implemented") +} + +func RegisterConfigServer(s *grpc.Server, srv ConfigServer) { + s.RegisterService(&_Config_serviceDesc, srv) +} + +func _Config_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConfigServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Config/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConfigServer).Create(ctx, req.(*CreateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Config_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConfigServer).Update(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Config/Update", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConfigServer).Update(ctx, req.(*UpdateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Config_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConfigServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Config/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConfigServer).Delete(ctx, req.(*DeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Config_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConfigServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Config/List", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConfigServer).List(ctx, req.(*ListRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Config_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReadRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConfigServer).Read(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Config/Read", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConfigServer).Read(ctx, req.(*ReadRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Config_Watch_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(WatchRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(ConfigServer).Watch(m, &configWatchServer{stream}) +} + +type Config_WatchServer interface { + Send(*WatchResponse) error + grpc.ServerStream +} + +type configWatchServer struct { + grpc.ServerStream +} + +func (x *configWatchServer) Send(m *WatchResponse) error { + return x.ServerStream.SendMsg(m) +} + +var _Config_serviceDesc = grpc.ServiceDesc{ + ServiceName: "Config", + HandlerType: (*ConfigServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _Config_Create_Handler, + }, + { + MethodName: "Update", + Handler: _Config_Update_Handler, + }, + { + MethodName: "Delete", + Handler: _Config_Delete_Handler, + }, + { + MethodName: "List", + Handler: _Config_List_Handler, + }, + { + MethodName: "Read", + Handler: _Config_Read_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "Watch", + Handler: _Config_Watch_Handler, + ServerStreams: true, + }, + }, + Metadata: "config/source/service/proto/service.proto", } diff --git a/config/source/service/proto/service.pb.micro.go b/config/source/service/proto/service.pb.micro.go index 17c0288e..58e606ee 100644 --- a/config/source/service/proto/service.pb.micro.go +++ b/config/source/service/proto/service.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: service.proto +// source: config/source/service/proto/service.proto package service diff --git a/debug/service/proto/debug.pb.go b/debug/service/proto/debug.pb.go index 83e43aaa..41e6aebe 100644 --- a/debug/service/proto/debug.pb.go +++ b/debug/service/proto/debug.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: micro/go-micro/debug/service/proto/debug.proto +// source: debug/service/proto/debug.proto package debug import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -42,7 +46,7 @@ func (x SpanType) String() string { } func (SpanType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_dea322649cde1ef2, []int{0} + return fileDescriptor_df91f41a5db378e6, []int{0} } type HealthRequest struct { @@ -57,7 +61,7 @@ func (m *HealthRequest) Reset() { *m = HealthRequest{} } func (m *HealthRequest) String() string { return proto.CompactTextString(m) } func (*HealthRequest) ProtoMessage() {} func (*HealthRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dea322649cde1ef2, []int{0} + return fileDescriptor_df91f41a5db378e6, []int{0} } func (m *HealthRequest) XXX_Unmarshal(b []byte) error { @@ -97,7 +101,7 @@ func (m *HealthResponse) Reset() { *m = HealthResponse{} } func (m *HealthResponse) String() string { return proto.CompactTextString(m) } func (*HealthResponse) ProtoMessage() {} func (*HealthResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dea322649cde1ef2, []int{1} + return fileDescriptor_df91f41a5db378e6, []int{1} } func (m *HealthResponse) XXX_Unmarshal(b []byte) error { @@ -137,7 +141,7 @@ func (m *StatsRequest) Reset() { *m = StatsRequest{} } func (m *StatsRequest) String() string { return proto.CompactTextString(m) } func (*StatsRequest) ProtoMessage() {} func (*StatsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dea322649cde1ef2, []int{2} + return fileDescriptor_df91f41a5db378e6, []int{2} } func (m *StatsRequest) XXX_Unmarshal(b []byte) error { @@ -191,7 +195,7 @@ func (m *StatsResponse) Reset() { *m = StatsResponse{} } func (m *StatsResponse) String() string { return proto.CompactTextString(m) } func (*StatsResponse) ProtoMessage() {} func (*StatsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dea322649cde1ef2, []int{3} + return fileDescriptor_df91f41a5db378e6, []int{3} } func (m *StatsResponse) XXX_Unmarshal(b []byte) error { @@ -289,7 +293,7 @@ func (m *LogRequest) Reset() { *m = LogRequest{} } func (m *LogRequest) String() string { return proto.CompactTextString(m) } func (*LogRequest) ProtoMessage() {} func (*LogRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dea322649cde1ef2, []int{4} + return fileDescriptor_df91f41a5db378e6, []int{4} } func (m *LogRequest) XXX_Unmarshal(b []byte) error { @@ -355,7 +359,7 @@ func (m *Record) Reset() { *m = Record{} } func (m *Record) String() string { return proto.CompactTextString(m) } func (*Record) ProtoMessage() {} func (*Record) Descriptor() ([]byte, []int) { - return fileDescriptor_dea322649cde1ef2, []int{5} + return fileDescriptor_df91f41a5db378e6, []int{5} } func (m *Record) XXX_Unmarshal(b []byte) error { @@ -409,7 +413,7 @@ func (m *TraceRequest) Reset() { *m = TraceRequest{} } func (m *TraceRequest) String() string { return proto.CompactTextString(m) } func (*TraceRequest) ProtoMessage() {} func (*TraceRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_dea322649cde1ef2, []int{6} + return fileDescriptor_df91f41a5db378e6, []int{6} } func (m *TraceRequest) XXX_Unmarshal(b []byte) error { @@ -448,7 +452,7 @@ func (m *TraceResponse) Reset() { *m = TraceResponse{} } func (m *TraceResponse) String() string { return proto.CompactTextString(m) } func (*TraceResponse) ProtoMessage() {} func (*TraceResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_dea322649cde1ef2, []int{7} + return fileDescriptor_df91f41a5db378e6, []int{7} } func (m *TraceResponse) XXX_Unmarshal(b []byte) error { @@ -501,7 +505,7 @@ func (m *Span) Reset() { *m = Span{} } func (m *Span) String() string { return proto.CompactTextString(m) } func (*Span) ProtoMessage() {} func (*Span) Descriptor() ([]byte, []int) { - return fileDescriptor_dea322649cde1ef2, []int{8} + return fileDescriptor_df91f41a5db378e6, []int{8} } func (m *Span) XXX_Unmarshal(b []byte) error { @@ -593,48 +597,262 @@ func init() { proto.RegisterMapType((map[string]string)(nil), "Span.MetadataEntry") } -func init() { - proto.RegisterFile("micro/go-micro/debug/service/proto/debug.proto", fileDescriptor_dea322649cde1ef2) +func init() { proto.RegisterFile("debug/service/proto/debug.proto", fileDescriptor_df91f41a5db378e6) } + +var fileDescriptor_df91f41a5db378e6 = []byte{ + // 594 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xdb, 0x6e, 0xd3, 0x40, + 0x10, 0x8d, 0xed, 0x38, 0xb1, 0xa7, 0x8d, 0xa9, 0x96, 0x8b, 0x2c, 0x73, 0x69, 0x65, 0x09, 0x29, + 0x5c, 0xe4, 0x40, 0x79, 0x41, 0xf0, 0x86, 0x8a, 0x04, 0x52, 0x69, 0xa5, 0x6d, 0xfb, 0x01, 0x5b, + 0x7b, 0xe4, 0x1a, 0xea, 0x0b, 0xbb, 0xeb, 0x4a, 0xf9, 0x16, 0xbe, 0x80, 0x37, 0x7e, 0x86, 0xff, + 0x41, 0x7b, 0x71, 0x1b, 0x0b, 0xa1, 0x3e, 0xf0, 0xb6, 0xe7, 0xec, 0xec, 0xc9, 0xcc, 0xc9, 0xf1, + 0xc0, 0x6e, 0x81, 0xe7, 0x7d, 0xb9, 0x12, 0xc8, 0xaf, 0xaa, 0x1c, 0x57, 0x1d, 0x6f, 0x65, 0xbb, + 0xd2, 0x5c, 0xa6, 0xcf, 0xe9, 0x33, 0x58, 0x7c, 0x42, 0x76, 0x29, 0x2f, 0x28, 0x7e, 0xef, 0x51, + 0x48, 0x12, 0xc3, 0xdc, 0x56, 0xc7, 0xce, 0x9e, 0xb3, 0x0c, 0xe9, 0x00, 0xd3, 0x25, 0x44, 0x43, + 0xa9, 0xe8, 0xda, 0x46, 0x20, 0x79, 0x00, 0x33, 0x21, 0x99, 0xec, 0x85, 0x2d, 0xb5, 0x28, 0x5d, + 0xc2, 0xf6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xd4, 0x62, 0x20, + 0xbb, 0xe0, 0x1d, 0xb6, 0x25, 0xd9, 0xca, 0x6e, 0x12, 0x9c, 0xcc, 0x6d, 0x50, 0xd2, 0xc9, 0x2b, + 0x87, 0xbc, 0x80, 0x99, 0x59, 0x04, 0x24, 0xca, 0x46, 0xcb, 0x23, 0xb9, 0x93, 0x8d, 0x37, 0x44, + 0x3a, 0x21, 0x4b, 0xf0, 0xf5, 0x07, 0x4e, 0x16, 0xd9, 0xe6, 0x4e, 0x48, 0xa2, 0x6c, 0xf4, 0xdd, + 0x9b, 0x4a, 0xfd, 0xa7, 0x93, 0x45, 0xb6, 0x19, 0x8e, 0x24, 0xca, 0x46, 0x59, 0x48, 0x27, 0xe7, + 0x33, 0xbd, 0xbb, 0xde, 0xfc, 0x09, 0x00, 0x00, 0xff, 0xff, 0x6e, 0x42, 0x7f, 0x05, 0xde, 0x04, + 0x00, 0x00, } -var fileDescriptor_dea322649cde1ef2 = []byte{ - // 595 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xa4, 0x54, 0x5b, 0x6e, 0xd3, 0x40, - 0x14, 0x8d, 0x63, 0x3b, 0x71, 0x6e, 0x1e, 0x54, 0xc3, 0x43, 0x56, 0x78, 0xca, 0x12, 0x52, 0x78, - 0x39, 0x10, 0x7e, 0x10, 0xfc, 0xa1, 0x22, 0x81, 0x04, 0xad, 0x34, 0x4d, 0x17, 0x30, 0xb5, 0x47, - 0xa9, 0xa1, 0xf6, 0x98, 0x99, 0x71, 0xa5, 0xac, 0x85, 0x15, 0xf0, 0xc7, 0x66, 0xd8, 0x0f, 0xf3, - 0x72, 0x1a, 0x0b, 0xa1, 0x7e, 0xf0, 0x77, 0xcf, 0xf5, 0x99, 0x33, 0xf7, 0x9e, 0x9c, 0x0c, 0xa4, - 0x65, 0x91, 0x71, 0xb6, 0xdc, 0xb0, 0x17, 0xb6, 0xc8, 0xe9, 0x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33, 0xf0, 0x4d, 0x33, 0xf0, 0x3f, 0x6d, 0xbe, 0x0f, - 0x81, 0xdc, 0xd6, 0xd4, 0x84, 0x68, 0xb6, 0x1a, 0x19, 0xf2, 0x5a, 0x35, 0xb0, 0x69, 0xff, 0x97, - 0xd7, 0x4f, 0x1f, 0x43, 0xd4, 0xca, 0xa1, 0x31, 0x0c, 0x3f, 0x1d, 0xbd, 0x3f, 0x3e, 0x3d, 0x3a, - 0x3c, 0xe8, 0xa1, 0x09, 0x44, 0xc7, 0xa7, 0x6b, 0x8b, 0xbc, 0xd5, 0x4f, 0x0f, 0xc2, 0x43, 0xfd, - 0x30, 0xa0, 0x87, 0xe0, 0xab, 0xec, 0xa2, 0x71, 0x7a, 0x95, 0xe0, 0xf9, 0xd0, 0x05, 0x25, 0xe9, - 0xbd, 0xf4, 0xd0, 0x33, 0x18, 0xd8, 0x87, 0x00, 0xcd, 0xd2, 0xce, 0xe3, 0x31, 0xbf, 0x91, 0x76, - 0x5f, 0x88, 0xa4, 0x87, 0x16, 0x10, 0x9a, 0x3f, 0x38, 0x9a, 0xa6, 0xfb, 0x6f, 0xc2, 0x7c, 0x96, - 0x76, 0xfe, 0xf7, 0x96, 0x69, 0x7e, 0x74, 0xc5, 0xdc, 0x0f, 0x87, 0x62, 0x76, 0xb2, 0x90, 0xf4, - 0xce, 0x06, 0xe6, 0xed, 0x7a, 0xfd, 0x27, 0x00, 0x00, 0xff, 0xff, 0xbc, 0xab, 0x72, 0x03, 0xed, - 0x04, 0x00, 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// DebugClient is the client API for Debug service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type DebugClient interface { + Log(ctx context.Context, in *LogRequest, opts ...grpc.CallOption) (Debug_LogClient, error) + Health(ctx context.Context, in *HealthRequest, opts ...grpc.CallOption) (*HealthResponse, error) + Stats(ctx context.Context, in *StatsRequest, opts ...grpc.CallOption) (*StatsResponse, error) + Trace(ctx context.Context, in *TraceRequest, opts ...grpc.CallOption) (*TraceResponse, error) +} + +type debugClient struct { + cc *grpc.ClientConn +} + +func NewDebugClient(cc *grpc.ClientConn) DebugClient { + return &debugClient{cc} +} + +func (c *debugClient) Log(ctx context.Context, in *LogRequest, opts ...grpc.CallOption) (Debug_LogClient, error) { + stream, err := c.cc.NewStream(ctx, &_Debug_serviceDesc.Streams[0], "/Debug/Log", opts...) + if err != nil { + return nil, err + } + x := &debugLogClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Debug_LogClient interface { + Recv() (*Record, error) + grpc.ClientStream +} + +type debugLogClient struct { + grpc.ClientStream +} + +func (x *debugLogClient) Recv() (*Record, error) { + m := new(Record) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *debugClient) Health(ctx context.Context, in *HealthRequest, opts ...grpc.CallOption) (*HealthResponse, error) { + out := new(HealthResponse) + err := c.cc.Invoke(ctx, "/Debug/Health", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *debugClient) Stats(ctx context.Context, in *StatsRequest, opts ...grpc.CallOption) (*StatsResponse, error) { + out := new(StatsResponse) + err := c.cc.Invoke(ctx, "/Debug/Stats", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *debugClient) Trace(ctx context.Context, in *TraceRequest, opts ...grpc.CallOption) (*TraceResponse, error) { + out := new(TraceResponse) + err := c.cc.Invoke(ctx, "/Debug/Trace", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// DebugServer is the server API for Debug service. +type DebugServer interface { + Log(*LogRequest, Debug_LogServer) error + Health(context.Context, *HealthRequest) (*HealthResponse, error) + Stats(context.Context, *StatsRequest) (*StatsResponse, error) + Trace(context.Context, *TraceRequest) (*TraceResponse, error) +} + +// UnimplementedDebugServer can be embedded to have forward compatible implementations. +type UnimplementedDebugServer struct { +} + +func (*UnimplementedDebugServer) Log(req *LogRequest, srv Debug_LogServer) error { + return status.Errorf(codes.Unimplemented, "method Log not implemented") +} +func (*UnimplementedDebugServer) Health(ctx context.Context, req *HealthRequest) (*HealthResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Health not implemented") +} +func (*UnimplementedDebugServer) Stats(ctx context.Context, req *StatsRequest) (*StatsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Stats not implemented") +} +func (*UnimplementedDebugServer) Trace(ctx context.Context, req *TraceRequest) (*TraceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Trace not implemented") +} + +func RegisterDebugServer(s *grpc.Server, srv DebugServer) { + s.RegisterService(&_Debug_serviceDesc, srv) +} + +func _Debug_Log_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(LogRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(DebugServer).Log(m, &debugLogServer{stream}) +} + +type Debug_LogServer interface { + Send(*Record) error + grpc.ServerStream +} + +type debugLogServer struct { + grpc.ServerStream +} + +func (x *debugLogServer) Send(m *Record) error { + return x.ServerStream.SendMsg(m) +} + +func _Debug_Health_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HealthRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DebugServer).Health(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Debug/Health", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DebugServer).Health(ctx, req.(*HealthRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Debug_Stats_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DebugServer).Stats(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Debug/Stats", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DebugServer).Stats(ctx, req.(*StatsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Debug_Trace_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TraceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DebugServer).Trace(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Debug/Trace", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DebugServer).Trace(ctx, req.(*TraceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Debug_serviceDesc = grpc.ServiceDesc{ + ServiceName: "Debug", + HandlerType: (*DebugServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Health", + Handler: _Debug_Health_Handler, + }, + { + MethodName: "Stats", + Handler: _Debug_Stats_Handler, + }, + { + MethodName: "Trace", + Handler: _Debug_Trace_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "Log", + Handler: _Debug_Log_Handler, + ServerStreams: true, + }, + }, + Metadata: "debug/service/proto/debug.proto", } diff --git a/debug/service/proto/debug.pb.micro.go b/debug/service/proto/debug.pb.micro.go index 0692209c..9747f3c2 100644 --- a/debug/service/proto/debug.pb.micro.go +++ b/debug/service/proto/debug.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: micro/go-micro/debug/service/proto/debug.proto +// source: debug/service/proto/debug.proto package debug diff --git a/errors/errors.pb.go b/errors/errors.pb.go index f749993d..90fda81a 100644 --- a/errors/errors.pb.go +++ b/errors/errors.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: errors.proto +// source: errors/errors.proto package errors @@ -34,7 +34,7 @@ func (m *Error) Reset() { *m = Error{} } func (m *Error) String() string { return proto.CompactTextString(m) } func (*Error) ProtoMessage() {} func (*Error) Descriptor() ([]byte, []int) { - return fileDescriptor_24fe73c7f0ddb19c, []int{0} + return fileDescriptor_85c4eef3398a32b2, []int{0} } func (m *Error) XXX_Unmarshal(b []byte) error { @@ -87,16 +87,16 @@ func init() { proto.RegisterType((*Error)(nil), "errors.Error") } -func init() { proto.RegisterFile("errors.proto", fileDescriptor_24fe73c7f0ddb19c) } +func init() { proto.RegisterFile("errors/errors.proto", fileDescriptor_85c4eef3398a32b2) } -var fileDescriptor_24fe73c7f0ddb19c = []byte{ - // 116 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0x2d, 0x2a, 0xca, - 0x2f, 0x2a, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0x94, 0xa2, 0xb9, 0x58, - 0x5d, 0x41, 0x2c, 0x21, 0x3e, 0x2e, 0xa6, 0xcc, 0x14, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20, - 0xa6, 0xcc, 0x14, 0x21, 0x21, 0x2e, 0x96, 0xe4, 0xfc, 0x94, 0x54, 0x09, 0x26, 0x05, 0x46, 0x0d, - 0xd6, 0x20, 0x30, 0x5b, 0x48, 0x8c, 0x8b, 0x2d, 0x25, 0xb5, 0x24, 0x31, 0x33, 0x47, 0x82, 0x19, - 0xac, 0x0e, 0xca, 0x03, 0x89, 0x17, 0x97, 0x24, 0x96, 0x94, 0x16, 0x4b, 0xb0, 0x40, 0xc4, 0x21, - 0xbc, 0x24, 0x36, 0xb0, 0x5d, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xef, 0xe7, 0x5d, 0xd3, - 0x7b, 0x00, 0x00, 0x00, +var fileDescriptor_85c4eef3398a32b2 = []byte{ + // 118 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4e, 0x2d, 0x2a, 0xca, + 0x2f, 0x2a, 0xd6, 0x87, 0x50, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x6c, 0x10, 0x9e, 0x52, + 0x34, 0x17, 0xab, 0x2b, 0x88, 0x25, 0xc4, 0xc7, 0xc5, 0x94, 0x99, 0x22, 0xc1, 0xa8, 0xc0, 0xa8, + 0xc1, 0x19, 0xc4, 0x94, 0x99, 0x22, 0x24, 0xc4, 0xc5, 0x92, 0x9c, 0x9f, 0x92, 0x2a, 0xc1, 0xa4, + 0xc0, 0xa8, 0xc1, 0x1a, 0x04, 0x66, 0x0b, 0x89, 0x71, 0xb1, 0xa5, 0xa4, 0x96, 0x24, 0x66, 0xe6, + 0x48, 0x30, 0x83, 0xd5, 0x41, 0x79, 0x20, 0xf1, 0xe2, 0x92, 0xc4, 0x92, 0xd2, 0x62, 0x09, 0x16, + 0x88, 0x38, 0x84, 0x97, 0xc4, 0x06, 0xb6, 0xcb, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xca, 0xc3, + 0xcb, 0x29, 0x82, 0x00, 0x00, 0x00, } diff --git a/errors/errors.pb.micro.go b/errors/errors.pb.micro.go new file mode 100644 index 00000000..7a26efe7 --- /dev/null +++ b/errors/errors.pb.micro.go @@ -0,0 +1,21 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: errors/errors.proto + +package errors + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package diff --git a/generate.go b/generate.go new file mode 100644 index 00000000..26d7e9f2 --- /dev/null +++ b/generate.go @@ -0,0 +1,3 @@ +package micro + +//go:generate ./.github/generate.sh diff --git a/go.mod b/go.mod index a0ce00d1..02f6f3dc 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,7 @@ require ( github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.3.2 + github.com/google/go-cmp v0.4.0 // indirect github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/websocket v1.4.1 diff --git a/go.sum b/go.sum index 07d12b66..57ad009a 100644 --- a/go.sum +++ b/go.sum @@ -191,6 +191,8 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= @@ -588,6 +590,8 @@ golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 h1:RIIXAeV6GvDBuADKumTODat golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= diff --git a/network/service/proto/network.pb.go b/network/service/proto/network.pb.go index 6dded795..553d74e6 100644 --- a/network/service/proto/network.pb.go +++ b/network/service/proto/network.pb.go @@ -1,12 +1,16 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: network.proto +// source: network/service/proto/network.proto package go_micro_network import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" proto1 "github.com/micro/go-micro/v2/router/service/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -37,7 +41,7 @@ func (m *Query) Reset() { *m = Query{} } func (m *Query) String() string { return proto.CompactTextString(m) } func (*Query) ProtoMessage() {} func (*Query) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{0} + return fileDescriptor_1aab434177f140e0, []int{0} } func (m *Query) XXX_Unmarshal(b []byte) error { @@ -104,7 +108,7 @@ func (m *ConnectRequest) Reset() { *m = ConnectRequest{} } func (m *ConnectRequest) String() string { return proto.CompactTextString(m) } func (*ConnectRequest) ProtoMessage() {} func (*ConnectRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{1} + return fileDescriptor_1aab434177f140e0, []int{1} } func (m *ConnectRequest) XXX_Unmarshal(b []byte) error { @@ -142,7 +146,7 @@ func (m *ConnectResponse) Reset() { *m = ConnectResponse{} } func (m *ConnectResponse) String() string { return proto.CompactTextString(m) } func (*ConnectResponse) ProtoMessage() {} func (*ConnectResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{2} + return fileDescriptor_1aab434177f140e0, []int{2} } func (m *ConnectResponse) XXX_Unmarshal(b []byte) error { @@ -176,7 +180,7 @@ func (m *NodesRequest) Reset() { *m = NodesRequest{} } func (m *NodesRequest) String() string { return proto.CompactTextString(m) } func (*NodesRequest) ProtoMessage() {} func (*NodesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{3} + return fileDescriptor_1aab434177f140e0, []int{3} } func (m *NodesRequest) XXX_Unmarshal(b []byte) error { @@ -217,7 +221,7 @@ func (m *NodesResponse) Reset() { *m = NodesResponse{} } func (m *NodesResponse) String() string { return proto.CompactTextString(m) } func (*NodesResponse) ProtoMessage() {} func (*NodesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{4} + return fileDescriptor_1aab434177f140e0, []int{4} } func (m *NodesResponse) XXX_Unmarshal(b []byte) error { @@ -257,7 +261,7 @@ func (m *GraphRequest) Reset() { *m = GraphRequest{} } func (m *GraphRequest) String() string { return proto.CompactTextString(m) } func (*GraphRequest) ProtoMessage() {} func (*GraphRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{5} + return fileDescriptor_1aab434177f140e0, []int{5} } func (m *GraphRequest) XXX_Unmarshal(b []byte) error { @@ -296,7 +300,7 @@ func (m *GraphResponse) Reset() { *m = GraphResponse{} } func (m *GraphResponse) String() string { return proto.CompactTextString(m) } func (*GraphResponse) ProtoMessage() {} func (*GraphResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{6} + return fileDescriptor_1aab434177f140e0, []int{6} } func (m *GraphResponse) XXX_Unmarshal(b []byte) error { @@ -336,7 +340,7 @@ func (m *RoutesRequest) Reset() { *m = RoutesRequest{} } func (m *RoutesRequest) String() string { return proto.CompactTextString(m) } func (*RoutesRequest) ProtoMessage() {} func (*RoutesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{7} + return fileDescriptor_1aab434177f140e0, []int{7} } func (m *RoutesRequest) XXX_Unmarshal(b []byte) error { @@ -375,7 +379,7 @@ func (m *RoutesResponse) Reset() { *m = RoutesResponse{} } func (m *RoutesResponse) String() string { return proto.CompactTextString(m) } func (*RoutesResponse) ProtoMessage() {} func (*RoutesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{8} + return fileDescriptor_1aab434177f140e0, []int{8} } func (m *RoutesResponse) XXX_Unmarshal(b []byte) error { @@ -413,7 +417,7 @@ func (m *ServicesRequest) Reset() { *m = ServicesRequest{} } func (m *ServicesRequest) String() string { return proto.CompactTextString(m) } func (*ServicesRequest) ProtoMessage() {} func (*ServicesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{9} + return fileDescriptor_1aab434177f140e0, []int{9} } func (m *ServicesRequest) XXX_Unmarshal(b []byte) error { @@ -445,7 +449,7 @@ func (m *ServicesResponse) Reset() { *m = ServicesResponse{} } func (m *ServicesResponse) String() string { return proto.CompactTextString(m) } func (*ServicesResponse) ProtoMessage() {} func (*ServicesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{10} + return fileDescriptor_1aab434177f140e0, []int{10} } func (m *ServicesResponse) XXX_Unmarshal(b []byte) error { @@ -483,7 +487,7 @@ func (m *StatusRequest) Reset() { *m = StatusRequest{} } func (m *StatusRequest) String() string { return proto.CompactTextString(m) } func (*StatusRequest) ProtoMessage() {} func (*StatusRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{11} + return fileDescriptor_1aab434177f140e0, []int{11} } func (m *StatusRequest) XXX_Unmarshal(b []byte) error { @@ -515,7 +519,7 @@ func (m *StatusResponse) Reset() { *m = StatusResponse{} } func (m *StatusResponse) String() string { return proto.CompactTextString(m) } func (*StatusResponse) ProtoMessage() {} func (*StatusResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{12} + return fileDescriptor_1aab434177f140e0, []int{12} } func (m *StatusResponse) XXX_Unmarshal(b []byte) error { @@ -556,7 +560,7 @@ func (m *Error) Reset() { *m = Error{} } func (m *Error) String() string { return proto.CompactTextString(m) } func (*Error) ProtoMessage() {} func (*Error) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{13} + return fileDescriptor_1aab434177f140e0, []int{13} } func (m *Error) XXX_Unmarshal(b []byte) error { @@ -603,7 +607,7 @@ func (m *Status) Reset() { *m = Status{} } func (m *Status) String() string { return proto.CompactTextString(m) } func (*Status) ProtoMessage() {} func (*Status) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{14} + return fileDescriptor_1aab434177f140e0, []int{14} } func (m *Status) XXX_Unmarshal(b []byte) error { @@ -652,7 +656,7 @@ func (m *Node) Reset() { *m = Node{} } func (m *Node) String() string { return proto.CompactTextString(m) } func (*Node) ProtoMessage() {} func (*Node) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{15} + return fileDescriptor_1aab434177f140e0, []int{15} } func (m *Node) XXX_Unmarshal(b []byte) error { @@ -721,7 +725,7 @@ func (m *Connect) Reset() { *m = Connect{} } func (m *Connect) String() string { return proto.CompactTextString(m) } func (*Connect) ProtoMessage() {} func (*Connect) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{16} + return fileDescriptor_1aab434177f140e0, []int{16} } func (m *Connect) XXX_Unmarshal(b []byte) error { @@ -762,7 +766,7 @@ func (m *Close) Reset() { *m = Close{} } func (m *Close) String() string { return proto.CompactTextString(m) } func (*Close) ProtoMessage() {} func (*Close) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{17} + return fileDescriptor_1aab434177f140e0, []int{17} } func (m *Close) XXX_Unmarshal(b []byte) error { @@ -805,7 +809,7 @@ func (m *Peer) Reset() { *m = Peer{} } func (m *Peer) String() string { return proto.CompactTextString(m) } func (*Peer) ProtoMessage() {} func (*Peer) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{18} + return fileDescriptor_1aab434177f140e0, []int{18} } func (m *Peer) XXX_Unmarshal(b []byte) error { @@ -855,7 +859,7 @@ func (m *Sync) Reset() { *m = Sync{} } func (m *Sync) String() string { return proto.CompactTextString(m) } func (*Sync) ProtoMessage() {} func (*Sync) Descriptor() ([]byte, []int) { - return fileDescriptor_8571034d60397816, []int{19} + return fileDescriptor_1aab434177f140e0, []int{19} } func (m *Sync) XXX_Unmarshal(b []byte) error { @@ -914,51 +918,324 @@ func init() { proto.RegisterType((*Sync)(nil), "go.micro.network.Sync") } -func init() { proto.RegisterFile("network.proto", fileDescriptor_8571034d60397816) } - -var fileDescriptor_8571034d60397816 = []byte{ - // 678 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0xdd, 0x4e, 0xdb, 0x30, - 0x14, 0xa6, 0x6d, 0x52, 0xe0, 0x8c, 0x14, 0x66, 0x4d, 0x2c, 0xca, 0xc5, 0xe8, 0x2c, 0x2e, 0xd0, - 0x34, 0xd2, 0x09, 0x34, 0x6d, 0x1a, 0x1a, 0x42, 0x43, 0x68, 0xd2, 0x24, 0x10, 0x4b, 0x5f, 0x60, - 0x21, 0xb1, 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0x46, 0xde, 0x4e, 0xe3, 0x7d, 0xd9, 0x97, 0xd6, 0xbf, 0x3a, 0x5f, 0x65, - 0xf9, 0xac, 0xf3, 0x55, 0x11, 0x4e, 0xba, 0x42, 0xce, 0xa1, 0x6b, 0x94, 0x86, 0xd4, 0x80, 0x2b, - 0x1a, 0xe6, 0xf5, 0x9b, 0x01, 0x85, 0xbb, 0x21, 0xac, 0xe5, 0x1a, 0x43, 0x6a, 0xea, 0xf2, 0x44, - 0x92, 0x3c, 0xba, 0x08, 0x52, 0x7e, 0x23, 0x4a, 0xc0, 0x4e, 0xe3, 0xd2, 0x34, 0xbf, 0xb1, 0x2a, - 0x59, 0x74, 0xe5, 0xaa, 0xab, 0x7f, 0xa4, 0x87, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x11, 0x45, - 0xe6, 0xf4, 0xa8, 0x07, 0x00, 0x00, +func init() { + proto.RegisterFile("network/service/proto/network.proto", fileDescriptor_1aab434177f140e0) +} + +var fileDescriptor_1aab434177f140e0 = []byte{ + // 667 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0xdd, 0x4e, 0xdb, 0x4c, + 0x10, 0xc5, 0xb1, 0x1d, 0x60, 0x3e, 0x1c, 0xf8, 0x56, 0x15, 0xb5, 0x7c, 0x51, 0xc2, 0x96, 0x0b, + 0x54, 0xb5, 0x4e, 0x05, 0xaa, 0x5a, 0x15, 0x15, 0xa1, 0x22, 0x54, 0xa9, 0x12, 0x88, 0x3a, 0x2f, + 0x50, 0x13, 0xaf, 0x20, 0x02, 0xbc, 0x61, 0xbd, 0x06, 0xe5, 0x09, 0xfa, 0xa6, 0x7d, 0x89, 0xde, + 0x54, 0xbb, 0x3b, 0x36, 0x36, 0xb1, 0xd3, 0x70, 0x97, 0x99, 0x3d, 0x67, 0xc6, 0xf3, 0x77, 0x02, + 0xaf, 0x53, 0x26, 0x1f, 0xb8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74, 0x1e, 0xa4, 0xfa, 0x8d, 0x28, 0x01, 0x5b, 0xad, + 0x47, 0xd3, 0xfe, 0x8d, 0x75, 0xc9, 0xa2, 0x4b, 0x17, 0x5d, 0xfd, 0x47, 0xba, 0xff, 0x37, 0x00, + 0x00, 0xff, 0xff, 0x13, 0x9f, 0x0c, 0xc2, 0xa4, 0x07, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// NetworkClient is the client API for Network service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type NetworkClient interface { + // Connect to the network + Connect(ctx context.Context, in *ConnectRequest, opts ...grpc.CallOption) (*ConnectResponse, error) + // Returns the entire network graph + Graph(ctx context.Context, in *GraphRequest, opts ...grpc.CallOption) (*GraphResponse, error) + // Returns a list of known nodes in the network + Nodes(ctx context.Context, in *NodesRequest, opts ...grpc.CallOption) (*NodesResponse, error) + // Returns a list of known routes in the network + Routes(ctx context.Context, in *RoutesRequest, opts ...grpc.CallOption) (*RoutesResponse, error) + // Returns a list of known services based on routes + Services(ctx context.Context, in *ServicesRequest, opts ...grpc.CallOption) (*ServicesResponse, error) + // Status returns network status + Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*StatusResponse, error) +} + +type networkClient struct { + cc *grpc.ClientConn +} + +func NewNetworkClient(cc *grpc.ClientConn) NetworkClient { + return &networkClient{cc} +} + +func (c *networkClient) Connect(ctx context.Context, in *ConnectRequest, opts ...grpc.CallOption) (*ConnectResponse, error) { + out := new(ConnectResponse) + err := c.cc.Invoke(ctx, "/go.micro.network.Network/Connect", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *networkClient) Graph(ctx context.Context, in *GraphRequest, opts ...grpc.CallOption) (*GraphResponse, error) { + out := new(GraphResponse) + err := c.cc.Invoke(ctx, "/go.micro.network.Network/Graph", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *networkClient) Nodes(ctx context.Context, in *NodesRequest, opts ...grpc.CallOption) (*NodesResponse, error) { + out := new(NodesResponse) + err := c.cc.Invoke(ctx, "/go.micro.network.Network/Nodes", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *networkClient) Routes(ctx context.Context, in *RoutesRequest, opts ...grpc.CallOption) (*RoutesResponse, error) { + out := new(RoutesResponse) + err := c.cc.Invoke(ctx, "/go.micro.network.Network/Routes", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *networkClient) Services(ctx context.Context, in *ServicesRequest, opts ...grpc.CallOption) (*ServicesResponse, error) { + out := new(ServicesResponse) + err := c.cc.Invoke(ctx, "/go.micro.network.Network/Services", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *networkClient) Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*StatusResponse, error) { + out := new(StatusResponse) + err := c.cc.Invoke(ctx, "/go.micro.network.Network/Status", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// NetworkServer is the server API for Network service. +type NetworkServer interface { + // Connect to the network + Connect(context.Context, *ConnectRequest) (*ConnectResponse, error) + // Returns the entire network graph + Graph(context.Context, *GraphRequest) (*GraphResponse, error) + // Returns a list of known nodes in the network + Nodes(context.Context, *NodesRequest) (*NodesResponse, error) + // Returns a list of known routes in the network + Routes(context.Context, *RoutesRequest) (*RoutesResponse, error) + // Returns a list of known services based on routes + Services(context.Context, *ServicesRequest) (*ServicesResponse, error) + // Status returns network status + Status(context.Context, *StatusRequest) (*StatusResponse, error) +} + +// UnimplementedNetworkServer can be embedded to have forward compatible implementations. +type UnimplementedNetworkServer struct { +} + +func (*UnimplementedNetworkServer) Connect(ctx context.Context, req *ConnectRequest) (*ConnectResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Connect not implemented") +} +func (*UnimplementedNetworkServer) Graph(ctx context.Context, req *GraphRequest) (*GraphResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Graph not implemented") +} +func (*UnimplementedNetworkServer) Nodes(ctx context.Context, req *NodesRequest) (*NodesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Nodes not implemented") +} +func (*UnimplementedNetworkServer) Routes(ctx context.Context, req *RoutesRequest) (*RoutesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Routes not implemented") +} +func (*UnimplementedNetworkServer) Services(ctx context.Context, req *ServicesRequest) (*ServicesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Services not implemented") +} +func (*UnimplementedNetworkServer) Status(ctx context.Context, req *StatusRequest) (*StatusResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Status not implemented") +} + +func RegisterNetworkServer(s *grpc.Server, srv NetworkServer) { + s.RegisterService(&_Network_serviceDesc, srv) +} + +func _Network_Connect_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ConnectRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(NetworkServer).Connect(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.network.Network/Connect", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(NetworkServer).Connect(ctx, req.(*ConnectRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Network_Graph_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GraphRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(NetworkServer).Graph(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.network.Network/Graph", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(NetworkServer).Graph(ctx, req.(*GraphRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Network_Nodes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(NodesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(NetworkServer).Nodes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.network.Network/Nodes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(NetworkServer).Nodes(ctx, req.(*NodesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Network_Routes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RoutesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(NetworkServer).Routes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.network.Network/Routes", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(NetworkServer).Routes(ctx, req.(*RoutesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Network_Services_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ServicesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(NetworkServer).Services(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.network.Network/Services", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(NetworkServer).Services(ctx, req.(*ServicesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Network_Status_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatusRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(NetworkServer).Status(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.network.Network/Status", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(NetworkServer).Status(ctx, req.(*StatusRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Network_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.network.Network", + HandlerType: (*NetworkServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Connect", + Handler: _Network_Connect_Handler, + }, + { + MethodName: "Graph", + Handler: _Network_Graph_Handler, + }, + { + MethodName: "Nodes", + Handler: _Network_Nodes_Handler, + }, + { + MethodName: "Routes", + Handler: _Network_Routes_Handler, + }, + { + MethodName: "Services", + Handler: _Network_Services_Handler, + }, + { + MethodName: "Status", + Handler: _Network_Status_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "network/service/proto/network.proto", } diff --git a/network/service/proto/network.pb.micro.go b/network/service/proto/network.pb.micro.go index 4fbda43d..8b5ab957 100644 --- a/network/service/proto/network.pb.micro.go +++ b/network/service/proto/network.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: network.proto +// source: network/service/proto/network.proto package go_micro_network @@ -55,12 +55,6 @@ type networkService struct { } func NewNetworkService(name string, c client.Client) NetworkService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "go.micro.network" - } return &networkService{ c: c, name: name, diff --git a/network/service/proto/network.proto b/network/service/proto/network.proto index f2bbdb9e..5822d48d 100644 --- a/network/service/proto/network.proto +++ b/network/service/proto/network.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package go.micro.network; -import "github.com/micro/go-micro/router/service/proto/router.proto"; +import "router/service/proto/router.proto"; // Network service is usesd to gain visibility into networks service Network { diff --git a/registry/service/proto/registry.pb.go b/registry/service/proto/registry.pb.go index 9383e99a..fe8063e6 100644 --- a/registry/service/proto/registry.pb.go +++ b/registry/service/proto/registry.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: micro/go-micro/registry/service/proto/registry.proto +// source: registry/service/proto/registry.proto package go_micro_registry import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -46,7 +50,7 @@ func (x EventType) String() string { } func (EventType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{0} + return fileDescriptor_3f5817c11f323eb6, []int{0} } // Service represents a go-micro service @@ -66,7 +70,7 @@ func (m *Service) Reset() { *m = Service{} } func (m *Service) String() string { return proto.CompactTextString(m) } func (*Service) ProtoMessage() {} func (*Service) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{0} + return fileDescriptor_3f5817c11f323eb6, []int{0} } func (m *Service) XXX_Unmarshal(b []byte) error { @@ -144,7 +148,7 @@ func (m *Node) Reset() { *m = Node{} } func (m *Node) String() string { return proto.CompactTextString(m) } func (*Node) ProtoMessage() {} func (*Node) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{1} + return fileDescriptor_3f5817c11f323eb6, []int{1} } func (m *Node) XXX_Unmarshal(b []byte) error { @@ -208,7 +212,7 @@ func (m *Endpoint) Reset() { *m = Endpoint{} } func (m *Endpoint) String() string { return proto.CompactTextString(m) } func (*Endpoint) ProtoMessage() {} func (*Endpoint) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{2} + return fileDescriptor_3f5817c11f323eb6, []int{2} } func (m *Endpoint) XXX_Unmarshal(b []byte) error { @@ -271,7 +275,7 @@ func (m *Value) Reset() { *m = Value{} } func (m *Value) String() string { return proto.CompactTextString(m) } func (*Value) ProtoMessage() {} func (*Value) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{3} + return fileDescriptor_3f5817c11f323eb6, []int{3} } func (m *Value) XXX_Unmarshal(b []byte) error { @@ -325,7 +329,7 @@ func (m *Options) Reset() { *m = Options{} } func (m *Options) String() string { return proto.CompactTextString(m) } func (*Options) ProtoMessage() {} func (*Options) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{4} + return fileDescriptor_3f5817c11f323eb6, []int{4} } func (m *Options) XXX_Unmarshal(b []byte) error { @@ -367,7 +371,7 @@ func (m *Result) Reset() { *m = Result{} } func (m *Result) String() string { return proto.CompactTextString(m) } func (*Result) ProtoMessage() {} func (*Result) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{5} + return fileDescriptor_3f5817c11f323eb6, []int{5} } func (m *Result) XXX_Unmarshal(b []byte) error { @@ -419,7 +423,7 @@ func (m *EmptyResponse) Reset() { *m = EmptyResponse{} } func (m *EmptyResponse) String() string { return proto.CompactTextString(m) } func (*EmptyResponse) ProtoMessage() {} func (*EmptyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{6} + return fileDescriptor_3f5817c11f323eb6, []int{6} } func (m *EmptyResponse) XXX_Unmarshal(b []byte) error { @@ -451,7 +455,7 @@ func (m *GetRequest) Reset() { *m = GetRequest{} } func (m *GetRequest) String() string { return proto.CompactTextString(m) } func (*GetRequest) ProtoMessage() {} func (*GetRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{7} + return fileDescriptor_3f5817c11f323eb6, []int{7} } func (m *GetRequest) XXX_Unmarshal(b []byte) error { @@ -490,7 +494,7 @@ func (m *GetResponse) Reset() { *m = GetResponse{} } func (m *GetResponse) String() string { return proto.CompactTextString(m) } func (*GetResponse) ProtoMessage() {} func (*GetResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{8} + return fileDescriptor_3f5817c11f323eb6, []int{8} } func (m *GetResponse) XXX_Unmarshal(b []byte) error { @@ -528,7 +532,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{9} + return fileDescriptor_3f5817c11f323eb6, []int{9} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -560,7 +564,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{10} + return fileDescriptor_3f5817c11f323eb6, []int{10} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -600,7 +604,7 @@ func (m *WatchRequest) Reset() { *m = WatchRequest{} } func (m *WatchRequest) String() string { return proto.CompactTextString(m) } func (*WatchRequest) ProtoMessage() {} func (*WatchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{11} + return fileDescriptor_3f5817c11f323eb6, []int{11} } func (m *WatchRequest) XXX_Unmarshal(b []byte) error { @@ -647,7 +651,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_2f73432195c6499a, []int{12} + return fileDescriptor_3f5817c11f323eb6, []int{12} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -717,52 +721,304 @@ func init() { } func init() { - proto.RegisterFile("micro/go-micro/registry/service/proto/registry.proto", fileDescriptor_2f73432195c6499a) + proto.RegisterFile("registry/service/proto/registry.proto", fileDescriptor_3f5817c11f323eb6) } -var fileDescriptor_2f73432195c6499a = []byte{ - // 681 bytes of a gzipped FileDescriptorProto +var fileDescriptor_3f5817c11f323eb6 = []byte{ + // 675 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xdd, 0x6e, 0xd3, 0x4c, - 0x10, 0x8d, 0xed, 0xfc, 0x4e, 0xda, 0x7e, 0xfd, 0x46, 0x08, 0x8c, 0x5b, 0x20, 0xb2, 0x04, 0x0a, - 0x48, 0x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ff, 0x15, 0x00, 0x00, 0xff, 0xff, 0xc6, 0xa5, 0x5a, 0xc9, 0xcf, + 0x07, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// RegistryClient is the client API for Registry service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type RegistryClient interface { + GetService(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) + Register(ctx context.Context, in *Service, opts ...grpc.CallOption) (*EmptyResponse, error) + Deregister(ctx context.Context, in *Service, opts ...grpc.CallOption) (*EmptyResponse, error) + ListServices(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) + Watch(ctx context.Context, in *WatchRequest, opts ...grpc.CallOption) (Registry_WatchClient, error) +} + +type registryClient struct { + cc *grpc.ClientConn +} + +func NewRegistryClient(cc *grpc.ClientConn) RegistryClient { + return ®istryClient{cc} +} + +func (c *registryClient) GetService(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) { + out := new(GetResponse) + err := c.cc.Invoke(ctx, "/go.micro.registry.Registry/GetService", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *registryClient) Register(ctx context.Context, in *Service, opts ...grpc.CallOption) (*EmptyResponse, error) { + out := new(EmptyResponse) + err := c.cc.Invoke(ctx, "/go.micro.registry.Registry/Register", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *registryClient) Deregister(ctx context.Context, in *Service, opts ...grpc.CallOption) (*EmptyResponse, error) { + out := new(EmptyResponse) + err := c.cc.Invoke(ctx, "/go.micro.registry.Registry/Deregister", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *registryClient) ListServices(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) { + out := new(ListResponse) + err := c.cc.Invoke(ctx, "/go.micro.registry.Registry/ListServices", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *registryClient) Watch(ctx context.Context, in *WatchRequest, opts ...grpc.CallOption) (Registry_WatchClient, error) { + stream, err := c.cc.NewStream(ctx, &_Registry_serviceDesc.Streams[0], "/go.micro.registry.Registry/Watch", opts...) + if err != nil { + return nil, err + } + x := ®istryWatchClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Registry_WatchClient interface { + Recv() (*Result, error) + grpc.ClientStream +} + +type registryWatchClient struct { + grpc.ClientStream +} + +func (x *registryWatchClient) Recv() (*Result, error) { + m := new(Result) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// RegistryServer is the server API for Registry service. +type RegistryServer interface { + GetService(context.Context, *GetRequest) (*GetResponse, error) + Register(context.Context, *Service) (*EmptyResponse, error) + Deregister(context.Context, *Service) (*EmptyResponse, error) + ListServices(context.Context, *ListRequest) (*ListResponse, error) + Watch(*WatchRequest, Registry_WatchServer) error +} + +// UnimplementedRegistryServer can be embedded to have forward compatible implementations. +type UnimplementedRegistryServer struct { +} + +func (*UnimplementedRegistryServer) GetService(ctx context.Context, req *GetRequest) (*GetResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetService not implemented") +} +func (*UnimplementedRegistryServer) Register(ctx context.Context, req *Service) (*EmptyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Register not implemented") +} +func (*UnimplementedRegistryServer) Deregister(ctx context.Context, req *Service) (*EmptyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Deregister not implemented") +} +func (*UnimplementedRegistryServer) ListServices(ctx context.Context, req *ListRequest) (*ListResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListServices not implemented") +} +func (*UnimplementedRegistryServer) Watch(req *WatchRequest, srv Registry_WatchServer) error { + return status.Errorf(codes.Unimplemented, "method Watch not implemented") +} + +func RegisterRegistryServer(s *grpc.Server, srv RegistryServer) { + s.RegisterService(&_Registry_serviceDesc, srv) +} + +func _Registry_GetService_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RegistryServer).GetService(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.registry.Registry/GetService", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RegistryServer).GetService(ctx, req.(*GetRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Registry_Register_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Service) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RegistryServer).Register(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.registry.Registry/Register", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RegistryServer).Register(ctx, req.(*Service)) + } + return interceptor(ctx, in, info, handler) +} + +func _Registry_Deregister_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Service) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RegistryServer).Deregister(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.registry.Registry/Deregister", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RegistryServer).Deregister(ctx, req.(*Service)) + } + return interceptor(ctx, in, info, handler) +} + +func _Registry_ListServices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RegistryServer).ListServices(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.registry.Registry/ListServices", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RegistryServer).ListServices(ctx, req.(*ListRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Registry_Watch_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(WatchRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(RegistryServer).Watch(m, ®istryWatchServer{stream}) +} + +type Registry_WatchServer interface { + Send(*Result) error + grpc.ServerStream +} + +type registryWatchServer struct { + grpc.ServerStream +} + +func (x *registryWatchServer) Send(m *Result) error { + return x.ServerStream.SendMsg(m) +} + +var _Registry_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.registry.Registry", + HandlerType: (*RegistryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetService", + Handler: _Registry_GetService_Handler, + }, + { + MethodName: "Register", + Handler: _Registry_Register_Handler, + }, + { + MethodName: "Deregister", + Handler: _Registry_Deregister_Handler, + }, + { + MethodName: "ListServices", + Handler: _Registry_ListServices_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "Watch", + Handler: _Registry_Watch_Handler, + ServerStreams: true, + }, + }, + Metadata: "registry/service/proto/registry.proto", } diff --git a/registry/service/proto/registry.pb.micro.go b/registry/service/proto/registry.pb.micro.go index 7317a4eb..96af6f7e 100644 --- a/registry/service/proto/registry.pb.micro.go +++ b/registry/service/proto/registry.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: micro/go-micro/registry/service/proto/registry.proto +// source: registry/service/proto/registry.proto package go_micro_registry @@ -47,12 +47,6 @@ type registryService struct { } func NewRegistryService(name string, c client.Client) RegistryService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "go.micro.registry" - } return ®istryService{ c: c, name: name, @@ -112,6 +106,7 @@ func (c *registryService) Watch(ctx context.Context, in *WatchRequest, opts ...c } type Registry_WatchService interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -126,6 +121,10 @@ func (x *registryServiceWatch) Close() error { return x.stream.Close() } +func (x *registryServiceWatch) Context() context.Context { + return x.stream.Context() +} + func (x *registryServiceWatch) SendMsg(m interface{}) error { return x.stream.Send(m) } @@ -197,6 +196,7 @@ func (h *registryHandler) Watch(ctx context.Context, stream server.Stream) error } type Registry_WatchStream interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -211,6 +211,10 @@ func (x *registryWatchStream) Close() error { return x.stream.Close() } +func (x *registryWatchStream) Context() context.Context { + return x.stream.Context() +} + func (x *registryWatchStream) SendMsg(m interface{}) error { return x.stream.Send(m) } diff --git a/router/service/proto/router.pb.go b/router/service/proto/router.pb.go index 153e9530..46e48715 100644 --- a/router/service/proto/router.pb.go +++ b/router/service/proto/router.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: micro/go-micro/router/service/proto/router.proto +// source: router/service/proto/router.proto -package go_micro_router +package router import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -43,7 +47,7 @@ func (x AdvertType) String() string { } func (AdvertType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{0} + return fileDescriptor_3123ad01af3cc940, []int{0} } // EventType defines the type of event @@ -72,7 +76,7 @@ func (x EventType) String() string { } func (EventType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{1} + return fileDescriptor_3123ad01af3cc940, []int{1} } // Empty request @@ -86,7 +90,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{0} + return fileDescriptor_3123ad01af3cc940, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { @@ -118,7 +122,7 @@ func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{1} + return fileDescriptor_3123ad01af3cc940, []int{1} } func (m *Response) XXX_Unmarshal(b []byte) error { @@ -151,7 +155,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{2} + return fileDescriptor_3123ad01af3cc940, []int{2} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -191,7 +195,7 @@ func (m *LookupRequest) Reset() { *m = LookupRequest{} } func (m *LookupRequest) String() string { return proto.CompactTextString(m) } func (*LookupRequest) ProtoMessage() {} func (*LookupRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{3} + return fileDescriptor_3123ad01af3cc940, []int{3} } func (m *LookupRequest) XXX_Unmarshal(b []byte) error { @@ -231,7 +235,7 @@ func (m *LookupResponse) Reset() { *m = LookupResponse{} } func (m *LookupResponse) String() string { return proto.CompactTextString(m) } func (*LookupResponse) ProtoMessage() {} func (*LookupResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{4} + return fileDescriptor_3123ad01af3cc940, []int{4} } func (m *LookupResponse) XXX_Unmarshal(b []byte) error { @@ -271,7 +275,7 @@ func (m *QueryRequest) Reset() { *m = QueryRequest{} } func (m *QueryRequest) String() string { return proto.CompactTextString(m) } func (*QueryRequest) ProtoMessage() {} func (*QueryRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{5} + return fileDescriptor_3123ad01af3cc940, []int{5} } func (m *QueryRequest) XXX_Unmarshal(b []byte) error { @@ -311,7 +315,7 @@ func (m *QueryResponse) Reset() { *m = QueryResponse{} } func (m *QueryResponse) String() string { return proto.CompactTextString(m) } func (*QueryResponse) ProtoMessage() {} func (*QueryResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{6} + return fileDescriptor_3123ad01af3cc940, []int{6} } func (m *QueryResponse) XXX_Unmarshal(b []byte) error { @@ -350,7 +354,7 @@ func (m *WatchRequest) Reset() { *m = WatchRequest{} } func (m *WatchRequest) String() string { return proto.CompactTextString(m) } func (*WatchRequest) ProtoMessage() {} func (*WatchRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{7} + return fileDescriptor_3123ad01af3cc940, []int{7} } func (m *WatchRequest) XXX_Unmarshal(b []byte) error { @@ -392,7 +396,7 @@ func (m *Advert) Reset() { *m = Advert{} } func (m *Advert) String() string { return proto.CompactTextString(m) } func (*Advert) ProtoMessage() {} func (*Advert) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{8} + return fileDescriptor_3123ad01af3cc940, []int{8} } func (m *Advert) XXX_Unmarshal(b []byte) error { @@ -459,7 +463,7 @@ func (m *ProcessResponse) Reset() { *m = ProcessResponse{} } func (m *ProcessResponse) String() string { return proto.CompactTextString(m) } func (*ProcessResponse) ProtoMessage() {} func (*ProcessResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{9} + return fileDescriptor_3123ad01af3cc940, []int{9} } func (m *ProcessResponse) XXX_Unmarshal(b []byte) error { @@ -491,7 +495,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{10} + return fileDescriptor_3123ad01af3cc940, []int{10} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -523,7 +527,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{11} + return fileDescriptor_3123ad01af3cc940, []int{11} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -555,7 +559,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{12} + return fileDescriptor_3123ad01af3cc940, []int{12} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -595,7 +599,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{13} + return fileDescriptor_3123ad01af3cc940, []int{13} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -661,7 +665,7 @@ func (m *Query) Reset() { *m = Query{} } func (m *Query) String() string { return proto.CompactTextString(m) } func (*Query) ProtoMessage() {} func (*Query) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{14} + return fileDescriptor_3123ad01af3cc940, []int{14} } func (m *Query) XXX_Unmarshal(b []byte) error { @@ -728,7 +732,7 @@ func (m *Route) Reset() { *m = Route{} } func (m *Route) String() string { return proto.CompactTextString(m) } func (*Route) ProtoMessage() {} func (*Route) Descriptor() ([]byte, []int) { - return fileDescriptor_c2b04f200fb3e806, []int{15} + return fileDescriptor_3123ad01af3cc940, []int{15} } func (m *Route) XXX_Unmarshal(b []byte) error { @@ -819,51 +823,510 @@ func init() { proto.RegisterType((*Route)(nil), "go.micro.router.Route") } -func init() { - proto.RegisterFile("micro/go-micro/router/service/proto/router.proto", fileDescriptor_c2b04f200fb3e806) +func init() { proto.RegisterFile("router/service/proto/router.proto", fileDescriptor_3123ad01af3cc940) } + +var fileDescriptor_3123ad01af3cc940 = []byte{ + // 673 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcd, 0x6e, 0xdb, 0x38, + 0x10, 0x96, 0x6c, 0x4b, 0x5e, 0xcd, 0x3a, 0x8e, 0x96, 0x87, 0xac, 0xe0, 0xdd, 0xa4, 0xae, 0x4e, + 0x41, 0x90, 0x4a, 0x85, 0x7b, 0x29, 0xfa, 0x9f, 0xa4, 0x2d, 0x0a, 0x34, 0x87, 0x56, 0x48, 0x50, + 0xa0, 0x37, 0x45, 0x1e, 0x38, 0x42, 0x6c, 0x51, 0x21, 0x69, 0x07, 0x7e, 0x8e, 0x3e, 0x43, 0x0f, + 0x3d, 0xf7, 0x91, 0xfa, 0x22, 0x85, 0x48, 0x2a, 0xb1, 0x2d, 0x2b, 0x68, 0x72, 0x12, 0xe7, 0xef, + 0x9b, 0xe1, 0xcc, 0x7c, 0x22, 0x3c, 0x64, 0x74, 0x2a, 0x90, 0x85, 0x1c, 0xd9, 0x2c, 0x4d, 0x30, + 0xcc, 0x19, 0x15, 0x34, 0x54, 0xca, 0x40, 0x0a, 0x64, 0x73, 0x44, 0x83, 0x49, 0x9a, 0x30, 0x1a, + 0x28, 0xb5, 0xef, 0x40, 0x3b, 0xc2, 0xcb, 0x29, 0x72, 0xe1, 0x03, 0xfc, 0x15, 0x21, 0xcf, 0x69, + 0xc6, 0xd1, 0x7f, 0x05, 0x9d, 0xe3, 0x94, 0x8b, 0x52, 0x26, 0x01, 0xd8, 0x32, 0x80, 0x7b, 0x66, + 0xbf, 0xb9, 0xfb, 0xf7, 0x60, 0x2b, 0x58, 0x01, 0x0a, 0xa2, 0xe2, 0x13, 0x69, 0x2f, 0xff, 0x25, + 0x6c, 0x1c, 0x53, 0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93, 0x1c, 0x82, 0xa3, 0xae, 0x97, 0x72, 0x24, 0x5e, 0x75, 0x73, 0x34, 0xc4, 0xbf, 0x35, 0xb4, + 0x94, 0x18, 0xef, 0xa1, 0xad, 0x09, 0x43, 0xea, 0xfc, 0x7a, 0xfd, 0x8a, 0x61, 0x95, 0x63, 0xc6, + 0xe0, 0x57, 0x03, 0xac, 0x93, 0xf8, 0x6c, 0x8c, 0xe4, 0xa8, 0xec, 0x2a, 0xa9, 0x59, 0xe6, 0x35, + 0xed, 0x59, 0x21, 0xa8, 0x51, 0x80, 0xa8, 0x71, 0xdc, 0x01, 0x64, 0x85, 0xd3, 0x12, 0x44, 0xcd, + 0xf1, 0x0e, 0x20, 0x2b, 0xbf, 0x01, 0x83, 0x1c, 0x40, 0xab, 0x78, 0x4d, 0x6e, 0xe9, 0x6f, 0x75, + 0x82, 0x8b, 0xcf, 0x8f, 0x6f, 0x90, 0x0f, 0x25, 0x6b, 0xb7, 0x6b, 0xfe, 0xdc, 0x1a, 0x68, 0xa7, + 0xce, 0x5c, 0x22, 0x1d, 0x3e, 0xfb, 0xfa, 0x74, 0x94, 0x8a, 0xf3, 0xe9, 0x59, 0x90, 0xd0, 0x49, + 0x28, 0x5d, 0xc3, 0x11, 0x7d, 0xa4, 0x0e, 0xb3, 0x41, 0xb8, 0xee, 0x11, 0x7d, 0xae, 0x94, 0x67, + 0xb6, 0x94, 0x9e, 0xfc, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x14, 0x01, 0x1d, 0x6a, 0x07, 0x00, + 0x00, } -var fileDescriptor_c2b04f200fb3e806 = []byte{ - // 645 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcd, 0x4e, 0xdb, 0x40, - 0x10, 0xb6, 0x93, 0xd8, 0xa9, 0xa7, 0x21, 0xb8, 0x73, 0xa0, 0x56, 0x5a, 0x68, 0xe4, 0x13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 0xed, - 0x59, 0x21, 0xa8, 0x25, 0x41, 0xf4, 0x38, 0xee, 0x01, 0xb2, 0xc2, 0x69, 0x05, 0xa2, 0xe7, 0x78, - 0x0f, 0x90, 0x95, 0xdf, 0x80, 0x85, 0xfb, 0xd0, 0x92, 0xaf, 0xc9, 0x1d, 0xfd, 0xad, 0x4e, 0x70, - 0xf1, 0xf9, 0x09, 0x2d, 0xfc, 0x5c, 0xb2, 0x76, 0xb3, 0xe6, 0xcf, 0x6d, 0x80, 0xb6, 0xea, 0xcc, - 0x25, 0xd2, 0xa9, 0xab, 0x5e, 0xc2, 0x57, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x5a, 0x08, 0x7e, - 0xf4, 0x3d, 0x07, 0x00, 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// RouterClient is the client API for Router service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type RouterClient interface { + Lookup(ctx context.Context, in *LookupRequest, opts ...grpc.CallOption) (*LookupResponse, error) + Watch(ctx context.Context, in *WatchRequest, opts ...grpc.CallOption) (Router_WatchClient, error) + Advertise(ctx context.Context, in *Request, opts ...grpc.CallOption) (Router_AdvertiseClient, error) + Process(ctx context.Context, in *Advert, opts ...grpc.CallOption) (*ProcessResponse, error) +} + +type routerClient struct { + cc *grpc.ClientConn +} + +func NewRouterClient(cc *grpc.ClientConn) RouterClient { + return &routerClient{cc} +} + +func (c *routerClient) Lookup(ctx context.Context, in *LookupRequest, opts ...grpc.CallOption) (*LookupResponse, error) { + out := new(LookupResponse) + err := c.cc.Invoke(ctx, "/go.micro.router.Router/Lookup", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *routerClient) Watch(ctx context.Context, in *WatchRequest, opts ...grpc.CallOption) (Router_WatchClient, error) { + stream, err := c.cc.NewStream(ctx, &_Router_serviceDesc.Streams[0], "/go.micro.router.Router/Watch", opts...) + if err != nil { + return nil, err + } + x := &routerWatchClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Router_WatchClient interface { + Recv() (*Event, error) + grpc.ClientStream +} + +type routerWatchClient struct { + grpc.ClientStream +} + +func (x *routerWatchClient) Recv() (*Event, error) { + m := new(Event) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *routerClient) Advertise(ctx context.Context, in *Request, opts ...grpc.CallOption) (Router_AdvertiseClient, error) { + stream, err := c.cc.NewStream(ctx, &_Router_serviceDesc.Streams[1], "/go.micro.router.Router/Advertise", opts...) + if err != nil { + return nil, err + } + x := &routerAdvertiseClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Router_AdvertiseClient interface { + Recv() (*Advert, error) + grpc.ClientStream +} + +type routerAdvertiseClient struct { + grpc.ClientStream +} + +func (x *routerAdvertiseClient) Recv() (*Advert, error) { + m := new(Advert) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *routerClient) Process(ctx context.Context, in *Advert, opts ...grpc.CallOption) (*ProcessResponse, error) { + out := new(ProcessResponse) + err := c.cc.Invoke(ctx, "/go.micro.router.Router/Process", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// RouterServer is the server API for Router service. +type RouterServer interface { + Lookup(context.Context, *LookupRequest) (*LookupResponse, error) + Watch(*WatchRequest, Router_WatchServer) error + Advertise(*Request, Router_AdvertiseServer) error + Process(context.Context, *Advert) (*ProcessResponse, error) +} + +// UnimplementedRouterServer can be embedded to have forward compatible implementations. +type UnimplementedRouterServer struct { +} + +func (*UnimplementedRouterServer) Lookup(ctx context.Context, req *LookupRequest) (*LookupResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Lookup not implemented") +} +func (*UnimplementedRouterServer) Watch(req *WatchRequest, srv Router_WatchServer) error { + return status.Errorf(codes.Unimplemented, "method Watch not implemented") +} +func (*UnimplementedRouterServer) Advertise(req *Request, srv Router_AdvertiseServer) error { + return status.Errorf(codes.Unimplemented, "method Advertise not implemented") +} +func (*UnimplementedRouterServer) Process(ctx context.Context, req *Advert) (*ProcessResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Process not implemented") +} + +func RegisterRouterServer(s *grpc.Server, srv RouterServer) { + s.RegisterService(&_Router_serviceDesc, srv) +} + +func _Router_Lookup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LookupRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RouterServer).Lookup(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.router.Router/Lookup", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RouterServer).Lookup(ctx, req.(*LookupRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Router_Watch_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(WatchRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(RouterServer).Watch(m, &routerWatchServer{stream}) +} + +type Router_WatchServer interface { + Send(*Event) error + grpc.ServerStream +} + +type routerWatchServer struct { + grpc.ServerStream +} + +func (x *routerWatchServer) Send(m *Event) error { + return x.ServerStream.SendMsg(m) +} + +func _Router_Advertise_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(Request) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(RouterServer).Advertise(m, &routerAdvertiseServer{stream}) +} + +type Router_AdvertiseServer interface { + Send(*Advert) error + grpc.ServerStream +} + +type routerAdvertiseServer struct { + grpc.ServerStream +} + +func (x *routerAdvertiseServer) Send(m *Advert) error { + return x.ServerStream.SendMsg(m) +} + +func _Router_Process_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Advert) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RouterServer).Process(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.router.Router/Process", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RouterServer).Process(ctx, req.(*Advert)) + } + return interceptor(ctx, in, info, handler) +} + +var _Router_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.router.Router", + HandlerType: (*RouterServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Lookup", + Handler: _Router_Lookup_Handler, + }, + { + MethodName: "Process", + Handler: _Router_Process_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "Watch", + Handler: _Router_Watch_Handler, + ServerStreams: true, + }, + { + StreamName: "Advertise", + Handler: _Router_Advertise_Handler, + ServerStreams: true, + }, + }, + Metadata: "router/service/proto/router.proto", +} + +// TableClient is the client API for Table service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type TableClient interface { + Create(ctx context.Context, in *Route, opts ...grpc.CallOption) (*CreateResponse, error) + Delete(ctx context.Context, in *Route, opts ...grpc.CallOption) (*DeleteResponse, error) + Update(ctx context.Context, in *Route, opts ...grpc.CallOption) (*UpdateResponse, error) + List(ctx context.Context, in *Request, opts ...grpc.CallOption) (*ListResponse, error) + Query(ctx context.Context, in *QueryRequest, opts ...grpc.CallOption) (*QueryResponse, error) +} + +type tableClient struct { + cc *grpc.ClientConn +} + +func NewTableClient(cc *grpc.ClientConn) TableClient { + return &tableClient{cc} +} + +func (c *tableClient) Create(ctx context.Context, in *Route, opts ...grpc.CallOption) (*CreateResponse, error) { + out := new(CreateResponse) + err := c.cc.Invoke(ctx, "/go.micro.router.Table/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *tableClient) Delete(ctx context.Context, in *Route, opts ...grpc.CallOption) (*DeleteResponse, error) { + out := new(DeleteResponse) + err := c.cc.Invoke(ctx, "/go.micro.router.Table/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *tableClient) Update(ctx context.Context, in *Route, opts ...grpc.CallOption) (*UpdateResponse, error) { + out := new(UpdateResponse) + err := c.cc.Invoke(ctx, "/go.micro.router.Table/Update", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *tableClient) List(ctx context.Context, in *Request, opts ...grpc.CallOption) (*ListResponse, error) { + out := new(ListResponse) + err := c.cc.Invoke(ctx, "/go.micro.router.Table/List", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *tableClient) Query(ctx context.Context, in *QueryRequest, opts ...grpc.CallOption) (*QueryResponse, error) { + out := new(QueryResponse) + err := c.cc.Invoke(ctx, "/go.micro.router.Table/Query", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// TableServer is the server API for Table service. +type TableServer interface { + Create(context.Context, *Route) (*CreateResponse, error) + Delete(context.Context, *Route) (*DeleteResponse, error) + Update(context.Context, *Route) (*UpdateResponse, error) + List(context.Context, *Request) (*ListResponse, error) + Query(context.Context, *QueryRequest) (*QueryResponse, error) +} + +// UnimplementedTableServer can be embedded to have forward compatible implementations. +type UnimplementedTableServer struct { +} + +func (*UnimplementedTableServer) Create(ctx context.Context, req *Route) (*CreateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") +} +func (*UnimplementedTableServer) Delete(ctx context.Context, req *Route) (*DeleteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} +func (*UnimplementedTableServer) Update(ctx context.Context, req *Route) (*UpdateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Update not implemented") +} +func (*UnimplementedTableServer) List(ctx context.Context, req *Request) (*ListResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method List not implemented") +} +func (*UnimplementedTableServer) Query(ctx context.Context, req *QueryRequest) (*QueryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Query not implemented") +} + +func RegisterTableServer(s *grpc.Server, srv TableServer) { + s.RegisterService(&_Table_serviceDesc, srv) +} + +func _Table_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Route) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(TableServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.router.Table/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(TableServer).Create(ctx, req.(*Route)) + } + return interceptor(ctx, in, info, handler) +} + +func _Table_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Route) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(TableServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.router.Table/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(TableServer).Delete(ctx, req.(*Route)) + } + return interceptor(ctx, in, info, handler) +} + +func _Table_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Route) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(TableServer).Update(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.router.Table/Update", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(TableServer).Update(ctx, req.(*Route)) + } + return interceptor(ctx, in, info, handler) +} + +func _Table_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Request) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(TableServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.router.Table/List", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(TableServer).List(ctx, req.(*Request)) + } + return interceptor(ctx, in, info, handler) +} + +func _Table_Query_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(TableServer).Query(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.router.Table/Query", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(TableServer).Query(ctx, req.(*QueryRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Table_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.router.Table", + HandlerType: (*TableServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _Table_Create_Handler, + }, + { + MethodName: "Delete", + Handler: _Table_Delete_Handler, + }, + { + MethodName: "Update", + Handler: _Table_Update_Handler, + }, + { + MethodName: "List", + Handler: _Table_List_Handler, + }, + { + MethodName: "Query", + Handler: _Table_Query_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "router/service/proto/router.proto", } diff --git a/router/service/proto/router.pb.micro.go b/router/service/proto/router.pb.micro.go index 5bc8c690..d554458a 100644 --- a/router/service/proto/router.pb.micro.go +++ b/router/service/proto/router.pb.micro.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: micro/go-micro/router/service/proto/router.proto +// source: router/service/proto/router.proto -package go_micro_router +package router import ( fmt "fmt" @@ -46,12 +46,6 @@ type routerService struct { } func NewRouterService(name string, c client.Client) RouterService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "go.micro.router" - } return &routerService{ c: c, name: name, @@ -81,6 +75,7 @@ func (c *routerService) Watch(ctx context.Context, in *WatchRequest, opts ...cli } type Router_WatchService interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -95,6 +90,10 @@ func (x *routerServiceWatch) Close() error { return x.stream.Close() } +func (x *routerServiceWatch) Context() context.Context { + return x.stream.Context() +} + func (x *routerServiceWatch) SendMsg(m interface{}) error { return x.stream.Send(m) } @@ -125,6 +124,7 @@ func (c *routerService) Advertise(ctx context.Context, in *Request, opts ...clie } type Router_AdvertiseService interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -139,6 +139,10 @@ func (x *routerServiceAdvertise) Close() error { return x.stream.Close() } +func (x *routerServiceAdvertise) Context() context.Context { + return x.stream.Context() +} + func (x *routerServiceAdvertise) SendMsg(m interface{}) error { return x.stream.Send(m) } @@ -206,6 +210,7 @@ func (h *routerHandler) Watch(ctx context.Context, stream server.Stream) error { } type Router_WatchStream interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -220,6 +225,10 @@ func (x *routerWatchStream) Close() error { return x.stream.Close() } +func (x *routerWatchStream) Context() context.Context { + return x.stream.Context() +} + func (x *routerWatchStream) SendMsg(m interface{}) error { return x.stream.Send(m) } @@ -241,6 +250,7 @@ func (h *routerHandler) Advertise(ctx context.Context, stream server.Stream) err } type Router_AdvertiseStream interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -255,6 +265,10 @@ func (x *routerAdvertiseStream) Close() error { return x.stream.Close() } +func (x *routerAdvertiseStream) Context() context.Context { + return x.stream.Context() +} + func (x *routerAdvertiseStream) SendMsg(m interface{}) error { return x.stream.Send(m) } @@ -287,12 +301,6 @@ type tableService struct { } func NewTableService(name string, c client.Client) TableService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "go.micro.router" - } return &tableService{ c: c, name: name, diff --git a/router/service/proto/router.proto b/router/service/proto/router.proto index a0926762..22dcf595 100644 --- a/router/service/proto/router.proto +++ b/router/service/proto/router.proto @@ -2,20 +2,21 @@ syntax = "proto3"; package go.micro.router; +option go_package = "github.com/micro/go-micro/v2/router/service/proto;router"; // Router service is used by the proxy to lookup routes service Router { - rpc Lookup(LookupRequest) returns (LookupResponse) {}; - rpc Watch(WatchRequest) returns (stream Event) {}; - rpc Advertise(Request) returns (stream Advert) {}; - rpc Process(Advert) returns (ProcessResponse) {}; + rpc Lookup(LookupRequest) returns (LookupResponse) {}; + rpc Watch(WatchRequest) returns (stream Event) {}; + rpc Advertise(Request) returns (stream Advert) {}; + rpc Process(Advert) returns (ProcessResponse) {}; } service Table { - rpc Create(Route) returns (CreateResponse) {}; - rpc Delete(Route) returns (DeleteResponse) {}; - rpc Update(Route) returns (UpdateResponse) {}; - rpc List(Request) returns (ListResponse) {}; - rpc Query(QueryRequest) returns (QueryResponse) {}; + rpc Create(Route) returns (CreateResponse) {}; + rpc Delete(Route) returns (DeleteResponse) {}; + rpc Update(Route) returns (UpdateResponse) {}; + rpc List(Request) returns (ListResponse) {}; + rpc Query(QueryRequest) returns (QueryResponse) {}; } // Empty request @@ -26,27 +27,27 @@ message Response {} // ListResponse is returned by List message ListResponse { - repeated Route routes = 1; + repeated Route routes = 1; } // LookupRequest is made to Lookup message LookupRequest { - Query query = 1; + Query query = 1; } // LookupResponse is returned by Lookup message LookupResponse { - repeated Route routes = 1; + repeated Route routes = 1; } // QueryRequest queries Table for Routes message QueryRequest{ - Query query = 1; + Query query = 1; } // QueryResponse is returned by Query message QueryResponse { - repeated Route routes = 1; + repeated Route routes = 1; } // WatchRequest is made to Watch Router @@ -54,22 +55,22 @@ message WatchRequest {} // AdvertType defines the type of advert enum AdvertType { - AdvertAnnounce = 0; - AdvertUpdate = 1; + AdvertAnnounce = 0; + AdvertUpdate = 1; } // Advert is router advertsement streamed by Watch message Advert { - // id of the advertising router - string id = 1; - // type of advertisement - AdvertType type = 2; - // unix timestamp of the advertisement - int64 timestamp = 3; - // TTL of the Advert - int64 ttl = 4; - // events is a list of advertised events - repeated Event events = 5; + // id of the advertising router + string id = 1; + // type of advertisement + AdvertType type = 2; + // unix timestamp of the advertisement + int64 timestamp = 3; + // TTL of the Advert + int64 ttl = 4; + // events is a list of advertised events + repeated Event events = 5; } // ProcessResponse is returned by Process @@ -86,47 +87,47 @@ message UpdateResponse {} // EventType defines the type of event enum EventType { - Create = 0; - Delete = 1; - Update = 2; + Create = 0; + Delete = 1; + Update = 2; } // Event is routing table event message Event { - // the unique event id - string id = 1; - // type of event - EventType type = 2; - // unix timestamp of event - int64 timestamp = 3; - // service route - Route route = 4; + // the unique event id + string id = 1; + // type of event + EventType type = 2; + // unix timestamp of event + int64 timestamp = 3; + // service route + Route route = 4; } // Query is passed in a LookupRequest message Query { - // service to lookup - string service = 1; - // gateway to lookup - string gateway = 2; - // network to lookup - string network = 3; + // service to lookup + string service = 1; + // gateway to lookup + string gateway = 2; + // network to lookup + string network = 3; } // Route is a service route message Route { - // service for the route - string service = 1; - // the address that advertise this route - string address = 2; - // gateway as the next hop - string gateway = 3; - // the network for this destination - string network = 4; - // router if the router id - string router = 5; - // the network link - string link = 6; - // the metric / score of this route - int64 metric = 7; + // service for the route + string service = 1; + // the address that advertise this route + string address = 2; + // gateway as the next hop + string gateway = 3; + // the network for this destination + string network = 4; + // router if the router id + string router = 5; + // the network link + string link = 6; + // the metric / score of this route + int64 metric = 7; } diff --git a/runtime/service/proto/runtime.pb.go b/runtime/service/proto/runtime.pb.go index 4d8df642..f51d25dc 100644 --- a/runtime/service/proto/runtime.pb.go +++ b/runtime/service/proto/runtime.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto +// source: runtime/service/proto/runtime.proto package go_micro_runtime import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -38,7 +42,7 @@ func (m *Service) Reset() { *m = Service{} } func (m *Service) String() string { return proto.CompactTextString(m) } func (*Service) ProtoMessage() {} func (*Service) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{0} + return fileDescriptor_2434d8152598889b, []int{0} } func (m *Service) XXX_Unmarshal(b []byte) error { @@ -101,7 +105,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{1} + return fileDescriptor_2434d8152598889b, []int{1} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -172,7 +176,7 @@ func (m *CreateOptions) Reset() { *m = CreateOptions{} } func (m *CreateOptions) String() string { return proto.CompactTextString(m) } func (*CreateOptions) ProtoMessage() {} func (*CreateOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{2} + return fileDescriptor_2434d8152598889b, []int{2} } func (m *CreateOptions) XXX_Unmarshal(b []byte) error { @@ -247,7 +251,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{3} + return fileDescriptor_2434d8152598889b, []int{3} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -292,7 +296,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{4} + return fileDescriptor_2434d8152598889b, []int{4} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -329,7 +333,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{5} + return fileDescriptor_2434d8152598889b, []int{5} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -382,7 +386,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{6} + return fileDescriptor_2434d8152598889b, []int{6} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -421,7 +425,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{7} + return fileDescriptor_2434d8152598889b, []int{7} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -460,7 +464,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{8} + return fileDescriptor_2434d8152598889b, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -498,7 +502,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{9} + return fileDescriptor_2434d8152598889b, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -530,7 +534,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{10} + return fileDescriptor_2434d8152598889b, []int{10} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -568,7 +572,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{11} + return fileDescriptor_2434d8152598889b, []int{11} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -599,7 +603,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{12} + return fileDescriptor_2434d8152598889b, []int{12} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -631,7 +635,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{13} + return fileDescriptor_2434d8152598889b, []int{13} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -678,45 +682,268 @@ func init() { } func init() { - proto.RegisterFile("github.com/micro/go-micro/runtime/service/proto/runtime.proto", fileDescriptor_976fccef828ab1f0) + proto.RegisterFile("runtime/service/proto/runtime.proto", fileDescriptor_2434d8152598889b) } -var fileDescriptor_976fccef828ab1f0 = []byte{ - // 563 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x4b, 0x6f, 0xd3, 0x40, - 0x10, 0xae, 0xe3, 0x3c, 0xda, 0x09, 0x41, 0xd1, 0xaa, 0x42, 0xa6, 0xe2, 0x11,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7, 0x2b, 0xfd, 0xe1, 0x67, 0x03, 0xeb, 0x74, - 0xbe, 0xad, 0x28, 0x1b, 0x9d, 0xcf, 0xef, 0x53, 0xae, 0xd1, 0xa8, 0x08, 0x2f, 0xe0, 0x91, 0xc1, - 0x31, 0x74, 0xc9, 0x1b, 0x38, 0xb5, 0x84, 0x84, 0x0e, 0xf1, 0x41, 0xc7, 0xca, 0xd5, 0x70, 0x0e, - 0xa3, 0x39, 0xde, 0xe1, 0x71, 0xc6, 0x2b, 0xf7, 0x1c, 0x8a, 0x75, 0x6f, 0x0e, 0xa3, 0x9b, 0x6c, - 0x4d, 0x8f, 0xc7, 0x75, 0x28, 0x16, 0x77, 0x04, 0xc3, 0xaf, 0x89, 0x90, 0x16, 0x55, 0xb9, 0x60, - 0xda, 0xa3, 0x5c, 0x98, 0xfd, 0xf1, 0x61, 0x10, 0x9b, 0x53, 0xb2, 0x84, 0xbe, 0xf9, 0x12, 0x48, - 0xeb, 0xd7, 0x63, 0x5f, 0xbf, 0x98, 0xb4, 0x2f, 0x58, 0xba, 0x27, 0xe4, 0x0b, 0x74, 0x55, 0x4e, - 0xa4, 0x25, 0x57, 0x07, 0xf5, 0xa2, 0xed, 0xb8, 0x04, 0x5a, 0x42, 0xdf, 0x78, 0xdc, 0xc4, 0x6b, - 0x2f, 0xc3, 0x26, 0x5e, 0x07, 0xf1, 0x68, 0x38, 0x63, 0x6d, 0x13, 0xdc, 0x5e, 0x74, 0x4d, 0x70, - 0x07, 0xa9, 0x68, 0x99, 0x2a, 0x88, 0x26, 0x99, 0xb5, 0xbc, 0x9a, 0x64, 0xd6, 0xf3, 0x0b, 0x4f, - 0x6e, 0xfb, 0xfa, 0xcf, 0x7f, 0xf5, 0x3f, 0x00, 0x00, 0xff, 0xff, 0x14, 0xdd, 0xee, 0x9f, 0x3a, - 0x06, 0x00, 0x00, +var fileDescriptor_2434d8152598889b = []byte{ + // 548 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00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0xea, 0x76, 0xfa, 0xe8, 0x93, 0xb3, 0xfa, 0xdd, 0x5a, 0x7f, 0xf0, 0x49, 0xc3, 0x5a, + 0x9d, 0x6f, 0x6b, 0xca, 0x5a, 0xe7, 0xf3, 0x87, 0x94, 0x1b, 0x34, 0x6a, 0xc2, 0x6b, 0x78, 0xa4, + 0x71, 0x34, 0x5d, 0xf2, 0x06, 0xce, 0x0d, 0x21, 0xae, 0x42, 0xfc, 0xaf, 0x63, 0xd5, 0x6a, 0xb0, + 0x02, 0x6f, 0x85, 0xf7, 0x78, 0x9a, 0xf1, 0xd2, 0x3d, 0x8b, 0x62, 0xdc, 0x5b, 0x81, 0x77, 0x97, + 0xed, 0xe8, 0xe9, 0xb8, 0x16, 0xc5, 0xe0, 0x7a, 0x30, 0xfd, 0x12, 0x73, 0x61, 0x50, 0xa5, 0x0b, + 0xba, 0x3d, 0xc9, 0x85, 0xe5, 0x6f, 0x17, 0x26, 0x91, 0x3e, 0x25, 0x1b, 0x18, 0xeb, 0x2f, 0x81, + 0xf4, 0x7e, 0x3d, 0xe6, 0xf5, 0xab, 0x79, 0xff, 0x82, 0xa1, 0x7b, 0x46, 0x3e, 0xc3, 0x50, 0xe6, + 0x44, 0x7a, 0x72, 0xb5, 0x50, 0x2f, 0xfa, 0x8e, 0x2b, 0xa0, 0x0d, 0x8c, 0xb5, 0xc7, 0x5d, 0xbc, + 0x5a, 0x19, 0x76, 0xf1, 0x3a, 0x8a, 0x47, 0xc1, 0x69, 0x6b, 0xbb, 0xe0, 0x5a, 0xd1, 0x75, 0xc1, + 0x1d, 0xa5, 0xa2, 0x64, 0xca, 0x20, 0xba, 0x64, 0x36, 0xf2, 0xea, 0x92, 0xd9, 0xcc, 0x2f, 0x38, + 0xfb, 0x3e, 0x56, 0x7f, 0xfe, 0x9b, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf9, 0x01, 0xa4, 0x43, + 0x20, 0x06, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// RuntimeClient is the client API for Runtime service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type RuntimeClient interface { + Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) + Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) + Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) + List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) +} + +type runtimeClient struct { + cc *grpc.ClientConn +} + +func NewRuntimeClient(cc *grpc.ClientConn) RuntimeClient { + return &runtimeClient{cc} +} + +func (c *runtimeClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { + out := new(CreateResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *runtimeClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { + out := new(ReadResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Read", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *runtimeClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { + out := new(DeleteResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *runtimeClient) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) { + out := new(UpdateResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Update", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *runtimeClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) { + out := new(ListResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/List", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// RuntimeServer is the server API for Runtime service. +type RuntimeServer interface { + Create(context.Context, *CreateRequest) (*CreateResponse, error) + Read(context.Context, *ReadRequest) (*ReadResponse, error) + Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) + Update(context.Context, *UpdateRequest) (*UpdateResponse, error) + List(context.Context, *ListRequest) (*ListResponse, error) +} + +// UnimplementedRuntimeServer can be embedded to have forward compatible implementations. +type UnimplementedRuntimeServer struct { +} + +func (*UnimplementedRuntimeServer) Create(ctx context.Context, req *CreateRequest) (*CreateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") +} +func (*UnimplementedRuntimeServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") +} +func (*UnimplementedRuntimeServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} +func (*UnimplementedRuntimeServer) Update(ctx context.Context, req *UpdateRequest) (*UpdateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Update not implemented") +} +func (*UnimplementedRuntimeServer) List(ctx context.Context, req *ListRequest) (*ListResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method List not implemented") +} + +func RegisterRuntimeServer(s *grpc.Server, srv RuntimeServer) { + s.RegisterService(&_Runtime_serviceDesc, srv) +} + +func _Runtime_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).Create(ctx, req.(*CreateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Runtime_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReadRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).Read(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/Read", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).Read(ctx, req.(*ReadRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Runtime_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).Delete(ctx, req.(*DeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Runtime_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).Update(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/Update", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).Update(ctx, req.(*UpdateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Runtime_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/List", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).List(ctx, req.(*ListRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Runtime_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.runtime.Runtime", + HandlerType: (*RuntimeServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _Runtime_Create_Handler, + }, + { + MethodName: "Read", + Handler: _Runtime_Read_Handler, + }, + { + MethodName: "Delete", + Handler: _Runtime_Delete_Handler, + }, + { + MethodName: "Update", + Handler: _Runtime_Update_Handler, + }, + { + MethodName: "List", + Handler: _Runtime_List_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "runtime/service/proto/runtime.proto", } diff --git a/runtime/service/proto/runtime.pb.micro.go b/runtime/service/proto/runtime.pb.micro.go index ddcba829..12b6691b 100644 --- a/runtime/service/proto/runtime.pb.micro.go +++ b/runtime/service/proto/runtime.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto +// source: runtime/service/proto/runtime.proto package go_micro_runtime diff --git a/server/grpc/proto/test.pb.go b/server/grpc/proto/test.pb.go index 5a778c9c..9028bc7e 100644 --- a/server/grpc/proto/test.pb.go +++ b/server/grpc/proto/test.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: go-micro/service/grpc/proto/test.proto +// source: server/grpc/proto/test.proto package test @@ -8,6 +8,8 @@ import ( fmt "fmt" proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -33,7 +35,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_a22a4245ce525bcd, []int{0} + return fileDescriptor_bb9c685b7640cf1e, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { @@ -72,7 +74,7 @@ func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_a22a4245ce525bcd, []int{1} + return fileDescriptor_bb9c685b7640cf1e, []int{1} } func (m *Response) XXX_Unmarshal(b []byte) error { @@ -105,21 +107,19 @@ func init() { proto.RegisterType((*Response)(nil), "Response") } -func init() { - proto.RegisterFile("go-micro/service/grpc/proto/test.proto", fileDescriptor_a22a4245ce525bcd) -} +func init() { proto.RegisterFile("server/grpc/proto/test.proto", fileDescriptor_bb9c685b7640cf1e) } -var fileDescriptor_a22a4245ce525bcd = []byte{ - // 142 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4b, 0xcf, 0xd7, 0xcd, - 0xcd, 0x4c, 0x2e, 0xca, 0xd7, 0x2f, 0x4e, 0x2d, 0x2a, 0xcb, 0x4c, 0x4e, 0xd5, 0x4f, 0x2f, 0x2a, - 0x48, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x2f, 0x49, 0x2d, 0x2e, 0xd1, 0x03, 0x33, 0x95, - 0x64, 0xb9, 0xd8, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x84, 0xb8, 0x58, 0xf2, 0x12, - 0x73, 0x53, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xc0, 0x6c, 0x25, 0x19, 0x2e, 0x8e, 0xa0, - 0xd4, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x21, 0x01, 0x2e, 0xe6, 0xdc, 0xe2, 0x74, 0xa8, 0x34, - 0x88, 0x69, 0xa4, 0xca, 0xc5, 0x12, 0x02, 0xd2, 0x29, 0xcb, 0xc5, 0xe2, 0x9c, 0x98, 0x93, 0x23, - 0xc4, 0xa1, 0x07, 0x35, 0x4b, 0x8a, 0x53, 0x0f, 0xa6, 0x4d, 0x89, 0x21, 0x89, 0x0d, 0x6c, 0x95, - 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x96, 0x1b, 0x22, 0x44, 0x94, 0x00, 0x00, 0x00, +var fileDescriptor_bb9c685b7640cf1e = []byte{ + // 132 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x29, 0x4e, 0x2d, 0x2a, + 0x4b, 0x2d, 0xd2, 0x4f, 0x2f, 0x2a, 0x48, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x2f, 0x49, + 0x2d, 0x2e, 0xd1, 0x03, 0x33, 0x95, 0x64, 0xb9, 0xd8, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, + 0x84, 0x84, 0xb8, 0x58, 0xf2, 0x12, 0x73, 0x53, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xc0, + 0x6c, 0x25, 0x19, 0x2e, 0x8e, 0xa0, 0xd4, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x21, 0x01, 0x2e, + 0xe6, 0xdc, 0xe2, 0x74, 0xa8, 0x34, 0x88, 0x69, 0xa4, 0xca, 0xc5, 0x12, 0x02, 0xd2, 0x29, 0xcb, + 0xc5, 0xe2, 0x9c, 0x98, 0x93, 0x23, 0xc4, 0xa1, 0x07, 0x35, 0x4b, 0x8a, 0x53, 0x0f, 0xa6, 0x4d, + 0x89, 0x21, 0x89, 0x0d, 0x6c, 0x95, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xe6, 0xc8, 0xea, 0xc1, + 0x8a, 0x00, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -159,6 +159,14 @@ type TestServer interface { Call(context.Context, *Request) (*Response, error) } +// UnimplementedTestServer can be embedded to have forward compatible implementations. +type UnimplementedTestServer struct { +} + +func (*UnimplementedTestServer) Call(ctx context.Context, req *Request) (*Response, error) { + return nil, status.Errorf(codes.Unimplemented, "method Call not implemented") +} + func RegisterTestServer(s *grpc.Server, srv TestServer) { s.RegisterService(&_Test_serviceDesc, srv) } @@ -191,5 +199,5 @@ var _Test_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "go-micro/service/grpc/proto/test.proto", + Metadata: "server/grpc/proto/test.proto", } diff --git a/server/grpc/proto/test.micro.go b/server/grpc/proto/test.pb.micro.go similarity index 93% rename from server/grpc/proto/test.micro.go rename to server/grpc/proto/test.pb.micro.go index 5cc8a4e0..a06bd3ee 100644 --- a/server/grpc/proto/test.micro.go +++ b/server/grpc/proto/test.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: go-micro/service/grpc/proto/test.proto +// source: server/grpc/proto/test.proto package test @@ -43,12 +43,6 @@ type testService struct { } func NewTestService(name string, c client.Client) TestService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "test" - } return &testService{ c: c, name: name, diff --git a/server/proto/server.pb.go b/server/proto/server.pb.go index d9fd74aa..5813ff28 100644 --- a/server/proto/server.pb.go +++ b/server/proto/server.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/v2/server/proto/server.proto +// source: server/proto/server.proto package go_micro_server import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -33,7 +37,7 @@ func (m *HandleRequest) Reset() { *m = HandleRequest{} } func (m *HandleRequest) String() string { return proto.CompactTextString(m) } func (*HandleRequest) ProtoMessage() {} func (*HandleRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4cb0c66620400ff8, []int{0} + return fileDescriptor_1959cecd4d1121a1, []int{0} } func (m *HandleRequest) XXX_Unmarshal(b []byte) error { @@ -85,7 +89,7 @@ func (m *HandleResponse) Reset() { *m = HandleResponse{} } func (m *HandleResponse) String() string { return proto.CompactTextString(m) } func (*HandleResponse) ProtoMessage() {} func (*HandleResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4cb0c66620400ff8, []int{1} + return fileDescriptor_1959cecd4d1121a1, []int{1} } func (m *HandleResponse) XXX_Unmarshal(b []byte) error { @@ -117,7 +121,7 @@ func (m *SubscribeRequest) Reset() { *m = SubscribeRequest{} } func (m *SubscribeRequest) String() string { return proto.CompactTextString(m) } func (*SubscribeRequest) ProtoMessage() {} func (*SubscribeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4cb0c66620400ff8, []int{2} + return fileDescriptor_1959cecd4d1121a1, []int{2} } func (m *SubscribeRequest) XXX_Unmarshal(b []byte) error { @@ -155,7 +159,7 @@ func (m *SubscribeResponse) Reset() { *m = SubscribeResponse{} } func (m *SubscribeResponse) String() string { return proto.CompactTextString(m) } func (*SubscribeResponse) ProtoMessage() {} func (*SubscribeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4cb0c66620400ff8, []int{3} + return fileDescriptor_1959cecd4d1121a1, []int{3} } func (m *SubscribeResponse) XXX_Unmarshal(b []byte) error { @@ -183,25 +187,138 @@ func init() { proto.RegisterType((*SubscribeResponse)(nil), "go.micro.server.SubscribeResponse") } -func init() { - proto.RegisterFile("github.com/micro/go-micro/v2/server/proto/server.proto", fileDescriptor_4cb0c66620400ff8) +func init() { proto.RegisterFile("server/proto/server.proto", fileDescriptor_1959cecd4d1121a1) } + +var fileDescriptor_1959cecd4d1121a1 = []byte{ + // 223 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2c, 0x4e, 0x2d, 0x2a, + 0x4b, 0x2d, 0xd2, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x87, 0x70, 0xf4, 0xc0, 0x1c, 0x21, 0xfe, + 0xf4, 0x7c, 0xbd, 0xdc, 0xcc, 0xe4, 0xa2, 0x7c, 0x3d, 0x88, 0xb0, 0x52, 0x22, 0x17, 0xaf, 0x47, + 0x62, 0x5e, 0x4a, 0x4e, 0x6a, 0x50, 0x6a, 0x61, 0x69, 0x6a, 0x71, 0x89, 0x90, 0x04, 0x17, 0x3b, + 0x48, 0x2a, 0x33, 0x39, 0x55, 0x82, 0x51, 0x81, 0x51, 0x83, 0x33, 0x08, 0xc6, 0x15, 0x92, 0xe2, + 0xe2, 0x48, 0xcd, 0x4b, 0x29, 0xc8, 0xcf, 0xcc, 0x2b, 0x91, 0x60, 0x02, 0x4b, 0xc1, 0xf9, 0x20, + 0x39, 0xb0, 0x05, 0xc9, 0xf9, 0x39, 0x12, 0xcc, 0x10, 0x39, 0x18, 0x5f, 0x49, 0x80, 0x8b, 0x0f, + 0x66, 0x45, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0xaa, 0x92, 0x06, 0x97, 0x40, 0x70, 0x69, 0x52, 0x71, + 0x72, 0x51, 0x66, 0x12, 0xdc, 0x5e, 0x11, 0x2e, 0xd6, 0x92, 0xfc, 0x82, 0xcc, 0x64, 0xa8, 0xad, + 0x10, 0x8e, 0x92, 0x30, 0x97, 0x20, 0x92, 0x4a, 0x88, 0x76, 0xa3, 0xd5, 0x8c, 0x5c, 0x6c, 0xc1, + 0x60, 0xe7, 0x0b, 0x79, 0x73, 0xb1, 0x41, 0xcc, 0x16, 0x92, 0xd3, 0x43, 0xf3, 0x9a, 0x1e, 0x8a, + 0xbf, 0xa4, 0xe4, 0x71, 0xca, 0x43, 0x1d, 0xc5, 0x20, 0x14, 0xc2, 0xc5, 0x09, 0xb7, 0x4c, 0x48, + 0x11, 0x43, 0x3d, 0xba, 0x93, 0xa5, 0x94, 0xf0, 0x29, 0x81, 0x99, 0x9a, 0xc4, 0x06, 0x0e, 0x08, + 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa4, 0x3f, 0x79, 0x80, 0x96, 0x01, 0x00, 0x00, } -var fileDescriptor_4cb0c66620400ff8 = []byte{ - // 236 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x90, 0xcd, 0x4e, 0x03, 0x21, - 0x14, 0x85, 0x1d, 0x8d, 0xa3, 0xbd, 0x89, 0x5a, 0xd1, 0x05, 0x99, 0x85, 0x3f, 0xac, 0xba, 0x91, - 0x49, 0xec, 0x4b, 0x98, 0xb8, 0x6b, 0x7d, 0x81, 0x42, 0x6f, 0x46, 0x92, 0x96, 0x8b, 0xc0, 0xf8, - 0x52, 0xbe, 0xa4, 0x29, 0x94, 0x89, 0x8e, 0xb1, 0x3b, 0x3e, 0xce, 0xe1, 0x9e, 0x73, 0x81, 0x79, - 0x67, 0xe2, 0x7b, 0xaf, 0xa4, 0xa6, 0x6d, 0xbb, 0x35, 0xda, 0x53, 0xdb, 0xd1, 0x53, 0x3e, 0x04, - 0xf4, 0x9f, 0xe8, 0x5b, 0xe7, 0x29, 0x16, 0x90, 0x09, 0xd8, 0x55, 0x47, 0x32, 0x79, 0x64, 0xbe, - 0x16, 0x2b, 0xb8, 0x78, 0x59, 0xd9, 0xf5, 0x06, 0x17, 0xf8, 0xd1, 0x63, 0x88, 0x8c, 0xc3, 0xd9, - 0x4e, 0x32, 0x1a, 0x79, 0xf5, 0x50, 0xcd, 0x26, 0x8b, 0x82, 0xac, 0x81, 0x73, 0xb4, 0x6b, 0x47, - 0xc6, 0x46, 0x7e, 0x9c, 0xa4, 0x81, 0x77, 0x5a, 0x0a, 0xd0, 0xb4, 0xe1, 0x27, 0x59, 0x2b, 0x2c, - 0xa6, 0x70, 0x59, 0x22, 0x82, 0x23, 0x1b, 0x50, 0xcc, 0x60, 0xba, 0xec, 0x55, 0xd0, 0xde, 0xa8, - 0x21, 0xf7, 0x16, 0x4e, 0x23, 0x39, 0xa3, 0xf7, 0xa9, 0x19, 0xc4, 0x0d, 0x5c, 0xff, 0x70, 0xe6, - 0xe7, 0xcf, 0x5f, 0x15, 0xd4, 0xcb, 0x54, 0x9f, 0xbd, 0x42, 0x9d, 0x67, 0xb3, 0x3b, 0x39, 0x5a, - 0x4d, 0xfe, 0xda, 0xab, 0xb9, 0xff, 0x57, 0xdf, 0x97, 0x3a, 0x62, 0x6f, 0x30, 0x19, 0xc2, 0xd8, - 0xe3, 0x1f, 0xff, 0xb8, 0x72, 0x23, 0x0e, 0x59, 0xca, 0x54, 0x55, 0xa7, 0x8f, 0x98, 0x7f, 0x07, - 0x00, 0x00, 0xff, 0xff, 0x30, 0xd3, 0x7a, 0x91, 0xb0, 0x01, 0x00, 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// ServerClient is the client API for Server service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ServerClient interface { + Handle(ctx context.Context, in *HandleRequest, opts ...grpc.CallOption) (*HandleResponse, error) + Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (*SubscribeResponse, error) +} + +type serverClient struct { + cc *grpc.ClientConn +} + +func NewServerClient(cc *grpc.ClientConn) ServerClient { + return &serverClient{cc} +} + +func (c *serverClient) Handle(ctx context.Context, in *HandleRequest, opts ...grpc.CallOption) (*HandleResponse, error) { + out := new(HandleResponse) + err := c.cc.Invoke(ctx, "/go.micro.server.Server/Handle", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *serverClient) Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (*SubscribeResponse, error) { + out := new(SubscribeResponse) + err := c.cc.Invoke(ctx, "/go.micro.server.Server/Subscribe", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ServerServer is the server API for Server service. +type ServerServer interface { + Handle(context.Context, *HandleRequest) (*HandleResponse, error) + Subscribe(context.Context, *SubscribeRequest) (*SubscribeResponse, error) +} + +// UnimplementedServerServer can be embedded to have forward compatible implementations. +type UnimplementedServerServer struct { +} + +func (*UnimplementedServerServer) Handle(ctx context.Context, req *HandleRequest) (*HandleResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Handle not implemented") +} +func (*UnimplementedServerServer) Subscribe(ctx context.Context, req *SubscribeRequest) (*SubscribeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Subscribe not implemented") +} + +func RegisterServerServer(s *grpc.Server, srv ServerServer) { + s.RegisterService(&_Server_serviceDesc, srv) +} + +func _Server_Handle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HandleRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServerServer).Handle(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.server.Server/Handle", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServerServer).Handle(ctx, req.(*HandleRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Server_Subscribe_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SubscribeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServerServer).Subscribe(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.server.Server/Subscribe", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServerServer).Subscribe(ctx, req.(*SubscribeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Server_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.server.Server", + HandlerType: (*ServerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Handle", + Handler: _Server_Handle_Handler, + }, + { + MethodName: "Subscribe", + Handler: _Server_Subscribe_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "server/proto/server.proto", } diff --git a/server/proto/server.pb.micro.go b/server/proto/server.pb.micro.go index 1c7ebd3d..892ce569 100644 --- a/server/proto/server.pb.micro.go +++ b/server/proto/server.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/v2/server/proto/server.proto +// source: server/proto/server.proto package go_micro_server @@ -44,12 +44,6 @@ type serverService struct { } func NewServerService(name string, c client.Client) ServerService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "go.micro.server" - } return &serverService{ c: c, name: name, diff --git a/service/grpc/proto/test.pb.go b/service/grpc/proto/test.pb.go index 5a778c9c..7ce3f3c4 100644 --- a/service/grpc/proto/test.pb.go +++ b/service/grpc/proto/test.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: go-micro/service/grpc/proto/test.proto +// source: service/grpc/proto/test.proto package test @@ -8,6 +8,8 @@ import ( fmt "fmt" proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -33,7 +35,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_a22a4245ce525bcd, []int{0} + return fileDescriptor_06b01994cb662112, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { @@ -72,7 +74,7 @@ func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_a22a4245ce525bcd, []int{1} + return fileDescriptor_06b01994cb662112, []int{1} } func (m *Response) XXX_Unmarshal(b []byte) error { @@ -105,21 +107,19 @@ func init() { proto.RegisterType((*Response)(nil), "Response") } -func init() { - proto.RegisterFile("go-micro/service/grpc/proto/test.proto", fileDescriptor_a22a4245ce525bcd) -} +func init() { proto.RegisterFile("service/grpc/proto/test.proto", fileDescriptor_06b01994cb662112) } -var fileDescriptor_a22a4245ce525bcd = []byte{ - // 142 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4b, 0xcf, 0xd7, 0xcd, - 0xcd, 0x4c, 0x2e, 0xca, 0xd7, 0x2f, 0x4e, 0x2d, 0x2a, 0xcb, 0x4c, 0x4e, 0xd5, 0x4f, 0x2f, 0x2a, - 0x48, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x2f, 0x49, 0x2d, 0x2e, 0xd1, 0x03, 0x33, 0x95, - 0x64, 0xb9, 0xd8, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x84, 0xb8, 0x58, 0xf2, 0x12, - 0x73, 0x53, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xc0, 0x6c, 0x25, 0x19, 0x2e, 0x8e, 0xa0, - 0xd4, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x21, 0x01, 0x2e, 0xe6, 0xdc, 0xe2, 0x74, 0xa8, 0x34, - 0x88, 0x69, 0xa4, 0xca, 0xc5, 0x12, 0x02, 0xd2, 0x29, 0xcb, 0xc5, 0xe2, 0x9c, 0x98, 0x93, 0x23, - 0xc4, 0xa1, 0x07, 0x35, 0x4b, 0x8a, 0x53, 0x0f, 0xa6, 0x4d, 0x89, 0x21, 0x89, 0x0d, 0x6c, 0x95, - 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x96, 0x1b, 0x22, 0x44, 0x94, 0x00, 0x00, 0x00, +var fileDescriptor_06b01994cb662112 = []byte{ + // 133 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2d, 0x4e, 0x2d, 0x2a, + 0xcb, 0x4c, 0x4e, 0xd5, 0x4f, 0x2f, 0x2a, 0x48, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x2f, + 0x49, 0x2d, 0x2e, 0xd1, 0x03, 0x33, 0x95, 0x64, 0xb9, 0xd8, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, + 0x4b, 0x84, 0x84, 0xb8, 0x58, 0xf2, 0x12, 0x73, 0x53, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, + 0xc0, 0x6c, 0x25, 0x19, 0x2e, 0x8e, 0xa0, 0xd4, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x21, 0x01, + 0x2e, 0xe6, 0xdc, 0xe2, 0x74, 0xa8, 0x34, 0x88, 0x69, 0xa4, 0xca, 0xc5, 0x12, 0x02, 0xd2, 0x29, + 0xcb, 0xc5, 0xe2, 0x9c, 0x98, 0x93, 0x23, 0xc4, 0xa1, 0x07, 0x35, 0x4b, 0x8a, 0x53, 0x0f, 0xa6, + 0x4d, 0x89, 0x21, 0x89, 0x0d, 0x6c, 0x95, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xe6, 0x7f, 0x80, + 0xd4, 0x8b, 0x00, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -159,6 +159,14 @@ type TestServer interface { Call(context.Context, *Request) (*Response, error) } +// UnimplementedTestServer can be embedded to have forward compatible implementations. +type UnimplementedTestServer struct { +} + +func (*UnimplementedTestServer) Call(ctx context.Context, req *Request) (*Response, error) { + return nil, status.Errorf(codes.Unimplemented, "method Call not implemented") +} + func RegisterTestServer(s *grpc.Server, srv TestServer) { s.RegisterService(&_Test_serviceDesc, srv) } @@ -191,5 +199,5 @@ var _Test_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "go-micro/service/grpc/proto/test.proto", + Metadata: "service/grpc/proto/test.proto", } diff --git a/service/grpc/proto/test.micro.go b/service/grpc/proto/test.pb.micro.go similarity index 93% rename from service/grpc/proto/test.micro.go rename to service/grpc/proto/test.pb.micro.go index 5cc8a4e0..f4d93011 100644 --- a/service/grpc/proto/test.micro.go +++ b/service/grpc/proto/test.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: go-micro/service/grpc/proto/test.proto +// source: service/grpc/proto/test.proto package test @@ -43,12 +43,6 @@ type testService struct { } func NewTestService(name string, c client.Client) TestService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "test" - } return &testService{ c: c, name: name, diff --git a/store/etcd/config.go b/store/etcd/config.go index f50b7f54..eb79cea1 100644 --- a/store/etcd/config.go +++ b/store/etcd/config.go @@ -10,7 +10,7 @@ import ( "google.golang.org/grpc" ) -// Implement all the options from https://pkg.go.dev/go.etcd.io/etcd/clientv3?tab=doc#Config +// Implement all the options from https://pkg.go.dev/github.com/coreos/etcd/clientv3?tab=doc#Config // Need to use non basic types in context.WithValue type autoSyncInterval string type dialTimeout string diff --git a/store/service/proto/store.pb.go b/store/service/proto/store.pb.go index b7cd9979..177e664d 100644 --- a/store/service/proto/store.pb.go +++ b/store/service/proto/store.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: store.proto +// source: store/service/proto/store.proto package go_micro_store import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -36,7 +40,7 @@ func (m *Record) Reset() { *m = Record{} } func (m *Record) String() string { return proto.CompactTextString(m) } func (*Record) ProtoMessage() {} func (*Record) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{0} + return fileDescriptor_1ba364858f5c3cdb, []int{0} } func (m *Record) XXX_Unmarshal(b []byte) error { @@ -92,7 +96,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{1} + return fileDescriptor_1ba364858f5c3cdb, []int{1} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -153,7 +157,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{2} + return fileDescriptor_1ba364858f5c3cdb, []int{2} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -199,7 +203,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{3} + return fileDescriptor_1ba364858f5c3cdb, []int{3} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -241,7 +245,7 @@ func (m *WriteOptions) Reset() { *m = WriteOptions{} } func (m *WriteOptions) String() string { return proto.CompactTextString(m) } func (*WriteOptions) ProtoMessage() {} func (*WriteOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{4} + return fileDescriptor_1ba364858f5c3cdb, []int{4} } func (m *WriteOptions) XXX_Unmarshal(b []byte) error { @@ -288,7 +292,7 @@ func (m *WriteRequest) Reset() { *m = WriteRequest{} } func (m *WriteRequest) String() string { return proto.CompactTextString(m) } func (*WriteRequest) ProtoMessage() {} func (*WriteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{5} + return fileDescriptor_1ba364858f5c3cdb, []int{5} } func (m *WriteRequest) XXX_Unmarshal(b []byte) error { @@ -333,7 +337,7 @@ func (m *WriteResponse) Reset() { *m = WriteResponse{} } func (m *WriteResponse) String() string { return proto.CompactTextString(m) } func (*WriteResponse) ProtoMessage() {} func (*WriteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{6} + return fileDescriptor_1ba364858f5c3cdb, []int{6} } func (m *WriteResponse) XXX_Unmarshal(b []byte) error { @@ -364,7 +368,7 @@ func (m *DeleteOptions) Reset() { *m = DeleteOptions{} } func (m *DeleteOptions) String() string { return proto.CompactTextString(m) } func (*DeleteOptions) ProtoMessage() {} func (*DeleteOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{7} + return fileDescriptor_1ba364858f5c3cdb, []int{7} } func (m *DeleteOptions) XXX_Unmarshal(b []byte) error { @@ -397,7 +401,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{8} + return fileDescriptor_1ba364858f5c3cdb, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -442,7 +446,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{9} + return fileDescriptor_1ba364858f5c3cdb, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -477,7 +481,7 @@ func (m *ListOptions) Reset() { *m = ListOptions{} } func (m *ListOptions) String() string { return proto.CompactTextString(m) } func (*ListOptions) ProtoMessage() {} func (*ListOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{10} + return fileDescriptor_1ba364858f5c3cdb, []int{10} } func (m *ListOptions) XXX_Unmarshal(b []byte) error { @@ -537,7 +541,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{11} + return fileDescriptor_1ba364858f5c3cdb, []int{11} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -576,7 +580,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{12} + return fileDescriptor_1ba364858f5c3cdb, []int{12} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -620,37 +624,254 @@ func init() { proto.RegisterType((*ListResponse)(nil), "go.micro.store.ListResponse") } -func init() { proto.RegisterFile("store.proto", fileDescriptor_98bbca36ef968dfc) } +func init() { proto.RegisterFile("store/service/proto/store.proto", fileDescriptor_1ba364858f5c3cdb) } -var fileDescriptor_98bbca36ef968dfc = []byte{ - // 463 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x5d, 0x6b, 0xd4, 0x40, - 0x14, 0xed, 0x6c, 0xb2, 0x69, 0xf7, 0x26, 0xd6, 0x65, 0x90, 0x12, 0xb4, 0x95, 0x30, 0x4f, 0x79, - 0x0a, 0x65, 0xc5, 0x8f, 0x47, 0xc1, 0x2a, 0x2a, 0x82, 0x30, 0x82, 0x82, 0x6f, 0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, 0x75, 0x80, 0x39, 0x9b, 0x38, 0xdd, 0xe2, 0x7c, 0x82, - 0xc4, 0xbd, 0x02, 0x9e, 0x78, 0xb7, 0x80, 0xf4, 0x7c, 0xea, 0x78, 0x0b, 0xf5, 0x1e, 0x62, 0xe3, - 0x05, 0x1e, 0x75, 0x6e, 0x52, 0x57, 0xdf, 0x3e, 0x72, 0x70, 0x8e, 0x7e, 0x25, 0xf6, 0x7f, 0xf5, - 0xe2, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa5, 0x11, 0xc3, 0x50, 0xbe, 0x04, 0x00, 0x00, +var fileDescriptor_1ba364858f5c3cdb = []byte{ + // 474 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x5d, 0x6f, 0xd3, 0x30, + 0x14, 0x9d, 0x9b, 0x34, 0x5b, 0x6f, 0xcb, 0xa8, 0x2c, 0x34, 0x45, 0xb0, 0x41, 0xe5, 0xa7, 0x3c, + 0xa5, 0x53, 0x11, 0x1f, 0x8f, 0x48, 0x0c, 0x04, 0x08, 0x09, 0xc9, 0x48, 0x20, 0xf1, 0x36, 0xba, + 0x5b, 0x64, 0xb5, 0x9b, 0x83, 0xed, 0x56, 0xeb, 0x1f, 0xe2, 0x77, 0x22, 0x7f, 0xb5, 0x69, 0x48, + 0x5e, 0x78, 0xf3, 0xbd, 0xbe, 0x39, 0xe7, 0x9e, 0xe3, 0xa3, 0xc0, 0x33, 0x6d, 0xa4, 0xc2, 0xa9, + 0x46, 0xb5, 0x11, 0x73, 0x9c, 0x56, 0x4a, 0x1a, 0x39, 0x75, 0xbd, 0xd2, 0x9d, 0xe9, 0xe9, 0x2f, + 0x59, 0xde, 0x8a, 0xb9, 0x92, 0xa5, 0xeb, 0xb2, 0x0f, 0x90, 0x71, 0x9c, 0x4b, 0x75, 0x43, 0xc7, + 0x90, 0x2c, 0x71, 0x9b, 0x93, 0x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, 0x07, 0xf5, 0xc5, 0xf6, 0x9a, + 0x1f, 0xc2, 0x83, 0xc0, 0xeb, 0x45, 0xdb, 0xc6, 0x15, 0xae, 0x70, 0x37, 0xca, 0x7e, 0xc4, 0x46, + 0xb7, 0xdf, 0xaf, 0x9a, 0xe4, 0x17, 0x4d, 0xf2, 0x03, 0xc8, 0x3d, 0xfb, 0x18, 0x4e, 0x23, 0x76, + 0xa0, 0x5f, 0xc2, 0xf0, 0xb3, 0xd0, 0xa6, 0x3d, 0x48, 0x83, 0x8e, 0x20, 0x0d, 0xfe, 0x33, 0x48, + 0x57, 0x9e, 0x2c, 0x0a, 0xab, 0xc5, 0x86, 0xb4, 0xc7, 0xa6, 0xb6, 0xda, 0x5e, 0x44, 0x01, 0x23, + 0x8f, 0x12, 0x62, 0x43, 0x21, 0x5d, 0xe2, 0xd6, 0x5a, 0x91, 0x14, 0x03, 0xee, 0xce, 0x9f, 0xd2, + 0x13, 0x32, 0xee, 0xcd, 0xfe, 0xf4, 0xa0, 0xff, 0xd5, 0x02, 0xd1, 0xb7, 0x90, 0xda, 0xa8, 0xd1, + 0xd6, 0x60, 0x86, 0x7d, 0x1e, 0x9f, 0xb7, 0x5f, 0x06, 0xa7, 0x8e, 0xe8, 0x7b, 0xe8, 0xbb, 0xb7, + 0xa3, 0xed, 0x6f, 0x1d, 0x61, 0x2e, 0x3a, 0x6e, 0x77, 0x38, 0x1f, 0x21, 0xf3, 0xaf, 0x40, 0x3b, + 0xde, 0x2d, 0x22, 0x3d, 0xed, 0xba, 0xde, 0x41, 0xbd, 0x83, 0xd4, 0x7a, 0x41, 0x5b, 0x9d, 0xeb, + 0xd4, 0x55, 0xb7, 0x8f, 0x1d, 0x5d, 0x92, 0x9f, 0x99, 0xfb, 0x5f, 0x3d, 0xff, 0x1b, 0x00, 0x00, + 0xff, 0xff, 0xdd, 0xdb, 0x9c, 0x15, 0xd2, 0x04, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// StoreClient is the client API for Store service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type StoreClient interface { + Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) + Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) + List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (Store_ListClient, error) +} + +type storeClient struct { + cc *grpc.ClientConn +} + +func NewStoreClient(cc *grpc.ClientConn) StoreClient { + return &storeClient{cc} +} + +func (c *storeClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { + out := new(ReadResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Read", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *storeClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) { + out := new(WriteResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Write", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *storeClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { + out := new(DeleteResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *storeClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (Store_ListClient, error) { + stream, err := c.cc.NewStream(ctx, &_Store_serviceDesc.Streams[0], "/go.micro.store.Store/List", opts...) + if err != nil { + return nil, err + } + x := &storeListClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Store_ListClient interface { + Recv() (*ListResponse, error) + grpc.ClientStream +} + +type storeListClient struct { + grpc.ClientStream +} + +func (x *storeListClient) Recv() (*ListResponse, error) { + m := new(ListResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// StoreServer is the server API for Store service. +type StoreServer interface { + Read(context.Context, *ReadRequest) (*ReadResponse, error) + Write(context.Context, *WriteRequest) (*WriteResponse, error) + Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) + List(*ListRequest, Store_ListServer) error +} + +// UnimplementedStoreServer can be embedded to have forward compatible implementations. +type UnimplementedStoreServer struct { +} + +func (*UnimplementedStoreServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") +} +func (*UnimplementedStoreServer) Write(ctx context.Context, req *WriteRequest) (*WriteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Write not implemented") +} +func (*UnimplementedStoreServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} +func (*UnimplementedStoreServer) List(req *ListRequest, srv Store_ListServer) error { + return status.Errorf(codes.Unimplemented, "method List not implemented") +} + +func RegisterStoreServer(s *grpc.Server, srv StoreServer) { + s.RegisterService(&_Store_serviceDesc, srv) +} + +func _Store_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReadRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Read(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Read", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Read(ctx, req.(*ReadRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Store_Write_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WriteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Write(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Write", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Write(ctx, req.(*WriteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Store_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Delete(ctx, req.(*DeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Store_List_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(ListRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(StoreServer).List(m, &storeListServer{stream}) +} + +type Store_ListServer interface { + Send(*ListResponse) error + grpc.ServerStream +} + +type storeListServer struct { + grpc.ServerStream +} + +func (x *storeListServer) Send(m *ListResponse) error { + return x.ServerStream.SendMsg(m) +} + +var _Store_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.store.Store", + HandlerType: (*StoreServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Read", + Handler: _Store_Read_Handler, + }, + { + MethodName: "Write", + Handler: _Store_Write_Handler, + }, + { + MethodName: "Delete", + Handler: _Store_Delete_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "List", + Handler: _Store_List_Handler, + ServerStreams: true, + }, + }, + Metadata: "store/service/proto/store.proto", } diff --git a/store/service/proto/store.pb.micro.go b/store/service/proto/store.pb.micro.go index 321449b5..4cdba07f 100644 --- a/store/service/proto/store.pb.micro.go +++ b/store/service/proto/store.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: store.proto +// source: store/service/proto/store.proto package go_micro_store diff --git a/transport/grpc/proto/transport.pb.go b/transport/grpc/proto/transport.pb.go index a9702987..88abb01a 100644 --- a/transport/grpc/proto/transport.pb.go +++ b/transport/grpc/proto/transport.pb.go @@ -1,13 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: go-micro/transport/grpc/proto/transport.proto +// source: transport/grpc/proto/transport.proto -package go_micro_grpc_transport +package go_micro_transport_grpc import ( context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -34,7 +36,7 @@ func (m *Message) Reset() { *m = Message{} } func (m *Message) String() string { return proto.CompactTextString(m) } func (*Message) ProtoMessage() {} func (*Message) Descriptor() ([]byte, []int) { - return fileDescriptor_29b90b9ccd5e0da5, []int{0} + return fileDescriptor_651718cd7c7ae974, []int{0} } func (m *Message) XXX_Unmarshal(b []byte) error { @@ -70,30 +72,30 @@ func (m *Message) GetBody() []byte { } func init() { - proto.RegisterType((*Message)(nil), "go.micro.grpc.transport.Message") - proto.RegisterMapType((map[string]string)(nil), "go.micro.grpc.transport.Message.HeaderEntry") + proto.RegisterType((*Message)(nil), "go.micro.transport.grpc.Message") + proto.RegisterMapType((map[string]string)(nil), "go.micro.transport.grpc.Message.HeaderEntry") } func init() { - proto.RegisterFile("go-micro/transport/grpc/proto/transport.proto", fileDescriptor_29b90b9ccd5e0da5) + proto.RegisterFile("transport/grpc/proto/transport.proto", fileDescriptor_651718cd7c7ae974) } -var fileDescriptor_29b90b9ccd5e0da5 = []byte{ - // 214 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4d, 0xcf, 0xd7, 0xcd, - 0x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x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x77, 0xa1, - 0xa4, 0xcb, 0x52, 0x01, 0x00, 0x00, +var fileDescriptor_651718cd7c7ae974 = []byte{ + // 209 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x29, 0x29, 0x4a, 0xcc, + 0x2b, 0x2e, 0xc8, 0x2f, 0x2a, 0xd1, 0x4f, 0x2f, 0x2a, 0x48, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc9, + 0xd7, 0x87, 0x0b, 0xea, 0x81, 0xf9, 0x42, 0xe2, 0xe9, 0xf9, 0x7a, 0xb9, 0x99, 0xc9, 0x45, 0xf9, + 0x7a, 0x08, 0x19, 0x90, 0x72, 0xa5, 0x79, 0x8c, 0x5c, 0xec, 0xbe, 0xa9, 0xc5, 0xc5, 0x89, 0xe9, + 0xa9, 0x42, 0x2e, 0x5c, 0x6c, 0x19, 0xa9, 0x89, 0x29, 0xa9, 0x45, 0x12, 0x8c, 0x0a, 0xcc, 0x1a, + 0xdc, 0x46, 0x3a, 0x7a, 0x38, 0x74, 0xe9, 0x41, 0x75, 0xe8, 0x79, 0x80, 0x95, 0xbb, 0xe6, 0x95, + 0x14, 0x55, 0x06, 0x41, 0xf5, 0x0a, 0x09, 0x71, 0xb1, 0x24, 0xe5, 0xa7, 0x54, 0x4a, 0x30, 0x29, + 0x30, 0x6a, 0xf0, 0x04, 0x81, 0xd9, 0x52, 0x96, 0x5c, 0xdc, 0x48, 0x4a, 0x85, 0x04, 0xb8, 0x98, + 0xb3, 0x53, 0x2b, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x40, 0x4c, 0x21, 0x11, 0x2e, 0xd6, + 0xb2, 0xc4, 0x9c, 0xd2, 0x54, 0xb0, 0x2e, 0xce, 0x20, 0x08, 0xc7, 0x8a, 0xc9, 0x82, 0xd1, 0x28, + 0x9e, 0x8b, 0x33, 0x04, 0x66, 0xb9, 0x50, 0x10, 0x17, 0x5b, 0x70, 0x49, 0x51, 0x6a, 0x62, 0xae, + 0x90, 0x02, 0x21, 0xb7, 0x49, 0x11, 0x54, 0xa1, 0xc4, 0xa0, 0xc1, 0x68, 0xc0, 0x98, 0xc4, 0x06, + 0x0e, 0x21, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd4, 0xd0, 0x4b, 0x4b, 0x49, 0x01, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -120,7 +122,7 @@ func NewTransportClient(cc *grpc.ClientConn) TransportClient { } func (c *transportClient) Stream(ctx context.Context, opts ...grpc.CallOption) (Transport_StreamClient, error) { - stream, err := c.cc.NewStream(ctx, &_Transport_serviceDesc.Streams[0], "/go.micro.grpc.transport.Transport/Stream", opts...) + stream, err := c.cc.NewStream(ctx, &_Transport_serviceDesc.Streams[0], "/go.micro.transport.grpc.Transport/Stream", opts...) if err != nil { return nil, err } @@ -155,6 +157,14 @@ type TransportServer interface { Stream(Transport_StreamServer) error } +// UnimplementedTransportServer can be embedded to have forward compatible implementations. +type UnimplementedTransportServer struct { +} + +func (*UnimplementedTransportServer) Stream(srv Transport_StreamServer) error { + return status.Errorf(codes.Unimplemented, "method Stream not implemented") +} + func RegisterTransportServer(s *grpc.Server, srv TransportServer) { s.RegisterService(&_Transport_serviceDesc, srv) } @@ -186,7 +196,7 @@ func (x *transportStreamServer) Recv() (*Message, error) { } var _Transport_serviceDesc = grpc.ServiceDesc{ - ServiceName: "go.micro.grpc.transport.Transport", + ServiceName: "go.micro.transport.grpc.Transport", HandlerType: (*TransportServer)(nil), Methods: []grpc.MethodDesc{}, Streams: []grpc.StreamDesc{ @@ -197,5 +207,5 @@ var _Transport_serviceDesc = grpc.ServiceDesc{ ClientStreams: true, }, }, - Metadata: "go-micro/transport/grpc/proto/transport.proto", + Metadata: "transport/grpc/proto/transport.proto", } diff --git a/transport/grpc/proto/transport.micro.go b/transport/grpc/proto/transport.pb.micro.go similarity index 92% rename from transport/grpc/proto/transport.micro.go rename to transport/grpc/proto/transport.pb.micro.go index 6cb11d4e..d3866eb3 100644 --- a/transport/grpc/proto/transport.micro.go +++ b/transport/grpc/proto/transport.pb.micro.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: go-micro/transport/grpc/proto/transport.proto +// source: transport/grpc/proto/transport.proto -package go_micro_grpc_transport +package go_micro_transport_grpc import ( fmt "fmt" @@ -43,12 +43,6 @@ type transportService struct { } func NewTransportService(name string, c client.Client) TransportService { - if c == nil { - c = client.NewClient() - } - if len(name) == 0 { - name = "go.micro.grpc.transport" - } return &transportService{ c: c, name: name, @@ -65,6 +59,7 @@ func (c *transportService) Stream(ctx context.Context, opts ...client.CallOption } type Transport_StreamService interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -80,6 +75,10 @@ func (x *transportServiceStream) Close() error { return x.stream.Close() } +func (x *transportServiceStream) Context() context.Context { + return x.stream.Context() +} + func (x *transportServiceStream) SendMsg(m interface{}) error { return x.stream.Send(m) } @@ -127,6 +126,7 @@ func (h *transportHandler) Stream(ctx context.Context, stream server.Stream) err } type Transport_StreamStream interface { + Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error Close() error @@ -142,6 +142,10 @@ func (x *transportStreamStream) Close() error { return x.stream.Close() } +func (x *transportStreamStream) Context() context.Context { + return x.stream.Context() +} + func (x *transportStreamStream) SendMsg(m interface{}) error { return x.stream.Send(m) } diff --git a/transport/grpc/proto/transport.proto b/transport/grpc/proto/transport.proto index 3ceb7622..1ec353a8 100644 --- a/transport/grpc/proto/transport.proto +++ b/transport/grpc/proto/transport.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package go.micro.grpc.transport; +package go.micro.transport.grpc; service Transport { rpc Stream(stream Message) returns (stream Message) {} From c706ebe3fb1fadbe9d883fb2efa876db41f6af51 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 31 Mar 2020 00:35:11 +0300 Subject: [PATCH 458/788] auth proto: provide help to protoc-gen-go (#1442) Signed-off-by: Vasiliy Tolstov --- auth/service/proto/accounts.pb.go | 20 +++--- auth/service/proto/accounts.pb.micro.go | 2 +- auth/service/proto/accounts.proto | 4 +- auth/service/proto/auth.pb.go | 83 +++++++++++++------------ auth/service/proto/auth.pb.micro.go | 2 +- auth/service/proto/auth.proto | 6 +- auth/service/proto/rules.pb.go | 50 +++++++-------- auth/service/proto/rules.pb.micro.go | 2 +- auth/service/proto/rules.proto | 4 +- 9 files changed, 90 insertions(+), 83 deletions(-) diff --git a/auth/service/proto/accounts.pb.go b/auth/service/proto/accounts.pb.go index 5d7a415c..d882ce47 100644 --- a/auth/service/proto/accounts.pb.go +++ b/auth/service/proto/accounts.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: auth/service/proto/accounts.proto -package go_micro_auth +package auth import ( context "context" @@ -102,18 +102,18 @@ func init() { func init() { proto.RegisterFile("auth/service/proto/accounts.proto", fileDescriptor_fdbfb9fc95541122) } var fileDescriptor_fdbfb9fc95541122 = []byte{ - // 164 bytes of a gzipped FileDescriptorProto + // 169 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4c, 0x2c, 0x2d, 0xc9, 0xd0, 0x2f, 0x4e, 0x2d, 0x2a, 0xcb, 0x4c, 0x4e, 0xd5, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x4f, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0x29, 0xd6, 0x03, 0x73, 0x85, 0x78, 0xd3, 0xf3, 0xf5, 0x72, - 0x33, 0x93, 0x8b, 0xf2, 0xf5, 0x40, 0x6a, 0xa5, 0x64, 0xb1, 0xe9, 0x28, 0x2d, 0xc9, 0x80, 0xa8, - 0x56, 0x12, 0xe5, 0x12, 0xf6, 0xc9, 0x2c, 0x2e, 0x71, 0x84, 0x9a, 0x11, 0x94, 0x5a, 0x58, 0x9a, - 0x5a, 0x5c, 0xa2, 0xe4, 0xc5, 0x25, 0x82, 0x2a, 0x5c, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x2a, 0x64, - 0xc4, 0xc5, 0x01, 0xb3, 0x4e, 0x82, 0x51, 0x81, 0x59, 0x83, 0xdb, 0x48, 0x4c, 0x0f, 0xc5, 0x3e, - 0x3d, 0xa8, 0x96, 0x20, 0xb8, 0x3a, 0xa3, 0x58, 0x2e, 0x0e, 0x98, 0x39, 0x42, 0x81, 0x5c, 0x2c, - 0x20, 0x73, 0x85, 0x94, 0xd0, 0x74, 0x61, 0x71, 0x83, 0x94, 0x32, 0x5e, 0x35, 0x10, 0x07, 0x29, - 0x31, 0x24, 0xb1, 0x81, 0x3d, 0x62, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x82, 0x00, 0x19, 0x2f, - 0x1b, 0x01, 0x00, 0x00, + 0x33, 0x93, 0x8b, 0xf2, 0xf5, 0x40, 0x6a, 0xa5, 0xb8, 0x40, 0x24, 0x44, 0x4a, 0x49, 0x94, 0x4b, + 0xd8, 0x27, 0xb3, 0xb8, 0xc4, 0x11, 0xaa, 0x21, 0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0x44, 0xc9, + 0x8b, 0x4b, 0x04, 0x55, 0xb8, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0xc8, 0x88, 0x8b, 0x03, 0x66, + 0xb6, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0x98, 0x1e, 0x8a, 0xe1, 0x7a, 0x50, 0x2d, 0x41, + 0x70, 0x75, 0x46, 0xb1, 0x5c, 0x1c, 0x30, 0x73, 0x84, 0x02, 0xb9, 0x58, 0x40, 0xe6, 0x0a, 0x29, + 0xa1, 0xe9, 0xc2, 0xe2, 0x06, 0x29, 0x65, 0xbc, 0x6a, 0x20, 0x0e, 0x52, 0x62, 0x70, 0xe2, 0x8e, + 0xe2, 0x04, 0x49, 0x5b, 0x83, 0x88, 0x24, 0x36, 0xb0, 0xaf, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, + 0xff, 0x88, 0x2c, 0xf7, 0xdc, 0x15, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/auth/service/proto/accounts.pb.micro.go b/auth/service/proto/accounts.pb.micro.go index d83f2a9f..1370868d 100644 --- a/auth/service/proto/accounts.pb.micro.go +++ b/auth/service/proto/accounts.pb.micro.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. // source: auth/service/proto/accounts.proto -package go_micro_auth +package auth import ( fmt "fmt" diff --git a/auth/service/proto/accounts.proto b/auth/service/proto/accounts.proto index 77967b51..d31d7cbd 100644 --- a/auth/service/proto/accounts.proto +++ b/auth/service/proto/accounts.proto @@ -2,7 +2,9 @@ syntax = "proto3"; package go.micro.auth; -import "auth/service/proto/auth.proto"; +option go_package = "auth;auth"; + +import "auth.proto"; service Accounts { rpc List(ListAccountsRequest) returns (ListAccountsResponse) {}; diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index 7d7d2ab5..8fee8f6e 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: auth/service/proto/auth.proto -package go_micro_auth +package auth import ( context "context" @@ -697,46 +697,47 @@ func init() { func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } var fileDescriptor_21300bfacc51fc2a = []byte{ - // 612 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0xae, 0xed, 0xfc, 0xb8, 0x93, 0x5f, 0xad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5, 0xec, 0x75, 0xa2, 0xfb, - 0x47, 0xbb, 0x9e, 0x8b, 0x58, 0x72, 0xc5, 0x0d, 0xac, 0x75, 0x1e, 0x37, 0xb0, 0x4a, 0xcc, 0xd8, - 0x7b, 0x97, 0x35, 0xf1, 0xe7, 0x74, 0xf2, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xa8, 0xe4, 0x21, 0xa9, - 0xbd, 0x06, 0x00, 0x00, + // 625 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x4d, 0x6f, 0xd3, 0x4c, + 0x10, 0xae, 0xed, 0x7c, 0x38, 0x93, 0xa6, 0x89, 0x56, 0x55, 0x5e, 0x2b, 0x7a, 0x5b, 0x82, 0x41, + 0x28, 0x42, 0x95, 0x83, 0xd2, 0x0b, 0xa2, 0x02, 0x51, 0xa0, 0x2a, 0x1f, 0x2a, 0x07, 0x0b, 0x09, + 0xc4, 0x05, 0xb9, 0xce, 0x40, 0x4c, 0x1a, 0xdb, 0xac, 0xd7, 0x11, 0x39, 0xf2, 0x87, 0xf8, 0x67, + 0xfc, 0x01, 0x4e, 0x68, 0xd7, 0xbb, 0x8e, 0xe3, 0x24, 0x08, 0xa1, 0x72, 0x89, 0x66, 0x66, 0x67, + 0x9e, 0x99, 0x79, 0xf6, 0xf1, 0x06, 0x0e, 0xbc, 0x94, 0x4d, 0x86, 0x09, 0xd2, 0x79, 0xe0, 0xe3, + 0x30, 0xa6, 0x11, 0x8b, 0x86, 0x3c, 0xe4, 0x08, 0x93, 0xb4, 0x3e, 0x45, 0xce, 0x2c, 0xf0, 0x69, + 0xe4, 0xf0, 0xa0, 0xfd, 0x5d, 0x87, 0xea, 0x9b, 0x68, 0x8a, 0x21, 0xd9, 0x87, 0x2a, 0xe3, 0x86, + 0xa5, 0xf5, 0xb5, 0x41, 0xc3, 0xcd, 0x1c, 0x42, 0xa0, 0xc2, 0x16,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, 0x6f, 0xff, 0x91, 0x62, 0x32, 0x51, 0xcd, 0xba, 0xf9, 0xf7, + 0x9c, 0x75, 0x53, 0x5f, 0xee, 0x4d, 0xd8, 0x15, 0x7d, 0x95, 0x62, 0x74, 0xa1, 0x98, 0xa6, 0x88, + 0x65, 0x82, 0xb1, 0x1f, 0x42, 0x3b, 0x07, 0x93, 0x13, 0xdd, 0x2d, 0x8e, 0xbe, 0xed, 0x71, 0xc8, + 0x52, 0x46, 0x3f, 0x34, 0xa8, 0x9c, 0xa6, 0x6c, 0x42, 0x2e, 0xc0, 0x54, 0xea, 0x20, 0x87, 0xbf, + 0x57, 0x78, 0xef, 0xc6, 0xd6, 0x73, 0x49, 0xe7, 0x0e, 0x79, 0x09, 0x75, 0x49, 0x14, 0x39, 0x28, + 0x65, 0xaf, 0x12, 0xdd, 0x3b, 0xdc, 0x76, 0x5c, 0xc4, 0x92, 0x2b, 0xae, 0x61, 0xad, 0xf2, 0xb8, + 0x86, 0x55, 0x62, 0xc6, 0xde, 0x79, 0xd2, 0x7c, 0xdf, 0xe0, 0x27, 0x27, 0xfc, 0xe7, 0xb2, 0x26, + 0xfe, 0xa9, 0x8e, 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0x52, 0x2c, 0xfc, 0x9c, 0xca, 0x06, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index db0d2a70..3e50f636 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. // source: auth/service/proto/auth.proto -package go_micro_auth +package auth import ( fmt "fmt" diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index 7d681de0..17934ec2 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -2,9 +2,11 @@ syntax = "proto3"; package go.micro.auth; +option go_package = "auth;auth"; + service Auth { rpc Generate(GenerateRequest) returns (GenerateResponse) {}; - rpc Inspect(InspectRequest) returns (InspectResponse) {}; + rpc Inspect(InspectRequest) returns (InspectResponse) {}; rpc Refresh(RefreshRequest) returns (RefreshResponse) {}; } @@ -74,4 +76,4 @@ message RefreshRequest { message RefreshResponse { Token token = 1; -} \ No newline at end of file +} diff --git a/auth/service/proto/rules.pb.go b/auth/service/proto/rules.pb.go index dc75ff0d..41919db0 100644 --- a/auth/service/proto/rules.pb.go +++ b/auth/service/proto/rules.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: auth/service/proto/rules.proto -package go_micro_auth +package auth import ( context "context" @@ -371,30 +371,30 @@ func init() { func init() { proto.RegisterFile("auth/service/proto/rules.proto", fileDescriptor_ce1ef0aa40cdd6dc) } var fileDescriptor_ce1ef0aa40cdd6dc = []byte{ - // 362 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x93, 0x51, 0x4b, 0xeb, 0x30, - 0x1c, 0xc5, 0x97, 0xae, 0xeb, 0xbd, 0xf7, 0xdf, 0xbb, 0x51, 0x72, 0xb9, 0x58, 0xaa, 0x93, 0xb2, - 0xa7, 0x2a, 0xd8, 0x41, 0xf7, 0xe4, 0xe3, 0xb0, 0x63, 0x88, 0x52, 0x21, 0x28, 0x3e, 0xcf, 0xee, - 0x8f, 0x16, 0xaa, 0x99, 0x49, 0xeb, 0x57, 0xf0, 0xcd, 0x4f, 0xe8, 0x87, 0x91, 0x26, 0xdd, 0x70, - 0xdd, 0x06, 0xfa, 0xe6, 0x5b, 0x92, 0x73, 0x72, 0xf2, 0xcb, 0x69, 0x03, 0x87, 0xb3, 0xb2, 0x78, - 0x18, 0x4a, 0x14, 0x2f, 0x59, 0x8a, 0xc3, 0x85, 0xe0, 0x05, 0x1f, 0x8a, 0x32, 0x47, 0x19, 0xaa, - 0x31, 0xed, 0x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0x50, 0x00, 0x2b, 0x9e, 0x24, 0xe7, - 0x93, 0xd8, 0x31, 0xa2, 0x77, 0x02, 0x9d, 0x6a, 0xbf, 0xa4, 0x53, 0xb0, 0x74, 0x63, 0xf4, 0xa0, - 0x91, 0xbf, 0xf6, 0x45, 0xbd, 0xfe, 0x0e, 0xb5, 0xbe, 0x4a, 0xab, 0x0a, 0xd2, 0xd7, 0xdb, 0x08, - 0x5a, 0xab, 0x7f, 0x23, 0xa8, 0xd1, 0x49, 0x8b, 0x8e, 0xc1, 0xac, 0x6a, 0xa0, 0x5e, 0xc3, 0xf8, - 0xa9, 0x2a, 0x6f, 0x7f, 0xab, 0xb6, 0x8c, 0xb8, 0xb3, 0xd4, 0x43, 0x19, 0x7d, 0x04, 0x00, 0x00, - 0xff, 0xff, 0xd9, 0x7d, 0x25, 0xd9, 0x78, 0x03, 0x00, 0x00, + // 368 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x93, 0x5f, 0x4b, 0xf3, 0x30, + 0x18, 0xc5, 0x97, 0xae, 0xeb, 0xfb, 0xee, 0xa9, 0x1b, 0x25, 0x22, 0x96, 0xfa, 0x87, 0xb2, 0xab, + 0x2a, 0xd8, 0x41, 0x77, 0x25, 0x5e, 0x4d, 0x3b, 0x86, 0x28, 0x15, 0x82, 0x22, 0x78, 0x37, 0xbb, + 0x07, 0x2d, 0x54, 0x3b, 0x93, 0xd6, 0xaf, 0xe0, 0x9d, 0x9f, 0xd0, 0x0f, 0x23, 0x69, 0xba, 0xe1, + 0x3a, 0x07, 0x7a, 0xe7, 0x4d, 0x48, 0x72, 0x4e, 0x4e, 0x7f, 0x39, 0x6d, 0x61, 0x7f, 0x52, 0xe4, + 0x8f, 0x7d, 0x81, 0xfc, 0x35, 0x89, 0xb1, 0x3f, 0xe3, 0x59, 0x9e, 0xf5, 0x79, 0x91, 0xa2, 0xf0, + 0xcb, 0x39, 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84, 0x02, 0x18, 0xe1, 0x28, 0x3a, 0x1f, 0x85, + 0x96, 0x16, 0x7c, 0x10, 0x68, 0xc9, 0xf3, 0x82, 0x8e, 0xc1, 0x50, 0x8d, 0xd1, 0xdd, 0x5a, 0xfe, + 0xd2, 0x1b, 0x75, 0xf6, 0xd6, 0xa8, 0xd5, 0x55, 0x1a, 0x32, 0x48, 0x5d, 0x6f, 0x25, 0x68, 0xa9, + 0xfe, 0x95, 0xa0, 0x5a, 0x27, 0x0d, 0x3a, 0x04, 0x5d, 0xd6, 0x40, 0x9d, 0x9a, 0xf1, 0x4b, 0x55, + 0xce, 0xce, 0xb7, 0xda, 0x3c, 0xe2, 0xd4, 0xbc, 0x6b, 0xcb, 0xed, 0x13, 0x39, 0xdc, 0x1b, 0xe5, + 0x5f, 0x33, 0xf8, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x63, 0x57, 0x37, 0xef, 0x72, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/auth/service/proto/rules.pb.micro.go b/auth/service/proto/rules.pb.micro.go index 9e24fe06..bcba2c50 100644 --- a/auth/service/proto/rules.pb.micro.go +++ b/auth/service/proto/rules.pb.micro.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. // source: auth/service/proto/rules.proto -package go_micro_auth +package auth import ( fmt "fmt" diff --git a/auth/service/proto/rules.proto b/auth/service/proto/rules.proto index 35355e5a..2acaff64 100644 --- a/auth/service/proto/rules.proto +++ b/auth/service/proto/rules.proto @@ -2,7 +2,9 @@ syntax = "proto3"; package go.micro.auth; -import "auth/service/proto/auth.proto"; +option go_package = "auth;auth"; + +import "auth.proto"; service Rules { rpc Create(CreateRequest) returns (CreateResponse) {}; From 76ade7efd9b8ca921b5a1fcd309421b71a057b12 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 31 Mar 2020 10:06:13 +0100 Subject: [PATCH 459/788] Auth - Swap Refresh to Token and change secrets to be strings, not tokens (#1444) * Refresh => Token * Secret is no longer a token Co-authored-by: Ben Toogood --- auth/auth.go | 6 +- auth/default.go | 6 +- auth/options.go | 29 +--- auth/service/proto/auth.pb.go | 210 ++++++++++++++-------------- auth/service/proto/auth.pb.micro.go | 16 +-- auth/service/proto/auth.proto | 18 +-- auth/service/service.go | 25 ++-- 7 files changed, 144 insertions(+), 166 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 155ffebc..4c175110 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -42,8 +42,8 @@ type Auth interface { Verify(acc *Account, res *Resource) error // Inspect a token Inspect(token string) (*Account, error) - // Refresh an account using a secret - Refresh(secret string, opts ...RefreshOption) (*Token, error) + // Token generated using an account ID and secret + Token(id, secret string, opts ...TokenOption) (*Token, error) // String returns the name of the implementation String() string } @@ -63,7 +63,7 @@ type Account struct { // ID of the account (UUIDV4, email or username) ID string `json:"id"` // Secret used to renew the account - Secret *Token `json:"secret"` + Secret string `json:"secret"` // Roles associated with the Account Roles []string `json:"roles"` // Any other associated metadata diff --git a/auth/default.go b/auth/default.go index 300bb41c..c637f7c6 100644 --- a/auth/default.go +++ b/auth/default.go @@ -41,7 +41,7 @@ func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) { ID: id, Roles: options.Roles, Metadata: options.Metadata, - Secret: &Token{}, + Secret: uuid.New().String(), }, nil } @@ -67,7 +67,7 @@ func (n *noop) Inspect(token string) (*Account, error) { }, nil } -// Refresh an account using a secret -func (n *noop) Refresh(secret string, opts ...RefreshOption) (*Token, error) { +// Token generation using an account id and secret +func (n *noop) Token(id, secret string, opts ...TokenOption) (*Token, error) { return &Token{}, nil } diff --git a/auth/options.go b/auth/options.go index 95665f15..274935b3 100644 --- a/auth/options.go +++ b/auth/options.go @@ -71,8 +71,6 @@ type GenerateOptions struct { Metadata map[string]string // Roles/scopes associated with the account Roles []string - // SecretExpiry is the time the secret should live for - SecretExpiry time.Duration // Namespace the account belongs too Namespace string } @@ -100,45 +98,32 @@ func WithNamespace(n string) GenerateOption { } } -// WithSecretExpiry for the generated account's secret expires -func WithSecretExpiry(ex time.Duration) GenerateOption { - return func(o *GenerateOptions) { - o.SecretExpiry = ex - } -} - // NewGenerateOptions from a slice of options func NewGenerateOptions(opts ...GenerateOption) GenerateOptions { var options GenerateOptions for _, o := range opts { o(&options) } - - // set defualt expiry of secret - if options.SecretExpiry == 0 { - options.SecretExpiry = time.Hour * 24 * 7 - } - return options } -type RefreshOptions struct { +type TokenOptions struct { // TokenExpiry is the time the token should live for TokenExpiry time.Duration } -type RefreshOption func(o *RefreshOptions) +type TokenOption func(o *TokenOptions) // WithTokenExpiry for the token -func WithTokenExpiry(ex time.Duration) RefreshOption { - return func(o *RefreshOptions) { +func WithTokenExpiry(ex time.Duration) TokenOption { + return func(o *TokenOptions) { o.TokenExpiry = ex } } -// NewRefreshOptions from a slice of options -func NewRefreshOptions(opts ...RefreshOption) RefreshOptions { - var options RefreshOptions +// NewTokenOptions from a slice of options +func NewTokenOptions(opts ...TokenOption) TokenOptions { + var options TokenOptions for _, o := range opts { o(&options) } diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index 8fee8f6e..fb56b3b4 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -121,7 +121,7 @@ func (m *Token) GetNamespace() string { type Account struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Secret *Token `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty"` + Secret string `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty"` Roles []string `protobuf:"bytes,3,rep,name=roles,proto3" json:"roles,omitempty"` Metadata map[string]string `protobuf:"bytes,4,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` Namespace string `protobuf:"bytes,5,opt,name=namespace,proto3" json:"namespace,omitempty"` @@ -162,11 +162,11 @@ func (m *Account) GetId() string { return "" } -func (m *Account) GetSecret() *Token { +func (m *Account) GetSecret() string { if m != nil { return m.Secret } - return nil + return "" } func (m *Account) GetRoles() []string { @@ -249,8 +249,7 @@ type GenerateRequest struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Roles []string `protobuf:"bytes,2,rep,name=roles,proto3" json:"roles,omitempty"` Metadata map[string]string `protobuf:"bytes,3,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - SecretExpiry int64 `protobuf:"varint,4,opt,name=secret_expiry,json=secretExpiry,proto3" json:"secret_expiry,omitempty"` - Namespace string `protobuf:"bytes,5,opt,name=namespace,proto3" json:"namespace,omitempty"` + Namespace string `protobuf:"bytes,4,opt,name=namespace,proto3" json:"namespace,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -302,13 +301,6 @@ func (m *GenerateRequest) GetMetadata() map[string]string { return nil } -func (m *GenerateRequest) GetSecretExpiry() int64 { - if m != nil { - return m.SecretExpiry - } - return 0 -} - func (m *GenerateRequest) GetNamespace() string { if m != nil { return m.Namespace @@ -589,86 +581,94 @@ func (m *InspectResponse) GetAccount() *Account { return nil } -type RefreshRequest struct { - Secret string `protobuf:"bytes,1,opt,name=secret,proto3" json:"secret,omitempty"` - TokenExpiry int64 `protobuf:"varint,2,opt,name=token_expiry,json=tokenExpiry,proto3" json:"token_expiry,omitempty"` +type TokenRequest struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Secret string `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty"` + TokenExpiry int64 `protobuf:"varint,3,opt,name=token_expiry,json=tokenExpiry,proto3" json:"token_expiry,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *RefreshRequest) Reset() { *m = RefreshRequest{} } -func (m *RefreshRequest) String() string { return proto.CompactTextString(m) } -func (*RefreshRequest) ProtoMessage() {} -func (*RefreshRequest) Descriptor() ([]byte, []int) { +func (m *TokenRequest) Reset() { *m = TokenRequest{} } +func (m *TokenRequest) String() string { return proto.CompactTextString(m) } +func (*TokenRequest) ProtoMessage() {} +func (*TokenRequest) Descriptor() ([]byte, []int) { return fileDescriptor_21300bfacc51fc2a, []int{11} } -func (m *RefreshRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_RefreshRequest.Unmarshal(m, b) +func (m *TokenRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_TokenRequest.Unmarshal(m, b) } -func (m *RefreshRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_RefreshRequest.Marshal(b, m, deterministic) +func (m *TokenRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_TokenRequest.Marshal(b, m, deterministic) } -func (m *RefreshRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_RefreshRequest.Merge(m, src) +func (m *TokenRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_TokenRequest.Merge(m, src) } -func (m *RefreshRequest) XXX_Size() int { - return xxx_messageInfo_RefreshRequest.Size(m) +func (m *TokenRequest) XXX_Size() int { + return xxx_messageInfo_TokenRequest.Size(m) } -func (m *RefreshRequest) XXX_DiscardUnknown() { - xxx_messageInfo_RefreshRequest.DiscardUnknown(m) +func (m *TokenRequest) XXX_DiscardUnknown() { + xxx_messageInfo_TokenRequest.DiscardUnknown(m) } -var xxx_messageInfo_RefreshRequest proto.InternalMessageInfo +var xxx_messageInfo_TokenRequest proto.InternalMessageInfo -func (m *RefreshRequest) GetSecret() string { +func (m *TokenRequest) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *TokenRequest) GetSecret() string { if m != nil { return m.Secret } return "" } -func (m *RefreshRequest) GetTokenExpiry() int64 { +func (m *TokenRequest) GetTokenExpiry() int64 { if m != nil { return m.TokenExpiry } return 0 } -type RefreshResponse struct { +type TokenResponse struct { Token *Token `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *RefreshResponse) Reset() { *m = RefreshResponse{} } -func (m *RefreshResponse) String() string { return proto.CompactTextString(m) } -func (*RefreshResponse) ProtoMessage() {} -func (*RefreshResponse) Descriptor() ([]byte, []int) { +func (m *TokenResponse) Reset() { *m = TokenResponse{} } +func (m *TokenResponse) String() string { return proto.CompactTextString(m) } +func (*TokenResponse) ProtoMessage() {} +func (*TokenResponse) Descriptor() ([]byte, []int) { return fileDescriptor_21300bfacc51fc2a, []int{12} } -func (m *RefreshResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_RefreshResponse.Unmarshal(m, b) +func (m *TokenResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_TokenResponse.Unmarshal(m, b) } -func (m *RefreshResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_RefreshResponse.Marshal(b, m, deterministic) +func (m *TokenResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_TokenResponse.Marshal(b, m, deterministic) } -func (m *RefreshResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_RefreshResponse.Merge(m, src) +func (m *TokenResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_TokenResponse.Merge(m, src) } -func (m *RefreshResponse) XXX_Size() int { - return xxx_messageInfo_RefreshResponse.Size(m) +func (m *TokenResponse) XXX_Size() int { + return xxx_messageInfo_TokenResponse.Size(m) } -func (m *RefreshResponse) XXX_DiscardUnknown() { - xxx_messageInfo_RefreshResponse.DiscardUnknown(m) +func (m *TokenResponse) XXX_DiscardUnknown() { + xxx_messageInfo_TokenResponse.DiscardUnknown(m) } -var xxx_messageInfo_RefreshResponse proto.InternalMessageInfo +var xxx_messageInfo_TokenResponse proto.InternalMessageInfo -func (m *RefreshResponse) GetToken() *Token { +func (m *TokenResponse) GetToken() *Token { if m != nil { return m.Token } @@ -690,54 +690,52 @@ func init() { proto.RegisterType((*RevokeResponse)(nil), "go.micro.auth.RevokeResponse") proto.RegisterType((*InspectRequest)(nil), "go.micro.auth.InspectRequest") proto.RegisterType((*InspectResponse)(nil), "go.micro.auth.InspectResponse") - proto.RegisterType((*RefreshRequest)(nil), "go.micro.auth.RefreshRequest") - proto.RegisterType((*RefreshResponse)(nil), "go.micro.auth.RefreshResponse") + proto.RegisterType((*TokenRequest)(nil), "go.micro.auth.TokenRequest") + proto.RegisterType((*TokenResponse)(nil), "go.micro.auth.TokenResponse") } func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } var fileDescriptor_21300bfacc51fc2a = []byte{ - // 625 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x4d, 0x6f, 0xd3, 0x4c, - 0x10, 0xae, 0xed, 0x7c, 0x38, 0x93, 0xa6, 0x89, 0x56, 0x55, 0x5e, 0x2b, 0x7a, 0x5b, 0x82, 0x41, - 0x28, 0x42, 0x95, 0x83, 0xd2, 0x0b, 0xa2, 0x02, 0x51, 0xa0, 0x2a, 0x1f, 0x2a, 0x07, 0x0b, 0x09, - 0xc4, 0x05, 0xb9, 0xce, 0x40, 0x4c, 0x1a, 0xdb, 0xac, 0xd7, 0x11, 0x39, 0xf2, 0x87, 0xf8, 0x67, - 0xfc, 0x01, 0x4e, 0x68, 0xd7, 0xbb, 0x8e, 0xe3, 0x24, 0x08, 0xa1, 0x72, 0x89, 0x66, 0x66, 0x67, - 0x9e, 0x99, 0x79, 0xf6, 0xf1, 0x06, 0x0e, 0xbc, 0x94, 0x4d, 0x86, 0x09, 0xd2, 0x79, 0xe0, 0xe3, - 0x30, 0x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0x49, 0xe0, 0x6c, - 0x36, 0xfb, 0x1d, 0xb4, 0x5c, 0x9c, 0x47, 0x53, 0xbc, 0xf6, 0x56, 0x1d, 0xd8, 0x53, 0xc8, 0xb2, - 0xd7, 0x1d, 0xd8, 0x7b, 0x11, 0x26, 0x31, 0xfa, 0xf9, 0x5e, 0x1b, 0x5f, 0x29, 0xfb, 0x29, 0xb4, - 0xf3, 0xbc, 0xbf, 0xa6, 0xf0, 0x15, 0x6f, 0xff, 0x91, 0x62, 0x32, 0x51, 0xcd, 0xba, 0xf9, 0xf7, - 0x9c, 0x75, 0x53, 0x5f, 0xee, 0x4d, 0xd8, 0x15, 0x7d, 0x95, 0x62, 0x74, 0xa1, 0x98, 0xa6, 0x88, - 0x65, 0x82, 0xb1, 0x1f, 0x42, 0x3b, 0x07, 0x93, 0x13, 0xdd, 0x2d, 0x8e, 0xbe, 0xed, 0x71, 0xc8, - 0x52, 0x46, 0x3f, 0x34, 0xa8, 0x9c, 0xa6, 0x6c, 0x42, 0x2e, 0xc0, 0x54, 0xea, 0x20, 0x87, 0xbf, - 0x57, 0x78, 0xef, 0xc6, 0xd6, 0x73, 0x49, 0xe7, 0x0e, 0x79, 0x09, 0x75, 0x49, 0x14, 0x39, 0x28, - 0x65, 0xaf, 0x12, 0xdd, 0x3b, 0xdc, 0x76, 0x5c, 0xc4, 0x92, 0x2b, 0xae, 0x61, 0xad, 0xf2, 0xb8, - 0x86, 0x55, 0x62, 0xc6, 0xde, 0x79, 0xd2, 0x7c, 0xdf, 0xe0, 0x27, 0x27, 0xfc, 0xe7, 0xb2, 0x26, - 0xfe, 0xa9, 0x8e, 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0x52, 0x2c, 0xfc, 0x9c, 0xca, 0x06, 0x00, - 0x00, + // 600 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x6d, 0x8b, 0xd3, 0x40, +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xc1, 0x9d, 0x52, 0x26, 0x12, 0xe7, 0xa0, 0xfc, 0x50, 0xa1, 0xbc, 0xb0, 0x3f, + 0xd5, 0x79, 0x7c, 0xc4, 0x7f, 0x2e, 0xab, 0xe2, 0xa3, 0x73, 0xfc, 0x27, 0x00, 0x00, 0xff, 0xff, + 0xc4, 0x24, 0xa4, 0xa3, 0x95, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -754,7 +752,7 @@ const _ = grpc.SupportPackageIsVersion4 type AuthClient interface { Generate(ctx context.Context, in *GenerateRequest, opts ...grpc.CallOption) (*GenerateResponse, error) Inspect(ctx context.Context, in *InspectRequest, opts ...grpc.CallOption) (*InspectResponse, error) - Refresh(ctx context.Context, in *RefreshRequest, opts ...grpc.CallOption) (*RefreshResponse, error) + Token(ctx context.Context, in *TokenRequest, opts ...grpc.CallOption) (*TokenResponse, error) } type authClient struct { @@ -783,9 +781,9 @@ func (c *authClient) Inspect(ctx context.Context, in *InspectRequest, opts ...gr return out, nil } -func (c *authClient) Refresh(ctx context.Context, in *RefreshRequest, opts ...grpc.CallOption) (*RefreshResponse, error) { - out := new(RefreshResponse) - err := c.cc.Invoke(ctx, "/go.micro.auth.Auth/Refresh", in, out, opts...) +func (c *authClient) Token(ctx context.Context, in *TokenRequest, opts ...grpc.CallOption) (*TokenResponse, error) { + out := new(TokenResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Auth/Token", in, out, opts...) if err != nil { return nil, err } @@ -796,7 +794,7 @@ func (c *authClient) Refresh(ctx context.Context, in *RefreshRequest, opts ...gr type AuthServer interface { Generate(context.Context, *GenerateRequest) (*GenerateResponse, error) Inspect(context.Context, *InspectRequest) (*InspectResponse, error) - Refresh(context.Context, *RefreshRequest) (*RefreshResponse, error) + Token(context.Context, *TokenRequest) (*TokenResponse, error) } // UnimplementedAuthServer can be embedded to have forward compatible implementations. @@ -809,8 +807,8 @@ func (*UnimplementedAuthServer) Generate(ctx context.Context, req *GenerateReque func (*UnimplementedAuthServer) Inspect(ctx context.Context, req *InspectRequest) (*InspectResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Inspect not implemented") } -func (*UnimplementedAuthServer) Refresh(ctx context.Context, req *RefreshRequest) (*RefreshResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Refresh not implemented") +func (*UnimplementedAuthServer) Token(ctx context.Context, req *TokenRequest) (*TokenResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Token not implemented") } func RegisterAuthServer(s *grpc.Server, srv AuthServer) { @@ -853,20 +851,20 @@ func _Auth_Inspect_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } -func _Auth_Refresh_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(RefreshRequest) +func _Auth_Token_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TokenRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(AuthServer).Refresh(ctx, in) + return srv.(AuthServer).Token(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/go.micro.auth.Auth/Refresh", + FullMethod: "/go.micro.auth.Auth/Token", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).Refresh(ctx, req.(*RefreshRequest)) + return srv.(AuthServer).Token(ctx, req.(*TokenRequest)) } return interceptor(ctx, in, info, handler) } @@ -884,8 +882,8 @@ var _Auth_serviceDesc = grpc.ServiceDesc{ Handler: _Auth_Inspect_Handler, }, { - MethodName: "Refresh", - Handler: _Auth_Refresh_Handler, + MethodName: "Token", + Handler: _Auth_Token_Handler, }, }, Streams: []grpc.StreamDesc{}, diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index 3e50f636..789e9e41 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -36,7 +36,7 @@ var _ server.Option type AuthService interface { Generate(ctx context.Context, in *GenerateRequest, opts ...client.CallOption) (*GenerateResponse, error) Inspect(ctx context.Context, in *InspectRequest, opts ...client.CallOption) (*InspectResponse, error) - Refresh(ctx context.Context, in *RefreshRequest, opts ...client.CallOption) (*RefreshResponse, error) + Token(ctx context.Context, in *TokenRequest, opts ...client.CallOption) (*TokenResponse, error) } type authService struct { @@ -71,9 +71,9 @@ func (c *authService) Inspect(ctx context.Context, in *InspectRequest, opts ...c return out, nil } -func (c *authService) Refresh(ctx context.Context, in *RefreshRequest, opts ...client.CallOption) (*RefreshResponse, error) { - req := c.c.NewRequest(c.name, "Auth.Refresh", in) - out := new(RefreshResponse) +func (c *authService) Token(ctx context.Context, in *TokenRequest, opts ...client.CallOption) (*TokenResponse, error) { + req := c.c.NewRequest(c.name, "Auth.Token", in) + out := new(TokenResponse) err := c.c.Call(ctx, req, out, opts...) if err != nil { return nil, err @@ -86,14 +86,14 @@ func (c *authService) Refresh(ctx context.Context, in *RefreshRequest, opts ...c type AuthHandler interface { Generate(context.Context, *GenerateRequest, *GenerateResponse) error Inspect(context.Context, *InspectRequest, *InspectResponse) error - Refresh(context.Context, *RefreshRequest, *RefreshResponse) error + Token(context.Context, *TokenRequest, *TokenResponse) error } func RegisterAuthHandler(s server.Server, hdlr AuthHandler, opts ...server.HandlerOption) error { type auth interface { Generate(ctx context.Context, in *GenerateRequest, out *GenerateResponse) error Inspect(ctx context.Context, in *InspectRequest, out *InspectResponse) error - Refresh(ctx context.Context, in *RefreshRequest, out *RefreshResponse) error + Token(ctx context.Context, in *TokenRequest, out *TokenResponse) error } type Auth struct { auth @@ -114,6 +114,6 @@ func (h *authHandler) Inspect(ctx context.Context, in *InspectRequest, out *Insp return h.AuthHandler.Inspect(ctx, in, out) } -func (h *authHandler) Refresh(ctx context.Context, in *RefreshRequest, out *RefreshResponse) error { - return h.AuthHandler.Refresh(ctx, in, out) +func (h *authHandler) Token(ctx context.Context, in *TokenRequest, out *TokenResponse) error { + return h.AuthHandler.Token(ctx, in, out) } diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index 17934ec2..60209252 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -6,8 +6,8 @@ option go_package = "auth;auth"; service Auth { rpc Generate(GenerateRequest) returns (GenerateResponse) {}; - rpc Inspect(InspectRequest) returns (InspectResponse) {}; - rpc Refresh(RefreshRequest) returns (RefreshResponse) {}; + rpc Inspect(InspectRequest) returns (InspectResponse) {}; + rpc Token(TokenRequest) returns (TokenResponse) {}; } message Token { @@ -23,7 +23,7 @@ message Token { message Account { string id = 1; - Token secret = 2; + string secret = 2; repeated string roles = 3; map metadata = 4; string namespace = 5; @@ -39,8 +39,7 @@ message GenerateRequest { string id = 1; repeated string roles = 2; map metadata = 3; - int64 secret_expiry = 4; - string namespace = 5; + string namespace = 4; } message GenerateResponse { @@ -69,11 +68,12 @@ message InspectResponse { Account account = 1; } -message RefreshRequest { - string secret = 1; - int64 token_expiry = 2; +message TokenRequest { + string id = 1; + string secret = 2; + int64 token_expiry = 3; } -message RefreshResponse { +message TokenResponse { Token token = 1; } diff --git a/auth/service/service.go b/auth/service/service.go index 21d918c7..2aade9fc 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -81,11 +81,10 @@ func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e options := auth.NewGenerateOptions(opts...) rsp, err := s.auth.Generate(context.TODO(), &pb.GenerateRequest{ - Id: id, - Roles: options.Roles, - Metadata: options.Metadata, - Namespace: options.Namespace, - SecretExpiry: int64(options.SecretExpiry.Seconds()), + Id: id, + Roles: options.Roles, + Metadata: options.Metadata, + Namespace: options.Namespace, }) if err != nil { return nil, err @@ -186,11 +185,12 @@ func (s *svc) Inspect(token string) (*auth.Account, error) { return serializeAccount(rsp.Account), nil } -// Refresh an account using a secret -func (s *svc) Refresh(secret string, opts ...auth.RefreshOption) (*auth.Token, error) { - options := auth.NewRefreshOptions(opts...) +// Token generation using an account ID and secret +func (s *svc) Token(id, secret string, opts ...auth.TokenOption) (*auth.Token, error) { + options := auth.NewTokenOptions(opts...) - rsp, err := s.auth.Refresh(context.Background(), &pb.RefreshRequest{ + rsp, err := s.auth.Token(context.Background(), &pb.TokenRequest{ + Id: id, Secret: secret, TokenExpiry: int64(options.TokenExpiry.Seconds()), }) @@ -269,16 +269,11 @@ func serializeToken(t *pb.Token) *auth.Token { } func serializeAccount(a *pb.Account) *auth.Account { - var secret *auth.Token - if a.Secret != nil { - secret = serializeToken(a.Secret) - } - return &auth.Account{ ID: a.Id, Roles: a.Roles, Metadata: a.Metadata, Namespace: a.Namespace, - Secret: secret, + Secret: a.Secret, } } From 1222d076f252733cd9264c503e2a10321d60708e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 31 Mar 2020 10:18:50 +0100 Subject: [PATCH 460/788] There can be only one! (#1445) * There can be only one * fix proto? --- auth/service/proto/accounts.pb.go | 197 ------- auth/service/proto/accounts.pb.micro.go | 85 --- auth/service/proto/accounts.proto | 18 - auth/service/proto/auth.pb.go | 697 +++++++++++++++++------- auth/service/proto/auth.pb.micro.go | 144 ++++- auth/service/proto/auth.proto | 55 +- auth/service/proto/rules.pb.go | 550 ------------------- auth/service/proto/rules.pb.micro.go | 119 ---- auth/service/proto/rules.proto | 49 -- 9 files changed, 681 insertions(+), 1233 deletions(-) delete mode 100644 auth/service/proto/accounts.pb.go delete mode 100644 auth/service/proto/accounts.pb.micro.go delete mode 100644 auth/service/proto/accounts.proto delete mode 100644 auth/service/proto/rules.pb.go delete mode 100644 auth/service/proto/rules.pb.micro.go delete mode 100644 auth/service/proto/rules.proto diff --git a/auth/service/proto/accounts.pb.go b/auth/service/proto/accounts.pb.go deleted file mode 100644 index d882ce47..00000000 --- a/auth/service/proto/accounts.pb.go +++ /dev/null @@ -1,197 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: auth/service/proto/accounts.proto - -package auth - -import ( - context "context" - fmt "fmt" - proto "github.com/golang/protobuf/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - math "math" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -type ListAccountsRequest struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ListAccountsRequest) Reset() { *m = ListAccountsRequest{} } -func (m *ListAccountsRequest) String() string { return proto.CompactTextString(m) } -func (*ListAccountsRequest) ProtoMessage() {} -func (*ListAccountsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fdbfb9fc95541122, []int{0} -} - -func (m *ListAccountsRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ListAccountsRequest.Unmarshal(m, b) -} -func (m *ListAccountsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ListAccountsRequest.Marshal(b, m, deterministic) -} -func (m *ListAccountsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ListAccountsRequest.Merge(m, src) -} -func (m *ListAccountsRequest) XXX_Size() int { - return xxx_messageInfo_ListAccountsRequest.Size(m) -} -func (m *ListAccountsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ListAccountsRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_ListAccountsRequest proto.InternalMessageInfo - -type ListAccountsResponse struct { - Accounts []*Account `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ListAccountsResponse) Reset() { *m = ListAccountsResponse{} } -func (m *ListAccountsResponse) String() string { return proto.CompactTextString(m) } -func (*ListAccountsResponse) ProtoMessage() {} -func (*ListAccountsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fdbfb9fc95541122, []int{1} -} - -func (m *ListAccountsResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ListAccountsResponse.Unmarshal(m, b) -} -func (m *ListAccountsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ListAccountsResponse.Marshal(b, m, deterministic) -} -func (m *ListAccountsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_ListAccountsResponse.Merge(m, src) -} -func (m *ListAccountsResponse) XXX_Size() int { - return xxx_messageInfo_ListAccountsResponse.Size(m) -} -func (m *ListAccountsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_ListAccountsResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_ListAccountsResponse proto.InternalMessageInfo - -func (m *ListAccountsResponse) GetAccounts() []*Account { - if m != nil { - return m.Accounts - } - return nil -} - -func init() { - proto.RegisterType((*ListAccountsRequest)(nil), "go.micro.auth.ListAccountsRequest") - proto.RegisterType((*ListAccountsResponse)(nil), "go.micro.auth.ListAccountsResponse") -} - -func init() { proto.RegisterFile("auth/service/proto/accounts.proto", fileDescriptor_fdbfb9fc95541122) } - -var fileDescriptor_fdbfb9fc95541122 = []byte{ - // 169 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4c, 0x2c, 0x2d, 0xc9, - 0xd0, 0x2f, 0x4e, 0x2d, 0x2a, 0xcb, 0x4c, 0x4e, 0xd5, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x4f, - 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0x29, 0xd6, 0x03, 0x73, 0x85, 0x78, 0xd3, 0xf3, 0xf5, 0x72, - 0x33, 0x93, 0x8b, 0xf2, 0xf5, 0x40, 0x6a, 0xa5, 0xb8, 0x40, 0x24, 0x44, 0x4a, 0x49, 0x94, 0x4b, - 0xd8, 0x27, 0xb3, 0xb8, 0xc4, 0x11, 0xaa, 0x21, 0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0x44, 0xc9, - 0x8b, 0x4b, 0x04, 0x55, 0xb8, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0xc8, 0x88, 0x8b, 0x03, 0x66, - 0xb6, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0x98, 0x1e, 0x8a, 0xe1, 0x7a, 0x50, 0x2d, 0x41, - 0x70, 0x75, 0x46, 0xb1, 0x5c, 0x1c, 0x30, 0x73, 0x84, 0x02, 0xb9, 0x58, 0x40, 0xe6, 0x0a, 0x29, - 0xa1, 0xe9, 0xc2, 0xe2, 0x06, 0x29, 0x65, 0xbc, 0x6a, 0x20, 0x0e, 0x52, 0x62, 0x70, 0xe2, 0x8e, - 0xe2, 0x04, 0x49, 0x5b, 0x83, 0x88, 0x24, 0x36, 0xb0, 0xaf, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, - 0xff, 0x88, 0x2c, 0xf7, 0xdc, 0x15, 0x01, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// AccountsClient is the client API for Accounts service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type AccountsClient interface { - List(ctx context.Context, in *ListAccountsRequest, opts ...grpc.CallOption) (*ListAccountsResponse, error) -} - -type accountsClient struct { - cc *grpc.ClientConn -} - -func NewAccountsClient(cc *grpc.ClientConn) AccountsClient { - return &accountsClient{cc} -} - -func (c *accountsClient) List(ctx context.Context, in *ListAccountsRequest, opts ...grpc.CallOption) (*ListAccountsResponse, error) { - out := new(ListAccountsResponse) - err := c.cc.Invoke(ctx, "/go.micro.auth.Accounts/List", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// AccountsServer is the server API for Accounts service. -type AccountsServer interface { - List(context.Context, *ListAccountsRequest) (*ListAccountsResponse, error) -} - -// UnimplementedAccountsServer can be embedded to have forward compatible implementations. -type UnimplementedAccountsServer struct { -} - -func (*UnimplementedAccountsServer) List(ctx context.Context, req *ListAccountsRequest) (*ListAccountsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method List not implemented") -} - -func RegisterAccountsServer(s *grpc.Server, srv AccountsServer) { - s.RegisterService(&_Accounts_serviceDesc, srv) -} - -func _Accounts_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ListAccountsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AccountsServer).List(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.auth.Accounts/List", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AccountsServer).List(ctx, req.(*ListAccountsRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Accounts_serviceDesc = grpc.ServiceDesc{ - ServiceName: "go.micro.auth.Accounts", - HandlerType: (*AccountsServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "List", - Handler: _Accounts_List_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "auth/service/proto/accounts.proto", -} diff --git a/auth/service/proto/accounts.pb.micro.go b/auth/service/proto/accounts.pb.micro.go deleted file mode 100644 index 1370868d..00000000 --- a/auth/service/proto/accounts.pb.micro.go +++ /dev/null @@ -1,85 +0,0 @@ -// Code generated by protoc-gen-micro. DO NOT EDIT. -// source: auth/service/proto/accounts.proto - -package auth - -import ( - fmt "fmt" - proto "github.com/golang/protobuf/proto" - math "math" -) - -import ( - context "context" - client "github.com/micro/go-micro/v2/client" - server "github.com/micro/go-micro/v2/server" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ client.Option -var _ server.Option - -// Client API for Accounts service - -type AccountsService interface { - List(ctx context.Context, in *ListAccountsRequest, opts ...client.CallOption) (*ListAccountsResponse, error) -} - -type accountsService struct { - c client.Client - name string -} - -func NewAccountsService(name string, c client.Client) AccountsService { - return &accountsService{ - c: c, - name: name, - } -} - -func (c *accountsService) List(ctx context.Context, in *ListAccountsRequest, opts ...client.CallOption) (*ListAccountsResponse, error) { - req := c.c.NewRequest(c.name, "Accounts.List", in) - out := new(ListAccountsResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Accounts service - -type AccountsHandler interface { - List(context.Context, *ListAccountsRequest, *ListAccountsResponse) error -} - -func RegisterAccountsHandler(s server.Server, hdlr AccountsHandler, opts ...server.HandlerOption) error { - type accounts interface { - List(ctx context.Context, in *ListAccountsRequest, out *ListAccountsResponse) error - } - type Accounts struct { - accounts - } - h := &accountsHandler{hdlr} - return s.Handle(s.NewHandler(&Accounts{h}, opts...)) -} - -type accountsHandler struct { - AccountsHandler -} - -func (h *accountsHandler) List(ctx context.Context, in *ListAccountsRequest, out *ListAccountsResponse) error { - return h.AccountsHandler.List(ctx, in, out) -} diff --git a/auth/service/proto/accounts.proto b/auth/service/proto/accounts.proto deleted file mode 100644 index d31d7cbd..00000000 --- a/auth/service/proto/accounts.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; - -package go.micro.auth; - -option go_package = "auth;auth"; - -import "auth.proto"; - -service Accounts { - rpc List(ListAccountsRequest) returns (ListAccountsResponse) {}; -} - -message ListAccountsRequest { -} - -message ListAccountsResponse { - repeated Account accounts = 1; -} diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index fb56b3b4..0b941edc 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -1,15 +1,11 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: auth/service/proto/auth.proto +// source: github.com/micro/go-micro/auth/service/proto/auth.proto -package auth +package go_micro_auth import ( - context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" math "math" ) @@ -24,6 +20,104 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +type Access int32 + +const ( + Access_UNKNOWN Access = 0 + Access_GRANTED Access = 1 + Access_DENIED Access = 2 +) + +var Access_name = map[int32]string{ + 0: "UNKNOWN", + 1: "GRANTED", + 2: "DENIED", +} + +var Access_value = map[string]int32{ + "UNKNOWN": 0, + "GRANTED": 1, + "DENIED": 2, +} + +func (x Access) String() string { + return proto.EnumName(Access_name, int32(x)) +} + +func (Access) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_11312eec02fd5712, []int{0} +} + +type ListAccountsRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListAccountsRequest) Reset() { *m = ListAccountsRequest{} } +func (m *ListAccountsRequest) String() string { return proto.CompactTextString(m) } +func (*ListAccountsRequest) ProtoMessage() {} +func (*ListAccountsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_11312eec02fd5712, []int{0} +} + +func (m *ListAccountsRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListAccountsRequest.Unmarshal(m, b) +} +func (m *ListAccountsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListAccountsRequest.Marshal(b, m, deterministic) +} +func (m *ListAccountsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListAccountsRequest.Merge(m, src) +} +func (m *ListAccountsRequest) XXX_Size() int { + return xxx_messageInfo_ListAccountsRequest.Size(m) +} +func (m *ListAccountsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ListAccountsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ListAccountsRequest proto.InternalMessageInfo + +type ListAccountsResponse struct { + Accounts []*Account `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListAccountsResponse) Reset() { *m = ListAccountsResponse{} } +func (m *ListAccountsResponse) String() string { return proto.CompactTextString(m) } +func (*ListAccountsResponse) ProtoMessage() {} +func (*ListAccountsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_11312eec02fd5712, []int{1} +} + +func (m *ListAccountsResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListAccountsResponse.Unmarshal(m, b) +} +func (m *ListAccountsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListAccountsResponse.Marshal(b, m, deterministic) +} +func (m *ListAccountsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListAccountsResponse.Merge(m, src) +} +func (m *ListAccountsResponse) XXX_Size() int { + return xxx_messageInfo_ListAccountsResponse.Size(m) +} +func (m *ListAccountsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListAccountsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ListAccountsResponse proto.InternalMessageInfo + +func (m *ListAccountsResponse) GetAccounts() []*Account { + if m != nil { + return m.Accounts + } + return nil +} + type Token struct { Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` @@ -42,7 +136,7 @@ func (m *Token) Reset() { *m = Token{} } func (m *Token) String() string { return proto.CompactTextString(m) } func (*Token) ProtoMessage() {} func (*Token) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{0} + return fileDescriptor_11312eec02fd5712, []int{2} } func (m *Token) XXX_Unmarshal(b []byte) error { @@ -134,7 +228,7 @@ func (m *Account) Reset() { *m = Account{} } func (m *Account) String() string { return proto.CompactTextString(m) } func (*Account) ProtoMessage() {} func (*Account) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{1} + return fileDescriptor_11312eec02fd5712, []int{3} } func (m *Account) XXX_Unmarshal(b []byte) error { @@ -203,7 +297,7 @@ func (m *Resource) Reset() { *m = Resource{} } func (m *Resource) String() string { return proto.CompactTextString(m) } func (*Resource) ProtoMessage() {} func (*Resource) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{2} + return fileDescriptor_11312eec02fd5712, []int{4} } func (m *Resource) XXX_Unmarshal(b []byte) error { @@ -259,7 +353,7 @@ func (m *GenerateRequest) Reset() { *m = GenerateRequest{} } func (m *GenerateRequest) String() string { return proto.CompactTextString(m) } func (*GenerateRequest) ProtoMessage() {} func (*GenerateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{3} + return fileDescriptor_11312eec02fd5712, []int{5} } func (m *GenerateRequest) XXX_Unmarshal(b []byte) error { @@ -319,7 +413,7 @@ func (m *GenerateResponse) Reset() { *m = GenerateResponse{} } func (m *GenerateResponse) String() string { return proto.CompactTextString(m) } func (*GenerateResponse) ProtoMessage() {} func (*GenerateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{4} + return fileDescriptor_11312eec02fd5712, []int{6} } func (m *GenerateResponse) XXX_Unmarshal(b []byte) error { @@ -359,7 +453,7 @@ func (m *GrantRequest) Reset() { *m = GrantRequest{} } func (m *GrantRequest) String() string { return proto.CompactTextString(m) } func (*GrantRequest) ProtoMessage() {} func (*GrantRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{5} + return fileDescriptor_11312eec02fd5712, []int{7} } func (m *GrantRequest) XXX_Unmarshal(b []byte) error { @@ -404,7 +498,7 @@ func (m *GrantResponse) Reset() { *m = GrantResponse{} } func (m *GrantResponse) String() string { return proto.CompactTextString(m) } func (*GrantResponse) ProtoMessage() {} func (*GrantResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{6} + return fileDescriptor_11312eec02fd5712, []int{8} } func (m *GrantResponse) XXX_Unmarshal(b []byte) error { @@ -437,7 +531,7 @@ func (m *RevokeRequest) Reset() { *m = RevokeRequest{} } func (m *RevokeRequest) String() string { return proto.CompactTextString(m) } func (*RevokeRequest) ProtoMessage() {} func (*RevokeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{7} + return fileDescriptor_11312eec02fd5712, []int{9} } func (m *RevokeRequest) XXX_Unmarshal(b []byte) error { @@ -482,7 +576,7 @@ func (m *RevokeResponse) Reset() { *m = RevokeResponse{} } func (m *RevokeResponse) String() string { return proto.CompactTextString(m) } func (*RevokeResponse) ProtoMessage() {} func (*RevokeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{8} + return fileDescriptor_11312eec02fd5712, []int{10} } func (m *RevokeResponse) XXX_Unmarshal(b []byte) error { @@ -514,7 +608,7 @@ func (m *InspectRequest) Reset() { *m = InspectRequest{} } func (m *InspectRequest) String() string { return proto.CompactTextString(m) } func (*InspectRequest) ProtoMessage() {} func (*InspectRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{9} + return fileDescriptor_11312eec02fd5712, []int{11} } func (m *InspectRequest) XXX_Unmarshal(b []byte) error { @@ -553,7 +647,7 @@ func (m *InspectResponse) Reset() { *m = InspectResponse{} } func (m *InspectResponse) String() string { return proto.CompactTextString(m) } func (*InspectResponse) ProtoMessage() {} func (*InspectResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{10} + return fileDescriptor_11312eec02fd5712, []int{12} } func (m *InspectResponse) XXX_Unmarshal(b []byte) error { @@ -594,7 +688,7 @@ func (m *TokenRequest) Reset() { *m = TokenRequest{} } func (m *TokenRequest) String() string { return proto.CompactTextString(m) } func (*TokenRequest) ProtoMessage() {} func (*TokenRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{11} + return fileDescriptor_11312eec02fd5712, []int{13} } func (m *TokenRequest) XXX_Unmarshal(b []byte) error { @@ -647,7 +741,7 @@ func (m *TokenResponse) Reset() { *m = TokenResponse{} } func (m *TokenResponse) String() string { return proto.CompactTextString(m) } func (*TokenResponse) ProtoMessage() {} func (*TokenResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_21300bfacc51fc2a, []int{12} + return fileDescriptor_11312eec02fd5712, []int{14} } func (m *TokenResponse) XXX_Unmarshal(b []byte) error { @@ -675,7 +769,315 @@ func (m *TokenResponse) GetToken() *Token { return nil } +type Rule struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` + Resource *Resource `protobuf:"bytes,3,opt,name=resource,proto3" json:"resource,omitempty"` + Access Access `protobuf:"varint,4,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Rule) Reset() { *m = Rule{} } +func (m *Rule) String() string { return proto.CompactTextString(m) } +func (*Rule) ProtoMessage() {} +func (*Rule) Descriptor() ([]byte, []int) { + return fileDescriptor_11312eec02fd5712, []int{15} +} + +func (m *Rule) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Rule.Unmarshal(m, b) +} +func (m *Rule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Rule.Marshal(b, m, deterministic) +} +func (m *Rule) XXX_Merge(src proto.Message) { + xxx_messageInfo_Rule.Merge(m, src) +} +func (m *Rule) XXX_Size() int { + return xxx_messageInfo_Rule.Size(m) +} +func (m *Rule) XXX_DiscardUnknown() { + xxx_messageInfo_Rule.DiscardUnknown(m) +} + +var xxx_messageInfo_Rule proto.InternalMessageInfo + +func (m *Rule) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *Rule) GetRole() string { + if m != nil { + return m.Role + } + return "" +} + +func (m *Rule) GetResource() *Resource { + if m != nil { + return m.Resource + } + return nil +} + +func (m *Rule) GetAccess() Access { + if m != nil { + return m.Access + } + return Access_UNKNOWN +} + +type CreateRequest struct { + Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` + Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` + Access Access `protobuf:"varint,3,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateRequest) Reset() { *m = CreateRequest{} } +func (m *CreateRequest) String() string { return proto.CompactTextString(m) } +func (*CreateRequest) ProtoMessage() {} +func (*CreateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_11312eec02fd5712, []int{16} +} + +func (m *CreateRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateRequest.Unmarshal(m, b) +} +func (m *CreateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateRequest.Marshal(b, m, deterministic) +} +func (m *CreateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateRequest.Merge(m, src) +} +func (m *CreateRequest) XXX_Size() int { + return xxx_messageInfo_CreateRequest.Size(m) +} +func (m *CreateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CreateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateRequest proto.InternalMessageInfo + +func (m *CreateRequest) GetRole() string { + if m != nil { + return m.Role + } + return "" +} + +func (m *CreateRequest) GetResource() *Resource { + if m != nil { + return m.Resource + } + return nil +} + +func (m *CreateRequest) GetAccess() Access { + if m != nil { + return m.Access + } + return Access_UNKNOWN +} + +type CreateResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateResponse) Reset() { *m = CreateResponse{} } +func (m *CreateResponse) String() string { return proto.CompactTextString(m) } +func (*CreateResponse) ProtoMessage() {} +func (*CreateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_11312eec02fd5712, []int{17} +} + +func (m *CreateResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateResponse.Unmarshal(m, b) +} +func (m *CreateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateResponse.Marshal(b, m, deterministic) +} +func (m *CreateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateResponse.Merge(m, src) +} +func (m *CreateResponse) XXX_Size() int { + return xxx_messageInfo_CreateResponse.Size(m) +} +func (m *CreateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CreateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateResponse proto.InternalMessageInfo + +type DeleteRequest struct { + Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` + Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` + Access Access `protobuf:"varint,3,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } +func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } +func (*DeleteRequest) ProtoMessage() {} +func (*DeleteRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_11312eec02fd5712, []int{18} +} + +func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteRequest.Unmarshal(m, b) +} +func (m *DeleteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteRequest.Marshal(b, m, deterministic) +} +func (m *DeleteRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteRequest.Merge(m, src) +} +func (m *DeleteRequest) XXX_Size() int { + return xxx_messageInfo_DeleteRequest.Size(m) +} +func (m *DeleteRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteRequest proto.InternalMessageInfo + +func (m *DeleteRequest) GetRole() string { + if m != nil { + return m.Role + } + return "" +} + +func (m *DeleteRequest) GetResource() *Resource { + if m != nil { + return m.Resource + } + return nil +} + +func (m *DeleteRequest) GetAccess() Access { + if m != nil { + return m.Access + } + return Access_UNKNOWN +} + +type DeleteResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } +func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } +func (*DeleteResponse) ProtoMessage() {} +func (*DeleteResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_11312eec02fd5712, []int{19} +} + +func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteResponse.Unmarshal(m, b) +} +func (m *DeleteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteResponse.Marshal(b, m, deterministic) +} +func (m *DeleteResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteResponse.Merge(m, src) +} +func (m *DeleteResponse) XXX_Size() int { + return xxx_messageInfo_DeleteResponse.Size(m) +} +func (m *DeleteResponse) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo + +type ListRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListRequest) Reset() { *m = ListRequest{} } +func (m *ListRequest) String() string { return proto.CompactTextString(m) } +func (*ListRequest) ProtoMessage() {} +func (*ListRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_11312eec02fd5712, []int{20} +} + +func (m *ListRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListRequest.Unmarshal(m, b) +} +func (m *ListRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListRequest.Marshal(b, m, deterministic) +} +func (m *ListRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListRequest.Merge(m, src) +} +func (m *ListRequest) XXX_Size() int { + return xxx_messageInfo_ListRequest.Size(m) +} +func (m *ListRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ListRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ListRequest proto.InternalMessageInfo + +type ListResponse struct { + Rules []*Rule `protobuf:"bytes,1,rep,name=rules,proto3" json:"rules,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListResponse) Reset() { *m = ListResponse{} } +func (m *ListResponse) String() string { return proto.CompactTextString(m) } +func (*ListResponse) ProtoMessage() {} +func (*ListResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_11312eec02fd5712, []int{21} +} + +func (m *ListResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListResponse.Unmarshal(m, b) +} +func (m *ListResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListResponse.Marshal(b, m, deterministic) +} +func (m *ListResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListResponse.Merge(m, src) +} +func (m *ListResponse) XXX_Size() int { + return xxx_messageInfo_ListResponse.Size(m) +} +func (m *ListResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ListResponse proto.InternalMessageInfo + +func (m *ListResponse) GetRules() []*Rule { + if m != nil { + return m.Rules + } + return nil +} + func init() { + proto.RegisterEnum("go.micro.auth.Access", Access_name, Access_value) + proto.RegisterType((*ListAccountsRequest)(nil), "go.micro.auth.ListAccountsRequest") + proto.RegisterType((*ListAccountsResponse)(nil), "go.micro.auth.ListAccountsResponse") proto.RegisterType((*Token)(nil), "go.micro.auth.Token") proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.Token.MetadataEntry") proto.RegisterType((*Account)(nil), "go.micro.auth.Account") @@ -692,200 +1094,73 @@ func init() { proto.RegisterType((*InspectResponse)(nil), "go.micro.auth.InspectResponse") proto.RegisterType((*TokenRequest)(nil), "go.micro.auth.TokenRequest") proto.RegisterType((*TokenResponse)(nil), "go.micro.auth.TokenResponse") + proto.RegisterType((*Rule)(nil), "go.micro.auth.Rule") + proto.RegisterType((*CreateRequest)(nil), "go.micro.auth.CreateRequest") + proto.RegisterType((*CreateResponse)(nil), "go.micro.auth.CreateResponse") + proto.RegisterType((*DeleteRequest)(nil), "go.micro.auth.DeleteRequest") + proto.RegisterType((*DeleteResponse)(nil), "go.micro.auth.DeleteResponse") + proto.RegisterType((*ListRequest)(nil), "go.micro.auth.ListRequest") + proto.RegisterType((*ListResponse)(nil), "go.micro.auth.ListResponse") } -func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } - -var fileDescriptor_21300bfacc51fc2a = []byte{ - // 600 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x6d, 0x8b, 0xd3, 0x40, - 0x10, 0x36, 0x2f, 0x6d, 0xd3, 0x49, 0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0, 0xfc, 0x50, 0xa1, 0xbc, 0xb0, 0x3f, - 0xd5, 0x79, 0x7c, 0xc4, 0x7f, 0x2e, 0xab, 0xe2, 0xa3, 0x73, 0xfc, 0x27, 0x00, 0x00, 0xff, 0xff, - 0xc4, 0x24, 0xa4, 0xa3, 0x95, 0x06, 0x00, 0x00, +func init() { + proto.RegisterFile("github.com/micro/go-micro/auth/service/proto/auth.proto", fileDescriptor_11312eec02fd5712) } -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// AuthClient is the client API for Auth service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type AuthClient interface { - Generate(ctx context.Context, in *GenerateRequest, opts ...grpc.CallOption) (*GenerateResponse, error) - Inspect(ctx context.Context, in *InspectRequest, opts ...grpc.CallOption) (*InspectResponse, error) - Token(ctx context.Context, in *TokenRequest, opts ...grpc.CallOption) (*TokenResponse, error) -} - -type authClient struct { - cc *grpc.ClientConn -} - -func NewAuthClient(cc *grpc.ClientConn) AuthClient { - return &authClient{cc} -} - -func (c *authClient) Generate(ctx context.Context, in *GenerateRequest, opts ...grpc.CallOption) (*GenerateResponse, error) { - out := new(GenerateResponse) - err := c.cc.Invoke(ctx, "/go.micro.auth.Auth/Generate", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) Inspect(ctx context.Context, in *InspectRequest, opts ...grpc.CallOption) (*InspectResponse, error) { - out := new(InspectResponse) - err := c.cc.Invoke(ctx, "/go.micro.auth.Auth/Inspect", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) Token(ctx context.Context, in *TokenRequest, opts ...grpc.CallOption) (*TokenResponse, error) { - out := new(TokenResponse) - err := c.cc.Invoke(ctx, "/go.micro.auth.Auth/Token", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// AuthServer is the server API for Auth service. -type AuthServer interface { - Generate(context.Context, *GenerateRequest) (*GenerateResponse, error) - Inspect(context.Context, *InspectRequest) (*InspectResponse, error) - Token(context.Context, *TokenRequest) (*TokenResponse, error) -} - -// UnimplementedAuthServer can be embedded to have forward compatible implementations. -type UnimplementedAuthServer struct { -} - -func (*UnimplementedAuthServer) Generate(ctx context.Context, req *GenerateRequest) (*GenerateResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Generate not implemented") -} -func (*UnimplementedAuthServer) Inspect(ctx context.Context, req *InspectRequest) (*InspectResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Inspect not implemented") -} -func (*UnimplementedAuthServer) Token(ctx context.Context, req *TokenRequest) (*TokenResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Token not implemented") -} - -func RegisterAuthServer(s *grpc.Server, srv AuthServer) { - s.RegisterService(&_Auth_serviceDesc, srv) -} - -func _Auth_Generate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GenerateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).Generate(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.auth.Auth/Generate", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).Generate(ctx, req.(*GenerateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_Inspect_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(InspectRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).Inspect(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.auth.Auth/Inspect", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).Inspect(ctx, req.(*InspectRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_Token_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(TokenRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).Token(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.auth.Auth/Token", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).Token(ctx, req.(*TokenRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Auth_serviceDesc = grpc.ServiceDesc{ - ServiceName: "go.micro.auth.Auth", - HandlerType: (*AuthServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Generate", - Handler: _Auth_Generate_Handler, - }, - { - MethodName: "Inspect", - Handler: _Auth_Inspect_Handler, - }, - { - MethodName: "Token", - Handler: _Auth_Token_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "auth/service/proto/auth.proto", +var fileDescriptor_11312eec02fd5712 = []byte{ + // 860 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xdd, 0x8e, 0xdb, 0x44, + 0x14, 0x5e, 0xff, 0xc4, 0xf1, 0x9e, 0xfc, 0x6c, 0x34, 0xdd, 0x16, 0x2b, 0xfd, 0x21, 0x18, 0x84, + 0x96, 0x8a, 0x3a, 0x28, 0xbd, 0xe0, 0xa7, 0x12, 0x22, 0x6a, 0xa2, 0xd0, 0x42, 0x83, 0xb0, 0x8a, + 0x0a, 0x17, 0x08, 0x79, 0x9d, 0xa3, 0x5d, 0xb3, 0x89, 0x1d, 0x3c, 0xe3, 0x15, 0x79, 0x02, 0xee, + 0x78, 0x14, 0x9e, 0xa8, 0x97, 0x48, 0xbc, 0x06, 0x9a, 0xf1, 0x8c, 0x37, 0x71, 0x9c, 0x55, 0x84, + 0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 0x42, 0xf7, 0x04, 0xac, + 0xbc, 0x4e, 0xb6, 0x80, 0x36, 0xea, 0x78, 0x0b, 0xa8, 0x54, 0x5c, 0x47, 0x64, 0x28, 0xe5, 0x76, + 0x2b, 0xa4, 0x28, 0x90, 0xfb, 0x95, 0x6b, 0x0a, 0xe2, 0xdc, 0x12, 0x6f, 0xc9, 0xa7, 0xff, 0x06, + 0x00, 0x00, 0xff, 0xff, 0x24, 0x1b, 0xf8, 0x32, 0x86, 0x0a, 0x00, 0x00, } diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index 789e9e41..334f2369 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: auth/service/proto/auth.proto +// source: github.com/micro/go-micro/auth/service/proto/auth.proto -package auth +package go_micro_auth import ( fmt "fmt" @@ -117,3 +117,143 @@ func (h *authHandler) Inspect(ctx context.Context, in *InspectRequest, out *Insp func (h *authHandler) Token(ctx context.Context, in *TokenRequest, out *TokenResponse) error { return h.AuthHandler.Token(ctx, in, out) } + +// Client API for Accounts service + +type AccountsService interface { + List(ctx context.Context, in *ListAccountsRequest, opts ...client.CallOption) (*ListAccountsResponse, error) +} + +type accountsService struct { + c client.Client + name string +} + +func NewAccountsService(name string, c client.Client) AccountsService { + return &accountsService{ + c: c, + name: name, + } +} + +func (c *accountsService) List(ctx context.Context, in *ListAccountsRequest, opts ...client.CallOption) (*ListAccountsResponse, error) { + req := c.c.NewRequest(c.name, "Accounts.List", in) + out := new(ListAccountsResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Accounts service + +type AccountsHandler interface { + List(context.Context, *ListAccountsRequest, *ListAccountsResponse) error +} + +func RegisterAccountsHandler(s server.Server, hdlr AccountsHandler, opts ...server.HandlerOption) error { + type accounts interface { + List(ctx context.Context, in *ListAccountsRequest, out *ListAccountsResponse) error + } + type Accounts struct { + accounts + } + h := &accountsHandler{hdlr} + return s.Handle(s.NewHandler(&Accounts{h}, opts...)) +} + +type accountsHandler struct { + AccountsHandler +} + +func (h *accountsHandler) List(ctx context.Context, in *ListAccountsRequest, out *ListAccountsResponse) error { + return h.AccountsHandler.List(ctx, in, out) +} + +// Client API for Rules service + +type RulesService interface { + Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) + List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) +} + +type rulesService struct { + c client.Client + name string +} + +func NewRulesService(name string, c client.Client) RulesService { + return &rulesService{ + c: c, + name: name, + } +} + +func (c *rulesService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { + req := c.c.NewRequest(c.name, "Rules.Create", in) + out := new(CreateResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *rulesService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { + req := c.c.NewRequest(c.name, "Rules.Delete", in) + out := new(DeleteResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *rulesService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { + req := c.c.NewRequest(c.name, "Rules.List", in) + out := new(ListResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Rules service + +type RulesHandler interface { + Create(context.Context, *CreateRequest, *CreateResponse) error + Delete(context.Context, *DeleteRequest, *DeleteResponse) error + List(context.Context, *ListRequest, *ListResponse) error +} + +func RegisterRulesHandler(s server.Server, hdlr RulesHandler, opts ...server.HandlerOption) error { + type rules interface { + Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error + Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error + List(ctx context.Context, in *ListRequest, out *ListResponse) error + } + type Rules struct { + rules + } + h := &rulesHandler{hdlr} + return s.Handle(s.NewHandler(&Rules{h}, opts...)) +} + +type rulesHandler struct { + RulesHandler +} + +func (h *rulesHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { + return h.RulesHandler.Create(ctx, in, out) +} + +func (h *rulesHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { + return h.RulesHandler.Delete(ctx, in, out) +} + +func (h *rulesHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { + return h.RulesHandler.List(ctx, in, out) +} diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index 60209252..ba53076b 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -2,14 +2,29 @@ syntax = "proto3"; package go.micro.auth; -option go_package = "auth;auth"; - service Auth { rpc Generate(GenerateRequest) returns (GenerateResponse) {}; rpc Inspect(InspectRequest) returns (InspectResponse) {}; rpc Token(TokenRequest) returns (TokenResponse) {}; } +service Accounts { + rpc List(ListAccountsRequest) returns (ListAccountsResponse) {}; +} + +service Rules { + rpc Create(CreateRequest) returns (CreateResponse) {}; + rpc Delete(DeleteRequest) returns (DeleteResponse) {}; + rpc List(ListRequest) returns (ListResponse) {}; +} + +message ListAccountsRequest { +} + +message ListAccountsResponse { + repeated Account accounts = 1; +} + message Token { string token = 1; string type = 2; @@ -77,3 +92,39 @@ message TokenRequest { message TokenResponse { Token token = 1; } + +enum Access { + UNKNOWN = 0; + GRANTED = 1; + DENIED = 2; +} + +message Rule { + string id = 1; + string role = 2; + Resource resource = 3; + Access access = 4; +} + +message CreateRequest { + string role = 1; + Resource resource = 2; + Access access = 3; +} + +message CreateResponse {} + +message DeleteRequest { + string role = 1; + Resource resource = 2; + Access access = 3; +} + +message DeleteResponse {} + +message ListRequest { +} + +message ListResponse { + repeated Rule rules = 1; +} diff --git a/auth/service/proto/rules.pb.go b/auth/service/proto/rules.pb.go deleted file mode 100644 index 41919db0..00000000 --- a/auth/service/proto/rules.pb.go +++ /dev/null @@ -1,550 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: auth/service/proto/rules.proto - -package auth - -import ( - context "context" - fmt "fmt" - proto "github.com/golang/protobuf/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - math "math" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -type Access int32 - -const ( - Access_UNKNOWN Access = 0 - Access_GRANTED Access = 1 - Access_DENIED Access = 2 -) - -var Access_name = map[int32]string{ - 0: "UNKNOWN", - 1: "GRANTED", - 2: "DENIED", -} - -var Access_value = map[string]int32{ - "UNKNOWN": 0, - "GRANTED": 1, - "DENIED": 2, -} - -func (x Access) String() string { - return proto.EnumName(Access_name, int32(x)) -} - -func (Access) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_ce1ef0aa40cdd6dc, []int{0} -} - -type Rule struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` - Resource *Resource `protobuf:"bytes,3,opt,name=resource,proto3" json:"resource,omitempty"` - Access Access `protobuf:"varint,4,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Rule) Reset() { *m = Rule{} } -func (m *Rule) String() string { return proto.CompactTextString(m) } -func (*Rule) ProtoMessage() {} -func (*Rule) Descriptor() ([]byte, []int) { - return fileDescriptor_ce1ef0aa40cdd6dc, []int{0} -} - -func (m *Rule) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Rule.Unmarshal(m, b) -} -func (m *Rule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Rule.Marshal(b, m, deterministic) -} -func (m *Rule) XXX_Merge(src proto.Message) { - xxx_messageInfo_Rule.Merge(m, src) -} -func (m *Rule) XXX_Size() int { - return xxx_messageInfo_Rule.Size(m) -} -func (m *Rule) XXX_DiscardUnknown() { - xxx_messageInfo_Rule.DiscardUnknown(m) -} - -var xxx_messageInfo_Rule proto.InternalMessageInfo - -func (m *Rule) GetId() string { - if m != nil { - return m.Id - } - return "" -} - -func (m *Rule) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -func (m *Rule) GetResource() *Resource { - if m != nil { - return m.Resource - } - return nil -} - -func (m *Rule) GetAccess() Access { - if m != nil { - return m.Access - } - return Access_UNKNOWN -} - -type CreateRequest struct { - Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` - Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` - Access Access `protobuf:"varint,3,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *CreateRequest) Reset() { *m = CreateRequest{} } -func (m *CreateRequest) String() string { return proto.CompactTextString(m) } -func (*CreateRequest) ProtoMessage() {} -func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ce1ef0aa40cdd6dc, []int{1} -} - -func (m *CreateRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_CreateRequest.Unmarshal(m, b) -} -func (m *CreateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_CreateRequest.Marshal(b, m, deterministic) -} -func (m *CreateRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_CreateRequest.Merge(m, src) -} -func (m *CreateRequest) XXX_Size() int { - return xxx_messageInfo_CreateRequest.Size(m) -} -func (m *CreateRequest) XXX_DiscardUnknown() { - xxx_messageInfo_CreateRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_CreateRequest proto.InternalMessageInfo - -func (m *CreateRequest) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -func (m *CreateRequest) GetResource() *Resource { - if m != nil { - return m.Resource - } - return nil -} - -func (m *CreateRequest) GetAccess() Access { - if m != nil { - return m.Access - } - return Access_UNKNOWN -} - -type CreateResponse struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *CreateResponse) Reset() { *m = CreateResponse{} } -func (m *CreateResponse) String() string { return proto.CompactTextString(m) } -func (*CreateResponse) ProtoMessage() {} -func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ce1ef0aa40cdd6dc, []int{2} -} - -func (m *CreateResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_CreateResponse.Unmarshal(m, b) -} -func (m *CreateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_CreateResponse.Marshal(b, m, deterministic) -} -func (m *CreateResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_CreateResponse.Merge(m, src) -} -func (m *CreateResponse) XXX_Size() int { - return xxx_messageInfo_CreateResponse.Size(m) -} -func (m *CreateResponse) XXX_DiscardUnknown() { - xxx_messageInfo_CreateResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_CreateResponse proto.InternalMessageInfo - -type DeleteRequest struct { - Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` - Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` - Access Access `protobuf:"varint,3,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } -func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } -func (*DeleteRequest) ProtoMessage() {} -func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ce1ef0aa40cdd6dc, []int{3} -} - -func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_DeleteRequest.Unmarshal(m, b) -} -func (m *DeleteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_DeleteRequest.Marshal(b, m, deterministic) -} -func (m *DeleteRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_DeleteRequest.Merge(m, src) -} -func (m *DeleteRequest) XXX_Size() int { - return xxx_messageInfo_DeleteRequest.Size(m) -} -func (m *DeleteRequest) XXX_DiscardUnknown() { - xxx_messageInfo_DeleteRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_DeleteRequest proto.InternalMessageInfo - -func (m *DeleteRequest) GetRole() string { - if m != nil { - return m.Role - } - return "" -} - -func (m *DeleteRequest) GetResource() *Resource { - if m != nil { - return m.Resource - } - return nil -} - -func (m *DeleteRequest) GetAccess() Access { - if m != nil { - return m.Access - } - return Access_UNKNOWN -} - -type DeleteResponse struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } -func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } -func (*DeleteResponse) ProtoMessage() {} -func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ce1ef0aa40cdd6dc, []int{4} -} - -func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_DeleteResponse.Unmarshal(m, b) -} -func (m *DeleteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_DeleteResponse.Marshal(b, m, deterministic) -} -func (m *DeleteResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_DeleteResponse.Merge(m, src) -} -func (m *DeleteResponse) XXX_Size() int { - return xxx_messageInfo_DeleteResponse.Size(m) -} -func (m *DeleteResponse) XXX_DiscardUnknown() { - xxx_messageInfo_DeleteResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo - -type ListRequest struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ListRequest) Reset() { *m = ListRequest{} } -func (m *ListRequest) String() string { return proto.CompactTextString(m) } -func (*ListRequest) ProtoMessage() {} -func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ce1ef0aa40cdd6dc, []int{5} -} - -func (m *ListRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ListRequest.Unmarshal(m, b) -} -func (m *ListRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ListRequest.Marshal(b, m, deterministic) -} -func (m *ListRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ListRequest.Merge(m, src) -} -func (m *ListRequest) XXX_Size() int { - return xxx_messageInfo_ListRequest.Size(m) -} -func (m *ListRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ListRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_ListRequest proto.InternalMessageInfo - -type ListResponse struct { - Rules []*Rule `protobuf:"bytes,1,rep,name=rules,proto3" json:"rules,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ListResponse) Reset() { *m = ListResponse{} } -func (m *ListResponse) String() string { return proto.CompactTextString(m) } -func (*ListResponse) ProtoMessage() {} -func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ce1ef0aa40cdd6dc, []int{6} -} - -func (m *ListResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ListResponse.Unmarshal(m, b) -} -func (m *ListResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ListResponse.Marshal(b, m, deterministic) -} -func (m *ListResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_ListResponse.Merge(m, src) -} -func (m *ListResponse) XXX_Size() int { - return xxx_messageInfo_ListResponse.Size(m) -} -func (m *ListResponse) XXX_DiscardUnknown() { - xxx_messageInfo_ListResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_ListResponse proto.InternalMessageInfo - -func (m *ListResponse) GetRules() []*Rule { - if m != nil { - return m.Rules - } - return nil -} - -func init() { - proto.RegisterEnum("go.micro.auth.Access", Access_name, Access_value) - proto.RegisterType((*Rule)(nil), "go.micro.auth.Rule") - proto.RegisterType((*CreateRequest)(nil), "go.micro.auth.CreateRequest") - proto.RegisterType((*CreateResponse)(nil), "go.micro.auth.CreateResponse") - proto.RegisterType((*DeleteRequest)(nil), "go.micro.auth.DeleteRequest") - proto.RegisterType((*DeleteResponse)(nil), "go.micro.auth.DeleteResponse") - proto.RegisterType((*ListRequest)(nil), "go.micro.auth.ListRequest") - proto.RegisterType((*ListResponse)(nil), "go.micro.auth.ListResponse") -} - -func init() { proto.RegisterFile("auth/service/proto/rules.proto", fileDescriptor_ce1ef0aa40cdd6dc) } - -var fileDescriptor_ce1ef0aa40cdd6dc = []byte{ - // 368 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x93, 0x5f, 0x4b, 0xf3, 0x30, - 0x18, 0xc5, 0x97, 0xae, 0xeb, 0xfb, 0xee, 0xa9, 0x1b, 0x25, 0x22, 0x96, 0xfa, 0x87, 0xb2, 0xab, - 0x2a, 0xd8, 0x41, 0x77, 0x25, 0x5e, 0x4d, 0x3b, 0x86, 0x28, 0x15, 0x82, 0x22, 0x78, 0x37, 0xbb, - 0x07, 0x2d, 0x54, 0x3b, 0x93, 0xd6, 0xaf, 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a, 0xa6, 0x07, - 0xd0, 0x2a, 0xbf, 0x08, 0x9b, 0xb8, 0x4d, 0xcf, 0x0c, 0x36, 0xeb, 0x44, 0x45, 0x8a, 0x4c, 0x39, - 0x0e, 0x7d, 0x30, 0xd4, 0xd3, 0xa8, 0x09, 0xff, 0x6e, 0xa2, 0x8b, 0xe8, 0xea, 0x36, 0xb2, 0x1a, - 0x72, 0x31, 0x66, 0xc3, 0xe8, 0x7a, 0x14, 0x5a, 0x84, 0x02, 0x18, 0xe1, 0x28, 0x3a, 0x1f, 0x85, - 0x96, 0x16, 0x7c, 0x10, 0x68, 0xc9, 0xf3, 0x82, 0x8e, 0xc1, 0x50, 0x8d, 0xd1, 0xdd, 0x5a, 0xfe, - 0xd2, 0x1b, 0x75, 0xf6, 0xd6, 0xa8, 0xd5, 0x55, 0x1a, 0x32, 0x48, 0x5d, 0x6f, 0x25, 0x68, 0xa9, - 0xfe, 0x95, 0xa0, 0x5a, 0x27, 0x0d, 0x3a, 0x04, 0x5d, 0xd6, 0x40, 0x9d, 0x9a, 0xf1, 0x4b, 0x55, - 0xce, 0xce, 0xb7, 0xda, 0x3c, 0xe2, 0xd4, 0xbc, 0x6b, 0xcb, 0xed, 0x13, 0x39, 0xdc, 0x1b, 0xe5, - 0x5f, 0x33, 0xf8, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x63, 0x57, 0x37, 0xef, 0x72, 0x03, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// RulesClient is the client API for Rules service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type RulesClient interface { - Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) - Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) - List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) -} - -type rulesClient struct { - cc *grpc.ClientConn -} - -func NewRulesClient(cc *grpc.ClientConn) RulesClient { - return &rulesClient{cc} -} - -func (c *rulesClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { - out := new(CreateResponse) - err := c.cc.Invoke(ctx, "/go.micro.auth.Rules/Create", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *rulesClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { - out := new(DeleteResponse) - err := c.cc.Invoke(ctx, "/go.micro.auth.Rules/Delete", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *rulesClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) { - out := new(ListResponse) - err := c.cc.Invoke(ctx, "/go.micro.auth.Rules/List", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// RulesServer is the server API for Rules service. -type RulesServer interface { - Create(context.Context, *CreateRequest) (*CreateResponse, error) - Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) - List(context.Context, *ListRequest) (*ListResponse, error) -} - -// UnimplementedRulesServer can be embedded to have forward compatible implementations. -type UnimplementedRulesServer struct { -} - -func (*UnimplementedRulesServer) Create(ctx context.Context, req *CreateRequest) (*CreateResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") -} -func (*UnimplementedRulesServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") -} -func (*UnimplementedRulesServer) List(ctx context.Context, req *ListRequest) (*ListResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method List not implemented") -} - -func RegisterRulesServer(s *grpc.Server, srv RulesServer) { - s.RegisterService(&_Rules_serviceDesc, srv) -} - -func _Rules_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CreateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RulesServer).Create(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.auth.Rules/Create", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RulesServer).Create(ctx, req.(*CreateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Rules_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DeleteRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RulesServer).Delete(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.auth.Rules/Delete", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RulesServer).Delete(ctx, req.(*DeleteRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Rules_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ListRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RulesServer).List(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.auth.Rules/List", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RulesServer).List(ctx, req.(*ListRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Rules_serviceDesc = grpc.ServiceDesc{ - ServiceName: "go.micro.auth.Rules", - HandlerType: (*RulesServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Create", - Handler: _Rules_Create_Handler, - }, - { - MethodName: "Delete", - Handler: _Rules_Delete_Handler, - }, - { - MethodName: "List", - Handler: _Rules_List_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "auth/service/proto/rules.proto", -} diff --git a/auth/service/proto/rules.pb.micro.go b/auth/service/proto/rules.pb.micro.go deleted file mode 100644 index bcba2c50..00000000 --- a/auth/service/proto/rules.pb.micro.go +++ /dev/null @@ -1,119 +0,0 @@ -// Code generated by protoc-gen-micro. DO NOT EDIT. -// source: auth/service/proto/rules.proto - -package auth - -import ( - fmt "fmt" - proto "github.com/golang/protobuf/proto" - math "math" -) - -import ( - context "context" - client "github.com/micro/go-micro/v2/client" - server "github.com/micro/go-micro/v2/server" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ client.Option -var _ server.Option - -// Client API for Rules service - -type RulesService interface { - Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) - Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) - List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) -} - -type rulesService struct { - c client.Client - name string -} - -func NewRulesService(name string, c client.Client) RulesService { - return &rulesService{ - c: c, - name: name, - } -} - -func (c *rulesService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) { - req := c.c.NewRequest(c.name, "Rules.Create", in) - out := new(CreateResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *rulesService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { - req := c.c.NewRequest(c.name, "Rules.Delete", in) - out := new(DeleteResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *rulesService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { - req := c.c.NewRequest(c.name, "Rules.List", in) - out := new(ListResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Rules service - -type RulesHandler interface { - Create(context.Context, *CreateRequest, *CreateResponse) error - Delete(context.Context, *DeleteRequest, *DeleteResponse) error - List(context.Context, *ListRequest, *ListResponse) error -} - -func RegisterRulesHandler(s server.Server, hdlr RulesHandler, opts ...server.HandlerOption) error { - type rules interface { - Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error - Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error - List(ctx context.Context, in *ListRequest, out *ListResponse) error - } - type Rules struct { - rules - } - h := &rulesHandler{hdlr} - return s.Handle(s.NewHandler(&Rules{h}, opts...)) -} - -type rulesHandler struct { - RulesHandler -} - -func (h *rulesHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error { - return h.RulesHandler.Create(ctx, in, out) -} - -func (h *rulesHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { - return h.RulesHandler.Delete(ctx, in, out) -} - -func (h *rulesHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { - return h.RulesHandler.List(ctx, in, out) -} diff --git a/auth/service/proto/rules.proto b/auth/service/proto/rules.proto deleted file mode 100644 index 2acaff64..00000000 --- a/auth/service/proto/rules.proto +++ /dev/null @@ -1,49 +0,0 @@ -syntax = "proto3"; - -package go.micro.auth; - -option go_package = "auth;auth"; - -import "auth.proto"; - -service Rules { - rpc Create(CreateRequest) returns (CreateResponse) {}; - rpc Delete(DeleteRequest) returns (DeleteResponse) {}; - rpc List(ListRequest) returns (ListResponse) {}; -} - -enum Access { - UNKNOWN = 0; - GRANTED = 1; - DENIED = 2; -} - -message Rule { - string id = 1; - string role = 2; - Resource resource = 3; - Access access = 4; -} - -message CreateRequest { - string role = 1; - Resource resource = 2; - Access access = 3; -} - -message CreateResponse {} - -message DeleteRequest { - string role = 1; - Resource resource = 2; - Access access = 3; -} - -message DeleteResponse {} - -message ListRequest { -} - -message ListResponse { - repeated Rule rules = 1; -} From 3d274ab6a2fcd1137e3a2d568547929972bed877 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 31 Mar 2020 12:03:32 +0100 Subject: [PATCH 461/788] Add namespace support to Kubernetes client (#1446) * Add namespace support to Kubernetes client * Fix LastUpdateTime Condition --- runtime/kubernetes/kubernetes.go | 2 +- util/kubernetes/client/templates.go | 14 ++++++++++++++ util/kubernetes/client/types.go | 13 +++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index f8568dc1..b0e68882 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -129,7 +129,7 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { // parse out deployment status and inject into service metadata if len(kdep.Status.Conditions) > 0 { svc.Metadata["status"] = kdep.Status.Conditions[0].Type - svc.Metadata["started"] = kdep.Status.Conditions[0].LastUpdate + svc.Metadata["started"] = kdep.Status.Conditions[0].LastUpdateTime delete(svc.Metadata, "error") } else { svc.Metadata["status"] = "n/a" diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index 84852cc0..feddfffc 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -3,6 +3,7 @@ package client var templates = map[string]string{ "deployment": deploymentTmpl, "service": serviceTmpl, + "namespace": namespaceTmpl, } // stripped image pull policy always @@ -108,3 +109,16 @@ spec: {{- end }} {{- end }} ` + +var namespaceTmpl = ` +apiVersion: v1 +kind: Namespace +metadata: + name: "{{ .Metadata.Name }}" + labels: + {{- with .Metadata.Labels }} + {{- range $key, $value := . }} + {{ $key }}: "{{ $value }}" + {{- end }} + {{- end }} +` diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index 0c6ecc29..c19fff1c 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -39,10 +39,10 @@ type DeploymentSpec struct { // DeploymentCondition describes the state of deployment type DeploymentCondition struct { - LastUpdate string `json:lastUpdateTime` - Type string `json:"type"` - reason string `json:"reason,omitempty"` - message string `json:"message,omitempty"` + LastUpdateTime string `json:"lastUpdateTime"` + Type string `json:"type"` + Reason string `json:"reason,omitempty"` + Message string `json:"message,omitempty"` } // DeploymentStatus is returned when querying deployment @@ -178,3 +178,8 @@ type Template struct { Metadata *Metadata `json:"metadata,omitempty"` PodSpec *PodSpec `json:"spec,omitempty"` } + +// Namespace is a Kubernetes Namespace +type Namespace struct { + Metadata *Metadata `json:"metadata,omitempty"` +} From d659e435c6604c264043c12b16ad631330293996 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 31 Mar 2020 12:44:34 +0100 Subject: [PATCH 462/788] Service => Service Auth --- auth/options.go | 15 ++++++++---- auth/service/service.go | 52 +++++++++++++++++++++++++++++++++++++++-- client/grpc/grpc.go | 10 +++++++- client/options.go | 20 ++++++++++++++++ config/cmd/cmd.go | 18 ++++++++++---- options.go | 1 + service.go | 7 +++--- util/wrapper/wrapper.go | 9 ------- 8 files changed, 106 insertions(+), 26 deletions(-) diff --git a/auth/options.go b/auth/options.go index 274935b3..90bbc1df 100644 --- a/auth/options.go +++ b/auth/options.go @@ -8,8 +8,12 @@ import ( ) type Options struct { - // Token is an auth token - Token string + // ID is the services auth ID + ID string + // Secret is used to generate new tokens + Secret string + // Token is the services token used to authenticate itself + Token *Token // Public key base64 encoded PublicKey string // Private key base64 encoded @@ -45,10 +49,11 @@ func PrivateKey(key string) Option { } } -// ServiceToken sets an auth token -func ServiceToken(t string) Option { +// Credentials sets the auth credentials +func Credentials(id, secret string) Option { return func(o *Options) { - o.Token = t + o.ID = id + o.Secret = secret } } diff --git a/auth/service/service.go b/auth/service/service.go index 2aade9fc..0cc11d98 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -55,13 +55,13 @@ func (s *svc) Init(opts ...auth.Option) { } // load rules periodically from the auth service - timer := time.NewTicker(time.Second * 30) + ruleTimer := time.NewTicker(time.Second * 30) go func() { // load rules immediately on startup s.loadRules() for { - <-timer.C + <-ruleTimer.C // jitter for up to 5 seconds, this stops // all the services calling the auth service @@ -70,9 +70,39 @@ func (s *svc) Init(opts ...auth.Option) { s.loadRules() } }() + + // we have client credentials and must load a new token + // periodically + if len(s.options.ID) > 0 || len(s.options.Secret) > 0 { + tokenTimer := time.NewTicker(time.Minute) + + go func() { + s.loadToken() + + for { + <-tokenTimer.C + + // Do not get a new token if the current one has more than three + // minutes remaining. We do 3 minutes to allow multiple retires in + // the case one request fails + t := s.Options().Token + if t != nil && t.Expiry.Unix() > time.Now().Add(time.Minute*3).Unix() { + continue + } + + // jitter for up to 5 seconds, this stops + // all the services calling the auth service + // at the exact same time + time.Sleep(jitter.Do(time.Second * 5)) + s.loadToken() + } + }() + } } func (s *svc) Options() auth.Options { + s.Lock() + defer s.Unlock() return s.options } @@ -256,6 +286,24 @@ func (s *svc) loadRules() { s.rules = rsp.Rules } +// loadToken generates a new token for the service to use when making calls +func (s *svc) loadToken() { + rsp, err := s.auth.Token(context.TODO(), &pb.TokenRequest{ + Id: s.Options().ID, + Secret: s.Options().Secret, + TokenExpiry: int64((time.Minute * 15).Seconds()), + }) + s.Lock() + defer s.Unlock() + + if err != nil { + log.Errorf("Error generating token: %v", err) + return + } + + s.options.Token = serializeToken(rsp.Token) +} + func serializeToken(t *pb.Token) *auth.Token { return &auth.Token{ Token: t.Token, diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 0357abc3..acc1e649 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -131,7 +131,15 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R // set the content type for the request header["x-content-type"] = req.ContentType() - // set the authorization token if one is saved locally + // if the caller specifies using service privelages, and the client + // has auth set, override the authorization header + if opts.WithServicePrivileges && g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { + t := g.opts.Auth.Options().Token + header["authorization"] = auth.BearerScheme + t.Token + } + + // fall back to using the authorization token set in config, + // this enables the CLI to provide a token if len(header["authorization"]) == 0 { if token, err := config.Get("token"); err == nil && len(token) > 0 { header["authorization"] = auth.BearerScheme + token diff --git a/client/options.go b/client/options.go index 2d201510..1366ad56 100644 --- a/client/options.go +++ b/client/options.go @@ -4,6 +4,7 @@ import ( "context" "time" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client/selector" "github.com/micro/go-micro/v2/codec" @@ -16,6 +17,7 @@ type Options struct { ContentType string // Plugged interfaces + Auth auth.Auth Broker broker.Broker Codecs map[string]codec.NewCodec Registry registry.Registry @@ -55,6 +57,8 @@ type CallOptions struct { Retries int // Request/Response timeout RequestTimeout time.Duration + // Use the services own auth token + WithServicePrivileges bool // Middleware for low level call func CallWrappers []CallWrapper @@ -99,6 +103,7 @@ func NewOptions(options ...Option) Options { }, PoolSize: DefaultPoolSize, PoolTTL: DefaultPoolTTL, + Auth: auth.DefaultAuth, Broker: broker.DefaultBroker, Selector: selector.DefaultSelector, Registry: registry.DefaultRegistry, @@ -119,6 +124,13 @@ func Broker(b broker.Broker) Option { } } +// Auth to be used when making a request +func Auth(a auth.Auth) Option { + return func(o *Options) { + o.Auth = a + } +} + // Codec to be used to encode/decode requests for a given content type func Codec(contentType string, c codec.NewCodec) Option { return func(o *Options) { @@ -291,6 +303,14 @@ func WithDialTimeout(d time.Duration) CallOption { } } +// WithServicePrivileges is a CallOption which overrides the +// authorization header with the services own auth token +func WithServicePrivileges() CallOption { + return func(o *CallOptions) { + o.WithServicePrivileges = true + } +} + func WithMessageContentType(ct string) MessageOption { return func(o *MessageOptions) { o.ContentType = ct diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 287c085e..0af37fdd 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -255,9 +255,14 @@ var ( Usage: "Auth for role based access control, e.g. service", }, &cli.StringFlag{ - Name: "auth_token", - EnvVars: []string{"MICRO_AUTH_TOKEN"}, - Usage: "Auth token used for client authentication", + Name: "auth_id", + EnvVars: []string{"MICRO_AUTH_ID"}, + Usage: "Account ID used for client authentication", + }, + &cli.StringFlag{ + Name: "auth_secret", + EnvVars: []string{"MICRO_AUTH_SECRET"}, + Usage: "Account secret used for client authentication", }, &cli.StringFlag{ Name: "auth_public_key", @@ -488,6 +493,7 @@ func (c *cmd) Before(ctx *cli.Context) error { } *c.opts.Auth = a() + clientOpts = append(clientOpts, client.Auth(*c.opts.Auth)) } // Set the profile @@ -655,8 +661,10 @@ func (c *cmd) Before(ctx *cli.Context) error { } } - if len(ctx.String("auth_token")) > 0 { - authOpts = append(authOpts, auth.ServiceToken(ctx.String("auth_token"))) + if len(ctx.String("auth_id")) > 0 || len(ctx.String("auth_secret")) > 0 { + authOpts = append(authOpts, auth.Credentials( + ctx.String("auth_id"), ctx.String("auth_secret"), + )) } if len(ctx.String("auth_public_key")) > 0 { diff --git a/options.go b/options.go index 36e290a3..1ef8b955 100644 --- a/options.go +++ b/options.go @@ -142,6 +142,7 @@ func Tracer(t trace.Tracer) Option { func Auth(a auth.Auth) Option { return func(o *Options) { o.Auth = a + o.Client.Init(client.Auth(a)) o.Server.Init(server.Auth(a)) } } diff --git a/service.go b/service.go index a693aa34..a13b4e19 100644 --- a/service.go +++ b/service.go @@ -18,7 +18,6 @@ import ( "github.com/micro/go-micro/v2/plugin" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/store" - "github.com/micro/go-micro/v2/util/config" "github.com/micro/go-micro/v2/util/wrapper" ) @@ -117,9 +116,9 @@ func (s *service) Init(opts ...Option) { // Right now we're just going to load a token // May need to re-read value on change // TODO: should be scoped to micro/auth/token - if tk, _ := config.Get("token"); len(tk) > 0 { - s.opts.Auth.Init(auth.ServiceToken(tk)) - } + // if tk, _ := config.Get("token"); len(tk) > 0 { + // s.opts.Auth.Init(auth.ServiceToken(tk)) + // } }) } diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index d28155c1..f795e705 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -38,15 +38,6 @@ func (c *clientWrapper) setHeaders(ctx context.Context) context.Context { mda, _ := metadata.FromContext(ctx) md := metadata.Copy(mda) - // get auth token - if a := c.auth(); a != nil { - tk := a.Options().Token - // if the token if exists and auth header isn't set then set it - if len(tk) > 0 && len(md["Authorization"]) == 0 { - md["Authorization"] = auth.BearerScheme + tk - } - } - // set headers for k, v := range c.headers { if _, ok := md[k]; !ok { From e0c7f48d20eb99718c4a5b491e4ed69f164a8c1f Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 31 Mar 2020 12:57:38 +0100 Subject: [PATCH 463/788] WithServicePrivileges => ServicePrivileges --- client/grpc/grpc.go | 2 +- client/options.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index acc1e649..340f2df7 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -133,7 +133,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R // if the caller specifies using service privelages, and the client // has auth set, override the authorization header - if opts.WithServicePrivileges && g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { + if opts.ServicePrivileges && g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { t := g.opts.Auth.Options().Token header["authorization"] = auth.BearerScheme + t.Token } diff --git a/client/options.go b/client/options.go index 1366ad56..72d9d2bd 100644 --- a/client/options.go +++ b/client/options.go @@ -58,7 +58,7 @@ type CallOptions struct { // Request/Response timeout RequestTimeout time.Duration // Use the services own auth token - WithServicePrivileges bool + ServicePrivileges bool // Middleware for low level call func CallWrappers []CallWrapper @@ -307,7 +307,7 @@ func WithDialTimeout(d time.Duration) CallOption { // authorization header with the services own auth token func WithServicePrivileges() CallOption { return func(o *CallOptions) { - o.WithServicePrivileges = true + o.ServicePrivileges = true } } From 956029ae3dc70481582ed890e64dfb45a2f51dd0 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 31 Mar 2020 13:30:14 +0100 Subject: [PATCH 464/788] Fixes for CLI login --- client/grpc/grpc.go | 2 +- util/config/config.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 340f2df7..54c4599d 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -141,7 +141,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R // fall back to using the authorization token set in config, // this enables the CLI to provide a token if len(header["authorization"]) == 0 { - if token, err := config.Get("token"); err == nil && len(token) > 0 { + if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 { header["authorization"] = auth.BearerScheme + token } } diff --git a/util/config/config.go b/util/config/config.go index e0e85e37..a15eade7 100644 --- a/util/config/config.go +++ b/util/config/config.go @@ -21,13 +21,13 @@ const FileName = ".micro" var config = newConfig() // Get a value from the .micro file -func Get(key string) (string, error) { - tk := config.Get(key).String("") +func Get(path ...string) (string, error) { + tk := config.Get(path...).String("") return strings.TrimSpace(tk), nil } // Set a value in the .micro file -func Set(key, value string) error { +func Set(value string, path ...string) error { // get the filepath fp, err := filePath() if err != nil { @@ -35,7 +35,7 @@ func Set(key, value string) error { } // set the value - config.Set(value, key) + config.Set(value, path...) // write to the file return ioutil.WriteFile(fp, config.Bytes(), 0644) From bd70820b6bd035b3d7802e6add6ef30ffa31a67e Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 31 Mar 2020 13:48:28 +0100 Subject: [PATCH 465/788] ServicePrivileges => ServiceToken --- client/grpc/grpc.go | 2 +- client/options.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 54c4599d..8cd55dd8 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -133,7 +133,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R // if the caller specifies using service privelages, and the client // has auth set, override the authorization header - if opts.ServicePrivileges && g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { + if opts.ServiceToken && g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { t := g.opts.Auth.Options().Token header["authorization"] = auth.BearerScheme + t.Token } diff --git a/client/options.go b/client/options.go index 72d9d2bd..378957ed 100644 --- a/client/options.go +++ b/client/options.go @@ -58,7 +58,7 @@ type CallOptions struct { // Request/Response timeout RequestTimeout time.Duration // Use the services own auth token - ServicePrivileges bool + ServiceToken bool // Middleware for low level call func CallWrappers []CallWrapper @@ -303,11 +303,11 @@ func WithDialTimeout(d time.Duration) CallOption { } } -// WithServicePrivileges is a CallOption which overrides the +// WithServiceToken is a CallOption which overrides the // authorization header with the services own auth token -func WithServicePrivileges() CallOption { +func WithServiceToken() CallOption { return func(o *CallOptions) { - o.ServicePrivileges = true + o.ServiceToken = true } } From 36386354d72e9d6ea72631a09bbbd810a5724c3c Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 31 Mar 2020 13:51:32 +0100 Subject: [PATCH 466/788] Fallback to service token --- client/grpc/grpc.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 8cd55dd8..5f14c25d 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -131,11 +131,14 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R // set the content type for the request header["x-content-type"] = req.ContentType() - // if the caller specifies using service privelages, and the client - // has auth set, override the authorization header - if opts.ServiceToken && g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { - t := g.opts.Auth.Options().Token - header["authorization"] = auth.BearerScheme + t.Token + // if the caller specifies using service token or no token + // was passed with the request, set the service token + var srvToken string + if g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { + srvToken = g.opts.Auth.Options().Token.Token + } + if (opts.ServiceToken || len(header["authorization"]) == 0) && len(srvToken) > 0 { + header["authorization"] = auth.BearerScheme + srvToken } // fall back to using the authorization token set in config, From 8dbb5153f4851c72d6e9f695daff8520241564f1 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 31 Mar 2020 17:01:51 +0100 Subject: [PATCH 467/788] Tweak Auth Interface --- auth/auth.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 4c175110..6bb9e479 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -33,7 +33,9 @@ type Auth interface { // Options set for auth Options() Options // Generate a new account - Generate(id string, opts ...GenerateOption) (*Account, error) + Generate(id, secret string, opts ...GenerateOption) (*Account, error) + // Login to an existing account + Login(id, secret string) (*Account, error) // Grant access to a resource Grant(role string, res *Resource) error // Revoke access to a resource @@ -42,8 +44,8 @@ type Auth interface { Verify(acc *Account, res *Resource) error // Inspect a token Inspect(token string) (*Account, error) - // Token generated using an account ID and secret - Token(id, secret string, opts ...TokenOption) (*Token, error) + // Token generated using refresh token + Token(id, refreshToken string, opts ...TokenOption) (*Token, error) // String returns the name of the implementation String() string } @@ -60,10 +62,12 @@ type Resource struct { // Account provided by an auth provider type Account struct { - // ID of the account (UUIDV4, email or username) + // Type of the account, e.g. service + Type string `json:"type"` + // ID of the account e.g. email ID string `json:"id"` - // Secret used to renew the account - Secret string `json:"secret"` + // RefreshToken used to renew the account + RefreshToken string `json:"refresh_token"` // Roles associated with the Account Roles []string `json:"roles"` // Any other associated metadata From 6c6c5359b188597d73455bda91ca40f2fde1d3c2 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 31 Mar 2020 17:13:21 +0100 Subject: [PATCH 468/788] Add options to config (#1450) --- config/config.go | 2 ++ config/default.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/config/config.go b/config/config.go index d70d5778..cd30f8b2 100644 --- a/config/config.go +++ b/config/config.go @@ -16,6 +16,8 @@ type Config interface { reader.Values // Init the config Init(opts ...Option) error + // Options in the config + Options() Options // Stop the config loader/watcher Close() error // Load config sources diff --git a/config/default.go b/config/default.go index 0b70cbcf..905ccad7 100644 --- a/config/default.go +++ b/config/default.go @@ -67,6 +67,10 @@ func (c *config) Init(opts ...Option) error { return nil } +func (c *config) Options() Options { + return c.opts +} + func (c *config) run() { watch := func(w loader.Watcher) error { for { From 134bc1c68aa18a77a5661921c131343001563b1c Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 31 Mar 2020 18:17:01 +0100 Subject: [PATCH 469/788] Implement new interface --- auth/auth.go | 2 + auth/default.go | 17 +- auth/options.go | 8 +- auth/service/proto/auth.pb.go | 286 ++++++++++++++++++++-------- auth/service/proto/auth.pb.micro.go | 17 ++ auth/service/proto/auth.proto | 17 +- auth/service/service.go | 38 ++-- 7 files changed, 275 insertions(+), 110 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 6bb9e479..739c6e91 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -74,6 +74,8 @@ type Account struct { Metadata map[string]string `json:"metadata"` // Namespace the account belongs to, default blank Namespace string `json:"namespace"` + // Secret for the account, e.g. the password + Secret string `json:"secret"` } // Token can be short or long lived diff --git a/auth/default.go b/auth/default.go index c637f7c6..6f618682 100644 --- a/auth/default.go +++ b/auth/default.go @@ -34,17 +34,22 @@ func (n *noop) Options() Options { } // Generate a new account -func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) { +func (n *noop) Generate(id, secret string, opts ...GenerateOption) (*Account, error) { options := NewGenerateOptions(opts...) return &Account{ - ID: id, - Roles: options.Roles, - Metadata: options.Metadata, - Secret: uuid.New().String(), + ID: id, + Roles: options.Roles, + Metadata: options.Metadata, + RefreshToken: uuid.New().String(), }, nil } +// Login to an existing account +func (n *noop) Login(id, secret string) (*Account, error) { + return &Account{ID: id}, nil +} + // Grant access to a resource func (n *noop) Grant(role string, res *Resource) error { return nil @@ -68,6 +73,6 @@ func (n *noop) Inspect(token string) (*Account, error) { } // Token generation using an account id and secret -func (n *noop) Token(id, secret string, opts ...TokenOption) (*Token, error) { +func (n *noop) Token(id, tok string, opts ...TokenOption) (*Token, error) { return &Token{}, nil } diff --git a/auth/options.go b/auth/options.go index 90bbc1df..f95710c8 100644 --- a/auth/options.go +++ b/auth/options.go @@ -10,8 +10,8 @@ import ( type Options struct { // ID is the services auth ID ID string - // Secret is used to generate new tokens - Secret string + // RefreshToken is used to generate new tokens + RefreshToken string // Token is the services token used to authenticate itself Token *Token // Public key base64 encoded @@ -50,10 +50,10 @@ func PrivateKey(key string) Option { } // Credentials sets the auth credentials -func Credentials(id, secret string) Option { +func Credentials(id, refresh string) Option { return func(o *Options) { o.ID = id - o.Secret = secret + o.RefreshToken = refresh } } diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index 0b941edc..95c39aa1 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -214,11 +214,13 @@ func (m *Token) GetNamespace() string { } type Account struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Secret string `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + // string secret = 2; Roles []string `protobuf:"bytes,3,rep,name=roles,proto3" json:"roles,omitempty"` Metadata map[string]string `protobuf:"bytes,4,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` Namespace string `protobuf:"bytes,5,opt,name=namespace,proto3" json:"namespace,omitempty"` + Type string `protobuf:"bytes,6,opt,name=type,proto3" json:"type,omitempty"` + RefreshToken string `protobuf:"bytes,7,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -256,13 +258,6 @@ func (m *Account) GetId() string { return "" } -func (m *Account) GetSecret() string { - if m != nil { - return m.Secret - } - return "" -} - func (m *Account) GetRoles() []string { if m != nil { return m.Roles @@ -284,6 +279,20 @@ func (m *Account) GetNamespace() string { return "" } +func (m *Account) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *Account) GetRefreshToken() string { + if m != nil { + return m.RefreshToken + } + return "" +} + type Resource struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` @@ -339,11 +348,99 @@ func (m *Resource) GetEndpoint() string { return "" } +type LoginRequest struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Secret string `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *LoginRequest) Reset() { *m = LoginRequest{} } +func (m *LoginRequest) String() string { return proto.CompactTextString(m) } +func (*LoginRequest) ProtoMessage() {} +func (*LoginRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_11312eec02fd5712, []int{5} +} + +func (m *LoginRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_LoginRequest.Unmarshal(m, b) +} +func (m *LoginRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_LoginRequest.Marshal(b, m, deterministic) +} +func (m *LoginRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_LoginRequest.Merge(m, src) +} +func (m *LoginRequest) XXX_Size() int { + return xxx_messageInfo_LoginRequest.Size(m) +} +func (m *LoginRequest) XXX_DiscardUnknown() { + xxx_messageInfo_LoginRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_LoginRequest proto.InternalMessageInfo + +func (m *LoginRequest) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *LoginRequest) GetSecret() string { + if m != nil { + return m.Secret + } + return "" +} + +type LoginResponse struct { + Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *LoginResponse) Reset() { *m = LoginResponse{} } +func (m *LoginResponse) String() string { return proto.CompactTextString(m) } +func (*LoginResponse) ProtoMessage() {} +func (*LoginResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_11312eec02fd5712, []int{6} +} + +func (m *LoginResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_LoginResponse.Unmarshal(m, b) +} +func (m *LoginResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_LoginResponse.Marshal(b, m, deterministic) +} +func (m *LoginResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_LoginResponse.Merge(m, src) +} +func (m *LoginResponse) XXX_Size() int { + return xxx_messageInfo_LoginResponse.Size(m) +} +func (m *LoginResponse) XXX_DiscardUnknown() { + xxx_messageInfo_LoginResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_LoginResponse proto.InternalMessageInfo + +func (m *LoginResponse) GetAccount() *Account { + if m != nil { + return m.Account + } + return nil +} + type GenerateRequest struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Roles []string `protobuf:"bytes,2,rep,name=roles,proto3" json:"roles,omitempty"` Metadata map[string]string `protobuf:"bytes,3,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` Namespace string `protobuf:"bytes,4,opt,name=namespace,proto3" json:"namespace,omitempty"` + Secret string `protobuf:"bytes,5,opt,name=secret,proto3" json:"secret,omitempty"` + Type string `protobuf:"bytes,6,opt,name=type,proto3" json:"type,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -353,7 +450,7 @@ func (m *GenerateRequest) Reset() { *m = GenerateRequest{} } func (m *GenerateRequest) String() string { return proto.CompactTextString(m) } func (*GenerateRequest) ProtoMessage() {} func (*GenerateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{5} + return fileDescriptor_11312eec02fd5712, []int{7} } func (m *GenerateRequest) XXX_Unmarshal(b []byte) error { @@ -402,6 +499,20 @@ func (m *GenerateRequest) GetNamespace() string { return "" } +func (m *GenerateRequest) GetSecret() string { + if m != nil { + return m.Secret + } + return "" +} + +func (m *GenerateRequest) GetType() string { + if m != nil { + return m.Type + } + return "" +} + type GenerateResponse struct { Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -413,7 +524,7 @@ func (m *GenerateResponse) Reset() { *m = GenerateResponse{} } func (m *GenerateResponse) String() string { return proto.CompactTextString(m) } func (*GenerateResponse) ProtoMessage() {} func (*GenerateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{6} + return fileDescriptor_11312eec02fd5712, []int{8} } func (m *GenerateResponse) XXX_Unmarshal(b []byte) error { @@ -453,7 +564,7 @@ func (m *GrantRequest) Reset() { *m = GrantRequest{} } func (m *GrantRequest) String() string { return proto.CompactTextString(m) } func (*GrantRequest) ProtoMessage() {} func (*GrantRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{7} + return fileDescriptor_11312eec02fd5712, []int{9} } func (m *GrantRequest) XXX_Unmarshal(b []byte) error { @@ -498,7 +609,7 @@ func (m *GrantResponse) Reset() { *m = GrantResponse{} } func (m *GrantResponse) String() string { return proto.CompactTextString(m) } func (*GrantResponse) ProtoMessage() {} func (*GrantResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{8} + return fileDescriptor_11312eec02fd5712, []int{10} } func (m *GrantResponse) XXX_Unmarshal(b []byte) error { @@ -531,7 +642,7 @@ func (m *RevokeRequest) Reset() { *m = RevokeRequest{} } func (m *RevokeRequest) String() string { return proto.CompactTextString(m) } func (*RevokeRequest) ProtoMessage() {} func (*RevokeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{9} + return fileDescriptor_11312eec02fd5712, []int{11} } func (m *RevokeRequest) XXX_Unmarshal(b []byte) error { @@ -576,7 +687,7 @@ func (m *RevokeResponse) Reset() { *m = RevokeResponse{} } func (m *RevokeResponse) String() string { return proto.CompactTextString(m) } func (*RevokeResponse) ProtoMessage() {} func (*RevokeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{10} + return fileDescriptor_11312eec02fd5712, []int{12} } func (m *RevokeResponse) XXX_Unmarshal(b []byte) error { @@ -608,7 +719,7 @@ func (m *InspectRequest) Reset() { *m = InspectRequest{} } func (m *InspectRequest) String() string { return proto.CompactTextString(m) } func (*InspectRequest) ProtoMessage() {} func (*InspectRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{11} + return fileDescriptor_11312eec02fd5712, []int{13} } func (m *InspectRequest) XXX_Unmarshal(b []byte) error { @@ -647,7 +758,7 @@ func (m *InspectResponse) Reset() { *m = InspectResponse{} } func (m *InspectResponse) String() string { return proto.CompactTextString(m) } func (*InspectResponse) ProtoMessage() {} func (*InspectResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{12} + return fileDescriptor_11312eec02fd5712, []int{14} } func (m *InspectResponse) XXX_Unmarshal(b []byte) error { @@ -677,7 +788,7 @@ func (m *InspectResponse) GetAccount() *Account { type TokenRequest struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Secret string `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty"` + RefreshToken string `protobuf:"bytes,2,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"` TokenExpiry int64 `protobuf:"varint,3,opt,name=token_expiry,json=tokenExpiry,proto3" json:"token_expiry,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -688,7 +799,7 @@ func (m *TokenRequest) Reset() { *m = TokenRequest{} } func (m *TokenRequest) String() string { return proto.CompactTextString(m) } func (*TokenRequest) ProtoMessage() {} func (*TokenRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{13} + return fileDescriptor_11312eec02fd5712, []int{15} } func (m *TokenRequest) XXX_Unmarshal(b []byte) error { @@ -716,9 +827,9 @@ func (m *TokenRequest) GetId() string { return "" } -func (m *TokenRequest) GetSecret() string { +func (m *TokenRequest) GetRefreshToken() string { if m != nil { - return m.Secret + return m.RefreshToken } return "" } @@ -741,7 +852,7 @@ func (m *TokenResponse) Reset() { *m = TokenResponse{} } func (m *TokenResponse) String() string { return proto.CompactTextString(m) } func (*TokenResponse) ProtoMessage() {} func (*TokenResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{14} + return fileDescriptor_11312eec02fd5712, []int{16} } func (m *TokenResponse) XXX_Unmarshal(b []byte) error { @@ -783,7 +894,7 @@ func (m *Rule) Reset() { *m = Rule{} } func (m *Rule) String() string { return proto.CompactTextString(m) } func (*Rule) ProtoMessage() {} func (*Rule) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{15} + return fileDescriptor_11312eec02fd5712, []int{17} } func (m *Rule) XXX_Unmarshal(b []byte) error { @@ -845,7 +956,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{16} + return fileDescriptor_11312eec02fd5712, []int{18} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -897,7 +1008,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{17} + return fileDescriptor_11312eec02fd5712, []int{19} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -931,7 +1042,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{18} + return fileDescriptor_11312eec02fd5712, []int{20} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -983,7 +1094,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{19} + return fileDescriptor_11312eec02fd5712, []int{21} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -1014,7 +1125,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{20} + return fileDescriptor_11312eec02fd5712, []int{22} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -1046,7 +1157,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{21} + return fileDescriptor_11312eec02fd5712, []int{23} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -1083,6 +1194,8 @@ func init() { proto.RegisterType((*Account)(nil), "go.micro.auth.Account") proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.Account.MetadataEntry") proto.RegisterType((*Resource)(nil), "go.micro.auth.Resource") + proto.RegisterType((*LoginRequest)(nil), "go.micro.auth.LoginRequest") + proto.RegisterType((*LoginResponse)(nil), "go.micro.auth.LoginResponse") proto.RegisterType((*GenerateRequest)(nil), "go.micro.auth.GenerateRequest") proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.GenerateRequest.MetadataEntry") proto.RegisterType((*GenerateResponse)(nil), "go.micro.auth.GenerateResponse") @@ -1108,59 +1221,64 @@ func init() { } var fileDescriptor_11312eec02fd5712 = []byte{ - // 860 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xdd, 0x8e, 0xdb, 0x44, - 0x14, 0x5e, 0xff, 0xc4, 0xf1, 0x9e, 0xfc, 0x6c, 0x34, 0xdd, 0x16, 0x2b, 0xfd, 0x21, 0x18, 0x84, - 0x96, 0x8a, 0x3a, 0x28, 0xbd, 0xe0, 0xa7, 0x12, 0x22, 0x6a, 0xa2, 0xd0, 0x42, 0x83, 0xb0, 0x8a, - 0x0a, 0x17, 0x08, 0x79, 0x9d, 0xa3, 0x5d, 0xb3, 0x89, 0x1d, 0x3c, 0xe3, 0x15, 0x79, 0x02, 0xee, - 0x78, 0x14, 0x9e, 0xa8, 0x97, 0x48, 0xbc, 0x06, 0x9a, 0xf1, 0x8c, 0x37, 0x71, 0x9c, 0x55, 0x84, - 0x72, 0xc1, 0xdd, 0x9c, 0x99, 0x33, 0xdf, 0x7c, 0xdf, 0xe7, 0x33, 0xc7, 0x03, 0x9f, 0x5e, 0x44, - 0xec, 0x32, 0x3b, 0xf7, 0xc2, 0x64, 0xd1, 0x5f, 0x44, 0x61, 0x9a, 0xf4, 0x2f, 0x92, 0x27, 0xf9, - 0x20, 0xc8, 0xd8, 0x65, 0x9f, 0x62, 0x7a, 0x1d, 0x85, 0xd8, 0x5f, 0xa6, 0x09, 0xcb, 0xa7, 0x3c, - 0x31, 0x24, 0xad, 0x8b, 0xc4, 0x13, 0x79, 0x1e, 0x9f, 0x74, 0xef, 0xc2, 0x9d, 0x6f, 0x23, 0xca, - 0x86, 0x61,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1, 0x17, 0xfa, 0x67, 0x9a, 0xfb, 0xb7, - 0x06, 0x75, 0x69, 0x23, 0x69, 0x83, 0x1e, 0xcd, 0xe4, 0x36, 0x3d, 0x12, 0xf2, 0x29, 0x86, 0x29, - 0x32, 0xb9, 0x4d, 0x46, 0x37, 0x22, 0x8d, 0x75, 0x91, 0x5f, 0xad, 0x89, 0x34, 0x85, 0xc8, 0x0f, - 0xaa, 0x3f, 0xd7, 0x7e, 0x32, 0x6b, 0x07, 0x95, 0x39, 0x05, 0xdb, 0x47, 0x9a, 0x64, 0x69, 0x88, - 0xbc, 0x06, 0x38, 0xaa, 0xdc, 0x28, 0xc6, 0x95, 0x75, 0xd1, 0x05, 0x1b, 0xe3, 0xd9, 0x32, 0x89, - 0x62, 0x26, 0x0a, 0xe3, 0xd8, 0x2f, 0x62, 0xf7, 0xad, 0x06, 0x27, 0x13, 0x8c, 0x31, 0x0d, 0x18, - 0xca, 0x3a, 0xde, 0xb2, 0xaf, 0xb0, 0x49, 0x5f, 0xb7, 0xe9, 0xeb, 0x35, 0x9b, 0x0c, 0x61, 0xd3, - 0xc7, 0x25, 0x9b, 0x4a, 0xb8, 0xfb, 0xd9, 0x65, 0x1e, 0xd4, 0xae, 0x11, 0x74, 0x6e, 0x58, 0xc8, - 0xeb, 0xf8, 0x09, 0xd4, 0xe5, 0x35, 0x13, 0x18, 0xbb, 0x6f, 0xa3, 0x4a, 0x73, 0xdf, 0x40, 0x73, - 0x92, 0x06, 0x31, 0x53, 0x06, 0x11, 0x30, 0xb9, 0x07, 0xca, 0x78, 0x3e, 0x26, 0x4f, 0xc1, 0x4e, - 0xe5, 0x87, 0x11, 0x34, 0x1a, 0x83, 0x77, 0x4a, 0xb0, 0xea, 0xbb, 0xf9, 0x45, 0xa2, 0x7b, 0x02, - 0x2d, 0x09, 0x9c, 0x73, 0x73, 0x7f, 0x84, 0x96, 0x8f, 0xd7, 0xc9, 0x15, 0x1e, 0xfc, 0xa8, 0x0e, - 0xb4, 0x15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0x30, 0xf1, 0x87, 0xd3, 0xd7, 0xe3, 0x51, 0x47, 0x23, - 0x00, 0xd6, 0x68, 0x3c, 0x7d, 0x31, 0x1e, 0x75, 0xf4, 0xc1, 0x3f, 0x1a, 0x98, 0xc3, 0x8c, 0x5d, - 0x92, 0x57, 0x60, 0xab, 0x66, 0x43, 0x1e, 0xdd, 0xde, 0x0b, 0xbb, 0xef, 0xee, 0x5c, 0x97, 0x7a, - 0x8e, 0xc8, 0x4b, 0xa8, 0xcb, 0x7b, 0x47, 0x1e, 0x96, 0xb2, 0x37, 0xef, 0x6d, 0xf7, 0xd1, 0xae, - 0xe5, 0x02, 0x6b, 0xa4, 0x5e, 0x13, 0xf7, 0x2b, 0x2f, 0x83, 0xc4, 0x79, 0x50, 0xbd, 0xa8, 0x50, - 0x06, 0x3f, 0x83, 0xad, 0x1e, 0x37, 0xe4, 0x7b, 0x30, 0xb9, 0xc1, 0xa4, 0xfc, 0x00, 0xa8, 0x78, - 0x18, 0x75, 0xdf, 0xbf, 0x35, 0xa7, 0x80, 0x7f, 0xab, 0x41, 0x8d, 0x7f, 0x08, 0x4a, 0x26, 0x60, - 0xe5, 0xa5, 0x47, 0xca, 0x94, 0x36, 0xae, 0x46, 0xf7, 0xe1, 0x8e, 0xd5, 0x42, 0xf7, 0x04, 0xac, - 0xbc, 0x4e, 0xb6, 0x80, 0x36, 0xea, 0x78, 0x0b, 0xa8, 0x54, 0x5c, 0x47, 0x64, 0x28, 0xe5, 0x76, - 0x2b, 0xa4, 0x28, 0x90, 0xfb, 0x95, 0x6b, 0x0a, 0xe2, 0xdc, 0x12, 0x6f, 0xc9, 0xa7, 0xff, 0x06, - 0x00, 0x00, 0xff, 0xff, 0x24, 0x1b, 0xf8, 0x32, 0x86, 0x0a, 0x00, 0x00, + // 931 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x6d, 0x6f, 0xdb,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x1a, 0x40, 0x5f, 0x79, 0x96, 0xb1, 0x3e, 0x82, 0xfe, 0x93, 0x98, 0xae, 0x30, + 0x2c, 0x78, 0x35, 0x5e, 0x99, 0xee, 0x63, 0xd8, 0x29, 0xec, 0xde, 0x3a, 0x85, 0xaf, 0xa1, 0x27, + 0x86, 0x74, 0x53, 0x3f, 0xd6, 0x06, 0x5c, 0xaf, 0x0f, 0x38, 0xf9, 0x00, 0x7a, 0x62, 0xf3, 0x95, + 0xbc, 0x94, 0xf3, 0xdb, 0xba, 0x2b, 0x74, 0x53, 0xa1, 0x72, 0x1f, 0x81, 0x2d, 0xe3, 0x48, 0xa8, + 0xf7, 0xcb, 0x9c, 0xba, 0xa3, 0xdd, 0xa6, 0x7b, 0x57, 0x31, 0xfd, 0x4b, 0x83, 0x96, 0x9f, 0x2d, + 0xb1, 0x86, 0x4e, 0x55, 0x41, 0xdf, 0x50, 0x05, 0xe3, 0x8a, 0x55, 0x20, 0x0f, 0xc0, 0x0c, 0xc2, + 0x10, 0x29, 0x15, 0x33, 0xd1, 0x1f, 0xdd, 0xac, 0xe7, 0x0d, 0x29, 0xf5, 0xa5, 0x91, 0xfb, 0x87, + 0x06, 0xf6, 0x63, 0xf1, 0x16, 0x5d, 0x77, 0x3f, 0x94, 0x90, 0x18, 0x57, 0x41, 0x32, 0x80, 0xbe, + 0x02, 0x22, 0xdb, 0x87, 0x63, 0x9b, 0xe0, 0x12, 0xff, 0x17, 0xd8, 0x14, 0x10, 0x89, 0xcd, 0x86, + 0x2e, 0xff, 0x51, 0xa8, 0x0f, 0xc6, 0x97, 0xd0, 0xcb, 0x45, 0xd9, 0x13, 0x1f, 0x43, 0x3b, 0xcd, + 0xf8, 0xe5, 0x97, 0xff, 0x2a, 0x6e, 0x54, 0x11, 0x65, 0x4b, 0xf4, 0x73, 0x8b, 0xfb, 0x1e, 0x98, + 0x79, 0x34, 0xd2, 0x85, 0xce, 0x8f, 0xf3, 0xef, 0xe6, 0xdf, 0xbf, 0x9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xa1, + 0x0b, 0x00, 0x00, } diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index 334f2369..9937569d 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -37,6 +37,7 @@ type AuthService interface { Generate(ctx context.Context, in *GenerateRequest, opts ...client.CallOption) (*GenerateResponse, error) Inspect(ctx context.Context, in *InspectRequest, opts ...client.CallOption) (*InspectResponse, error) Token(ctx context.Context, in *TokenRequest, opts ...client.CallOption) (*TokenResponse, error) + Login(ctx context.Context, in *LoginRequest, opts ...client.CallOption) (*LoginResponse, error) } type authService struct { @@ -81,12 +82,23 @@ func (c *authService) Token(ctx context.Context, in *TokenRequest, opts ...clien return out, nil } +func (c *authService) Login(ctx context.Context, in *LoginRequest, opts ...client.CallOption) (*LoginResponse, error) { + req := c.c.NewRequest(c.name, "Auth.Login", in) + out := new(LoginResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for Auth service type AuthHandler interface { Generate(context.Context, *GenerateRequest, *GenerateResponse) error Inspect(context.Context, *InspectRequest, *InspectResponse) error Token(context.Context, *TokenRequest, *TokenResponse) error + Login(context.Context, *LoginRequest, *LoginResponse) error } func RegisterAuthHandler(s server.Server, hdlr AuthHandler, opts ...server.HandlerOption) error { @@ -94,6 +106,7 @@ func RegisterAuthHandler(s server.Server, hdlr AuthHandler, opts ...server.Handl Generate(ctx context.Context, in *GenerateRequest, out *GenerateResponse) error Inspect(ctx context.Context, in *InspectRequest, out *InspectResponse) error Token(ctx context.Context, in *TokenRequest, out *TokenResponse) error + Login(ctx context.Context, in *LoginRequest, out *LoginResponse) error } type Auth struct { auth @@ -118,6 +131,10 @@ func (h *authHandler) Token(ctx context.Context, in *TokenRequest, out *TokenRes return h.AuthHandler.Token(ctx, in, out) } +func (h *authHandler) Login(ctx context.Context, in *LoginRequest, out *LoginResponse) error { + return h.AuthHandler.Login(ctx, in, out) +} + // Client API for Accounts service type AccountsService interface { diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index ba53076b..2edd1390 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -6,6 +6,7 @@ service Auth { rpc Generate(GenerateRequest) returns (GenerateResponse) {}; rpc Inspect(InspectRequest) returns (InspectResponse) {}; rpc Token(TokenRequest) returns (TokenResponse) {}; + rpc Login(LoginRequest) returns (LoginResponse) {}; } service Accounts { @@ -38,10 +39,11 @@ message Token { message Account { string id = 1; - string secret = 2; repeated string roles = 3; map metadata = 4; string namespace = 5; + string type = 6; + string refresh_token = 7; } message Resource{ @@ -50,11 +52,22 @@ message Resource{ string endpoint = 3; } +message LoginRequest { + string id = 1; + string secret = 2; +} + +message LoginResponse { + Account account = 1; +} + message GenerateRequest { string id = 1; repeated string roles = 2; map metadata = 3; string namespace = 4; + string secret = 5; + string type = 6; } message GenerateResponse { @@ -85,7 +98,7 @@ message InspectResponse { message TokenRequest { string id = 1; - string secret = 2; + string refresh_token = 2; int64 token_expiry = 3; } diff --git a/auth/service/service.go b/auth/service/service.go index 0cc11d98..c83fefbf 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -73,7 +73,7 @@ func (s *svc) Init(opts ...auth.Option) { // we have client credentials and must load a new token // periodically - if len(s.options.ID) > 0 || len(s.options.Secret) > 0 { + if len(s.options.ID) > 0 || len(s.options.RefreshToken) > 0 { tokenTimer := time.NewTicker(time.Minute) go func() { @@ -107,11 +107,12 @@ func (s *svc) Options() auth.Options { } // Generate a new account -func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { +func (s *svc) Generate(id, secret string, opts ...auth.GenerateOption) (*auth.Account, error) { options := auth.NewGenerateOptions(opts...) rsp, err := s.auth.Generate(context.TODO(), &pb.GenerateRequest{ Id: id, + Secret: secret, Roles: options.Roles, Metadata: options.Metadata, Namespace: options.Namespace, @@ -123,6 +124,15 @@ func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e return serializeAccount(rsp.Account), nil } +// Login to an account +func (s *svc) Login(id, secret string) (*auth.Account, error) { + rsp, err := s.auth.Login(context.TODO(), &pb.LoginRequest{Id: id, Secret: secret}) + if err != nil { + return nil, err + } + return serializeAccount(rsp.Account), nil +} + // Grant access to a resource func (s *svc) Grant(role string, res *auth.Resource) error { _, err := s.rule.Create(context.TODO(), &pb.CreateRequest{ @@ -216,13 +226,13 @@ func (s *svc) Inspect(token string) (*auth.Account, error) { } // Token generation using an account ID and secret -func (s *svc) Token(id, secret string, opts ...auth.TokenOption) (*auth.Token, error) { +func (s *svc) Token(id, refresh string, opts ...auth.TokenOption) (*auth.Token, error) { options := auth.NewTokenOptions(opts...) rsp, err := s.auth.Token(context.Background(), &pb.TokenRequest{ - Id: id, - Secret: secret, - TokenExpiry: int64(options.TokenExpiry.Seconds()), + Id: id, + RefreshToken: refresh, + TokenExpiry: int64(options.TokenExpiry.Seconds()), }) if err != nil { return nil, err @@ -289,9 +299,9 @@ func (s *svc) loadRules() { // loadToken generates a new token for the service to use when making calls func (s *svc) loadToken() { rsp, err := s.auth.Token(context.TODO(), &pb.TokenRequest{ - Id: s.Options().ID, - Secret: s.Options().Secret, - TokenExpiry: int64((time.Minute * 15).Seconds()), + Id: s.Options().ID, + RefreshToken: s.Options().RefreshToken, + TokenExpiry: int64((time.Minute * 15).Seconds()), }) s.Lock() defer s.Unlock() @@ -318,10 +328,10 @@ func serializeToken(t *pb.Token) *auth.Token { func serializeAccount(a *pb.Account) *auth.Account { return &auth.Account{ - ID: a.Id, - Roles: a.Roles, - Metadata: a.Metadata, - Namespace: a.Namespace, - Secret: a.Secret, + ID: a.Id, + Roles: a.Roles, + Metadata: a.Metadata, + Namespace: a.Namespace, + RefreshToken: a.RefreshToken, } } From cffb0a1eaec987609b488f8dc0aa837827886133 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 31 Mar 2020 18:34:31 +0100 Subject: [PATCH 470/788] Remove ContextWithToken --- auth/auth.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 739c6e91..fefff162 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -5,7 +5,6 @@ import ( "context" "encoding/json" "errors" - "fmt" "time" "github.com/micro/go-micro/v2/metadata" @@ -138,8 +137,3 @@ func ContextWithAccount(ctx context.Context, account *Account) (context.Context, // generate a new context with the MetadataKey set return metadata.Set(ctx, MetadataKey, string(bytes)), nil } - -// ContextWithToken sets the auth token in the context -func ContextWithToken(ctx context.Context, token string) context.Context { - return metadata.Set(ctx, "Authorization", fmt.Sprintf("%v%v", BearerScheme, token)) -} From 82bc3cbf8d4ee91e8ce8e581599621148e6fbdfa Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 31 Mar 2020 19:01:43 +0100 Subject: [PATCH 471/788] Update interface to add provider and make secret optional --- auth/auth.go | 10 ++- auth/default.go | 4 +- auth/options.go | 50 ++++++++++++ auth/service/proto/auth.pb.go | 150 +++++++++++++++++++--------------- auth/service/proto/auth.proto | 6 +- auth/service/service.go | 12 ++- 6 files changed, 153 insertions(+), 79 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index fefff162..ccd877f1 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -32,9 +32,9 @@ type Auth interface { // Options set for auth Options() Options // Generate a new account - Generate(id, secret string, opts ...GenerateOption) (*Account, error) + Generate(id string, opts ...GenerateOption) (*Account, error) // Login to an existing account - Login(id, secret string) (*Account, error) + Login(id string, opts ...LoginOption) (*Account, error) // Grant access to a resource Grant(role string, res *Resource) error // Revoke access to a resource @@ -61,10 +61,12 @@ type Resource struct { // Account provided by an auth provider type Account struct { - // Type of the account, e.g. service - Type string `json:"type"` // ID of the account e.g. email ID string `json:"id"` + // Type of the account, e.g. service + Type string `json:"type"` + // Provider who issued the account + Provider string `json:"provider"` // RefreshToken used to renew the account RefreshToken string `json:"refresh_token"` // Roles associated with the Account diff --git a/auth/default.go b/auth/default.go index 6f618682..88a8b4a6 100644 --- a/auth/default.go +++ b/auth/default.go @@ -34,7 +34,7 @@ func (n *noop) Options() Options { } // Generate a new account -func (n *noop) Generate(id, secret string, opts ...GenerateOption) (*Account, error) { +func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) { options := NewGenerateOptions(opts...) return &Account{ @@ -46,7 +46,7 @@ func (n *noop) Generate(id, secret string, opts ...GenerateOption) (*Account, er } // Login to an existing account -func (n *noop) Login(id, secret string) (*Account, error) { +func (n *noop) Login(id string, opts ...LoginOption) (*Account, error) { return &Account{ID: id}, nil } diff --git a/auth/options.go b/auth/options.go index f95710c8..99fba52d 100644 --- a/auth/options.go +++ b/auth/options.go @@ -78,10 +78,23 @@ type GenerateOptions struct { Roles []string // Namespace the account belongs too Namespace string + // Secret to use with the account + Secret string + // Provider of the account, e.g. oauth + Provider string + // Type of the account, e.g. user + Type string } type GenerateOption func(o *GenerateOptions) +// WithType for the generated account +func WithType(t string) GenerateOption { + return func(o *GenerateOptions) { + o.Type = t + } +} + // WithMetadata for the generated account func WithMetadata(md map[string]string) GenerateOption { return func(o *GenerateOptions) { @@ -103,6 +116,20 @@ func WithNamespace(n string) GenerateOption { } } +// WithSecret for the generated account +func WithSecret(s string) GenerateOption { + return func(o *GenerateOptions) { + o.Secret = s + } +} + +// WithProvider for the generated account +func WithProvider(p string) GenerateOption { + return func(o *GenerateOptions) { + o.Provider = p + } +} + // NewGenerateOptions from a slice of options func NewGenerateOptions(opts ...GenerateOption) GenerateOptions { var options GenerateOptions @@ -112,6 +139,29 @@ func NewGenerateOptions(opts ...GenerateOption) GenerateOptions { return options } +type LoginOptions struct { + // Secret to use for rlogin + Secret string +} + +type LoginOption func(o *LoginOptions) + +// WithLoginSecret for the generated account +func WithLoginSecret(s string) LoginOption { + return func(o *LoginOptions) { + o.Secret = s + } +} + +// NewLoginOptions from a slice of options +func NewLoginOptions(opts ...LoginOption) LoginOptions { + var options LoginOptions + for _, o := range opts { + o(&options) + } + return options +} + type TokenOptions struct { // TokenExpiry is the time the token should live for TokenExpiry time.Duration diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index 95c39aa1..604ea538 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -214,13 +214,13 @@ func (m *Token) GetNamespace() string { } type Account struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - // string secret = 2; + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` Roles []string `protobuf:"bytes,3,rep,name=roles,proto3" json:"roles,omitempty"` Metadata map[string]string `protobuf:"bytes,4,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` Namespace string `protobuf:"bytes,5,opt,name=namespace,proto3" json:"namespace,omitempty"` - Type string `protobuf:"bytes,6,opt,name=type,proto3" json:"type,omitempty"` - RefreshToken string `protobuf:"bytes,7,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"` + RefreshToken string `protobuf:"bytes,6,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"` + Provider string `protobuf:"bytes,7,opt,name=provider,proto3" json:"provider,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -258,6 +258,13 @@ func (m *Account) GetId() string { return "" } +func (m *Account) GetType() string { + if m != nil { + return m.Type + } + return "" +} + func (m *Account) GetRoles() []string { if m != nil { return m.Roles @@ -279,16 +286,16 @@ func (m *Account) GetNamespace() string { return "" } -func (m *Account) GetType() string { +func (m *Account) GetRefreshToken() string { if m != nil { - return m.Type + return m.RefreshToken } return "" } -func (m *Account) GetRefreshToken() string { +func (m *Account) GetProvider() string { if m != nil { - return m.RefreshToken + return m.Provider } return "" } @@ -441,6 +448,7 @@ type GenerateRequest struct { Namespace string `protobuf:"bytes,4,opt,name=namespace,proto3" json:"namespace,omitempty"` Secret string `protobuf:"bytes,5,opt,name=secret,proto3" json:"secret,omitempty"` Type string `protobuf:"bytes,6,opt,name=type,proto3" json:"type,omitempty"` + Provider string `protobuf:"bytes,7,opt,name=provider,proto3" json:"provider,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -513,6 +521,13 @@ func (m *GenerateRequest) GetType() string { return "" } +func (m *GenerateRequest) GetProvider() string { + if m != nil { + return m.Provider + } + return "" +} + type GenerateResponse struct { Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -1221,64 +1236,65 @@ func init() { } var fileDescriptor_11312eec02fd5712 = []byte{ - // 931 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x6d, 0x6f, 0xdb, 0x36, - 0x10, 0x8e, 0x24, 0x5b, 0x56, 0xce, 0x96, 0x63, 0xb0, 0x69, 0x26, 0xb8, 0x2f, 0xcb, 0xd4, 0x61, - 0xc8, 0x8a, 0x55, 0x19, 0x5c, 0x60, 0x6f, 0x05, 0x86, 0x19, 0xb5, 0xe1, 0xb5, 0x6b, 0x3d, 0x4c, - 0xe8, 0xd0, 0x7d, 0x19, 0x0a, 0x45, 0xbe, 0x26, 0x5a, 0x1c, 0xc9, 0x13, 0xa9, 0x60, 0xf9, 0x01, - 0xc3, 0xf6, 0x69, 0xff, 0x64, 0xfb, 0x45, 0xfb, 0x31, 0x03, 0x29, 0x52, 0x91, 0x25, 0xb9, 0x08, - 0xda, 0x7c, 0xd8, 0x37, 0xde, 0xf1, 0x78, 0xf7, 0x3c, 0xf7, 0x42, 0x12, 0x3e, 0x3f, 0x8e, 0xd8, - 0x49, 0x76, 0xe4, 0x85, 0xc9, 0xd9, 0xe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9a, 0x97, 0xb5, 0xb7, 0xcd, 0xdd, 0x1a, 0xfd, 0x0c, 0x96, 0xfa, 0xf7, 0x91, 0x1f, 0xa0, 0xc5, - 0xcb, 0x44, 0xaa, 0x7f, 0xa3, 0x86, 0x3f, 0xe3, 0xf0, 0xde, 0x1b, 0x6d, 0x0a, 0xf7, 0xff, 0x6a, - 0xd0, 0xe6, 0xe5, 0xa4, 0x64, 0x06, 0x66, 0xde, 0xc0, 0xa4, 0x0a, 0x69, 0x6d, 0xc0, 0x86, 0x77, - 0x36, 0xec, 0x16, 0xbc, 0x67, 0x60, 0xe6, 0xdd, 0x56, 0x73, 0xb4, 0x36, 0x0d, 0x35, 0x47, 0x95, - 0x16, 0xdd, 0x22, 0x63, 0x49, 0x77, 0xd8, 0x40, 0x45, 0x39, 0xb9, 0xd5, 0xb8, 0xa7, 0x5c, 0x1c, - 0x99, 0xe2, 0x9b, 0xfd, 0xf0, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd9, 0x7a, 0xd4, 0x05, 0xa1, + // 947 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xdd, 0x8e, 0xdb, 0x44, + 0x14, 0x5e, 0xdb, 0x89, 0xe3, 0x3d, 0x89, 0xb3, 0xd1, 0x74, 0xbb, 0x58, 0xe9, 0x0f, 0x8b, 0x8b, + 0xd0, 0x52, 0xd1, 0x2c, 0x4a, 0x25, 0xfe, 0x2a, 0x21, 0xa2, 0x26, 0x0a, 0x2d, 0x6d, 0x10, 0x56, + 0x51, 0xb9, 0x41, 0x95, 0xd7, 0x39, 0xdd, 0x35, 0x9b, 0xb5, 0xc3, 0xcc, 0x78, 0xc5, 0x3e, 0x01, + 0x77, 0xbc, 0x03, 0x12, 0xb7, 0xf0, 0x44, 0x3c, 0x0c, 0x9a, 0xf1, 0x8c, 0xd7, 0x71, 0x9c, 0x6a, + 0x55, 0x16,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, 0xe2, 0xb3, 0x45, 0x9e, 0x42, 0x4b, 0x35, 0x21, + 0xb9, 0x53, 0xd1, 0x5e, 0x6d, 0xe2, 0xfe, 0xdd, 0x4d, 0xc7, 0x05, 0xd6, 0x58, 0x7f, 0xad, 0x6e, + 0xd5, 0x36, 0x83, 0xc2, 0xb9, 0x5d, 0x7f, 0x58, 0x46, 0x91, 0x8f, 0xd8, 0x1a, 0x4a, 0xf9, 0x49, + 0x5c, 0x43, 0x59, 0x79, 0xf7, 0xfc, 0xad, 0xe1, 0x8f, 0xe0, 0xe8, 0xff, 0x22, 0xf9, 0x0e, 0x1a, + 0x22, 0x4d, 0xa4, 0xfa, 0xa7, 0xaa, 0xf9, 0x6b, 0xf6, 0xef, 0xbd, 0x51, 0xa7, 0x80, 0xff, 0xdb, + 0x80, 0xa6, 0x48, 0x27, 0x23, 0x53, 0xb0, 0xf3, 0x02, 0x26, 0x55, 0x97, 0x56, 0x1a, 0xac, 0x7f, + 0x67, 0xc3, 0x69, 0xc1, 0x7b, 0x0a, 0x76, 0x5e, 0x6d, 0x6b, 0x40, 0x2b, 0xdd, 0xb0, 0x06, 0x54, + 0x29, 0xd1, 0x2d, 0x32, 0x52, 0x74, 0xfb, 0x35, 0x54, 0x34, 0xc8, 0xad, 0xda, 0x33, 0x0d, 0x71, + 0x64, 0xcb, 0xef, 0xf9, 0xc3, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x8f, 0xd3, 0xdd, 0x57, 0xd9, 0x0b, 0x00, 0x00, } diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index 2edd1390..9c27ecb7 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -39,11 +39,12 @@ message Token { message Account { string id = 1; + string type = 2; repeated string roles = 3; map metadata = 4; string namespace = 5; - string type = 6; - string refresh_token = 7; + string refresh_token = 6; + string provider = 7; } message Resource{ @@ -68,6 +69,7 @@ message GenerateRequest { string namespace = 4; string secret = 5; string type = 6; + string provider = 7; } message GenerateResponse { diff --git a/auth/service/service.go b/auth/service/service.go index c83fefbf..90c5122c 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -107,14 +107,16 @@ func (s *svc) Options() auth.Options { } // Generate a new account -func (s *svc) Generate(id, secret string, opts ...auth.GenerateOption) (*auth.Account, error) { +func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { options := auth.NewGenerateOptions(opts...) rsp, err := s.auth.Generate(context.TODO(), &pb.GenerateRequest{ Id: id, - Secret: secret, + Type: options.Type, Roles: options.Roles, + Secret: options.Secret, Metadata: options.Metadata, + Provider: options.Provider, Namespace: options.Namespace, }) if err != nil { @@ -125,8 +127,9 @@ func (s *svc) Generate(id, secret string, opts ...auth.GenerateOption) (*auth.Ac } // Login to an account -func (s *svc) Login(id, secret string) (*auth.Account, error) { - rsp, err := s.auth.Login(context.TODO(), &pb.LoginRequest{Id: id, Secret: secret}) +func (s *svc) Login(id string, opts ...auth.LoginOption) (*auth.Account, error) { + options := auth.NewLoginOptions(opts...) + rsp, err := s.auth.Login(context.TODO(), &pb.LoginRequest{Id: id, Secret: options.Secret}) if err != nil { return nil, err } @@ -331,6 +334,7 @@ func serializeAccount(a *pb.Account) *auth.Account { ID: a.Id, Roles: a.Roles, Metadata: a.Metadata, + Provider: a.Provider, Namespace: a.Namespace, RefreshToken: a.RefreshToken, } From d6bef84de08b00c3059a073fc26872f9545b2893 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 31 Mar 2020 21:59:35 +0300 Subject: [PATCH 472/788] api/handler/rpc: fix metadata cleanup (#1451) Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index c6bd6daf..d7c3c75c 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -289,8 +289,8 @@ func requestPayload(r *http.Request) ([]byte, error) { for k, v := range md { if strings.HasPrefix(k, "x-api-field-") { matches[strings.TrimPrefix(k, "x-api-field-")] = v + delete(md, k) } - delete(md, k) } // restore context without fields From 18061723bbddef80393b809c2cf9096ea2a4f874 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 31 Mar 2020 22:36:51 +0300 Subject: [PATCH 473/788] fix api metadata extract from context (#1452) Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 16 ++++++++++++++-- api/router/static/static.go | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index d7c3c75c..8e830a8c 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -118,6 +118,17 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // create context cx := ctx.FromRequest(r) + // get context from http handler wrappers + md, ok := r.Context().Value(metadata.MetadataKey{}).(metadata.Metadata) + if !ok { + md = make(metadata.Metadata) + } + + // merge context with overwrite + cx = metadata.MergeContext(cx, md, true) + + // set merged context to request + *r = *r.WithContext(cx) // if stream we currently only support json if isStream(r, service) { @@ -287,6 +298,7 @@ func requestPayload(r *http.Request) ([]byte, error) { // allocate maximum matches := make(map[string]string, len(md)) for k, v := range md { + // filter own keys if strings.HasPrefix(k, "x-api-field-") { matches[strings.TrimPrefix(k, "x-api-field-")] = v delete(md, k) @@ -294,8 +306,8 @@ func requestPayload(r *http.Request) ([]byte, error) { } // restore context without fields - ctx = metadata.NewContext(ctx, md) - *r = *r.WithContext(ctx) + *r = *r.WithContext(metadata.NewContext(ctx, md)) + req := make(map[string]interface{}, len(md)) for k, v := range matches { ps := strings.Split(k, ".") diff --git a/api/router/static/static.go b/api/router/static/static.go index 2f8a0962..f391cd5a 100644 --- a/api/router/static/static.go +++ b/api/router/static/static.go @@ -255,7 +255,7 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { } pMatch = true ctx := req.Context() - md, ok := metadata.FromContext(ctx) + md, ok := ctx.Value(metadata.MetadataKey{}).(metadata.Metadata) if !ok { md = make(metadata.Metadata) } From 5e65a46be384c8051a89e498a080afe47472762b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 31 Mar 2020 22:55:33 +0300 Subject: [PATCH 474/788] metadata: allow to remove key from metadata (#1453) Signed-off-by: Vasiliy Tolstov --- metadata/metadata.go | 22 ++++++++++++++++++++-- metadata/metadata_test.go | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/metadata/metadata.go b/metadata/metadata.go index 5ba0e4c0..d9d89236 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -25,6 +25,13 @@ func (md Metadata) Get(key string) (string, bool) { return val, ok } +func (md Metadata) Del(key string) { + // delete key as-is + delete(md, key) + // delete also Title key + delete(md, strings.Title(key)) +} + // Copy makes a copy of the metadata func Copy(md Metadata) Metadata { cmd := make(Metadata) @@ -34,13 +41,22 @@ func Copy(md Metadata) Metadata { return cmd } +// Del key from metadata +func Del(ctx context.Context, k string) context.Context { + return Set(ctx, k, "") +} + // Set add key with val to metadata func Set(ctx context.Context, k, v string) context.Context { md, ok := FromContext(ctx) if !ok { md = make(Metadata) } - md[k] = v + if v == "" { + delete(md, k) + } else { + md[k] = v + } return context.WithValue(ctx, MetadataKey{}, md) } @@ -96,8 +112,10 @@ func MergeContext(ctx context.Context, patchMd Metadata, overwrite bool) context for k, v := range patchMd { if _, ok := cmd[k]; ok && !overwrite { // skip - } else { + } else if v != "" { cmd[k] = v + } else { + delete(cmd, k) } } return context.WithValue(ctx, MetadataKey{}, cmd) diff --git a/metadata/metadata_test.go b/metadata/metadata_test.go index 8dacfa84..485923e2 100644 --- a/metadata/metadata_test.go +++ b/metadata/metadata_test.go @@ -18,6 +18,27 @@ func TestMetadataSet(t *testing.T) { } } +func TestMetadataDel(t *testing.T) { + md := Metadata{ + "Foo": "bar", + "Baz": "empty", + } + + ctx := NewContext(context.TODO(), md) + ctx = Set(ctx, "Baz", "") + + emd, ok := FromContext(ctx) + if !ok { + t.Fatal("key Key not found") + } + + _, ok = emd["Baz"] + if ok { + t.Fatal("key Baz not deleted") + } + +} + func TestMetadataCopy(t *testing.T) { md := Metadata{ "Foo": "bar", From 3a22efbd7dad62d75f6cdb233db6ecfef078053c Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 31 Mar 2020 23:39:18 +0300 Subject: [PATCH 475/788] metadata: change method name (#1454) Signed-off-by: Vasiliy Tolstov --- metadata/metadata.go | 6 +++--- metadata/metadata_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/metadata/metadata.go b/metadata/metadata.go index d9d89236..96693cf6 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -25,7 +25,7 @@ func (md Metadata) Get(key string) (string, bool) { return val, ok } -func (md Metadata) Del(key string) { +func (md Metadata) Delete(key string) { // delete key as-is delete(md, key) // delete also Title key @@ -41,8 +41,8 @@ func Copy(md Metadata) Metadata { return cmd } -// Del key from metadata -func Del(ctx context.Context, k string) context.Context { +// Delete key from metadata +func Delete(ctx context.Context, k string) context.Context { return Set(ctx, k, "") } diff --git a/metadata/metadata_test.go b/metadata/metadata_test.go index 485923e2..6a3764b4 100644 --- a/metadata/metadata_test.go +++ b/metadata/metadata_test.go @@ -18,14 +18,14 @@ func TestMetadataSet(t *testing.T) { } } -func TestMetadataDel(t *testing.T) { +func TestMetadataDelete(t *testing.T) { md := Metadata{ "Foo": "bar", "Baz": "empty", } ctx := NewContext(context.TODO(), md) - ctx = Set(ctx, "Baz", "") + ctx = Delete(ctx, "Baz") emd, ok := FromContext(ctx) if !ok { From 1490aff38ee3ee820c7c01bcd7fb4cfc116204f7 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 1 Apr 2020 00:23:17 +0300 Subject: [PATCH 476/788] api/handler/rpc: correctly parse nested url vars (#1455) Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 8e830a8c..0aeceb43 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -297,6 +297,8 @@ func requestPayload(r *http.Request) ([]byte, error) { } // allocate maximum matches := make(map[string]string, len(md)) + + // get fields from url path for k, v := range md { // filter own keys if strings.HasPrefix(k, "x-api-field-") { @@ -305,6 +307,18 @@ func requestPayload(r *http.Request) ([]byte, error) { } } + // get fields from url values + if len(r.URL.RawQuery) > 0 { + umd := make(map[string]string) + err = qson.Unmarshal(&umd, r.URL.RawQuery) + if err != nil { + return nil, err + } + for k, v := range umd { + matches[k] = v + } + } + // restore context without fields *r = *r.WithContext(metadata.NewContext(ctx, md)) @@ -315,7 +329,6 @@ func requestPayload(r *http.Request) ([]byte, error) { req[k] = v continue } - em := make(map[string]interface{}) em[ps[len(ps)-1]] = v for i := len(ps) - 2; i > 0; i-- { @@ -323,7 +336,15 @@ func requestPayload(r *http.Request) ([]byte, error) { nm[ps[i]] = em em = nm } - req[ps[0]] = em + if vm, ok := req[ps[0]]; ok { + // nested map + nm := vm.(map[string]interface{}) + for vk, vv := range em { + nm[vk] = vv + } + } else { + req[ps[0]] = em + } } pathbuf := []byte("{}") if len(req) > 0 { @@ -332,14 +353,8 @@ func requestPayload(r *http.Request) ([]byte, error) { return nil, err } } - urlbuf := []byte("{}") - if len(r.URL.RawQuery) > 0 { - urlbuf, err = qson.ToJSON(r.URL.RawQuery) - if err != nil { - return nil, err - } - } + urlbuf := []byte("{}") out, err := jsonpatch.MergeMergePatches(urlbuf, pathbuf) if err != nil { return nil, err From 68b0238a5d37fd48d70be14162bd6b33c4528e54 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 31 Mar 2020 23:22:11 +0100 Subject: [PATCH 477/788] add stream timeout option which defaults to 0 (#1456) * add stream timeout option which defaults to 0 * fix option --- client/grpc/grpc.go | 4 +++- client/options.go | 16 ++++++++++++++++ client/rpc_client.go | 4 +++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 5f14c25d..71a89f9c 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -221,7 +221,9 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client } // set timeout in nanoseconds - header["timeout"] = fmt.Sprintf("%d", opts.RequestTimeout) + if opts.StreamTimeout > time.Duration(0) { + header["timeout"] = fmt.Sprintf("%d", opts.StreamTimeout) + } // set the content type for the request header["x-content-type"] = req.ContentType() diff --git a/client/options.go b/client/options.go index 378957ed..da3d592e 100644 --- a/client/options.go +++ b/client/options.go @@ -57,6 +57,8 @@ type CallOptions struct { Retries int // Request/Response timeout RequestTimeout time.Duration + // Stream timeout for the stream + StreamTimeout time.Duration // Use the services own auth token ServiceToken bool @@ -227,6 +229,13 @@ func RequestTimeout(d time.Duration) Option { } } +// StreamTimeout sets the stream timeout +func StreamTimeout(d time.Duration) Option { + return func(o *Options) { + o.CallOptions.StreamTimeout = d + } +} + // Transport dial timeout func DialTimeout(d time.Duration) Option { return func(o *Options) { @@ -295,6 +304,13 @@ func WithRequestTimeout(d time.Duration) CallOption { } } +// WithStreamTimeout sets the stream timeout +func WithStreamTimeout(d time.Duration) CallOption { + return func(o *CallOptions) { + o.StreamTimeout = d + } +} + // WithDialTimeout is a CallOption which overrides that which // set in Options.CallOptions func WithDialTimeout(d time.Duration) CallOption { diff --git a/client/rpc_client.go b/client/rpc_client.go index 8b4b806b..ea68bfb2 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -198,7 +198,9 @@ func (r *rpcClient) stream(ctx context.Context, node *registry.Node, req Request } // set timeout in nanoseconds - msg.Header["Timeout"] = fmt.Sprintf("%d", opts.RequestTimeout) + if opts.StreamTimeout > time.Duration(0) { + msg.Header["Timeout"] = fmt.Sprintf("%d", opts.StreamTimeout) + } // set the content type for the request msg.Header["Content-Type"] = req.ContentType() // set the accept header From 8a8742f86765688dda3fef4ee27220eed75053e2 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 1 Apr 2020 01:26:58 +0300 Subject: [PATCH 478/788] api/handler/rpc: dont change types of url fields (#1457) Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 0aeceb43..543f5e8c 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -295,8 +295,9 @@ func requestPayload(r *http.Request) ([]byte, error) { if !ok { md = make(map[string]string) } + // allocate maximum - matches := make(map[string]string, len(md)) + matches := make(map[string]interface{}, len(md)) // get fields from url path for k, v := range md { @@ -307,9 +308,12 @@ func requestPayload(r *http.Request) ([]byte, error) { } } + // map of all fields + req := make(map[string]interface{}, len(md)) + // get fields from url values if len(r.URL.RawQuery) > 0 { - umd := make(map[string]string) + umd := make(map[string]interface{}) err = qson.Unmarshal(&umd, r.URL.RawQuery) if err != nil { return nil, err @@ -322,7 +326,6 @@ func requestPayload(r *http.Request) ([]byte, error) { // restore context without fields *r = *r.WithContext(metadata.NewContext(ctx, md)) - req := make(map[string]interface{}, len(md)) for k, v := range matches { ps := strings.Split(k, ".") if len(ps) == 1 { @@ -342,6 +345,7 @@ func requestPayload(r *http.Request) ([]byte, error) { for vk, vv := range em { nm[vk] = vv } + req[ps[0]] = nm } else { req[ps[0]] = em } From 7b7a859a03b5da591d839071818027df00a14b5b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 1 Apr 2020 01:50:37 +0300 Subject: [PATCH 479/788] api: use http request Clone (#1458) Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 4 ++-- api/router/static/static.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 543f5e8c..b3ab0db5 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -128,7 +128,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { cx = metadata.MergeContext(cx, md, true) // set merged context to request - *r = *r.WithContext(cx) + *r = *r.Clone(cx) // if stream we currently only support json if isStream(r, service) { @@ -324,7 +324,7 @@ func requestPayload(r *http.Request) ([]byte, error) { } // restore context without fields - *r = *r.WithContext(metadata.NewContext(ctx, md)) + *r = *r.Clone(metadata.NewContext(ctx, md)) for k, v := range matches { ps := strings.Split(k, ".") diff --git a/api/router/static/static.go b/api/router/static/static.go index f391cd5a..3cf3bebe 100644 --- a/api/router/static/static.go +++ b/api/router/static/static.go @@ -262,7 +262,7 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { for k, v := range matches { md[fmt.Sprintf("x-api-field-%s", k)] = v } - *req = *req.WithContext(context.WithValue(ctx, metadata.MetadataKey{}, md)) + *req = *req.Clone(context.WithValue(ctx, metadata.MetadataKey{}, md)) break pathLoop } if !pMatch { From 20c95d94cd29cc5ef0d2f6e33389523f18d4d3b5 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 1 Apr 2020 12:07:50 +0100 Subject: [PATCH 480/788] api completeness (#1460) --- api/api.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/api/api.go b/api/api.go index 1e81b184..736dbf77 100644 --- a/api/api.go +++ b/api/api.go @@ -10,19 +10,22 @@ import ( ) type Api interface { + // Initialise options + Init(...Option) error + // Get the options + Options() Options // Register a http handler Register(*Endpoint) error // Register a route Deregister(*Endpoint) error - // Init initialises the command line. - // It also parses further options. - //Init(...Option) error - // Options - //Options() Options - // String + // Implemenation of api String() string } +type Options struct {} + +type Option func(*Options) error + // Endpoint is a mapping between an RPC method and HTTP endpoint type Endpoint struct { // RPC Method e.g. Greeter.Hello From 8e4d9e17024a9525e37ca4e39a431bc18d8939d5 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 1 Apr 2020 14:25:00 +0100 Subject: [PATCH 481/788] Further Refactoring --- auth/auth.go | 24 +-- auth/default.go | 15 +- auth/options.go | 61 +++--- auth/service/proto/auth.pb.go | 276 ++++++++++------------------ auth/service/proto/auth.pb.micro.go | 17 -- auth/service/proto/auth.proto | 22 +-- auth/service/service.go | 91 ++++----- auth/token/basic/basic.go | 39 ++-- auth/token/jwt/jwt.go | 32 ++-- auth/token/options.go | 27 --- auth/token/token.go | 14 +- client/grpc/grpc.go | 2 +- config/cmd/cmd.go | 4 - 13 files changed, 223 insertions(+), 401 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index ccd877f1..b82f0af7 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -32,9 +32,7 @@ type Auth interface { // Options set for auth Options() Options // Generate a new account - Generate(id string, opts ...GenerateOption) (*Account, error) - // Login to an existing account - Login(id string, opts ...LoginOption) (*Account, error) + Generate(id, secret string, opts ...GenerateOption) (*Account, error) // Grant access to a resource Grant(role string, res *Resource) error // Revoke access to a resource @@ -44,7 +42,7 @@ type Auth interface { // Inspect a token Inspect(token string) (*Account, error) // Token generated using refresh token - Token(id, refreshToken string, opts ...TokenOption) (*Token, error) + Token(opts ...TokenOption) (*Token, error) // String returns the name of the implementation String() string } @@ -67,8 +65,6 @@ type Account struct { Type string `json:"type"` // Provider who issued the account Provider string `json:"provider"` - // RefreshToken used to renew the account - RefreshToken string `json:"refresh_token"` // Roles associated with the Account Roles []string `json:"roles"` // Any other associated metadata @@ -81,22 +77,14 @@ type Account struct { // Token can be short or long lived type Token struct { - // The token itself - Token string `json:"token"` - // Type of token, e.g. JWT - Type string `json:"type"` + // The token to be used for accessing resources + AccessToken string `json:"access_token"` + // RefreshToken to be used to generate a new token + RefreshToken string `json:"refresh_token"` // Time of token creation Created time.Time `json:"created"` // Time of token expiry Expiry time.Time `json:"expiry"` - // Subject of the token, e.g. the account ID - Subject string `json:"subject"` - // Roles granted to the token - Roles []string `json:"roles"` - // Metadata embedded in the token - Metadata map[string]string `json:"metadata"` - // Namespace the token belongs to - Namespace string `json:"namespace"` } const ( diff --git a/auth/default.go b/auth/default.go index 88a8b4a6..e04305cf 100644 --- a/auth/default.go +++ b/auth/default.go @@ -34,20 +34,19 @@ func (n *noop) Options() Options { } // Generate a new account -func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) { +func (n *noop) Generate(id, secret string, opts ...GenerateOption) (*Account, error) { options := NewGenerateOptions(opts...) return &Account{ - ID: id, - Roles: options.Roles, - Metadata: options.Metadata, - RefreshToken: uuid.New().String(), + ID: id, + Roles: options.Roles, + Metadata: options.Metadata, }, nil } // Login to an existing account -func (n *noop) Login(id string, opts ...LoginOption) (*Account, error) { - return &Account{ID: id}, nil +func (n *noop) Login(opts ...LoginOption) (*Account, error) { + return &Account{}, nil } // Grant access to a resource @@ -73,6 +72,6 @@ func (n *noop) Inspect(token string) (*Account, error) { } // Token generation using an account id and secret -func (n *noop) Token(id, tok string, opts ...TokenOption) (*Token, error) { +func (n *noop) Token(opts ...TokenOption) (*Token, error) { return &Token{}, nil } diff --git a/auth/options.go b/auth/options.go index 99fba52d..cd06e676 100644 --- a/auth/options.go +++ b/auth/options.go @@ -10,14 +10,12 @@ import ( type Options struct { // ID is the services auth ID ID string - // RefreshToken is used to generate new tokens - RefreshToken string + // Secret is used to authenticate the service + Secret string // Token is the services token used to authenticate itself Token *Token - // Public key base64 encoded + // PublicKey for decoding JWTs PublicKey string - // Private key base64 encoded - PrivateKey string // Provider is an auth provider Provider provider.Provider // LoginURL is the relative url path where a user can login @@ -42,18 +40,11 @@ func PublicKey(key string) Option { } } -// PrivateKey is the JWT private key -func PrivateKey(key string) Option { - return func(o *Options) { - o.PrivateKey = key - } -} - // Credentials sets the auth credentials -func Credentials(id, refresh string) Option { +func Credentials(id, secret string) Option { return func(o *Options) { o.ID = id - o.RefreshToken = refresh + o.Secret = secret } } @@ -78,8 +69,6 @@ type GenerateOptions struct { Roles []string // Namespace the account belongs too Namespace string - // Secret to use with the account - Secret string // Provider of the account, e.g. oauth Provider string // Type of the account, e.g. user @@ -116,13 +105,6 @@ func WithNamespace(n string) GenerateOption { } } -// WithSecret for the generated account -func WithSecret(s string) GenerateOption { - return func(o *GenerateOptions) { - o.Secret = s - } -} - // WithProvider for the generated account func WithProvider(p string) GenerateOption { return func(o *GenerateOptions) { @@ -163,16 +145,35 @@ func NewLoginOptions(opts ...LoginOption) LoginOptions { } type TokenOptions struct { - // TokenExpiry is the time the token should live for - TokenExpiry time.Duration + // ID for the account + ID string + // Secret for the account + Secret string + // RefreshToken is used to refesh a token + RefreshToken string + // Expiry is the time the token should live for + Expiry time.Duration } type TokenOption func(o *TokenOptions) -// WithTokenExpiry for the token -func WithTokenExpiry(ex time.Duration) TokenOption { +// WithExpiry for the token +func WithExpiry(ex time.Duration) TokenOption { return func(o *TokenOptions) { - o.TokenExpiry = ex + o.Expiry = ex + } +} + +func WithCredentials(id, secret string) TokenOption { + return func(o *TokenOptions) { + o.ID = id + o.Secret = secret + } +} + +func WithToken(rt string) TokenOption { + return func(o *TokenOptions) { + o.RefreshToken = rt } } @@ -184,8 +185,8 @@ func NewTokenOptions(opts ...TokenOption) TokenOptions { } // set defualt expiry of token - if options.TokenExpiry == 0 { - options.TokenExpiry = time.Minute + if options.Expiry == 0 { + options.Expiry = time.Minute } return options diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index 604ea538..fc1527f4 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -119,8 +119,8 @@ func (m *ListAccountsResponse) GetAccounts() []*Account { } type Token struct { - Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` - Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` + AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"` + RefreshToken string `protobuf:"bytes,2,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"` Created int64 `protobuf:"varint,3,opt,name=created,proto3" json:"created,omitempty"` Expiry int64 `protobuf:"varint,4,opt,name=expiry,proto3" json:"expiry,omitempty"` Subject string `protobuf:"bytes,5,opt,name=subject,proto3" json:"subject,omitempty"` @@ -157,16 +157,16 @@ func (m *Token) XXX_DiscardUnknown() { var xxx_messageInfo_Token proto.InternalMessageInfo -func (m *Token) GetToken() string { +func (m *Token) GetAccessToken() string { if m != nil { - return m.Token + return m.AccessToken } return "" } -func (m *Token) GetType() string { +func (m *Token) GetRefreshToken() string { if m != nil { - return m.Type + return m.RefreshToken } return "" } @@ -219,8 +219,7 @@ type Account struct { Roles []string `protobuf:"bytes,3,rep,name=roles,proto3" json:"roles,omitempty"` Metadata map[string]string `protobuf:"bytes,4,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` Namespace string `protobuf:"bytes,5,opt,name=namespace,proto3" json:"namespace,omitempty"` - RefreshToken string `protobuf:"bytes,6,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"` - Provider string `protobuf:"bytes,7,opt,name=provider,proto3" json:"provider,omitempty"` + Provider string `protobuf:"bytes,6,opt,name=provider,proto3" json:"provider,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -286,13 +285,6 @@ func (m *Account) GetNamespace() string { return "" } -func (m *Account) GetRefreshToken() string { - if m != nil { - return m.RefreshToken - } - return "" -} - func (m *Account) GetProvider() string { if m != nil { return m.Provider @@ -355,92 +347,6 @@ func (m *Resource) GetEndpoint() string { return "" } -type LoginRequest struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Secret string `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *LoginRequest) Reset() { *m = LoginRequest{} } -func (m *LoginRequest) String() string { return proto.CompactTextString(m) } -func (*LoginRequest) ProtoMessage() {} -func (*LoginRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{5} -} - -func (m *LoginRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_LoginRequest.Unmarshal(m, b) -} -func (m *LoginRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_LoginRequest.Marshal(b, m, deterministic) -} -func (m *LoginRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_LoginRequest.Merge(m, src) -} -func (m *LoginRequest) XXX_Size() int { - return xxx_messageInfo_LoginRequest.Size(m) -} -func (m *LoginRequest) XXX_DiscardUnknown() { - xxx_messageInfo_LoginRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_LoginRequest proto.InternalMessageInfo - -func (m *LoginRequest) GetId() string { - if m != nil { - return m.Id - } - return "" -} - -func (m *LoginRequest) GetSecret() string { - if m != nil { - return m.Secret - } - return "" -} - -type LoginResponse struct { - Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *LoginResponse) Reset() { *m = LoginResponse{} } -func (m *LoginResponse) String() string { return proto.CompactTextString(m) } -func (*LoginResponse) ProtoMessage() {} -func (*LoginResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{6} -} - -func (m *LoginResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_LoginResponse.Unmarshal(m, b) -} -func (m *LoginResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_LoginResponse.Marshal(b, m, deterministic) -} -func (m *LoginResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_LoginResponse.Merge(m, src) -} -func (m *LoginResponse) XXX_Size() int { - return xxx_messageInfo_LoginResponse.Size(m) -} -func (m *LoginResponse) XXX_DiscardUnknown() { - xxx_messageInfo_LoginResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_LoginResponse proto.InternalMessageInfo - -func (m *LoginResponse) GetAccount() *Account { - if m != nil { - return m.Account - } - return nil -} - type GenerateRequest struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Roles []string `protobuf:"bytes,2,rep,name=roles,proto3" json:"roles,omitempty"` @@ -458,7 +364,7 @@ func (m *GenerateRequest) Reset() { *m = GenerateRequest{} } func (m *GenerateRequest) String() string { return proto.CompactTextString(m) } func (*GenerateRequest) ProtoMessage() {} func (*GenerateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{7} + return fileDescriptor_11312eec02fd5712, []int{5} } func (m *GenerateRequest) XXX_Unmarshal(b []byte) error { @@ -539,7 +445,7 @@ func (m *GenerateResponse) Reset() { *m = GenerateResponse{} } func (m *GenerateResponse) String() string { return proto.CompactTextString(m) } func (*GenerateResponse) ProtoMessage() {} func (*GenerateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{8} + return fileDescriptor_11312eec02fd5712, []int{6} } func (m *GenerateResponse) XXX_Unmarshal(b []byte) error { @@ -579,7 +485,7 @@ func (m *GrantRequest) Reset() { *m = GrantRequest{} } func (m *GrantRequest) String() string { return proto.CompactTextString(m) } func (*GrantRequest) ProtoMessage() {} func (*GrantRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{9} + return fileDescriptor_11312eec02fd5712, []int{7} } func (m *GrantRequest) XXX_Unmarshal(b []byte) error { @@ -624,7 +530,7 @@ func (m *GrantResponse) Reset() { *m = GrantResponse{} } func (m *GrantResponse) String() string { return proto.CompactTextString(m) } func (*GrantResponse) ProtoMessage() {} func (*GrantResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{10} + return fileDescriptor_11312eec02fd5712, []int{8} } func (m *GrantResponse) XXX_Unmarshal(b []byte) error { @@ -657,7 +563,7 @@ func (m *RevokeRequest) Reset() { *m = RevokeRequest{} } func (m *RevokeRequest) String() string { return proto.CompactTextString(m) } func (*RevokeRequest) ProtoMessage() {} func (*RevokeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{11} + return fileDescriptor_11312eec02fd5712, []int{9} } func (m *RevokeRequest) XXX_Unmarshal(b []byte) error { @@ -702,7 +608,7 @@ func (m *RevokeResponse) Reset() { *m = RevokeResponse{} } func (m *RevokeResponse) String() string { return proto.CompactTextString(m) } func (*RevokeResponse) ProtoMessage() {} func (*RevokeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{12} + return fileDescriptor_11312eec02fd5712, []int{10} } func (m *RevokeResponse) XXX_Unmarshal(b []byte) error { @@ -734,7 +640,7 @@ func (m *InspectRequest) Reset() { *m = InspectRequest{} } func (m *InspectRequest) String() string { return proto.CompactTextString(m) } func (*InspectRequest) ProtoMessage() {} func (*InspectRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{13} + return fileDescriptor_11312eec02fd5712, []int{11} } func (m *InspectRequest) XXX_Unmarshal(b []byte) error { @@ -773,7 +679,7 @@ func (m *InspectResponse) Reset() { *m = InspectResponse{} } func (m *InspectResponse) String() string { return proto.CompactTextString(m) } func (*InspectResponse) ProtoMessage() {} func (*InspectResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{14} + return fileDescriptor_11312eec02fd5712, []int{12} } func (m *InspectResponse) XXX_Unmarshal(b []byte) error { @@ -803,8 +709,9 @@ func (m *InspectResponse) GetAccount() *Account { type TokenRequest struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - RefreshToken string `protobuf:"bytes,2,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"` - TokenExpiry int64 `protobuf:"varint,3,opt,name=token_expiry,json=tokenExpiry,proto3" json:"token_expiry,omitempty"` + Secret string `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty"` + RefreshToken string `protobuf:"bytes,3,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"` + TokenExpiry int64 `protobuf:"varint,4,opt,name=token_expiry,json=tokenExpiry,proto3" json:"token_expiry,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -814,7 +721,7 @@ func (m *TokenRequest) Reset() { *m = TokenRequest{} } func (m *TokenRequest) String() string { return proto.CompactTextString(m) } func (*TokenRequest) ProtoMessage() {} func (*TokenRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{15} + return fileDescriptor_11312eec02fd5712, []int{13} } func (m *TokenRequest) XXX_Unmarshal(b []byte) error { @@ -842,6 +749,13 @@ func (m *TokenRequest) GetId() string { return "" } +func (m *TokenRequest) GetSecret() string { + if m != nil { + return m.Secret + } + return "" +} + func (m *TokenRequest) GetRefreshToken() string { if m != nil { return m.RefreshToken @@ -867,7 +781,7 @@ func (m *TokenResponse) Reset() { *m = TokenResponse{} } func (m *TokenResponse) String() string { return proto.CompactTextString(m) } func (*TokenResponse) ProtoMessage() {} func (*TokenResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{16} + return fileDescriptor_11312eec02fd5712, []int{14} } func (m *TokenResponse) XXX_Unmarshal(b []byte) error { @@ -909,7 +823,7 @@ func (m *Rule) Reset() { *m = Rule{} } func (m *Rule) String() string { return proto.CompactTextString(m) } func (*Rule) ProtoMessage() {} func (*Rule) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{17} + return fileDescriptor_11312eec02fd5712, []int{15} } func (m *Rule) XXX_Unmarshal(b []byte) error { @@ -971,7 +885,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{18} + return fileDescriptor_11312eec02fd5712, []int{16} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -1023,7 +937,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{19} + return fileDescriptor_11312eec02fd5712, []int{17} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -1057,7 +971,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{20} + return fileDescriptor_11312eec02fd5712, []int{18} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -1109,7 +1023,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{21} + return fileDescriptor_11312eec02fd5712, []int{19} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -1140,7 +1054,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{22} + return fileDescriptor_11312eec02fd5712, []int{20} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -1172,7 +1086,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{23} + return fileDescriptor_11312eec02fd5712, []int{21} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -1209,8 +1123,6 @@ func init() { proto.RegisterType((*Account)(nil), "go.micro.auth.Account") proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.Account.MetadataEntry") proto.RegisterType((*Resource)(nil), "go.micro.auth.Resource") - proto.RegisterType((*LoginRequest)(nil), "go.micro.auth.LoginRequest") - proto.RegisterType((*LoginResponse)(nil), "go.micro.auth.LoginResponse") proto.RegisterType((*GenerateRequest)(nil), "go.micro.auth.GenerateRequest") proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.GenerateRequest.MetadataEntry") proto.RegisterType((*GenerateResponse)(nil), "go.micro.auth.GenerateResponse") @@ -1236,65 +1148,63 @@ func init() { } var fileDescriptor_11312eec02fd5712 = []byte{ - // 947 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xdd, 0x8e, 0xdb, 0x44, - 0x14, 0x5e, 0xdb, 0x89, 0xe3, 0x3d, 0x89, 0xb3, 0xd1, 0x74, 0xbb, 0x58, 0xe9, 0x0f, 0x8b, 0x8b, - 0xd0, 0x52, 0xd1, 0x2c, 0x4a, 0x25, 0xfe, 0x2a, 0x21, 0xa2, 0x26, 0x0a, 0x2d, 0x6d, 0x10, 0x56, - 0x51, 0xb9, 0x41, 0x95, 0xd7, 0x39, 0xdd, 0x35, 0x9b, 0xb5, 0xc3, 0xcc, 0x78, 0xc5, 0x3e, 0x01, - 0x77, 0xbc, 0x03, 0x12, 0xb7, 0xf0, 0x44, 0x3c, 0x0c, 0x9a, 0xf1, 0x8c, 0xd7, 0x71, 0x9c, 0x6a, - 0x55, 0x16, 0x89, 0xbb, 0x39, 0x33, 0x67, 0xb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0x4b, 0x35, 0x21, - 0xb9, 0x53, 0xd1, 0x5e, 0x6d, 0xe2, 0xfe, 0xdd, 0x4d, 0xc7, 0x05, 0xd6, 0x58, 0x7f, 0xad, 0x6e, - 0xd5, 0x36, 0x83, 0xc2, 0xb9, 0x5d, 0x7f, 0x58, 0x46, 0x91, 0x8f, 0xd8, 0x1a, 0x4a, 0xf9, 0x49, - 0x5c, 0x43, 0x59, 0x79, 0xf7, 0xfc, 0xad, 0xe1, 0x8f, 0xe0, 0xe8, 0xff, 0x22, 0xf9, 0x0e, 0x1a, - 0x22, 0x4d, 0xa4, 0xfa, 0xa7, 0xaa, 0xf9, 0x6b, 0xf6, 0xef, 0xbd, 0x51, 0xa7, 0x80, 0xff, 0xdb, - 0x80, 0xa6, 0x48, 0x27, 0x23, 0x53, 0xb0, 0xf3, 0x02, 0x26, 0x55, 0x97, 0x56, 0x1a, 0xac, 0x7f, - 0x67, 0xc3, 0x69, 0xc1, 0x7b, 0x0a, 0x76, 0x5e, 0x6d, 0x6b, 0x40, 0x2b, 0xdd, 0xb0, 0x06, 0x54, - 0x29, 0xd1, 0x2d, 0x32, 0x52, 0x74, 0xfb, 0x35, 0x54, 0x34, 0xc8, 0xad, 0xda, 0x33, 0x0d, 0x71, - 0x64, 0xcb, 0xef, 0xf9, 0xc3, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x8f, 0xd3, 0xdd, 0x57, 0xd9, - 0x0b, 0x00, 0x00, + // 924 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4b, 0x6f, 0xdb, 0x46, + 0x10, 0x36, 0x49, 0x89, 0xa2, 0x47, 0x0f, 0x0b, 0x1b, 0xc7, 0x25, 0x94, 0x47, 0x1d, 0xa6, 0x28, + 0xdc, 0xa0, 0x91, 0x0b, 0xe5, 0xd0, 0x47, 0x80, 0xa2, 0x46, 0x24, 0xa8, 0x49, 0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37, 0x47, 0x7f, 0x1b, 0xd0, 0x38, 0xca, 0xf8, 0x29, + 0x79, 0x09, 0x8e, 0x9e, 0x48, 0xe4, 0xfe, 0xf5, 0x83, 0x77, 0xf0, 0xee, 0x5a, 0xbb, 0xc2, 0xb3, + 0x45, 0x5e, 0x40, 0x4b, 0x7d, 0x9c, 0xe4, 0x5e, 0xc5, 0xbb, 0xfc, 0x71, 0x0f, 0xee, 0xaf, 0x33, + 0x17, 0xb1, 0xc6, 0x7a, 0xe1, 0xb9, 0x53, 0xfb, 0x31, 0xa8, 0x38, 0x77, 0xeb, 0x8d, 0x3a, 0xca, + 0xe8, 0x07, 0x70, 0xf4, 0xfe, 0x45, 0xbe, 0x85, 0x46, 0x4e, 0x30, 0xa9, 0x6e, 0x21, 0x35, 0xbb, + 0xdb, 0xe0, 0xe1, 0xb5, 0x3e, 0x45, 0xf8, 0xbf, 0x0c, 0x68, 0xe6, 0x85, 0x60, 0x64, 0x0a, 0xb6, + 0x6c, 0x3d, 0x52, 0x4d, 0xa9, 0xf4, 0x69, 0x0c, 0xee, 0xad, 0xb1, 0x16, 0xb8, 0xa7, 0x60, 0xcb, + 0x3e, 0x59, 0x09, 0x54, 0xea, 0xe3, 0x95, 0x40, 0x95, 0xe6, 0xda, 0x22, 0x47, 0x0a, 0xee, 0xa0, + 0x06, 0x8a, 0x0e, 0x72, 0xa7, 0xd6, 0xa6, 0x43, 0x1c, 0xdb, 0x62, 0xdd, 0x7d, 0xf2, 0x6f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xd8, 0x6c, 0xbf, 0xd6, 0x29, 0x0b, 0x00, 0x00, } diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index 9937569d..334f2369 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -37,7 +37,6 @@ type AuthService interface { Generate(ctx context.Context, in *GenerateRequest, opts ...client.CallOption) (*GenerateResponse, error) Inspect(ctx context.Context, in *InspectRequest, opts ...client.CallOption) (*InspectResponse, error) Token(ctx context.Context, in *TokenRequest, opts ...client.CallOption) (*TokenResponse, error) - Login(ctx context.Context, in *LoginRequest, opts ...client.CallOption) (*LoginResponse, error) } type authService struct { @@ -82,23 +81,12 @@ func (c *authService) Token(ctx context.Context, in *TokenRequest, opts ...clien return out, nil } -func (c *authService) Login(ctx context.Context, in *LoginRequest, opts ...client.CallOption) (*LoginResponse, error) { - req := c.c.NewRequest(c.name, "Auth.Login", in) - out := new(LoginResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - // Server API for Auth service type AuthHandler interface { Generate(context.Context, *GenerateRequest, *GenerateResponse) error Inspect(context.Context, *InspectRequest, *InspectResponse) error Token(context.Context, *TokenRequest, *TokenResponse) error - Login(context.Context, *LoginRequest, *LoginResponse) error } func RegisterAuthHandler(s server.Server, hdlr AuthHandler, opts ...server.HandlerOption) error { @@ -106,7 +94,6 @@ func RegisterAuthHandler(s server.Server, hdlr AuthHandler, opts ...server.Handl Generate(ctx context.Context, in *GenerateRequest, out *GenerateResponse) error Inspect(ctx context.Context, in *InspectRequest, out *InspectResponse) error Token(ctx context.Context, in *TokenRequest, out *TokenResponse) error - Login(ctx context.Context, in *LoginRequest, out *LoginResponse) error } type Auth struct { auth @@ -131,10 +118,6 @@ func (h *authHandler) Token(ctx context.Context, in *TokenRequest, out *TokenRes return h.AuthHandler.Token(ctx, in, out) } -func (h *authHandler) Login(ctx context.Context, in *LoginRequest, out *LoginResponse) error { - return h.AuthHandler.Login(ctx, in, out) -} - // Client API for Accounts service type AccountsService interface { diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index 9c27ecb7..ecc17f08 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -6,7 +6,6 @@ service Auth { rpc Generate(GenerateRequest) returns (GenerateResponse) {}; rpc Inspect(InspectRequest) returns (InspectResponse) {}; rpc Token(TokenRequest) returns (TokenResponse) {}; - rpc Login(LoginRequest) returns (LoginResponse) {}; } service Accounts { @@ -27,8 +26,8 @@ message ListAccountsResponse { } message Token { - string token = 1; - string type = 2; + string access_token = 1; + string refresh_token = 2; int64 created = 3; int64 expiry = 4; string subject = 5; @@ -43,8 +42,7 @@ message Account { repeated string roles = 3; map metadata = 4; string namespace = 5; - string refresh_token = 6; - string provider = 7; + string provider = 6; } message Resource{ @@ -53,15 +51,6 @@ message Resource{ string endpoint = 3; } -message LoginRequest { - string id = 1; - string secret = 2; -} - -message LoginResponse { - Account account = 1; -} - message GenerateRequest { string id = 1; repeated string roles = 2; @@ -100,8 +89,9 @@ message InspectResponse { message TokenRequest { string id = 1; - string refresh_token = 2; - int64 token_expiry = 3; + string secret = 2; + string refresh_token = 3; + int64 token_expiry = 4; } message TokenResponse { diff --git a/auth/service/service.go b/auth/service/service.go index 90c5122c..9c4a6573 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -73,11 +73,11 @@ func (s *svc) Init(opts ...auth.Option) { // we have client credentials and must load a new token // periodically - if len(s.options.ID) > 0 || len(s.options.RefreshToken) > 0 { + if len(s.options.ID) > 0 || len(s.options.Secret) > 0 { tokenTimer := time.NewTicker(time.Minute) go func() { - s.loadToken() + s.refreshToken() for { <-tokenTimer.C @@ -94,7 +94,7 @@ func (s *svc) Init(opts ...auth.Option) { // all the services calling the auth service // at the exact same time time.Sleep(jitter.Do(time.Second * 5)) - s.loadToken() + s.refreshToken() } }() } @@ -107,14 +107,14 @@ func (s *svc) Options() auth.Options { } // Generate a new account -func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { +func (s *svc) Generate(id, secret string, opts ...auth.GenerateOption) (*auth.Account, error) { options := auth.NewGenerateOptions(opts...) rsp, err := s.auth.Generate(context.TODO(), &pb.GenerateRequest{ Id: id, + Secret: secret, Type: options.Type, Roles: options.Roles, - Secret: options.Secret, Metadata: options.Metadata, Provider: options.Provider, Namespace: options.Namespace, @@ -126,16 +126,6 @@ func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e return serializeAccount(rsp.Account), nil } -// Login to an account -func (s *svc) Login(id string, opts ...auth.LoginOption) (*auth.Account, error) { - options := auth.NewLoginOptions(opts...) - rsp, err := s.auth.Login(context.TODO(), &pb.LoginRequest{Id: id, Secret: options.Secret}) - if err != nil { - return nil, err - } - return serializeAccount(rsp.Account), nil -} - // Grant access to a resource func (s *svc) Grant(role string, res *auth.Resource) error { _, err := s.rule.Create(context.TODO(), &pb.CreateRequest{ @@ -204,23 +194,14 @@ func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { // Inspect a token func (s *svc) Inspect(token string) (*auth.Account, error) { - // try to decode JWT locally and fall back to srv if an error - // occurs, TODO: find a better way of determining if the token - // is a JWT, possibly update the interface to take an auth.Token - // and not just the string + // try to decode JWT locally and fall back to srv if an error occurs if len(strings.Split(token, ".")) == 3 && s.jwt != nil { - if tok, err := s.jwt.Inspect(token); err == nil { - return &auth.Account{ - ID: tok.Subject, - Roles: tok.Roles, - Metadata: tok.Metadata, - }, nil + if acc, err := s.jwt.Inspect(token); err == nil { + return acc, nil } } - rsp, err := s.auth.Inspect(context.TODO(), &pb.InspectRequest{ - Token: token, - }) + rsp, err := s.auth.Inspect(context.TODO(), &pb.InspectRequest{Token: token}) if err != nil { return nil, err } @@ -229,13 +210,14 @@ func (s *svc) Inspect(token string) (*auth.Account, error) { } // Token generation using an account ID and secret -func (s *svc) Token(id, refresh string, opts ...auth.TokenOption) (*auth.Token, error) { +func (s *svc) Token(opts ...auth.TokenOption) (*auth.Token, error) { options := auth.NewTokenOptions(opts...) rsp, err := s.auth.Token(context.Background(), &pb.TokenRequest{ - Id: id, - RefreshToken: refresh, - TokenExpiry: int64(options.TokenExpiry.Seconds()), + Id: options.ID, + Secret: options.Secret, + RefreshToken: options.RefreshToken, + TokenExpiry: int64(options.Expiry.Seconds()), }) if err != nil { return nil, err @@ -299,13 +281,22 @@ func (s *svc) loadRules() { s.rules = rsp.Rules } -// loadToken generates a new token for the service to use when making calls -func (s *svc) loadToken() { - rsp, err := s.auth.Token(context.TODO(), &pb.TokenRequest{ - Id: s.Options().ID, - RefreshToken: s.Options().RefreshToken, - TokenExpiry: int64((time.Minute * 15).Seconds()), - }) +// refreshToken generates a new token for the service to use when making calls +func (s *svc) refreshToken() { + req := &pb.TokenRequest{ + TokenExpiry: int64((time.Minute * 15).Seconds()), + } + + if s.Options().Token == nil { + // we do not have a token, use the credentials to get one + req.Id = s.Options().ID + req.Secret = s.Options().Secret + } else { + // we have a token, refresh it + req.RefreshToken = s.Options().Token.RefreshToken + } + + rsp, err := s.auth.Token(context.TODO(), req) s.Lock() defer s.Unlock() @@ -319,23 +310,19 @@ func (s *svc) loadToken() { func serializeToken(t *pb.Token) *auth.Token { return &auth.Token{ - Token: t.Token, - Type: t.Type, - Created: time.Unix(t.Created, 0), - Expiry: time.Unix(t.Expiry, 0), - Subject: t.Subject, - Roles: t.Roles, - Metadata: t.Metadata, + AccessToken: t.AccessToken, + RefreshToken: t.RefreshToken, + Created: time.Unix(t.Created, 0), + Expiry: time.Unix(t.Expiry, 0), } } func serializeAccount(a *pb.Account) *auth.Account { return &auth.Account{ - ID: a.Id, - Roles: a.Roles, - Metadata: a.Metadata, - Provider: a.Provider, - Namespace: a.Namespace, - RefreshToken: a.RefreshToken, + ID: a.Id, + Roles: a.Roles, + Metadata: a.Metadata, + Provider: a.Provider, + Namespace: a.Namespace, } } diff --git a/auth/token/basic/basic.go b/auth/token/basic/basic.go index 34b79f92..364e2f3a 100644 --- a/auth/token/basic/basic.go +++ b/auth/token/basic/basic.go @@ -35,30 +35,19 @@ func NewTokenProvider(opts ...token.Option) token.Provider { } // Generate a token for an account -func (b *Basic) Generate(subject string, opts ...token.GenerateOption) (*auth.Token, error) { +func (b *Basic) Generate(acc *auth.Account, opts ...token.GenerateOption) (*token.Token, error) { options := token.NewGenerateOptions(opts...) - // construct the token - token := auth.Token{ - Subject: subject, - Type: b.String(), - Token: uuid.New().String(), - Created: time.Now(), - Expiry: time.Now().Add(options.Expiry), - Metadata: options.Metadata, - Roles: options.Roles, - Namespace: options.Namespace, - } - // marshal the account to bytes - bytes, err := json.Marshal(token) + bytes, err := json.Marshal(acc) if err != nil { return nil, err } // write to the store + key := uuid.New().String() err = b.store.Write(&store.Record{ - Key: fmt.Sprintf("%v%v", StorePrefix, token.Token), + Key: fmt.Sprintf("%v%v", StorePrefix, key), Value: bytes, Expiry: options.Expiry, }) @@ -67,11 +56,15 @@ func (b *Basic) Generate(subject string, opts ...token.GenerateOption) (*auth.To } // return the token - return &token, nil + return &token.Token{ + Token: key, + Created: time.Now(), + Expiry: time.Now().Add(options.Expiry), + }, nil } // Inspect a token -func (b *Basic) Inspect(t string) (*auth.Token, error) { +func (b *Basic) Inspect(t string) (*auth.Account, error) { // lookup the token in the store recs, err := b.store.Read(StorePrefix + t) if err == store.ErrNotFound { @@ -82,18 +75,12 @@ func (b *Basic) Inspect(t string) (*auth.Token, error) { bytes := recs[0].Value // unmarshal the bytes - var tok *auth.Token - if err := json.Unmarshal(bytes, &tok); err != nil { + var acc *auth.Account + if err := json.Unmarshal(bytes, &acc); err != nil { return nil, err } - // ensure the token hasn't expired, the store should - // expire the token but we're checking again - if tok.Expiry.Unix() < time.Now().Unix() { - return nil, token.ErrInvalidToken - } - - return tok, err + return acc, nil } // String returns basic diff --git a/auth/token/jwt/jwt.go b/auth/token/jwt/jwt.go index e35ac5e7..a633736d 100644 --- a/auth/token/jwt/jwt.go +++ b/auth/token/jwt/jwt.go @@ -11,7 +11,9 @@ import ( // authClaims to be encoded in the JWT type authClaims struct { + Type string `json:"type"` Roles []string `json:"roles"` + Provider string `json:"provider"` Metadata map[string]string `json:"metadata"` Namespace string `json:"namespace"` @@ -31,7 +33,7 @@ func NewTokenProvider(opts ...token.Option) token.Provider { } // Generate a new JWT -func (j *JWT) Generate(subject string, opts ...token.GenerateOption) (*auth.Token, error) { +func (j *JWT) Generate(acc *auth.Account, opts ...token.GenerateOption) (*token.Token, error) { // decode the private key priv, err := base64.StdEncoding.DecodeString(j.opts.PrivateKey) if err != nil { @@ -50,8 +52,8 @@ func (j *JWT) Generate(subject string, opts ...token.GenerateOption) (*auth.Toke // generate the JWT expiry := time.Now().Add(options.Expiry) t := jwt.NewWithClaims(jwt.SigningMethodRS256, authClaims{ - options.Roles, options.Metadata, options.Namespace, jwt.StandardClaims{ - Subject: subject, + acc.Type, acc.Roles, acc.Provider, acc.Metadata, acc.Namespace, jwt.StandardClaims{ + Subject: acc.ID, ExpiresAt: expiry.Unix(), }, }) @@ -61,20 +63,15 @@ func (j *JWT) Generate(subject string, opts ...token.GenerateOption) (*auth.Toke } // return the token - return &auth.Token{ - Subject: subject, - Token: tok, - Type: j.String(), - Created: time.Now(), - Expiry: expiry, - Roles: options.Roles, - Metadata: options.Metadata, - Namespace: options.Namespace, + return &token.Token{ + Token: tok, + Expiry: expiry, + Created: time.Now(), }, nil } // Inspect a JWT -func (j *JWT) Inspect(t string) (*auth.Token, error) { +func (j *JWT) Inspect(t string) (*auth.Account, error) { // decode the public key pub, err := base64.StdEncoding.DecodeString(j.opts.PublicKey) if err != nil { @@ -99,11 +96,12 @@ func (j *JWT) Inspect(t string) (*auth.Token, error) { } // return the token - return &auth.Token{ - Token: t, - Subject: claims.Subject, - Metadata: claims.Metadata, + return &auth.Account{ + ID: claims.Subject, + Type: claims.Type, Roles: claims.Roles, + Provider: claims.Provider, + Metadata: claims.Metadata, Namespace: claims.Namespace, }, nil } diff --git a/auth/token/options.go b/auth/token/options.go index 2e8d3bbd..8afe174d 100644 --- a/auth/token/options.go +++ b/auth/token/options.go @@ -53,12 +53,6 @@ func NewOptions(opts ...Option) Options { type GenerateOptions struct { // Expiry for the token Expiry time.Duration - // Metadata associated with the account - Metadata map[string]string - // Roles/scopes associated with the account - Roles []string - // Namespace the account belongs too - Namespace string } type GenerateOption func(o *GenerateOptions) @@ -70,27 +64,6 @@ func WithExpiry(d time.Duration) GenerateOption { } } -// WithMetadata for the token -func WithMetadata(md map[string]string) func(o *GenerateOptions) { - return func(o *GenerateOptions) { - o.Metadata = md - } -} - -// WithRoles for the token -func WithRoles(rs ...string) func(o *GenerateOptions) { - return func(o *GenerateOptions) { - o.Roles = rs - } -} - -// WithNamespace for the token -func WithNamespace(n string) func(o *GenerateOptions) { - return func(o *GenerateOptions) { - o.Namespace = n - } -} - // NewGenerateOptions from a slice of options func NewGenerateOptions(opts ...GenerateOption) GenerateOptions { var options GenerateOptions diff --git a/auth/token/token.go b/auth/token/token.go index da8409f1..61b1b6f5 100644 --- a/auth/token/token.go +++ b/auth/token/token.go @@ -2,6 +2,7 @@ package token import ( "errors" + "time" "github.com/micro/go-micro/v2/auth" ) @@ -17,7 +18,16 @@ var ( // Provider generates and inspects tokens type Provider interface { - Generate(subject string, opts ...GenerateOption) (*auth.Token, error) - Inspect(token string) (*auth.Token, error) + Generate(account *auth.Account, opts ...GenerateOption) (*Token, error) + Inspect(token string) (*auth.Account, error) String() string } + +type Token struct { + // The actual token + Token string `json:"token"` + // Time of token creation + Created time.Time `json:"created"` + // Time of token expiry + Expiry time.Time `json:"expiry"` +} diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 5f14c25d..0fa955bf 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -135,7 +135,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R // was passed with the request, set the service token var srvToken string if g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { - srvToken = g.opts.Auth.Options().Token.Token + srvToken = g.opts.Auth.Options().Token.AccessToken } if (opts.ServiceToken || len(header["authorization"]) == 0) && len(srvToken) > 0 { header["authorization"] = auth.BearerScheme + srvToken diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 0af37fdd..c984391b 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -671,10 +671,6 @@ func (c *cmd) Before(ctx *cli.Context) error { authOpts = append(authOpts, auth.PublicKey(ctx.String("auth_public_key"))) } - if len(ctx.String("auth_private_key")) > 0 { - authOpts = append(authOpts, auth.PrivateKey(ctx.String("auth_private_key"))) - } - if name := ctx.String("auth_provider"); len(name) > 0 { p, ok := DefaultAuthProviders[name] if !ok { From 9cbbd71855ec06d5822d878a0338baa6b07c3710 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 1 Apr 2020 14:26:24 +0100 Subject: [PATCH 482/788] Remove default login --- auth/default.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/auth/default.go b/auth/default.go index e04305cf..d9f973e9 100644 --- a/auth/default.go +++ b/auth/default.go @@ -44,11 +44,6 @@ func (n *noop) Generate(id, secret string, opts ...GenerateOption) (*Account, er }, nil } -// Login to an existing account -func (n *noop) Login(opts ...LoginOption) (*Account, error) { - return &Account{}, nil -} - // Grant access to a resource func (n *noop) Grant(role string, res *Resource) error { return nil From 26cb6bf5b9f4b2a31e08269f8ec089ead8caefef Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 1 Apr 2020 14:27:56 +0100 Subject: [PATCH 483/788] Remove Legacy JWT fields --- auth/service/proto/auth.pb.go | 161 +++++++++++++--------------------- auth/service/proto/auth.proto | 4 - 2 files changed, 63 insertions(+), 102 deletions(-) diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index fc1527f4..78064eb4 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -119,17 +119,13 @@ func (m *ListAccountsResponse) GetAccounts() []*Account { } type Token struct { - AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"` - RefreshToken string `protobuf:"bytes,2,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"` - Created int64 `protobuf:"varint,3,opt,name=created,proto3" json:"created,omitempty"` - Expiry int64 `protobuf:"varint,4,opt,name=expiry,proto3" json:"expiry,omitempty"` - Subject string `protobuf:"bytes,5,opt,name=subject,proto3" json:"subject,omitempty"` - Roles []string `protobuf:"bytes,6,rep,name=roles,proto3" json:"roles,omitempty"` - Metadata map[string]string `protobuf:"bytes,7,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Namespace string `protobuf:"bytes,8,opt,name=namespace,proto3" json:"namespace,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"` + RefreshToken string `protobuf:"bytes,2,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"` + Created int64 `protobuf:"varint,3,opt,name=created,proto3" json:"created,omitempty"` + Expiry int64 `protobuf:"varint,4,opt,name=expiry,proto3" json:"expiry,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Token) Reset() { *m = Token{} } @@ -185,34 +181,6 @@ func (m *Token) GetExpiry() int64 { return 0 } -func (m *Token) GetSubject() string { - if m != nil { - return m.Subject - } - return "" -} - -func (m *Token) GetRoles() []string { - if m != nil { - return m.Roles - } - return nil -} - -func (m *Token) GetMetadata() map[string]string { - if m != nil { - return m.Metadata - } - return nil -} - -func (m *Token) GetNamespace() string { - if m != nil { - return m.Namespace - } - return "" -} - type Account struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` @@ -1119,7 +1087,6 @@ func init() { proto.RegisterType((*ListAccountsRequest)(nil), "go.micro.auth.ListAccountsRequest") proto.RegisterType((*ListAccountsResponse)(nil), "go.micro.auth.ListAccountsResponse") proto.RegisterType((*Token)(nil), "go.micro.auth.Token") - proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.Token.MetadataEntry") proto.RegisterType((*Account)(nil), "go.micro.auth.Account") proto.RegisterMapType((map[string]string)(nil), "go.micro.auth.Account.MetadataEntry") proto.RegisterType((*Resource)(nil), "go.micro.auth.Resource") @@ -1148,63 +1115,61 @@ func init() { } var fileDescriptor_11312eec02fd5712 = []byte{ - // 924 bytes of a gzipped FileDescriptorProto + // 888 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4b, 0x6f, 0xdb, 0x46, - 0x10, 0x36, 0x49, 0x89, 0xa2, 0x47, 0x0f, 0x0b, 0x1b, 0xc7, 0x25, 0x94, 0x47, 0x1d, 0xa6, 0x28, - 0xdc, 0xa0, 0x91, 0x0b, 0xe5, 0xd0, 0x47, 0x80, 0xa2, 0x46, 0x24, 0xa8, 0x49, 0x1b, 0x15, 0x25, - 0x52, 0xa4, 0x97, 0x22, 0xa0, 0xa9, 0xa9, 0xcd, 0x5a, 0x26, 0xd9, 0xdd, 0xa5, 0x51, 0x5f, 0x7a, - 0xed, 0xad, 0xbf, 0xa2, 0x3f, 0xa7, 0x3f, 0xa1, 0xf7, 0xfe, 0x89, 0x1e, 0x0a, 0xee, 0x83, 0x16, - 0x29, 0xca, 0x10, 0x5a, 0x1f, 0x72, 0xdb, 0x79, 0xec, 0xec, 0x7c, 0xdf, 0x0c, 0x87, 0x03, 0x1f, - 0x9f, 0x44, 0xfc, 0x34, 0x3b, 0x1e, 0x86, 0xc9, 0xf9, 0xe1, 0x79, 0x14, 0xd2, 0xe4, 0xf0, 0x24, - 0x79, 0x2c, 0x0f, 0x41, 0xc6, 0x4f, 0x0f, 0x19, 0xd2, 0x8b, 0x28, 0xc4, 0xc3, 0x94, 0x26, 0x5c, - 0xaa, 0x86, 0xe2, 0x48, 0xba, 0x27, 0xc9, 0x50, 0xf8, 0x0d, 0x73, 0xa5, 0x77, 0x1b, 0x6e, 0x7d, - 0x1d, 0x31, 0x7e, 0x14, 0x86, 0x49, 0x16, 0x73, 0xe6, 0xe3,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f8, 0xc8, 0x8f, 0x79, 0x5a, 0x17, 0xc1, 0x22, 0x43, 0x85, 0x5f, 0x0a, 0x9f, 0x99, 0x9f, 0x18, - 0xde, 0x3f, 0x06, 0xb4, 0x14, 0xc9, 0xa4, 0x07, 0x66, 0x34, 0x57, 0xd7, 0xcc, 0x68, 0x4e, 0x08, - 0x34, 0xf8, 0x65, 0xaa, 0x2f, 0x89, 0xf3, 0x15, 0x40, 0x6b, 0x19, 0xe0, 0x17, 0x4b, 0x00, 0x1b, - 0x02, 0xe0, 0x7b, 0xf5, 0x85, 0xdc, 0x0c, 0x62, 0xb3, 0x02, 0x91, 0x0c, 0xc0, 0x49, 0x69, 0x72, - 0x11, 0xcd, 0x91, 0xba, 0xb6, 0x30, 0x16, 0xf2, 0xff, 0x83, 0x3f, 0x03, 0xc7, 0x47, 0x96, 0x64, - 0x34, 0xc4, 0x1c, 0x6e, 0xfe, 0xa2, 0xba, 0x28, 0xce, 0xb5, 0x14, 0x0c, 0xc0, 0xc1, 0x78, 0x9e, - 0x26, 0x51, 0xcc, 0x45, 0xc3, 0x6c, 0xfb, 0x85, 0xec, 0xfd, 0x61, 0xc2, 0xce, 0x14, 0x63, 0xa4, - 0x01, 0x47, 0xd5, 0xfd, 0x2b, 0xb4, 0x16, 0x14, 0x9a, 0xcb, 0x14, 0x7e, 0xb9, 0x44, 0xa1, 0x25, - 0x28, 0xfc, 0xb0, 0x42, 0x61, 0x25, 0xee, 0x66, 0x54, 0x36, 0xaa, 0x54, 0xee, 0x81, 0xcd, 0x30, - 0xa4, 0xa8, 0x5b, 0x57, 0x49, 0x05, 0x52, 0xbb, 0x8c, 0xb4, 0xa0, 0xbd, 0x75, 0x93, 0xb4, 0x8f, - 0xa1, 0x7f, 0x85, 0x46, 0x0d, 0x83, 0x8f, 0xa0, 0xa5, 0x3e, 0x72, 0x11, 0x63, 0xfd, 0x2c, 0xd0, - 0x6e, 0xde, 0x6b, 0xe8, 0x4c, 0x69, 0x10, 0x73, 0x4d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, 0xf7, 0x02, 0xf6, + 0xab, 0xdb, 0x2c, 0x4b, 0x13, 0x86, 0x64, 0x0c, 0xdd, 0x50, 0xed, 0x39, 0xc6, 0xa1, 0x75, 0xd4, + 0x1b, 0x1f, 0xf8, 0x15, 0x40, 0x5f, 0x7d, 0x12, 0x94, 0x71, 0xde, 0x6f, 0x06, 0xb4, 0x5f, 0xa5, + 0xe7, 0x98, 0x90, 0x07, 0xd0, 0x0f, 0xa3, 0x08, 0x19, 0x7b, 0xc3, 0x0b, 0xdb, 0x31, 0x0e, 0x8d, + 0xa3, 0xdd, 0xa0, 0x27, 0xf7, 0x64, 0xc8, 0x43, 0x18, 0x50, 0xfc, 0x89, 0x22, 0x3b, 0x53, 0x31, + 0xa6, 0x88, 0xe9, 0xab, 0x4d, 0x19, 0xe4, 0x40, 0x27, 0xa2, 0x18, 0x72, 0x5c, 0x38, 0xd6, 0xa1, + 0x71, 0x64, 0x05, 0xda, 0x24, 0x07, 0x60, 0xe3, 0x2f, 0x59, 0x4c, 0x57, 0x4e, 0x4b, 0x38, 0x94, + 0xe5, 0xfd, 0x63, 0x40, 0x47, 0x55, 0x46, 0x86, 0x60, 0xc6, 0x0b, 0x95, 0xdb, 0x8c, 0x17, 0x84, + 0x40, 0x8b, 0xaf, 0x32, 0x54, 0x99, 0xc4, 0x9a, 0xec, 0x43, 0x9b, 0xa6, 0x4b, 0x64, 0x8e, 0x75, + 0x68, 0x1d, 0xed, 0x06, 0xd2, 0x20, 0x5f, 0x42, 0xf7, 0x02, 0x79, 0xb8, 0x08, 0x79, 0xe8, 0xb4, + 0x04, 0xfb, 0x0f, 0x9a, 0xd9, 0xfb, 0x2f, 0x55, 0xd8, 0x34, 0xe1, 0x74, 0x15, 0x94, 0x5f, 0x91, + 0xbb, 0xb0, 0x9b, 0x84, 0x17, 0xc8, 0xb2, 0x30, 0x42, 0xa7, 0x2d, 0x12, 0x5e, 0x6d, 0x10, 0x17, + 0xba, 0x19, 0x4d, 0x2f, 0xe3,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x00, } diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index ecc17f08..c42d1631 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -30,10 +30,6 @@ message Token { string refresh_token = 2; int64 created = 3; int64 expiry = 4; - string subject = 5; - repeated string roles = 6; - map metadata = 7; - string namespace = 8; } message Account { From bb51b8203e5fe094d8ff18fbe2c8fb01b54cdd58 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Wed, 1 Apr 2020 15:40:15 +0200 Subject: [PATCH 484/788] Runtime logs (#1447) * Runtime logs * Slightly broken * Pushing for diff * Log trailing works locally * LogsOptions * Comments and streamcount support for local logs * Adding kubernetes logs * Fixing k8s logs * K8s fixes * StreamCount is now nuked * PR comments * PR comments again * Fix typo --- go.mod | 19 +- go.sum | 53 +++ runtime/default.go | 79 ++++ runtime/kubernetes/kubernetes.go | 47 +++ runtime/kubernetes/kubernetes_logs.go | 170 ++++++++ runtime/options.go | 25 ++ runtime/runtime.go | 13 + runtime/service/proto/runtime.pb.go | 471 +++++++++------------- runtime/service/proto/runtime.pb.micro.go | 94 ++++- runtime/service/proto/runtime.proto | 24 ++ runtime/service/service.go | 48 +++ 11 files changed, 744 insertions(+), 299 deletions(-) create mode 100644 runtime/kubernetes/kubernetes_logs.go diff --git a/go.mod b/go.mod index 02f6f3dc..99ad210d 100644 --- a/go.mod +++ b/go.mod @@ -6,13 +6,8 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/beevik/ntp v0.2.0 github.com/bitly/go-simplejson v0.5.0 - github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect github.com/bwmarrin/discordgo v0.20.2 - github.com/coreos/bbolt v1.3.3 // indirect github.com/coreos/etcd v3.3.18+incompatible - github.com/coreos/go-semver v0.3.0 // indirect - github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect - github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 @@ -23,27 +18,24 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/go-acme/lego/v3 v3.3.0 github.com/go-playground/universal-translator v0.17.0 // indirect - github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.3.2 github.com/google/go-cmp v0.4.0 // indirect github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/websocket v1.4.1 - github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect - github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.9.5 github.com/hashicorp/hcl v1.0.0 + github.com/hpcloud/tail v1.0.0 github.com/imdario/mergo v0.3.8 - github.com/jonboulle/clockwork v0.1.0 // indirect github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 github.com/json-iterator/go v1.1.9 // indirect github.com/kr/pretty v0.1.0 - github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 github.com/mholt/certmagic v0.9.3 github.com/micro/cli/v2 v2.1.2 + github.com/micro/go-micro v1.18.0 github.com/micro/mdns v0.3.0 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 @@ -53,20 +45,13 @@ require ( github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 - github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 - github.com/technoweenie/multipartstreamer v1.0.1 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect - github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect - go.etcd.io/bbolt v1.3.3 // indirect go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 - golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 // indirect google.golang.org/grpc v1.26.0 - gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 - sigs.k8s.io/yaml v1.1.0 // indirect ) diff --git a/go.sum b/go.sum index 57ad009a..f218c3b2 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,10 @@ github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvd github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 h1:ygIc8M6trr62pF5DucadTWGdEB4mEyvzi0e2nbcmcyA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= +github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= @@ -64,6 +66,8 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= +github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= +github.com/bwmarrin/discordgo v0.20.1/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= @@ -80,6 +84,7 @@ github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0 h1:xjvXQWABwS2uiv3TWgQt5Uth60Gu86LTGZXMJkjc7rY= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= +github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVlf61smEIq1nwLLAjQVEK2EADoW3CX9AuT+8= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= @@ -88,6 +93,7 @@ github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDG github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= @@ -107,6 +113,7 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decker502/dnspod-go v0.2.0/go.mod h1:qsurYu1FgxcDwfSwXJdLt4kRsBLZeosEb9uq4Sy+08g= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= @@ -114,6 +121,7 @@ github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s9 github.com/dnsimple/dnsimple-go v0.30.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v1.4.2-0.20190710153559-aa8249ae1b8b/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23 h1:oqgGT9O61YAYvI41EBsLePOr+LE6roB0xY4gpkZuFSE= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= @@ -127,6 +135,7 @@ github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 h1:jFGzikHboUMRXmMBt github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1/go.mod h1:HvODWzv6Y6kBf3Ah2WzN1bHjDUezGLaAhwuWVwfpEJs= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch/v5 v5.0.0 h1:dKTrUeykyQwKb/kx7Z+4ukDs6l+4L41HqG1XHnhX7WE= @@ -139,12 +148,14 @@ github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXj github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsouza/go-dockerclient v1.4.4/go.mod h1:PrwszSL5fbmsESocROrOGq/NULMXRw+bajY0ltzD6MA= github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4GGn3Hig= github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= +github.com/go-acme/lego/v3 v3.1.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= github.com/go-acme/lego/v3 v3.3.0 h1:6BePZsOiYA4/w+M7QDytxQtMfCipMPGnWAHs9pWks98= github.com/go-acme/lego/v3 v3.3.0/go.mod h1:iGSY2vQrvQs3WezicSB/oVbO2eCrD88dpWPwb1qLqu0= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= @@ -152,10 +163,13 @@ github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-log/log v0.1.0/go.mod h1:4mBwpdRMFLiuXZDCwU2lKQFsoSCo72j3HqBK9d81N2M= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -170,6 +184,7 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -234,6 +249,7 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= +github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd/go.mod h1:3LVOLeyx9XVvwPgrt2be44XgSqndprz1G18rSk8KD84= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= @@ -247,6 +263,7 @@ github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1/go.mod h1:DFXrEwSR github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= @@ -271,17 +288,22 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= +github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ= +github.com/lucas-clemente/quic-go v0.12.1/go.mod h1:UXJJPE4RfFef/xPO5wQm0tITK8gNfqwTxjbE7s3Vb8s= +github.com/lucas-clemente/quic-go v0.13.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= github.com/lucas-clemente/quic-go v0.14.1 h1:c1aKoBZKOPA+49q96B1wGkibyPP0AxYh45WuAoq+87E= github.com/lucas-clemente/quic-go v0.14.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ= github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE= github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= +github.com/marten-seemann/qtls v0.3.2/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -290,14 +312,23 @@ github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mholt/certmagic v0.7.5/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= +github.com/mholt/certmagic v0.8.3/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU= github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= +github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= +github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= +github.com/micro/go-micro v1.16.0/go.mod h1:A0F58bHLh2m0LAI9QyhvmbN8c1cxhAZo3cM6s+iDsrM= +github.com/micro/go-micro v1.18.0 h1:gP70EZVHpJuUIT0YWth192JmlIci+qMOEByHm83XE9E= +github.com/micro/go-micro v1.18.0/go.mod h1:klwUJL1gkdY1MHFyz+fFJXn52dKcty4hoe95Mp571AA= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= +github.com/micro/protoc-gen-micro v1.0.0/go.mod h1:C8ij4DJhapBmypcT00AXdb0cZ675/3PqUO02buWWqbE= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -319,16 +350,20 @@ github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= +github.com/nats-io/nats-server/v2 v2.1.0/go.mod h1:r5y0WgCag0dTj/qiHkHrXAcKQ/f5GMOZaEGdoxxnJ4I= github.com/nats-io/nats-server/v2 v2.1.4 h1:BILRnsJ2Yb/fefiFbBWADpViGF69uh4sxe8poVDQ06g= github.com/nats-io/nats-server/v2 v2.1.4/go.mod h1:Jw1Z28soD/QasIA2uWjXyM9El1jly3YwyFOuR8tH1rg= +github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= +github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= +github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= @@ -421,6 +456,7 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc h1:yUaosFVTJwnltaHbSNC3i82I92quFs+OFPRl8kNMVwo= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= @@ -447,28 +483,35 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.2.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.12.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw= golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -513,7 +556,9 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 h1:MsuvTghUPjX762sGLnGsxC3HM0B5r83wEtYcYR8/vRs= golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -537,6 +582,7 @@ golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -546,10 +592,12 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 h1:Hynbrlo6LbYI3H1IqXpkVDOcX/3HiPdhVEuyj5a59RM= @@ -579,6 +627,7 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -611,6 +660,7 @@ google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1 h1:aQktFqmDE2yjveXJlVIfslDFmFnUXSqG0i6KRcJAeMc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= @@ -620,6 +670,8 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= @@ -631,6 +683,7 @@ gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= diff --git a/runtime/default.go b/runtime/default.go index c9b381be..125fd9b1 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -2,9 +2,16 @@ package runtime import ( "errors" + "fmt" + "io" + "log" + "os" + "path/filepath" + "strings" "sync" "time" + "github.com/hpcloud/tail" "github.com/micro/go-micro/v2/logger" ) @@ -169,6 +176,11 @@ func (r *runtime) run(events <-chan Event) { } } +func logFile(serviceName string) string { + name := strings.Replace(serviceName, "/", "-", -1) + return filepath.Join(os.TempDir(), fmt.Sprintf("%v.log", name)) +} + // Create creates a new service which is then started by runtime func (r *runtime) Create(s *Service, opts ...CreateOption) error { r.Lock() @@ -191,6 +203,17 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error { // create new service service := newService(s, options) + f, err := os.OpenFile(logFile(service.Name), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + logger.Info(f, err) + if err != nil { + log.Fatal(err) + } + + if service.output != nil { + service.output = io.MultiWriter(service.output, f) + } else { + service.output = f + } // start the service if err := service.Start(); err != nil { return err @@ -202,6 +225,62 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error { return nil } +// @todo: Getting existing lines is not supported yet. +// The reason for this is because it's hard to calculate line offset +// as opposed to character offset. +// This logger streams by default and only supports the `StreamCount` option. +func (r *runtime) Logs(s *Service, options ...LogsOption) (LogStream, error) { + lopts := LogsOptions{} + for _, o := range options { + o(&lopts) + } + ret := &logStream{ + service: s.Name, + stream: make(chan LogRecord), + stop: make(chan bool), + } + t, err := tail.TailFile(logFile(s.Name), tail.Config{Follow: true, Location: &tail.SeekInfo{ + Whence: 2, + Offset: 0, + }, Logger: tail.DiscardingLogger}) + if err != nil { + return nil, err + } + ret.tail = t + go func() { + for line := range t.Lines { + ret.stream <- LogRecord{Message: line.Text} + } + }() + return ret, nil +} + +type logStream struct { + tail *tail.Tail + service string + stream chan LogRecord + stop chan bool +} + +func (l *logStream) Chan() chan LogRecord { + return l.stream +} + +func (l *logStream) Stop() error { + // @todo seems like this is causing a hangup + //err := l.tail.Stop() + //if err != nil { + // return err + //} + select { + case <-l.stop: + return nil + default: + close(l.stop) + } + return nil +} + // Read returns all instances of requested service // If no service name is provided we return all the track services. func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) { diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index b0e68882..4924b64d 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -301,6 +301,53 @@ func (k *kubernetes) Init(opts ...runtime.Option) error { return nil } +func (k *kubernetes) Logs(s *runtime.Service, options ...runtime.LogsOption) (runtime.LogStream, error) { + klo := newLog(k.client, s.Name, options...) + stream, err := klo.Stream() + if err != nil { + return nil, err + } + // If requested, also read existing records and stream those too + if klo.options.Count > 0 { + go func() { + records, err := klo.Read() + if err != nil { + logger.Errorf("Failed to get logs for service '%v' from k8s: %v", err) + return + } + // @todo: this might actually not run before podLogStream starts + // and might cause out of order log retrieval at the receiving end. + // A better approach would probably to suppor this inside the `klog.Stream` method. + for _, record := range records { + stream.Chan() <- record + } + }() + } + return stream, nil +} + +type kubeStream struct { + // the k8s log stream + stream chan runtime.LogRecord + // the stop chan + stop chan bool +} + +func (k *kubeStream) Chan() chan runtime.LogRecord { + return k.stream +} + +func (k *kubeStream) Stop() error { + select { + case <-k.stop: + return nil + default: + close(k.stop) + close(k.stream) + } + return nil +} + // Creates a service func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) error { k.Lock() diff --git a/runtime/kubernetes/kubernetes_logs.go b/runtime/kubernetes/kubernetes_logs.go new file mode 100644 index 00000000..68b556f2 --- /dev/null +++ b/runtime/kubernetes/kubernetes_logs.go @@ -0,0 +1,170 @@ +// Package kubernetes taken from https://github.com/micro/go-micro/blob/master/debug/log/kubernetes/kubernetes.go +// There are some modifications compared to the other files as +// this package doesn't provide write functionality. +// With the write functionality gone, structured logs also go away. +package kubernetes + +import ( + "bufio" + "fmt" + "os" + "strconv" + "time" + + "github.com/micro/go-micro/v2/runtime" + "github.com/micro/go-micro/v2/util/kubernetes/client" +) + +type klog struct { + client client.Client + serviceName string + options runtime.LogsOptions +} + +func (k *klog) podLogStream(podName string, stream *kubeStream) { + p := make(map[string]string) + p["follow"] = "true" + + // get the logs for the pod + body, err := k.client.Log(&client.Resource{ + Name: podName, + Kind: "pod", + }, client.LogParams(p)) + + if err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + return + } + + s := bufio.NewScanner(body) + defer body.Close() + + for { + select { + case <-stream.stop: + return + default: + if s.Scan() { + record := runtime.LogRecord{ + Message: s.Text(), + } + stream.stream <- record + } else { + // TODO: is there a blocking call + // rather than a sleep loop? + time.Sleep(time.Second) + } + } + } +} + +func (k *klog) getMatchingPods() ([]string, error) { + r := &client.Resource{ + Kind: "pod", + Value: new(client.PodList), + } + + l := make(map[string]string) + + l["name"] = client.Format(k.serviceName) + // TODO: specify micro:service + // l["micro"] = "service" + + if err := k.client.Get(r, l); err != nil { + return nil, err + } + + var matches []string + + for _, p := range r.Value.(*client.PodList).Items { + // find labels that match the name + if p.Metadata.Labels["name"] == client.Format(k.serviceName) { + matches = append(matches, p.Metadata.Name) + } + } + + return matches, nil +} + +func (k *klog) Read() ([]runtime.LogRecord, error) { + pods, err := k.getMatchingPods() + if err != nil { + return nil, err + } + + var records []runtime.LogRecord + + for _, pod := range pods { + logParams := make(map[string]string) + + //if !opts.Since.Equal(time.Time{}) { + // logParams["sinceSeconds"] = strconv.Itoa(int(time.Since(opts.Since).Seconds())) + //} + + if k.options.Count != 0 { + logParams["tailLines"] = strconv.Itoa(int(k.options.Count)) + } + + if k.options.Stream == true { + logParams["follow"] = "true" + } + + logs, err := k.client.Log(&client.Resource{ + Name: pod, + Kind: "pod", + }, client.LogParams(logParams)) + + if err != nil { + return nil, err + } + defer logs.Close() + + s := bufio.NewScanner(logs) + + for s.Scan() { + record := runtime.LogRecord{ + Message: s.Text(), + } + // record.Metadata["pod"] = pod + records = append(records, record) + } + } + + // sort the records + // sort.Slice(records, func(i, j int) bool { return records[i].Timestamp.Before(records[j].Timestamp) }) + + return records, nil +} + +func (k *klog) Stream() (runtime.LogStream, error) { + // find the matching pods + pods, err := k.getMatchingPods() + if err != nil { + return nil, err + } + + stream := &kubeStream{ + stream: make(chan runtime.LogRecord), + stop: make(chan bool), + } + + // stream from the individual pods + for _, pod := range pods { + go k.podLogStream(pod, stream) + } + + return stream, nil +} + +// NewLog returns a configured Kubernetes logger +func newLog(client client.Client, serviceName string, opts ...runtime.LogsOption) *klog { + klog := &klog{ + serviceName: serviceName, + client: client, + } + for _, o := range opts { + o(&klog.options) + } + + return klog +} diff --git a/runtime/options.go b/runtime/options.go index 489c6ee7..3ae7f506 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -149,3 +149,28 @@ func ReadType(t string) ReadOption { o.Type = t } } + +// LogsOption configures runtime logging +type LogsOption func(o *LogsOptions) + +// LogsOptions configure runtime logging +type LogsOptions struct { + // How many existing lines to show + Count int64 + // Stream new lines? + Stream bool +} + +// LogsExistingCount confiures how many existing lines to show +func LogsCount(count int64) LogsOption { + return func(l *LogsOptions) { + l.Count = count + } +} + +// LogsStream configures whether to stream new lines +func LogsStream(stream bool) LogsOption { + return func(l *LogsOptions) { + l.Stream = stream + } +} diff --git a/runtime/runtime.go b/runtime/runtime.go index ce1b03f3..e7ece1f9 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -35,6 +35,19 @@ type Runtime interface { Start() error // Stop shuts down the runtime Stop() error + // Logs + Logs(*Service, ...LogsOption) (LogStream, error) +} + +// Stream returns a log stream +type LogStream interface { + Chan() chan LogRecord + Stop() error +} + +type LogRecord struct { + Message string + Metadata map[string]string } // Scheduler is a runtime service scheduler diff --git a/runtime/service/proto/runtime.pb.go b/runtime/service/proto/runtime.pb.go index f51d25dc..2ac1af66 100644 --- a/runtime/service/proto/runtime.pb.go +++ b/runtime/service/proto/runtime.pb.go @@ -1,15 +1,11 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: runtime/service/proto/runtime.proto +// source: micro/go-micro/runtime/service/proto/runtime.proto package go_micro_runtime import ( - context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" math "math" ) @@ -42,7 +38,7 @@ func (m *Service) Reset() { *m = Service{} } func (m *Service) String() string { return proto.CompactTextString(m) } func (*Service) ProtoMessage() {} func (*Service) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{0} + return fileDescriptor_4bc91a8efec81434, []int{0} } func (m *Service) XXX_Unmarshal(b []byte) error { @@ -105,7 +101,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{1} + return fileDescriptor_4bc91a8efec81434, []int{1} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -176,7 +172,7 @@ func (m *CreateOptions) Reset() { *m = CreateOptions{} } func (m *CreateOptions) String() string { return proto.CompactTextString(m) } func (*CreateOptions) ProtoMessage() {} func (*CreateOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{2} + return fileDescriptor_4bc91a8efec81434, []int{2} } func (m *CreateOptions) XXX_Unmarshal(b []byte) error { @@ -251,7 +247,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{3} + return fileDescriptor_4bc91a8efec81434, []int{3} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -296,7 +292,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{4} + return fileDescriptor_4bc91a8efec81434, []int{4} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -333,7 +329,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{5} + return fileDescriptor_4bc91a8efec81434, []int{5} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -386,7 +382,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{6} + return fileDescriptor_4bc91a8efec81434, []int{6} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -425,7 +421,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{7} + return fileDescriptor_4bc91a8efec81434, []int{7} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -464,7 +460,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{8} + return fileDescriptor_4bc91a8efec81434, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -502,7 +498,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{9} + return fileDescriptor_4bc91a8efec81434, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -534,7 +530,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{10} + return fileDescriptor_4bc91a8efec81434, []int{10} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -572,7 +568,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{11} + return fileDescriptor_4bc91a8efec81434, []int{11} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -603,7 +599,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{12} + return fileDescriptor_4bc91a8efec81434, []int{12} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -635,7 +631,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{13} + return fileDescriptor_4bc91a8efec81434, []int{13} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -663,6 +659,133 @@ func (m *ListResponse) GetServices() []*Service { return nil } +type LogsRequest struct { + // service to request logs for + Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` + // stream records continuously + Stream bool `protobuf:"varint,2,opt,name=stream,proto3" json:"stream,omitempty"` + // count of records to request + Count int64 `protobuf:"varint,3,opt,name=count,proto3" json:"count,omitempty"` + // relative time in seconds + // before the current time + // from which to show logs + Since int64 `protobuf:"varint,4,opt,name=since,proto3" json:"since,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *LogsRequest) Reset() { *m = LogsRequest{} } +func (m *LogsRequest) String() string { return proto.CompactTextString(m) } +func (*LogsRequest) ProtoMessage() {} +func (*LogsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_4bc91a8efec81434, []int{14} +} + +func (m *LogsRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_LogsRequest.Unmarshal(m, b) +} +func (m *LogsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_LogsRequest.Marshal(b, m, deterministic) +} +func (m *LogsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_LogsRequest.Merge(m, src) +} +func (m *LogsRequest) XXX_Size() int { + return xxx_messageInfo_LogsRequest.Size(m) +} +func (m *LogsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_LogsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_LogsRequest proto.InternalMessageInfo + +func (m *LogsRequest) GetService() string { + if m != nil { + return m.Service + } + return "" +} + +func (m *LogsRequest) GetStream() bool { + if m != nil { + return m.Stream + } + return false +} + +func (m *LogsRequest) GetCount() int64 { + if m != nil { + return m.Count + } + return 0 +} + +func (m *LogsRequest) GetSince() int64 { + if m != nil { + return m.Since + } + return 0 +} + +type LogRecord struct { + // timestamp of log record + Timestamp int64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + // record metadata + Metadata map[string]string `protobuf:"bytes,2,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + // message + Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *LogRecord) Reset() { *m = LogRecord{} } +func (m *LogRecord) String() string { return proto.CompactTextString(m) } +func (*LogRecord) ProtoMessage() {} +func (*LogRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_4bc91a8efec81434, []int{15} +} + +func (m *LogRecord) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_LogRecord.Unmarshal(m, b) +} +func (m *LogRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_LogRecord.Marshal(b, m, deterministic) +} +func (m *LogRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_LogRecord.Merge(m, src) +} +func (m *LogRecord) XXX_Size() int { + return xxx_messageInfo_LogRecord.Size(m) +} +func (m *LogRecord) XXX_DiscardUnknown() { + xxx_messageInfo_LogRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_LogRecord proto.InternalMessageInfo + +func (m *LogRecord) GetTimestamp() int64 { + if m != nil { + return m.Timestamp + } + return 0 +} + +func (m *LogRecord) GetMetadata() map[string]string { + if m != nil { + return m.Metadata + } + return nil +} + +func (m *LogRecord) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + func init() { proto.RegisterType((*Service)(nil), "go.micro.runtime.Service") proto.RegisterMapType((map[string]string)(nil), "go.micro.runtime.Service.MetadataEntry") @@ -679,271 +802,57 @@ func init() { proto.RegisterType((*UpdateResponse)(nil), "go.micro.runtime.UpdateResponse") proto.RegisterType((*ListRequest)(nil), "go.micro.runtime.ListRequest") proto.RegisterType((*ListResponse)(nil), "go.micro.runtime.ListResponse") + proto.RegisterType((*LogsRequest)(nil), "go.micro.runtime.LogsRequest") + proto.RegisterType((*LogRecord)(nil), "go.micro.runtime.LogRecord") + proto.RegisterMapType((map[string]string)(nil), "go.micro.runtime.LogRecord.MetadataEntry") } func init() { - proto.RegisterFile("runtime/service/proto/runtime.proto", fileDescriptor_2434d8152598889b) + proto.RegisterFile("micro/go-micro/runtime/service/proto/runtime.proto", fileDescriptor_4bc91a8efec81434) } -var fileDescriptor_2434d8152598889b = []byte{ - // 548 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x49, 0x6f, 0xd3, 0x40, - 0x14, 0xae, 0xe3, 0x2c, 0xed, 0x0b, 0x46, 0xd1, 0xa8, 0x42, 0xa6, 0x62, 0x89, 0xcc, 0x81, 0x9e, - 0x1c, 0x29, 0x15, 0x62, 0x3b, 0x36, 0x81, 0x0b, 0x11, 0x92, 0x51, 0x7f, 0xc0, 0x90, 0x3c, 0x45, - 0x16, 0xb5, 0xc7, 0x78, 0xc6, 0x96, 0x72, 0xe2, 0xca, 0x95, 0x9f, 0xc6, 0x3f, 0x42, 0xb3, 0x79, - 0x49, 0x6d, 0x2e, 0xb9, 0xbd, 0xf7, 0xe6, 0xcd, 0x37, 0xdf, 0x62, 0x19, 0x5e, 0xe5, 0x45, 0x2a, - 0xe2, 0x04, 0x17, 0x1c, 0xf3, 0x32, 0xde, 0xe2, 0x22, 0xcb, 0x99, 0x60, 0x0b, 0x33, 0x0d, 0x55, - 0x47, 0x66, 0x7b, 0x16, 0x26, 0xf1, 0x36, 0x67, 0xa1, 0x99, 0x07, 0x7f, 0x1d, 0x98, 0x7c, 0xd3, - 0x37, 0x08, 0x81, 0x61, 0x4a, 0x13, 0xf4, 0x9d, 0xb9, 0x73, 0x7d, 0x11, 0xa9, 0x9a, 0xf8, 0x30, - 0x29, 0x31, 0xe7, 0x31, 0x4b, 0xfd, 0x81, 0x1a, 0xdb, 0x96, 0x3c, 0x81, 0x31, 0x67, 0x45, 0xbe, - 0x45, 0xdf, 0x55, 0x07, 0xa6, 0x23, 0xb7, 0x70, 0x9e, 0xa0, 0xa0, 0x3b, 0x2a, 0xa8, 0x3f, 0x9c, - 0xbb, 0xd7, 0xd3, 0xe5, 0xeb, 0xf0, 0xf8, 0xd9, 0xd0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xfe, 0x9b, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf9, 0x01, 0xa4, 0x43, - 0x20, 0x06, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// RuntimeClient is the client API for Runtime service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type RuntimeClient interface { - Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) - Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) - Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) - Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) - List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) -} - -type runtimeClient struct { - cc *grpc.ClientConn -} - -func NewRuntimeClient(cc *grpc.ClientConn) RuntimeClient { - return &runtimeClient{cc} -} - -func (c *runtimeClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { - out := new(CreateResponse) - err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Create", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *runtimeClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { - out := new(ReadResponse) - err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Read", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *runtimeClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { - out := new(DeleteResponse) - err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Delete", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *runtimeClient) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) { - out := new(UpdateResponse) - err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Update", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *runtimeClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) { - out := new(ListResponse) - err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/List", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// RuntimeServer is the server API for Runtime service. -type RuntimeServer interface { - Create(context.Context, *CreateRequest) (*CreateResponse, error) - Read(context.Context, *ReadRequest) (*ReadResponse, error) - Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) - Update(context.Context, *UpdateRequest) (*UpdateResponse, error) - List(context.Context, *ListRequest) (*ListResponse, error) -} - -// UnimplementedRuntimeServer can be embedded to have forward compatible implementations. -type UnimplementedRuntimeServer struct { -} - -func (*UnimplementedRuntimeServer) Create(ctx context.Context, req *CreateRequest) (*CreateResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") -} -func (*UnimplementedRuntimeServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") -} -func (*UnimplementedRuntimeServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") -} -func (*UnimplementedRuntimeServer) Update(ctx context.Context, req *UpdateRequest) (*UpdateResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Update not implemented") -} -func (*UnimplementedRuntimeServer) List(ctx context.Context, req *ListRequest) (*ListResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method List not implemented") -} - -func RegisterRuntimeServer(s *grpc.Server, srv RuntimeServer) { - s.RegisterService(&_Runtime_serviceDesc, srv) -} - -func _Runtime_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CreateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RuntimeServer).Create(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.runtime.Runtime/Create", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RuntimeServer).Create(ctx, req.(*CreateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Runtime_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ReadRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RuntimeServer).Read(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.runtime.Runtime/Read", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RuntimeServer).Read(ctx, req.(*ReadRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Runtime_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DeleteRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RuntimeServer).Delete(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.runtime.Runtime/Delete", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RuntimeServer).Delete(ctx, req.(*DeleteRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Runtime_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UpdateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RuntimeServer).Update(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.runtime.Runtime/Update", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RuntimeServer).Update(ctx, req.(*UpdateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Runtime_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ListRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RuntimeServer).List(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.runtime.Runtime/List", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RuntimeServer).List(ctx, req.(*ListRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Runtime_serviceDesc = grpc.ServiceDesc{ - ServiceName: "go.micro.runtime.Runtime", - HandlerType: (*RuntimeServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Create", - Handler: _Runtime_Create_Handler, - }, - { - MethodName: "Read", - Handler: _Runtime_Read_Handler, - }, - { - MethodName: "Delete", - Handler: _Runtime_Delete_Handler, - }, - { - MethodName: "Update", - Handler: _Runtime_Update_Handler, - }, - { - MethodName: "List", - Handler: _Runtime_List_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "runtime/service/proto/runtime.proto", +var fileDescriptor_4bc91a8efec81434 = []byte{ + // 663 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcb, 0x6e, 0xd3, 0x40, + 0x14, 0xad, 0xe3, 0x3c, 0xda, 0x6b, 0x82, 0xaa, 0x51, 0x85, 0x4c, 0x79, 0x45, 0xde, 0x50, 0x16, + 0xb8, 0x28, 0x15, 0xe2, 0xb5, 0x6c, 0x53, 0x36, 0x8d, 0x90, 0x8c, 0xfa, 0x01, 0x83, 0x73, 0x65, + 0x59, 0xad, 0x3d, 0xc6, 0x33, 0x8e, 0x94, 0x15, 0xdf, 0xc0, 0x57, 0xb1, 0x85, 0x3f, 0x42, 0xf3, + 0xf0, 0x2b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 0x76, 0xc9, 0x6c, 0xc4, 0xbc, 0x4b, 0x66, 0x33, 0xf6, + 0xde, 0x01, 0xb9, 0x86, 0xa1, 0x4c, 0x70, 0x27, 0x50, 0x9d, 0xec, 0xd3, 0x67, 0x0f, 0xa4, 0xc7, + 0x3b, 0x78, 0x67, 0xfd, 0x18, 0xab, 0x3f, 0xde, 0x8b, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x17, + 0xe1, 0xab, 0x77, 0xae, 0x07, 0x00, 0x00, } diff --git a/runtime/service/proto/runtime.pb.micro.go b/runtime/service/proto/runtime.pb.micro.go index 12b6691b..eff7c76e 100644 --- a/runtime/service/proto/runtime.pb.micro.go +++ b/runtime/service/proto/runtime.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: runtime/service/proto/runtime.proto +// source: micro/go-micro/runtime/service/proto/runtime.proto package go_micro_runtime @@ -39,6 +39,7 @@ type RuntimeService interface { Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) + Logs(ctx context.Context, in *LogsRequest, opts ...client.CallOption) (Runtime_LogsService, error) } type runtimeService struct { @@ -103,6 +104,55 @@ func (c *runtimeService) List(ctx context.Context, in *ListRequest, opts ...clie return out, nil } +func (c *runtimeService) Logs(ctx context.Context, in *LogsRequest, opts ...client.CallOption) (Runtime_LogsService, error) { + req := c.c.NewRequest(c.name, "Runtime.Logs", &LogsRequest{}) + stream, err := c.c.Stream(ctx, req, opts...) + if err != nil { + return nil, err + } + if err := stream.Send(in); err != nil { + return nil, err + } + return &runtimeServiceLogs{stream}, nil +} + +type Runtime_LogsService interface { + Context() context.Context + SendMsg(interface{}) error + RecvMsg(interface{}) error + Close() error + Recv() (*LogRecord, error) +} + +type runtimeServiceLogs struct { + stream client.Stream +} + +func (x *runtimeServiceLogs) Close() error { + return x.stream.Close() +} + +func (x *runtimeServiceLogs) Context() context.Context { + return x.stream.Context() +} + +func (x *runtimeServiceLogs) SendMsg(m interface{}) error { + return x.stream.Send(m) +} + +func (x *runtimeServiceLogs) RecvMsg(m interface{}) error { + return x.stream.Recv(m) +} + +func (x *runtimeServiceLogs) Recv() (*LogRecord, error) { + m := new(LogRecord) + err := x.stream.Recv(m) + if err != nil { + return nil, err + } + return m, nil +} + // Server API for Runtime service type RuntimeHandler interface { @@ -111,6 +161,7 @@ type RuntimeHandler interface { Delete(context.Context, *DeleteRequest, *DeleteResponse) error Update(context.Context, *UpdateRequest, *UpdateResponse) error List(context.Context, *ListRequest, *ListResponse) error + Logs(context.Context, *LogsRequest, Runtime_LogsStream) error } func RegisterRuntimeHandler(s server.Server, hdlr RuntimeHandler, opts ...server.HandlerOption) error { @@ -120,6 +171,7 @@ func RegisterRuntimeHandler(s server.Server, hdlr RuntimeHandler, opts ...server Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error List(ctx context.Context, in *ListRequest, out *ListResponse) error + Logs(ctx context.Context, stream server.Stream) error } type Runtime struct { runtime @@ -151,3 +203,43 @@ func (h *runtimeHandler) Update(ctx context.Context, in *UpdateRequest, out *Upd func (h *runtimeHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { return h.RuntimeHandler.List(ctx, in, out) } + +func (h *runtimeHandler) Logs(ctx context.Context, stream server.Stream) error { + m := new(LogsRequest) + if err := stream.Recv(m); err != nil { + return err + } + return h.RuntimeHandler.Logs(ctx, m, &runtimeLogsStream{stream}) +} + +type Runtime_LogsStream interface { + Context() context.Context + SendMsg(interface{}) error + RecvMsg(interface{}) error + Close() error + Send(*LogRecord) error +} + +type runtimeLogsStream struct { + stream server.Stream +} + +func (x *runtimeLogsStream) Close() error { + return x.stream.Close() +} + +func (x *runtimeLogsStream) Context() context.Context { + return x.stream.Context() +} + +func (x *runtimeLogsStream) SendMsg(m interface{}) error { + return x.stream.Send(m) +} + +func (x *runtimeLogsStream) RecvMsg(m interface{}) error { + return x.stream.Recv(m) +} + +func (x *runtimeLogsStream) Send(m *LogRecord) error { + return x.stream.Send(m) +} diff --git a/runtime/service/proto/runtime.proto b/runtime/service/proto/runtime.proto index 3fb235b9..e8d563e0 100644 --- a/runtime/service/proto/runtime.proto +++ b/runtime/service/proto/runtime.proto @@ -8,6 +8,7 @@ service Runtime { rpc Delete(DeleteRequest) returns (DeleteResponse) {}; rpc Update(UpdateRequest) returns (UpdateResponse) {}; rpc List(ListRequest) returns (ListResponse) {}; + rpc Logs(LogsRequest) returns (stream LogRecord) {}; } message Service { @@ -84,3 +85,26 @@ message ListRequest {} message ListResponse { repeated Service services = 1; } + +message LogsRequest{ + // service to request logs for + string service = 1; + // stream records continuously + bool stream = 2; + // count of records to request + int64 count = 3; + // relative time in seconds + // before the current time + // from which to show logs + int64 since = 4; +} + +message LogRecord { + // timestamp of log record + int64 timestamp = 1; + // record metadata + map metadata = 2; + // message + string message = 3; +} + diff --git a/runtime/service/service.go b/runtime/service/service.go index 5cb30805..80474495 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -7,6 +7,7 @@ import ( "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/runtime" pb "github.com/micro/go-micro/v2/runtime/service/proto" + "github.com/micro/go-micro/v2/util/log" ) type svc struct { @@ -64,6 +65,53 @@ func (s *svc) Create(svc *runtime.Service, opts ...runtime.CreateOption) error { return nil } +func (s *svc) Logs(service *runtime.Service, options ...runtime.LogsOption) (runtime.LogStream, error) { + ls, err := s.runtime.Logs(context.Background(), &pb.LogsRequest{ + Service: service.Name, + Stream: true, + Count: 10, // @todo pass in actual options + }) + if err != nil { + return nil, err + } + logStream := &serviceLogStream{ + service: service.Name, + stream: make(chan runtime.LogRecord), + stop: make(chan bool), + } + go func() { + for { + record := runtime.LogRecord{} + err := ls.RecvMsg(&record) + if err != nil { + log.Error(err) + } + logStream.stream <- record + } + }() + return logStream, nil +} + +type serviceLogStream struct { + service string + stream chan runtime.LogRecord + stop chan bool +} + +func (l *serviceLogStream) Chan() chan runtime.LogRecord { + return l.stream +} + +func (l *serviceLogStream) Stop() error { + select { + case <-l.stop: + return nil + default: + close(l.stop) + } + return nil +} + // Read returns the service with the given name from the runtime func (s *svc) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error) { options := runtime.ReadOptions{} From 525ab094c850262eed90c6807bb57a46240cad98 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 1 Apr 2020 14:42:11 +0100 Subject: [PATCH 485/788] Remove LoginOptions --- auth/options.go | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/auth/options.go b/auth/options.go index cd06e676..11010361 100644 --- a/auth/options.go +++ b/auth/options.go @@ -121,29 +121,6 @@ func NewGenerateOptions(opts ...GenerateOption) GenerateOptions { return options } -type LoginOptions struct { - // Secret to use for rlogin - Secret string -} - -type LoginOption func(o *LoginOptions) - -// WithLoginSecret for the generated account -func WithLoginSecret(s string) LoginOption { - return func(o *LoginOptions) { - o.Secret = s - } -} - -// NewLoginOptions from a slice of options -func NewLoginOptions(opts ...LoginOption) LoginOptions { - var options LoginOptions - for _, o := range opts { - o(&options) - } - return options -} - type TokenOptions struct { // ID for the account ID string From 15fcd5ecef6825f6aca69a641bc3ba2abfbc6443 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Wed, 1 Apr 2020 16:14:08 +0200 Subject: [PATCH 486/788] Remove Go micro 1.18 dependency (#1462) --- go.mod | 4 +- go.sum | 184 --------------------------------------------------------- 2 files changed, 3 insertions(+), 185 deletions(-) diff --git a/go.mod b/go.mod index 99ad210d..7a8615a6 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/bitly/go-simplejson v0.5.0 github.com/bwmarrin/discordgo v0.20.2 github.com/coreos/etcd v3.3.18+incompatible + github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 @@ -31,11 +32,11 @@ require ( github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 github.com/json-iterator/go v1.1.9 // indirect github.com/kr/pretty v0.1.0 + github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 github.com/mholt/certmagic v0.9.3 github.com/micro/cli/v2 v2.1.2 - github.com/micro/go-micro v1.18.0 github.com/micro/mdns v0.3.0 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 @@ -46,6 +47,7 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.4.0 + github.com/technoweenie/multipartstreamer v1.0.1 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d diff --git a/go.sum b/go.sum index f218c3b2..d8ce8185 100644 --- a/go.sum +++ b/go.sum @@ -13,7 +13,6 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy contrib.go.opencensus.io/exporter/ocagent v0.4.12/go.mod h1:450APlNTSR6FrvC3CTRqYosuDstRB9un7SOx2k/9ckA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-autorest/autorest v0.1.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg= github.com/Azure/go-autorest/autorest v0.5.0/go.mod h1:9HLKlQjVBH6U3oDfsXOeVc56THsLPw1L03yban4xThw= @@ -30,151 +29,97 @@ github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvd github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= -github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 h1:ygIc8M6trr62pF5DucadTWGdEB4mEyvzi0e2nbcmcyA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= -github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg= -github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/akamai/AkamaiOPEN-edgegrid-golang v0.9.0/go.mod h1:zpDJeKyp9ScW4NNrbdr+Eyxvry3ilGPewKoXw3XGN1k= -github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75 h1:3ILjVyslFbc4jl1w5TWuvvslFD/nDfR2H8tVaMVLrEY= github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75/go.mod h1:uAXEEpARkRhCZfEvy/y0Jcc888f9tHCc1W7/UeEtreE= -github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190808125512-07798873deee/go.mod h1:myCDvQSzCW+wB1WAlocEru4wMGJxy+vlxHdhegi1CDQ= github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= -github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= -github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aws/aws-sdk-go v1.23.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= -github.com/beevik/ntp v0.2.0 h1:sGsd+kAXzT0bfVfzJfce04g+dSRfrs+tbQW8lweuYgw= github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y= github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= -github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= -github.com/bwmarrin/discordgo v0.20.1/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= -github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= -github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloudflare/cloudflare-go v0.10.2 h1:VBodKICVPnwmDxstcW3biKcDSpFIfS/RELUXsZSBYK4= github.com/cloudflare/cloudflare-go v0.10.2/go.mod h1:qhVI5MKwBGhdNU89ZRz2plgYutcJ5PCekLxXn56w6SY= github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko= github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= -github.com/containerd/containerd v1.3.0 h1:xjvXQWABwS2uiv3TWgQt5Uth60Gu86LTGZXMJkjc7rY= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= -github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= -github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVlf61smEIq1nwLLAjQVEK2EADoW3CX9AuT+8= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3/go.mod h1:IV7qH3hrUgRmyYrtgEeGWJfWbgcHL9CSRruz2Vqcph0= github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDGpgqzQIzDW1TphrGLssLDZp2GuS+X5DkEJB8o= github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= -github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= -github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c= -github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpu/goacmedns v0.0.1/go.mod h1:sesf/pNnCYwUevQEQfEwY0Y3DydlQWSGZbaMElOWxok= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/decker502/dnspod-go v0.2.0/go.mod h1:qsurYu1FgxcDwfSwXJdLt4kRsBLZeosEb9uq4Sy+08g= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= github.com/dnsimple/dnsimple-go v0.30.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= -github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v1.4.2-0.20190710153559-aa8249ae1b8b/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= -github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23 h1:oqgGT9O61YAYvI41EBsLePOr+LE6roB0xY4gpkZuFSE= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= -github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= -github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= -github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 h1:jFGzikHboUMRXmMBtwD/PbxoTHPs2919Irp/3rxMbvM= github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1/go.mod h1:HvODWzv6Y6kBf3Ah2WzN1bHjDUezGLaAhwuWVwfpEJs= -github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/evanphx/json-patch/v5 v5.0.0 h1:dKTrUeykyQwKb/kx7Z+4ukDs6l+4L41HqG1XHnhX7WE= github.com/evanphx/json-patch/v5 v5.0.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= -github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXju1m8W4lnEeIqTHPOzhTUO81a7yknM/xQR4= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsouza/go-dockerclient v1.4.4/go.mod h1:PrwszSL5fbmsESocROrOGq/NULMXRw+bajY0ltzD6MA= -github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4GGn3Hig= github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= -github.com/go-acme/lego/v3 v3.1.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= -github.com/go-acme/lego/v3 v3.3.0 h1:6BePZsOiYA4/w+M7QDytxQtMfCipMPGnWAHs9pWks98= github.com/go-acme/lego/v3 v3.3.0/go.mod h1:iGSY2vQrvQs3WezicSB/oVbO2eCrD88dpWPwb1qLqu0= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-log/log v0.1.0/go.mod h1:4mBwpdRMFLiuXZDCwU2lKQFsoSCo72j3HqBK9d81N2M= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= -github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= -github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU= -github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM= github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -182,15 +127,10 @@ github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= @@ -198,15 +138,11 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -221,22 +157,13 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m github.com/gophercloud/gophercloud v0.3.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= -github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg= github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg= -github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.8.5 h1:2+KSC78XiO6Qy0hIjfc1OD9H+hsaJdJlb8Kqsd41CTE= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -249,122 +176,80 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= -github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd/go.mod h1:3LVOLeyx9XVvwPgrt2be44XgSqndprz1G18rSk8KD84= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= -github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= -github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= -github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= -github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 h1:lnrOS18wZBYrzdDmnUeg1OVk+kQ3rxG8mZWU89DpMIA= github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1/go.mod h1:DFXrEwSRX0p/aSvxE21319menCBFeQO0jXpRj7LEZUA= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY= github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/kolo/xmlrpc v0.0.0-20190717152603-07c4ee3fd181/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= -github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= -github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ= -github.com/lucas-clemente/quic-go v0.12.1/go.mod h1:UXJJPE4RfFef/xPO5wQm0tITK8gNfqwTxjbE7s3Vb8s= -github.com/lucas-clemente/quic-go v0.13.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= -github.com/lucas-clemente/quic-go v0.14.1 h1:c1aKoBZKOPA+49q96B1wGkibyPP0AxYh45WuAoq+87E= github.com/lucas-clemente/quic-go v0.14.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= -github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ= github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE= github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= -github.com/marten-seemann/qtls v0.3.2/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= -github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= -github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mholt/certmagic v0.7.5/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= -github.com/mholt/certmagic v0.8.3/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= -github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU= github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= -github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= -github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= -github.com/micro/go-micro v1.16.0/go.mod h1:A0F58bHLh2m0LAI9QyhvmbN8c1cxhAZo3cM6s+iDsrM= -github.com/micro/go-micro v1.18.0 h1:gP70EZVHpJuUIT0YWth192JmlIci+qMOEByHm83XE9E= -github.com/micro/go-micro v1.18.0/go.mod h1:klwUJL1gkdY1MHFyz+fFJXn52dKcty4hoe95Mp571AA= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= -github.com/micro/protoc-gen-micro v1.0.0/go.mod h1:C8ij4DJhapBmypcT00AXdb0cZ675/3PqUO02buWWqbE= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed/go.mod h1:3rdaFaCv4AyBgu5ALFM0+tSuHrBh6v692nyQe3ikrq0= github.com/mitchellh/hashstructure v1.0.0 h1:ZkRJX1CyOoTkar7p/mLS5TZU4nJ1Rn/F8u9dGS02Q3Y= github.com/mitchellh/hashstructure v1.0.0/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8dQu6DMTwH4oIuGN8GJDAlqDdVE= github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server/v2 v2.1.0/go.mod h1:r5y0WgCag0dTj/qiHkHrXAcKQ/f5GMOZaEGdoxxnJ4I= github.com/nats-io/nats-server/v2 v2.1.4 h1:BILRnsJ2Yb/fefiFbBWADpViGF69uh4sxe8poVDQ06g= github.com/nats-io/nats-server/v2 v2.1.4/go.mod h1:Jw1Z28soD/QasIA2uWjXyM9El1jly3YwyFOuR8tH1rg= -github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= -github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= -github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= -github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= github.com/nrdcg/dnspod-go v0.3.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgPTGKr6KQ= @@ -372,21 +257,15 @@ github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2 github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= -github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= -github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI= github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= -github.com/opencontainers/runc v0.1.1 h1:GlxAyO6x8rfZYN9Tt0Kti5a/cP41iuiO2yYT0IJGY8Y= github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/runtime-tools v0.0.0-20181011054405-1d69bd0f9c39/go.mod h1:r3f7wjNzSs2extwzU3Y+6pKfobzPh+kKFJ3ofN+3nfs= -github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/oracle/oci-go-sdk v7.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014/go.mod h1:joRatxRJaZBsY3JAOEMcoOp05CnZzsx4scTxi95DHyQ= @@ -400,27 +279,22 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.1.0 h1:BQ53HtBmfOitExawJ6LokA4x8ov/z0SYYb0+HxJfRI8= github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= -github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKcyumwBO6qip7RNQ5r77yrssm9bfCowcLEBcU5IA= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= @@ -430,88 +304,63 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sacloud/libsacloud v1.26.1/go.mod h1:79ZwATmHLIFZIMd7sxA3LwzVy/B77uj3LDoToVTxDoQ= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= -github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= -github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= -github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc h1:yUaosFVTJwnltaHbSNC3i82I92quFs+OFPRl8kNMVwo= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= -github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= -go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.2.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.12.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw= golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -527,9 +376,7 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -556,9 +403,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 h1:MsuvTghUPjX762sGLnGsxC3HM0B5r83wEtYcYR8/vRs= golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -569,7 +414,6 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180622082034-63fc586f45fe/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -582,7 +426,6 @@ golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -592,23 +435,18 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4 h1:Hynbrlo6LbYI3H1IqXpkVDOcX/3HiPdhVEuyj5a59RM= -golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 h1:xQwXv67TxFo9nC1GJFyab5eq/5B590r6RlnL/G8Sz7w= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -627,19 +465,15 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 h1:RIIXAeV6GvDBuADKumTODatUqANFZ+5BPMnzsy4hulY= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= @@ -660,7 +494,6 @@ google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1 h1:aQktFqmDE2yjveXJlVIfslDFmFnUXSqG0i6KRcJAeMc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= @@ -670,21 +503,14 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= -gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= -gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= -gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= @@ -692,34 +518,24 @@ gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ns1/ns1-go.v2 v2.0.0-20190730140822-b51389932cbc/go.mod h1:VV+3haRsgDiVLxyifmMBrBIuCWFBPYKbRssXB9z67Hw= gopkg.in/resty.v1 v1.9.1/go.mod h1:vo52Hzryw9PnPHcJfPsBiFW62XhNx5OczbV9y+IMpgc= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4= gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= -gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg= gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= -gopkg.in/src-d/go-git-fixtures.v3 v3.5.0 h1:ivZFOIltbce2Mo8IjzUHAFoq/IylO9WHhNOAJK+LsJg= gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= -gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE= gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= -gopkg.in/telegram-bot-api.v4 v4.6.4 h1:hpHWhzn4jTCsAJZZ2loNKfy2QWyPDRJVl3aTFXeMW8g= gopkg.in/telegram-bot-api.v4 v4.6.4/go.mod h1:5DpGO5dbumb40px+dXcwCpcjmeHNYLpk0bp3XRNvWDM= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= -sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= From ae15793fc38ad2ca43953688fcf582a7b7dd851f Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 1 Apr 2020 15:36:22 +0100 Subject: [PATCH 487/788] Support oauth codes --- auth/provider/basic/basic.go | 2 +- auth/provider/oauth/oauth.go | 15 +++++++++++---- auth/provider/provider.go | 14 +++++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/auth/provider/basic/basic.go b/auth/provider/basic/basic.go index 413053ef..ed19190a 100644 --- a/auth/provider/basic/basic.go +++ b/auth/provider/basic/basic.go @@ -25,7 +25,7 @@ func (b *basic) Options() provider.Options { return b.opts } -func (b *basic) Endpoint() string { +func (b *basic) Endpoint(...provider.EndpointOption) string { return "" } diff --git a/auth/provider/oauth/oauth.go b/auth/provider/oauth/oauth.go index 52ae08a6..e279784e 100644 --- a/auth/provider/oauth/oauth.go +++ b/auth/provider/oauth/oauth.go @@ -3,7 +3,6 @@ package oauth import ( "fmt" "net/url" - "strings" "github.com/micro/go-micro/v2/auth/provider" ) @@ -29,17 +28,25 @@ func (o *oauth) Options() provider.Options { return o.opts } -func (o *oauth) Endpoint() string { +func (o *oauth) Endpoint(opts ...provider.EndpointOption) string { + var options provider.EndpointOptions + for _, o := range opts { + o(&options) + } + params := make(url.Values) params.Add("response_type", "code") + if len(options.Code) > 0 { + params.Add("code", options.Code) + } + if clientID := o.opts.ClientID; len(clientID) > 0 { params.Add("client_id", clientID) } if scope := o.opts.Scope; len(scope) > 0 { - // spaces are url encoded since this cannot be passed in env vars - params.Add("scope", strings.ReplaceAll(scope, "%20", " ")) + params.Add("scope", scope) } if redir := o.Redirect(); len(redir) > 0 { diff --git a/auth/provider/provider.go b/auth/provider/provider.go index 86a4504d..ff269e25 100644 --- a/auth/provider/provider.go +++ b/auth/provider/provider.go @@ -12,7 +12,7 @@ type Provider interface { // Options returns the options of a provider Options() Options // Endpoint for the provider - Endpoint() string + Endpoint(...EndpointOption) string // Redirect url incase of UI Redirect() string } @@ -26,3 +26,15 @@ type Grant struct { // Scopes associated with grant Scopes []string } + +type EndpointOptions struct { + Code string +} + +type EndpointOption func(*EndpointOptions) + +func WithCode(c string) EndpointOption { + return func(o *EndpointOptions) { + o.Code = c + } +} From 365dfe9df591659c06f1a55272bf74f4fd1e4ad1 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 1 Apr 2020 17:11:46 +0100 Subject: [PATCH 488/788] Code => State --- auth/provider/oauth/oauth.go | 4 ++-- auth/provider/provider.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/auth/provider/oauth/oauth.go b/auth/provider/oauth/oauth.go index e279784e..45b79c8e 100644 --- a/auth/provider/oauth/oauth.go +++ b/auth/provider/oauth/oauth.go @@ -37,8 +37,8 @@ func (o *oauth) Endpoint(opts ...provider.EndpointOption) string { params := make(url.Values) params.Add("response_type", "code") - if len(options.Code) > 0 { - params.Add("code", options.Code) + if len(options.State) > 0 { + params.Add("state", options.State) } if clientID := o.opts.ClientID; len(clientID) > 0 { diff --git a/auth/provider/provider.go b/auth/provider/provider.go index ff269e25..26f80034 100644 --- a/auth/provider/provider.go +++ b/auth/provider/provider.go @@ -28,13 +28,13 @@ type Grant struct { } type EndpointOptions struct { - Code string + State string } type EndpointOption func(*EndpointOptions) -func WithCode(c string) EndpointOption { +func WithState(c string) EndpointOption { return func(o *EndpointOptions) { - o.Code = c + o.State = c } } From d577c32563d025a6b9b9572c1d4150c3090c7c18 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 1 Apr 2020 17:17:40 +0100 Subject: [PATCH 489/788] Add back auth.PrivateKey --- auth/options.go | 9 +++++++++ config/cmd/cmd.go | 3 +++ 2 files changed, 12 insertions(+) diff --git a/auth/options.go b/auth/options.go index 11010361..5ba08fe5 100644 --- a/auth/options.go +++ b/auth/options.go @@ -16,6 +16,8 @@ type Options struct { Token *Token // PublicKey for decoding JWTs PublicKey string + // PrivateKey for encoding JWTs + PrivateKey string // Provider is an auth provider Provider provider.Provider // LoginURL is the relative url path where a user can login @@ -40,6 +42,13 @@ func PublicKey(key string) Option { } } +// PrivateKey is the JWT private key +func PrivateKey(key string) Option { + return func(o *Options) { + o.PrivateKey = key + } +} + // Credentials sets the auth credentials func Credentials(id, secret string) Option { return func(o *Options) { diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index c984391b..7b90b29a 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -670,6 +670,9 @@ func (c *cmd) Before(ctx *cli.Context) error { if len(ctx.String("auth_public_key")) > 0 { authOpts = append(authOpts, auth.PublicKey(ctx.String("auth_public_key"))) } + if len(ctx.String("auth_private_key")) > 0 { + authOpts = append(authOpts, auth.PrivateKey(ctx.String("auth_private_key"))) + } if name := ctx.String("auth_provider"); len(name) > 0 { p, ok := DefaultAuthProviders[name] From df8c0bb5e12b7dc426e9f8397d81e8dc1454cdef Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 1 Apr 2020 17:20:02 +0100 Subject: [PATCH 490/788] Auth Generate, make secret optional --- auth/auth.go | 2 +- auth/default.go | 3 +- auth/options.go | 9 +++ auth/service/proto/auth.pb.go | 118 ++++++++++++++++++---------------- auth/service/proto/auth.proto | 1 + auth/service/service.go | 5 +- 6 files changed, 79 insertions(+), 59 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index b82f0af7..206d2d76 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -32,7 +32,7 @@ type Auth interface { // Options set for auth Options() Options // Generate a new account - Generate(id, secret string, opts ...GenerateOption) (*Account, error) + Generate(id string, opts ...GenerateOption) (*Account, error) // Grant access to a resource Grant(role string, res *Resource) error // Revoke access to a resource diff --git a/auth/default.go b/auth/default.go index d9f973e9..d319f793 100644 --- a/auth/default.go +++ b/auth/default.go @@ -34,12 +34,13 @@ func (n *noop) Options() Options { } // Generate a new account -func (n *noop) Generate(id, secret string, opts ...GenerateOption) (*Account, error) { +func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) { options := NewGenerateOptions(opts...) return &Account{ ID: id, Roles: options.Roles, + Secret: options.Secret,s Metadata: options.Metadata, }, nil } diff --git a/auth/options.go b/auth/options.go index 5ba08fe5..929cf674 100644 --- a/auth/options.go +++ b/auth/options.go @@ -82,10 +82,19 @@ type GenerateOptions struct { Provider string // Type of the account, e.g. user Type string + // Secret used to authenticate the account + Secret string } type GenerateOption func(o *GenerateOptions) +// WithSecret for the generated account +func WithSecret(s string) GenerateOption { + return func(o *GenerateOptions) { + o.Secret = s + } +} + // WithType for the generated account func WithType(t string) GenerateOption { return func(o *GenerateOptions) { diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index 78064eb4..3cffecb4 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -188,6 +188,7 @@ type Account struct { Metadata map[string]string `protobuf:"bytes,4,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` Namespace string `protobuf:"bytes,5,opt,name=namespace,proto3" json:"namespace,omitempty"` Provider string `protobuf:"bytes,6,opt,name=provider,proto3" json:"provider,omitempty"` + Secret string `protobuf:"bytes,7,opt,name=secret,proto3" json:"secret,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -260,6 +261,13 @@ func (m *Account) GetProvider() string { return "" } +func (m *Account) GetSecret() string { + if m != nil { + return m.Secret + } + return "" +} + type Resource struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` @@ -1115,61 +1123,61 @@ func init() { } var fileDescriptor_11312eec02fd5712 = []byte{ - // 888 bytes of a gzipped FileDescriptorProto + // 896 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4b, 0x6f, 0xdb, 0x46, - 0x10, 0x36, 0x49, 0x89, 0x92, 0x47, 0x0f, 0x0b, 0x1b, 0xc7, 0x25, 0x98, 0x47, 0x1d, 0xa6, 0x28, + 0x10, 0x36, 0x49, 0x89, 0x92, 0x47, 0x0f, 0x0b, 0x1b, 0x27, 0x25, 0x98, 0x47, 0x1d, 0xa6, 0x28, 0xdc, 0xa0, 0xa1, 0x0b, 0xe5, 0xd0, 0x47, 0x2e, 0x35, 0x22, 0x41, 0x4d, 0xda, 0xa8, 0x28, 0x91, - 0x22, 0xbd, 0x14, 0x01, 0x43, 0x4d, 0x6d, 0xc2, 0x32, 0xc9, 0xee, 0x2e, 0x8d, 0xea, 0x52, 0xa0, - 0xa7, 0xde, 0xfa, 0x2b, 0xfa, 0xb3, 0x7a, 0xef, 0x9f, 0xe8, 0xa1, 0xe0, 0x3e, 0x68, 0x91, 0xa2, - 0x02, 0xa3, 0xf0, 0xa1, 0xb7, 0x9d, 0x9d, 0xe1, 0x37, 0xf3, 0x7d, 0x3b, 0x3b, 0x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x22, 0x76, 0x0a, 0x00, 0x00, } diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index c42d1631..d7d09418 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -39,6 +39,7 @@ message Account { map metadata = 4; string namespace = 5; string provider = 6; + string secret = 7; } message Resource{ diff --git a/auth/service/service.go b/auth/service/service.go index 9c4a6573..a0ce48b7 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -107,13 +107,13 @@ func (s *svc) Options() auth.Options { } // Generate a new account -func (s *svc) Generate(id, secret string, opts ...auth.GenerateOption) (*auth.Account, error) { +func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { options := auth.NewGenerateOptions(opts...) rsp, err := s.auth.Generate(context.TODO(), &pb.GenerateRequest{ Id: id, - Secret: secret, Type: options.Type, + Secret: options.Secret, Roles: options.Roles, Metadata: options.Metadata, Provider: options.Provider, @@ -321,6 +321,7 @@ func serializeAccount(a *pb.Account) *auth.Account { return &auth.Account{ ID: a.Id, Roles: a.Roles, + Secret: a.Secret, Metadata: a.Metadata, Provider: a.Provider, Namespace: a.Namespace, From c76667968705ffff8d39e07f3746d3ad89dc22e9 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 1 Apr 2020 17:22:01 +0100 Subject: [PATCH 491/788] Fix typo --- auth/default.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/default.go b/auth/default.go index d319f793..20f16a4f 100644 --- a/auth/default.go +++ b/auth/default.go @@ -40,7 +40,7 @@ func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) { return &Account{ ID: id, Roles: options.Roles, - Secret: options.Secret,s + Secret: options.Secret, Metadata: options.Metadata, }, nil } From 9de69529cee6aecac1e42a7fe54e81ce81365824 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 1 Apr 2020 17:29:17 +0100 Subject: [PATCH 492/788] Fix token tests --- auth/token/basic/basic_test.go | 26 +++++--------------------- auth/token/jwt/jwt_test.go | 17 +++++++---------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/auth/token/basic/basic_test.go b/auth/token/basic/basic_test.go index 4498db3c..127e201d 100644 --- a/auth/token/basic/basic_test.go +++ b/auth/token/basic/basic_test.go @@ -2,8 +2,8 @@ package basic import ( "testing" - "time" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/auth/token" "github.com/micro/go-micro/v2/store/memory" ) @@ -12,7 +12,7 @@ func TestGenerate(t *testing.T) { store := memory.NewStore() b := NewTokenProvider(token.WithStore(store)) - _, err := b.Generate("test") + _, err := b.Generate(&auth.Account{ID: "test"}) if err != nil { t.Fatalf("Generate returned %v error, expected nil", err) } @@ -35,12 +35,7 @@ func TestInspect(t *testing.T) { roles := []string{"admin"} subject := "test" - opts := []token.GenerateOption{ - token.WithMetadata(md), - token.WithRoles(roles...), - } - - tok, err := b.Generate(subject, opts...) + tok, err := b.Generate(&auth.Account{ID: subject, Roles: roles, Metadata: md}) if err != nil { t.Fatalf("Generate returned %v error, expected nil", err) } @@ -49,8 +44,8 @@ func TestInspect(t *testing.T) { if err != nil { t.Fatalf("Inspect returned %v error, expected nil", err) } - if tok2.Subject != subject { - t.Errorf("Inspect returned %v as the token subject, expected %v", tok2.Subject, subject) + if tok2.ID != subject { + t.Errorf("Inspect returned %v as the token subject, expected %v", tok2.ID, subject) } if len(tok2.Roles) != len(roles) { t.Errorf("Inspect returned %v roles, expected %v", len(tok2.Roles), len(roles)) @@ -60,17 +55,6 @@ func TestInspect(t *testing.T) { } }) - t.Run("Expired token", func(t *testing.T) { - tok, err := b.Generate("foo", token.WithExpiry(-10*time.Second)) - if err != nil { - t.Fatalf("Generate returned %v error, expected nil", err) - } - - if _, err = b.Inspect(tok.Token); err != token.ErrInvalidToken { - t.Fatalf("Inspect returned %v error, expected %v", err, token.ErrInvalidToken) - } - }) - t.Run("Invalid token", func(t *testing.T) { _, err := b.Inspect("Invalid token") if err != token.ErrInvalidToken { diff --git a/auth/token/jwt/jwt_test.go b/auth/token/jwt/jwt_test.go index 576a1e2e..5d4b5591 100644 --- a/auth/token/jwt/jwt_test.go +++ b/auth/token/jwt/jwt_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/auth/token" ) @@ -18,7 +19,7 @@ func TestGenerate(t *testing.T) { token.WithPrivateKey(string(privKey)), ) - _, err = j.Generate("test") + _, err = j.Generate(&auth.Account{ID: "test"}) if err != nil { t.Fatalf("Generate returned %v error, expected nil", err) } @@ -44,12 +45,8 @@ func TestInspect(t *testing.T) { roles := []string{"admin"} subject := "test" - opts := []token.GenerateOption{ - token.WithMetadata(md), - token.WithRoles(roles...), - } - - tok, err := j.Generate(subject, opts...) + acc := &auth.Account{ID: subject, Roles: roles, Metadata: md} + tok, err := j.Generate(acc) if err != nil { t.Fatalf("Generate returned %v error, expected nil", err) } @@ -58,8 +55,8 @@ func TestInspect(t *testing.T) { if err != nil { t.Fatalf("Inspect returned %v error, expected nil", err) } - if tok2.Subject != subject { - t.Errorf("Inspect returned %v as the token subject, expected %v", tok2.Subject, subject) + if acc.ID != subject { + t.Errorf("Inspect returned %v as the token subject, expected %v", acc.ID, subject) } if len(tok2.Roles) != len(roles) { t.Errorf("Inspect returned %v roles, expected %v", len(tok2.Roles), len(roles)) @@ -70,7 +67,7 @@ func TestInspect(t *testing.T) { }) t.Run("Expired token", func(t *testing.T) { - tok, err := j.Generate("foo", token.WithExpiry(-10*time.Second)) + tok, err := j.Generate(&auth.Account{}, token.WithExpiry(-10*time.Second)) if err != nil { t.Fatalf("Generate returned %v error, expected nil", err) } From e1bc0f6288d986f1f9a0caf1302470629854cfe3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 1 Apr 2020 20:19:21 +0100 Subject: [PATCH 493/788] replace strings for store prefix (#1465) Co-authored-by: ben-toogood --- store/cockroach/cockroach.go | 1 + 1 file changed, 1 insertion(+) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index b555c9c0..e1d84b1d 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -315,6 +315,7 @@ func (s *sqlStore) configure() error { return errors.New("error compiling regex for namespace") } namespace = reg.ReplaceAllString(namespace, "_") + prefix = reg.ReplaceAllString(prefix, "_") source := s.options.Nodes[0] // check if it is a standard connection string eg: host=%s port=%d user=%s password=%s dbname=%s sslmode=disable From d2b6d35220e14248fc44fa6db205b9c5302b04fe Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Thu, 2 Apr 2020 00:03:26 +0200 Subject: [PATCH 494/788] log.Errorf when pod streaming fails (#1463) * log.Errorf when pod streaming fails * Error method added for loggers Co-authored-by: Asim Aslam --- go.sum | 57 +++++++++++++++++++++++++++ runtime/default.go | 5 +++ runtime/kubernetes/kubernetes.go | 5 +++ runtime/kubernetes/kubernetes_logs.go | 18 +++++---- runtime/runtime.go | 1 + runtime/service/service.go | 5 +++ 6 files changed, 84 insertions(+), 7 deletions(-) diff --git a/go.sum b/go.sum index d8ce8185..898b26f4 100644 --- a/go.sum +++ b/go.sum @@ -46,6 +46,7 @@ github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aws/aws-sdk-go v1.23.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= +github.com/beevik/ntp v0.2.0 h1:sGsd+kAXzT0bfVfzJfce04g+dSRfrs+tbQW8lweuYgw= github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -53,17 +54,23 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y= github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= +github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= +github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cloudflare/cloudflare-go v0.10.2 h1:VBodKICVPnwmDxstcW3biKcDSpFIfS/RELUXsZSBYK4= github.com/cloudflare/cloudflare-go v0.10.2/go.mod h1:qhVI5MKwBGhdNU89ZRz2plgYutcJ5PCekLxXn56w6SY= github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko= github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= +github.com/containerd/containerd v1.3.0 h1:xjvXQWABwS2uiv3TWgQt5Uth60Gu86LTGZXMJkjc7rY= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= +github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVlf61smEIq1nwLLAjQVEK2EADoW3CX9AuT+8= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3/go.mod h1:IV7qH3hrUgRmyYrtgEeGWJfWbgcHL9CSRruz2Vqcph0= @@ -81,34 +88,45 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= github.com/dnsimple/dnsimple-go v0.30.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= +github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23 h1:oqgGT9O61YAYvI41EBsLePOr+LE6roB0xY4gpkZuFSE= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 h1:jFGzikHboUMRXmMBtwD/PbxoTHPs2919Irp/3rxMbvM= github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1/go.mod h1:HvODWzv6Y6kBf3Ah2WzN1bHjDUezGLaAhwuWVwfpEJs= +github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/evanphx/json-patch/v5 v5.0.0 h1:dKTrUeykyQwKb/kx7Z+4ukDs6l+4L41HqG1XHnhX7WE= github.com/evanphx/json-patch/v5 v5.0.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= +github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXju1m8W4lnEeIqTHPOzhTUO81a7yknM/xQR4= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4GGn3Hig= github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= +github.com/go-acme/lego/v3 v3.3.0 h1:6BePZsOiYA4/w+M7QDytxQtMfCipMPGnWAHs9pWks98= github.com/go-acme/lego/v3 v3.3.0/go.mod h1:iGSY2vQrvQs3WezicSB/oVbO2eCrD88dpWPwb1qLqu0= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= @@ -117,7 +135,9 @@ github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3I github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= @@ -127,6 +147,7 @@ github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -157,13 +178,16 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m github.com/gophercloud/gophercloud v0.3.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg= github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -178,9 +202,11 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 h1:lnrOS18wZBYrzdDmnUeg1OVk+kQ3rxG8mZWU89DpMIA= github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1/go.mod h1:DFXrEwSRX0p/aSvxE21319menCBFeQO0jXpRj7LEZUA= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= @@ -189,33 +215,43 @@ github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY= github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/kolo/xmlrpc v0.0.0-20190717152603-07c4ee3fd181/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= +github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ= +github.com/lucas-clemente/quic-go v0.14.1 h1:c1aKoBZKOPA+49q96B1wGkibyPP0AxYh45WuAoq+87E= github.com/lucas-clemente/quic-go v0.14.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= +github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ= github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE= github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= +github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU= github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= @@ -225,6 +261,7 @@ github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nr github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed/go.mod h1:3rdaFaCv4AyBgu5ALFM0+tSuHrBh6v692nyQe3ikrq0= github.com/mitchellh/hashstructure v1.0.0 h1:ZkRJX1CyOoTkar7p/mLS5TZU4nJ1Rn/F8u9dGS02Q3Y= @@ -234,6 +271,7 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8dQu6DMTwH4oIuGN8GJDAlqDdVE= github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= @@ -250,6 +288,7 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= +github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= github.com/nrdcg/dnspod-go v0.3.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgPTGKr6KQ= @@ -260,9 +299,12 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= +github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= +github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI= github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= +github.com/opencontainers/runc v0.1.1 h1:GlxAyO6x8rfZYN9Tt0Kti5a/cP41iuiO2yYT0IJGY8Y= github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/runtime-tools v0.0.0-20181011054405-1d69bd0f9c39/go.mod h1:r3f7wjNzSs2extwzU3Y+6pKfobzPh+kKFJ3ofN+3nfs= @@ -279,6 +321,7 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= @@ -304,23 +347,28 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sacloud/libsacloud v1.26.1/go.mod h1:79ZwATmHLIFZIMd7sxA3LwzVy/B77uj3LDoToVTxDoQ= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= +github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= @@ -329,6 +377,7 @@ github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= +github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= @@ -414,6 +463,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180622082034-63fc586f45fe/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -447,6 +497,7 @@ golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 h1:xQwXv67TxFo9nC1GJFyab5eq/5B590r6RlnL/G8Sz7w= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -511,6 +562,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= @@ -518,13 +570,18 @@ gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ns1/ns1-go.v2 v2.0.0-20190730140822-b51389932cbc/go.mod h1:VV+3haRsgDiVLxyifmMBrBIuCWFBPYKbRssXB9z67Hw= gopkg.in/resty.v1 v1.9.1/go.mod h1:vo52Hzryw9PnPHcJfPsBiFW62XhNx5OczbV9y+IMpgc= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4= gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= +gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg= gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= +gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE= gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= +gopkg.in/telegram-bot-api.v4 v4.6.4 h1:hpHWhzn4jTCsAJZZ2loNKfy2QWyPDRJVl3aTFXeMW8g= gopkg.in/telegram-bot-api.v4 v4.6.4/go.mod h1:5DpGO5dbumb40px+dXcwCpcjmeHNYLpk0bp3XRNvWDM= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/runtime/default.go b/runtime/default.go index 125fd9b1..c0452bc8 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -260,12 +260,17 @@ type logStream struct { service string stream chan LogRecord stop chan bool + err error } func (l *logStream) Chan() chan LogRecord { return l.stream } +func (l *logStream) Error() error { + return l.err +} + func (l *logStream) Stop() error { // @todo seems like this is causing a hangup //err := l.tail.Stop() diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 4924b64d..e381721e 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -331,6 +331,11 @@ type kubeStream struct { stream chan runtime.LogRecord // the stop chan stop chan bool + err error +} + +func (k *kubeStream) Error() error { + return k.err } func (k *kubeStream) Chan() chan runtime.LogRecord { diff --git a/runtime/kubernetes/kubernetes_logs.go b/runtime/kubernetes/kubernetes_logs.go index 68b556f2..45e928a1 100644 --- a/runtime/kubernetes/kubernetes_logs.go +++ b/runtime/kubernetes/kubernetes_logs.go @@ -6,13 +6,12 @@ package kubernetes import ( "bufio" - "fmt" - "os" "strconv" "time" "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/util/kubernetes/client" + "github.com/micro/go-micro/v2/util/log" ) type klog struct { @@ -21,7 +20,7 @@ type klog struct { options runtime.LogsOptions } -func (k *klog) podLogStream(podName string, stream *kubeStream) { +func (k *klog) podLogStream(podName string, stream *kubeStream) error { p := make(map[string]string) p["follow"] = "true" @@ -32,8 +31,8 @@ func (k *klog) podLogStream(podName string, stream *kubeStream) { }, client.LogParams(p)) if err != nil { - fmt.Fprintf(os.Stderr, err.Error()) - return + stream.err = err + return err } s := bufio.NewScanner(body) @@ -42,7 +41,7 @@ func (k *klog) podLogStream(podName string, stream *kubeStream) { for { select { case <-stream.stop: - return + return stream.Error() default: if s.Scan() { record := runtime.LogRecord{ @@ -150,7 +149,12 @@ func (k *klog) Stream() (runtime.LogStream, error) { // stream from the individual pods for _, pod := range pods { - go k.podLogStream(pod, stream) + go func(podName string) { + err := k.podLogStream(podName, stream) + if err != nil { + log.Errorf("Error streaming from pod: %v", err) + } + }(pod) } return stream, nil diff --git a/runtime/runtime.go b/runtime/runtime.go index e7ece1f9..f13db91b 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -41,6 +41,7 @@ type Runtime interface { // Stream returns a log stream type LogStream interface { + Error() error Chan() chan LogRecord Stop() error } diff --git a/runtime/service/service.go b/runtime/service/service.go index 80474495..4f7dd6e6 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -96,6 +96,11 @@ type serviceLogStream struct { service string stream chan runtime.LogRecord stop chan bool + err error +} + +func (l *serviceLogStream) Error() error { + return l.err } func (l *serviceLogStream) Chan() chan runtime.LogRecord { From 0a15ae9b9dfa945725807cf4c12d5f6295f77366 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 1 Apr 2020 23:27:15 +0100 Subject: [PATCH 495/788] Move String method (#1467) --- store/store.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/store/store.go b/store/store.go index 21101cb8..057ad4ea 100644 --- a/store/store.go +++ b/store/store.go @@ -20,8 +20,6 @@ type Store interface { Init(...Option) error // Options allows you to view the current options. Options() Options - // String returns the name of the implementation. - String() string // Read takes a single key name and optional ReadOptions. It returns matching []*Record or an error. Read(key string, opts ...ReadOption) ([]*Record, error) // Write() writes a record to the store, and returns an error if the record was not written. @@ -30,6 +28,8 @@ type Store interface { Delete(key string, opts ...DeleteOption) error // List returns any keys that match, or an empty list with no error if none matched. List(opts ...ListOption) ([]string, error) + // String returns the name of the implementation. + String() string } // Record is an item stored or retrieved from a Store From 0241197c6a1e1314fe246c8b145d85eb080ef2ad Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 2 Apr 2020 12:13:04 +0300 Subject: [PATCH 496/788] api/handler/rpc: binary streaming support (#1466) * api/handler/rpc: binary streaming support Signed-off-by: Vasiliy Tolstov * fixup Signed-off-by: Vasiliy Tolstov * fix Signed-off-by: Vasiliy Tolstov * fix sec webscoekt protol Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 4 +- api/handler/rpc/stream.go | 170 +++++++++++++++++++++++++++--------- api/router/static/static.go | 14 ++- go.mod | 5 ++ go.sum | 6 ++ 5 files changed, 154 insertions(+), 45 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index b3ab0db5..83a0d877 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -129,9 +129,11 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // set merged context to request *r = *r.Clone(cx) - // if stream we currently only support json if isStream(r, service) { + // drop older context as it can have timeouts and create new + // md, _ := metadata.FromContext(cx) + //serveWebsocket(context.TODO(), w, r, service, c) serveWebsocket(cx, w, r, service, c) return } diff --git a/api/handler/rpc/stream.go b/api/handler/rpc/stream.go index 29eee41b..a4741769 100644 --- a/api/handler/rpc/stream.go +++ b/api/handler/rpc/stream.go @@ -1,107 +1,194 @@ package rpc import ( + "bytes" "context" "encoding/json" + "io" "net/http" "strings" + "time" - "github.com/gorilla/websocket" + "github.com/gobwas/httphead" + "github.com/gobwas/ws" + "github.com/gobwas/ws/wsutil" "github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" + raw "github.com/micro/go-micro/v2/codec/bytes" + "github.com/micro/go-micro/v2/logger" ) -var upgrader = websocket.Upgrader{ - ReadBufferSize: 1024, - WriteBufferSize: 1024, -} - // serveWebsocket will stream rpc back over websockets assuming json func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request, service *api.Service, c client.Client) { - // upgrade the connection - conn, err := upgrader.Upgrade(w, r, nil) - if err != nil { - return - } - // close on exit - defer conn.Close() + var op ws.OpCode - // wait for the first request so we know - _, p, err := conn.ReadMessage() + ct := r.Header.Get("Content-Type") + // Strip charset from Content-Type (like `application/json; charset=UTF-8`) + if idx := strings.IndexRune(ct, ';'); idx >= 0 { + ct = ct[:idx] + } + + // check proto from request + switch ct { + case "application/json": + op = ws.OpText + default: + op = ws.OpBinary + } + + hdr := make(http.Header) + if proto, ok := r.Header["Sec-WebSocket-Protocol"]; ok { + for _, p := range proto { + switch p { + case "binary": + hdr["Sec-WebSocket-Protocol"] = []string{"binary"} + op = ws.OpBinary + } + } + } + payload, err := requestPayload(r) if err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } return } - // send to backend - // default to trying json - var request json.RawMessage - // if the extracted payload isn't empty lets use it - if len(p) > 0 { - request = json.RawMessage(p) + upgrader := ws.HTTPUpgrader{Timeout: 5 * time.Second, + Protocol: func(proto string) bool { + if strings.Contains(proto, "binary") { + return true + } + // fallback to support all protocols now + return true + }, + Extension: func(httphead.Option) bool { + // disable extensions for compatibility + return false + }, + Header: hdr, } - // create a request to the backend + conn, rw, _, err := upgrader.Upgrade(r, w) + if err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } + return + } + + defer func() { + if err := conn.Close(); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } + return + } + }() + + var request interface{} + if !bytes.Equal(payload, []byte(`{}`)) { + switch ct { + case "application/json", "": + m := json.RawMessage(payload) + request = &m + default: + request = &raw.Frame{Data: payload} + } + } + + // we always need to set content type for message + if ct == "" { + ct = "application/json" + } req := c.NewRequest( service.Name, service.Endpoint.Name, - &request, - client.WithContentType("application/json"), + request, + client.WithContentType(ct), + client.StreamingRequest(), ) so := selector.WithStrategy(strategy(service.Services)) - // create a new stream stream, err := c.Stream(ctx, req, client.WithSelectOption(so)) if err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } return } - // send the first request for the client - // since - if err := stream.Send(request); err != nil { - return + if request != nil { + if err = stream.Send(request); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } + return + } } - go writeLoop(conn, stream) + go writeLoop(rw, stream) - resp := stream.Response() + rsp := stream.Response() // receive from stream and send to client for { // read backend response body - body, err := resp.Read() + buf, err := rsp.Read() if err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } return } // write the response - if err := conn.WriteMessage(websocket.TextMessage, body); err != nil { + if err := wsutil.WriteServerMessage(rw, op, buf); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } + return + } + if err = rw.Flush(); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } return } } } // writeLoop -func writeLoop(conn *websocket.Conn, stream client.Stream) { +func writeLoop(rw io.ReadWriter, stream client.Stream) { // close stream when done defer stream.Close() for { - _, p, err := conn.ReadMessage() + buf, op, err := wsutil.ReadClientData(rw) if err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } return } - + switch op { + default: + // not relevant + continue + case ws.OpText, ws.OpBinary: + break + } // send to backend // default to trying json - var request json.RawMessage // if the extracted payload isn't empty lets use it - if len(p) > 0 { - request = json.RawMessage(p) - } + request := &raw.Frame{Data: buf} if err := stream.Send(request); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } return } } @@ -112,7 +199,6 @@ func isStream(r *http.Request, srv *api.Service) bool { if !isWebSocket(r) { return false } - // check if the endpoint supports streaming for _, service := range srv.Services { for _, ep := range service.Endpoints { @@ -120,14 +206,12 @@ func isStream(r *http.Request, srv *api.Service) bool { if ep.Name != srv.Endpoint.Name { continue } - // matched if the name if v := ep.Metadata["stream"]; v == "true" { return true } } } - return false } diff --git a/api/router/static/static.go b/api/router/static/static.go index 3cf3bebe..3c2c25d4 100644 --- a/api/router/static/static.go +++ b/api/router/static/static.go @@ -15,6 +15,7 @@ import ( "github.com/micro/go-micro/v2/api/router" "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" + "github.com/micro/go-micro/v2/registry" ) type endpoint struct { @@ -163,13 +164,23 @@ func (r *staticRouter) Endpoint(req *http.Request) (*api.Service, error) { // hack for stream endpoint if ep.apiep.Stream { - for _, svc := range services { + svcs := registry.Copy(services) + for _, svc := range svcs { + if len(svc.Endpoints) == 0 { + e := ®istry.Endpoint{} + e.Name = strings.Join(epf[1:], ".") + e.Metadata = make(map[string]string) + e.Metadata["stream"] = "true" + svc.Endpoints = append(svc.Endpoints, e) + } for _, e := range svc.Endpoints { e.Name = strings.Join(epf[1:], ".") e.Metadata = make(map[string]string) e.Metadata["stream"] = "true" } } + + services = svcs } svc := &api.Service{ @@ -180,6 +191,7 @@ func (r *staticRouter) Endpoint(req *http.Request) (*api.Service, error) { Host: ep.apiep.Host, Method: ep.apiep.Method, Path: ep.apiep.Path, + Stream: ep.apiep.Stream, }, Services: services, } diff --git a/go.mod b/go.mod index 7a8615a6..c18607a6 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,9 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/go-acme/lego/v3 v3.3.0 github.com/go-playground/universal-translator v0.17.0 // indirect + github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee + github.com/gobwas/pool v0.2.0 // indirect + github.com/gobwas/ws v1.0.3 github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.3.2 github.com/google/go-cmp v0.4.0 // indirect @@ -57,3 +60,5 @@ require ( gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 ) + +replace github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.4 diff --git a/go.sum b/go.sum index 898b26f4..7d8a1ee1 100644 --- a/go.sum +++ b/go.sum @@ -140,6 +140,12 @@ github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTM github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= +github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= +github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= +github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= +github.com/gobwas/ws v1.0.3 h1:ZOigqf7iBxkA4jdQ3am7ATzdlOFp9YzA6NmuvEEZc9g= +github.com/gobwas/ws v1.0.3/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= From 2cafa289b6b77a86e4c43b6a7063c2c3e52a6ecc Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Thu, 2 Apr 2020 13:16:35 +0200 Subject: [PATCH 497/788] Stop LogStream if there is an error in k8s pod log streaming (#1469) * Stop LogStream if there is an error in k8s pod log streaming * Locking stream Stops * PR comment --- debug/log/kubernetes/stream.go | 4 ++++ runtime/default.go | 7 +++++-- runtime/kubernetes/kubernetes.go | 3 +++ runtime/kubernetes/kubernetes_logs.go | 1 + runtime/service/service.go | 7 +++++-- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/debug/log/kubernetes/stream.go b/debug/log/kubernetes/stream.go index e8fd3e98..50d18100 100644 --- a/debug/log/kubernetes/stream.go +++ b/debug/log/kubernetes/stream.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "os" + "sync" "github.com/micro/go-micro/v2/debug/log" ) @@ -20,6 +21,7 @@ func write(l log.Record) error { type kubeStream struct { // the k8s log stream stream chan log.Record + sync.Mutex // the stop chan stop chan bool } @@ -29,6 +31,8 @@ func (k *kubeStream) Chan() <-chan log.Record { } func (k *kubeStream) Stop() error { + k.Lock() + defer k.Unlock() select { case <-k.stop: return nil diff --git a/runtime/default.go b/runtime/default.go index c0452bc8..614319d3 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -259,8 +259,9 @@ type logStream struct { tail *tail.Tail service string stream chan LogRecord - stop chan bool - err error + sync.Mutex + stop chan bool + err error } func (l *logStream) Chan() chan LogRecord { @@ -272,6 +273,8 @@ func (l *logStream) Error() error { } func (l *logStream) Stop() error { + l.Lock() + defer l.Unlock() // @todo seems like this is causing a hangup //err := l.tail.Stop() //if err != nil { diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index e381721e..12733bdb 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -330,6 +330,7 @@ type kubeStream struct { // the k8s log stream stream chan runtime.LogRecord // the stop chan + sync.Mutex stop chan bool err error } @@ -343,6 +344,8 @@ func (k *kubeStream) Chan() chan runtime.LogRecord { } func (k *kubeStream) Stop() error { + k.Lock() + defer k.Unlock() select { case <-k.stop: return nil diff --git a/runtime/kubernetes/kubernetes_logs.go b/runtime/kubernetes/kubernetes_logs.go index 45e928a1..3600170b 100644 --- a/runtime/kubernetes/kubernetes_logs.go +++ b/runtime/kubernetes/kubernetes_logs.go @@ -32,6 +32,7 @@ func (k *klog) podLogStream(podName string, stream *kubeStream) error { if err != nil { stream.err = err + stream.Stop() return err } diff --git a/runtime/service/service.go b/runtime/service/service.go index 4f7dd6e6..8cadfcdf 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -95,8 +95,9 @@ func (s *svc) Logs(service *runtime.Service, options ...runtime.LogsOption) (run type serviceLogStream struct { service string stream chan runtime.LogRecord - stop chan bool - err error + sync.Mutex + stop chan bool + err error } func (l *serviceLogStream) Error() error { @@ -108,6 +109,8 @@ func (l *serviceLogStream) Chan() chan runtime.LogRecord { } func (l *serviceLogStream) Stop() error { + l.Lock() + defer l.Unlock() select { case <-l.stop: return nil From 31c4452fc7b909f23f7c6f5f7a43b75ed1806da9 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 2 Apr 2020 14:05:17 +0100 Subject: [PATCH 498/788] delete monitor (#1470) --- monitor/default.go | 329 ---------------------------------------- monitor/default_test.go | 37 ----- monitor/monitor.go | 45 ------ monitor/options.go | 25 --- 4 files changed, 436 deletions(-) delete mode 100644 monitor/default.go delete mode 100644 monitor/default_test.go delete mode 100644 monitor/monitor.go delete mode 100644 monitor/options.go diff --git a/monitor/default.go b/monitor/default.go deleted file mode 100644 index 380c036b..00000000 --- a/monitor/default.go +++ /dev/null @@ -1,329 +0,0 @@ -package monitor - -import ( - "context" - "errors" - "sync" - "time" - - "github.com/micro/go-micro/v2/client" - pb "github.com/micro/go-micro/v2/debug/service/proto" - "github.com/micro/go-micro/v2/registry" - "github.com/micro/go-micro/v2/registry/cache" -) - -type monitor struct { - options Options - - exit chan bool - registry cache.Cache - client client.Client - - sync.RWMutex - running bool - services map[string]*Status -} - -func (m *monitor) Check(service string) error { - status, err := m.check(service) - if err != nil { - return err - } - m.Lock() - m.services[service] = status - m.Unlock() - - if status.Code != StatusRunning { - return errors.New(status.Info) - } - - return nil -} - -// check provides binary running/failed status. -// In the event Debug.Health cannot be called on a service we reap the node. -func (m *monitor) check(service string) (*Status, error) { - services, err := m.registry.GetService(service) - if err != nil { - return nil, err - } - - // create debug client - debug := pb.NewDebugService(service, m.client) - - var status *Status - var gerr error - - // iterate through multiple versions of a service - for _, service := range services { - for _, node := range service.Nodes { - // TODO: checks that are not just RPC based - // TODO: better matching of the protocol - // TODO: maybe everything has to be a go-micro service? - if node.Metadata["server"] != m.client.String() { - continue - } - // check the transport matches - if node.Metadata["transport"] != m.client.Options().Transport.String() { - continue - } - - rsp, err := debug.Health( - context.Background(), - // empty health request - &pb.HealthRequest{}, - // call this specific node - client.WithAddress(node.Address), - // retry in the event of failure - client.WithRetries(3), - ) - if err != nil { - // save the error - gerr = err - continue - } - - // expecting ok response status - if rsp.Status != "ok" { - gerr = errors.New(rsp.Status) - continue - } - - // no error set status - status = &Status{ - Code: StatusRunning, - Info: "running", - } - } - } - - // if we got the success case return it - if status != nil { - return status, nil - } - - // if gerr is not nil return it - if gerr != nil { - return &Status{ - Code: StatusFailed, - Info: "not running", - Error: gerr.Error(), - }, nil - } - - // otherwise unknown status - return &Status{ - Code: StatusUnknown, - Info: "unknown status", - }, nil -} - -func (m *monitor) reap() { - services, err := m.registry.ListServices() - if err != nil { - return - } - - serviceMap := make(map[string]bool) - for _, service := range services { - serviceMap[service.Name] = true - } - - m.Lock() - defer m.Unlock() - - // range over our watched services - for service := range m.services { - // check if the service exists in the registry - if !serviceMap[service] { - // if not, delete it in our status map - delete(m.services, service) - } - } -} - -func (m *monitor) run() { - // check the status every tick - t := time.NewTicker(time.Minute) - defer t.Stop() - - // reap dead services - t2 := time.NewTicker(time.Hour) - defer t2.Stop() - - // list the known services - services, _ := m.registry.ListServices() - - // create a check chan of same length - check := make(chan string, len(services)) - - // front-load the services to watch - for _, service := range services { - check <- service.Name - } - - for { - select { - // exit if we're told to - case <-m.exit: - return - // check a service when told to - case service := <-check: - // check the status - status, err := m.check(service) - if err != nil { - status = &Status{ - Code: StatusUnknown, - Info: "unknown status", - } - } - - // save the status - m.Lock() - m.services[service] = status - m.Unlock() - // on the tick interval get all services and issue a check - case <-t.C: - // create a list of services - serviceMap := make(map[string]bool) - - m.RLock() - for service := range m.services { - serviceMap[service] = true - } - m.RUnlock() - - go func() { - // check the status of all watched services - for service := range serviceMap { - select { - case <-m.exit: - return - case check <- service: - default: - // barf if we block - } - } - - // list services - services, _ := m.registry.ListServices() - - for _, service := range services { - // start watching the service - if ok := serviceMap[service.Name]; !ok { - m.Watch(service.Name) - } - } - }() - case <-t2.C: - // reap any dead/non-existent services - m.reap() - } - } -} - -func (m *monitor) Reap(service string) error { - services, err := m.registry.GetService(service) - if err != nil { - return nil - } - m.Lock() - defer m.Unlock() - delete(m.services, service) - for _, service := range services { - m.registry.Deregister(service) - } - return nil -} - -func (m *monitor) Status(service string) (Status, error) { - m.RLock() - defer m.RUnlock() - if status, ok := m.services[service]; ok { - return *status, nil - } - return Status{}, ErrNotWatching -} - -func (m *monitor) Watch(service string) error { - m.Lock() - defer m.Unlock() - - // check if we're watching - if _, ok := m.services[service]; ok { - return nil - } - - // get the status - status, err := m.check(service) - if err != nil { - return err - } - - // set the status - m.services[service] = status - return nil -} - -func (m *monitor) Run() error { - m.Lock() - defer m.Unlock() - - if m.running { - return nil - } - - // reset the exit channel - m.exit = make(chan bool) - // setup a new cache - m.registry = cache.New(m.options.Registry) - - // start running - go m.run() - - // set to running - m.running = true - - return nil -} - -func (m *monitor) Stop() error { - m.Lock() - defer m.Unlock() - - if !m.running { - return nil - } - - select { - case <-m.exit: - return nil - default: - close(m.exit) - for s := range m.services { - delete(m.services, s) - } - m.registry.Stop() - m.running = false - return nil - } -} - -func newMonitor(opts ...Option) Monitor { - options := Options{ - Client: client.DefaultClient, - Registry: registry.DefaultRegistry, - } - - for _, o := range opts { - o(&options) - } - - return &monitor{ - options: options, - exit: make(chan bool), - client: options.Client, - registry: cache.New(options.Registry), - services: make(map[string]*Status), - } -} diff --git a/monitor/default_test.go b/monitor/default_test.go deleted file mode 100644 index 335df305..00000000 --- a/monitor/default_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package monitor - -import ( - "testing" -) - -func TestMonitor(t *testing.T) { - // create new monitor - m := NewMonitor() - - if err := m.Run(); err != nil { - t.Fatalf("failed to stop monitor: %v", err) - } - - services := []string{"foo", "bar", "baz"} - - for _, service := range services { - _, err := m.Status(service) - if err == nil { - t.Fatal("expected status error for unknown service") - } - - if err := m.Watch(service); err == nil { - t.Fatal("expected watch error for unknown service") - } - - // TODO: - // 1. start a service - // 2. watch service - // 3. get service status - } - - // stop monitor - if err := m.Stop(); err != nil { - t.Fatalf("failed to stop monitor: %v", err) - } -} diff --git a/monitor/monitor.go b/monitor/monitor.go deleted file mode 100644 index c5f5033d..00000000 --- a/monitor/monitor.go +++ /dev/null @@ -1,45 +0,0 @@ -// Package monitor monitors service health -package monitor - -import ( - "errors" -) - -const ( - StatusUnknown StatusCode = iota - StatusRunning - StatusFailed -) - -type StatusCode int - -// Monitor monitors a service and reaps dead instances -type Monitor interface { - // Reap a service and stop monitoring - Reap(service string) error - // Check the status of the service now - Check(service string) error - // Status of the service - Status(service string) (Status, error) - // Watch starts watching the service - Watch(service string) error - // Run the monitor to watch all services - Run() error - // Stop monitoring - Stop() error -} - -type Status struct { - Code StatusCode - Info string - Error string -} - -var ( - ErrNotWatching = errors.New("not watching") -) - -// NewMonitor returns a new monitor -func NewMonitor(opts ...Option) Monitor { - return newMonitor(opts...) -} diff --git a/monitor/options.go b/monitor/options.go deleted file mode 100644 index 6bb74a02..00000000 --- a/monitor/options.go +++ /dev/null @@ -1,25 +0,0 @@ -package monitor - -import ( - "github.com/micro/go-micro/v2/client" - "github.com/micro/go-micro/v2/registry" -) - -type Options struct { - Client client.Client - Registry registry.Registry -} - -type Option func(*Options) - -func Client(c client.Client) Option { - return func(o *Options) { - o.Client = c - } -} - -func Registry(r registry.Registry) Option { - return func(o *Options) { - o.Registry = r - } -} From 4999f6dfd4cae3d233ae6d7aa7b6af84516da7ab Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 2 Apr 2020 17:01:06 +0100 Subject: [PATCH 499/788] Namespace requests coming via api & web --- api/server/auth/auth.go | 90 +++++++++++++++++++++++++++----- auth/auth.go | 18 ++++--- auth/default.go | 12 +++-- auth/service/proto/auth.pb.go | 97 +++++++++++++++++++---------------- auth/service/proto/auth.proto | 1 + auth/service/service.go | 57 +++++++++++++------- 6 files changed, 189 insertions(+), 86 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 1bd60508..34f4c654 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -2,27 +2,44 @@ package auth import ( "fmt" + "net" "net/http" "net/url" "strings" + "github.com/micro/go-micro/v2/api/resolver" + "github.com/micro/go-micro/v2/api/resolver/path" "github.com/micro/go-micro/v2/auth" + "github.com/micro/go-micro/v2/logger" ) // CombinedAuthHandler wraps a server and authenticates requests func CombinedAuthHandler(h http.Handler) http.Handler { return authHandler{ - handler: h, - auth: auth.DefaultAuth, + handler: h, + auth: auth.DefaultAuth, + resolver: path.NewResolver(), + // namespace: } } type authHandler struct { - handler http.Handler - auth auth.Auth + handler http.Handler + auth auth.Auth + resolver resolver.Resolver } func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { + // Determine the namespace + namespace, err := namespaceFromRequest(req) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + return + } + + // Set the namespace in the header + req.Header.Set(auth.NamespaceKey, namespace) + // Extract the token from the request var token string if header := req.Header.Get("Authorization"); len(header) > 0 { @@ -43,23 +60,39 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // account doesn't necesserially mean a forbidden request acc, err := h.auth.Inspect(token) if err != nil { - acc = &auth.Account{} + acc = &auth.Account{Namespace: namespace} } + + // Check the accounts namespace matches the namespace we're operating + // within. If not forbid the request and log the occurance. + if acc.Namespace != namespace { + logger.Warnf("Cross namespace request forbidden: account %v (%v) requested access to %v in the %v namespace", acc.ID, acc.Namespace, req.URL.Path, namespace) + w.WriteHeader(http.StatusForbidden) + } + + // WIP: Determine the name of the service being requested + // endpoint, err := h.resolver.Resolve(req) + // fmt.Printf("EndpointName: %v\n", endpoint.Name) + // fmt.Printf("EndpointMethod: %v\n", endpoint.Method) + // fmt.Printf("EndpointPath: %v\n", endpoint.Path) + + // Perform the verification check to see if the account has access to + // the resource they're requesting err = h.auth.Verify(acc, &auth.Resource{ - Type: "service", - Name: "go.micro.web", - Endpoint: req.URL.Path, + Type: "service", + Name: "go.micro.web", + Endpoint: req.URL.Path, + Namespace: namespace, }) - // The account has the necessary permissions to access the - // resource + // The account has the necessary permissions to access the resource if err == nil { h.handler.ServeHTTP(w, req) return } - // The account is set, but they don't have enough permissions, - // hence we 403. + // The account is set, but they don't have enough permissions, hence + // we return a forbidden error. if len(acc.ID) > 0 { w.WriteHeader(http.StatusForbidden) return @@ -77,3 +110,36 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { loginWithRedirect := fmt.Sprintf("%v?%v", loginURL, params.Encode()) http.Redirect(w, req, loginWithRedirect, http.StatusTemporaryRedirect) } + +func namespaceFromRequest(req *http.Request) (string, error) { + // check for an ip address + if net.ParseIP(req.Host) != nil { + return auth.DefaultNamespace, nil + } + + // split the host to remove the port + host, _, err := net.SplitHostPort(req.Host) + if err != nil { + return "", err + } + + // check for dev enviroment + if host == "localhost" || host == "127.0.0.1" { + return auth.DefaultNamespace, nil + } + + // if host is not a subdomain, deturn default namespace + comps := strings.Split(host, ".") + if len(comps) != 3 { + return auth.DefaultNamespace, nil + } + + // check for the micro.mu domain + domain := fmt.Sprintf("%v.%v", comps[1], comps[2]) + if domain == "micro.mu" { + return auth.DefaultNamespace, nil + } + + // return the subdomain as the host + return comps[0], nil +} diff --git a/auth/auth.go b/auth/auth.go index 206d2d76..5f954776 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -21,8 +21,6 @@ var ( ErrInvalidRole = errors.New("invalid role") // ErrForbidden is returned when a user does not have the necessary roles to access a resource ErrForbidden = errors.New("resource forbidden") - // BearerScheme used for Authorization header - BearerScheme = "Bearer " ) // Auth providers authentication and authorization @@ -50,11 +48,13 @@ type Auth interface { // Resource is an entity such as a user or type Resource struct { // Name of the resource - Name string + Name string `json:"name"` // Type of resource, e.g. - Type string + Type string `json:"type"` // Endpoint resource e.g NotesService.Create - Endpoint string + Endpoint string `json:"endpoint"` + // Namespace the resource belongs to + Namespace string `json:"namespace"` } // Account provided by an auth provider @@ -69,7 +69,7 @@ type Account struct { Roles []string `json:"roles"` // Any other associated metadata Metadata map[string]string `json:"metadata"` - // Namespace the account belongs to, default blank + // Namespace the account belongs to Namespace string `json:"namespace"` // Secret for the account, e.g. the password Secret string `json:"secret"` @@ -88,12 +88,18 @@ type Token struct { } const ( + // DefaultNamespace used for auth + DefaultNamespace = "micro" + // NamespaceKey is the key used when storing the namespace in metadata + NamespaceKey = "Micro-Namespace" // MetadataKey is the key used when storing the account in metadata MetadataKey = "auth-account" // TokenCookieName is the name of the cookie which stores the auth token TokenCookieName = "micro-token" // SecretCookieName is the name of the cookie which stores the auth secret SecretCookieName = "micro-secret" + // BearerScheme used for Authorization header + BearerScheme = "Bearer " ) // AccountFromContext gets the account from the context, which diff --git a/auth/default.go b/auth/default.go index 20f16a4f..358cf099 100644 --- a/auth/default.go +++ b/auth/default.go @@ -38,10 +38,11 @@ func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) { options := NewGenerateOptions(opts...) return &Account{ - ID: id, - Roles: options.Roles, - Secret: options.Secret, - Metadata: options.Metadata, + ID: id, + Roles: options.Roles, + Secret: options.Secret, + Metadata: options.Metadata, + Namespace: DefaultNamespace, }, nil } @@ -63,7 +64,8 @@ func (n *noop) Verify(acc *Account, res *Resource) error { // Inspect a token func (n *noop) Inspect(token string) (*Account, error) { return &Account{ - ID: uuid.New().String(), + ID: uuid.New().String(), + Namespace: DefaultNamespace, }, nil } diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index 3cffecb4..aac61c2a 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -272,6 +272,7 @@ type Resource struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` Endpoint string `protobuf:"bytes,3,opt,name=endpoint,proto3" json:"endpoint,omitempty"` + Namespace string `protobuf:"bytes,4,opt,name=namespace,proto3" json:"namespace,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -323,6 +324,13 @@ func (m *Resource) GetEndpoint() string { return "" } +func (m *Resource) GetNamespace() string { + if m != nil { + return m.Namespace + } + return "" +} + type GenerateRequest struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Roles []string `protobuf:"bytes,2,rep,name=roles,proto3" json:"roles,omitempty"` @@ -1123,12 +1131,12 @@ func init() { } var fileDescriptor_11312eec02fd5712 = []byte{ - // 896 bytes of a gzipped FileDescriptorProto + // 901 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4b, 0x6f, 0xdb, 0x46, 0x10, 0x36, 0x49, 0x89, 0x92, 0x47, 0x0f, 0x0b, 0x1b, 0x27, 0x25, 0x98, 0x47, 0x1d, 0xa6, 0x28, 0xdc, 0xa0, 0xa1, 0x0b, 0xe5, 0xd0, 0x47, 0x2e, 0x35, 0x22, 0x41, 0x4d, 0xda, 0xa8, 0x28, 0x91, - 0x22, 0xbd, 0x14, 0x01, 0x43, 0x4d, 0x6d, 0xc2, 0x32, 0xc9, 0xee, 0x2e, 0x8d, 0xfa, 0x52, 0xa0, - 0xa7, 0xde, 0x7a, 0xea, 0x4f, 0xe8, 0xcf, 0xea, 0xbd, 0x7f, 0xa3, 0xe0, 0x3e, 0x28, 0x91, 0xa2, + 0x22, 0xbd, 0x14, 0x01, 0x43, 0x4d, 0x6d, 0xc2, 0x32, 0xc9, 0xee, 0x2e, 0x8d, 0xea, 0x52, 0xa0, + 0xa7, 0xde, 0x7a, 0xea, 0x4f, 0xe8, 0xcf, 0xea, 0xbd, 0x7f, 0xa3, 0xe0, 0x3e, 0x68, 0x91, 0xa2, 0x02, 0xa3, 0xf5, 0x21, 0xb7, 0x9d, 0x07, 0x67, 0xe6, 0xfb, 0x66, 0x76, 0xb8, 0xf0, 0xe9, 0x49, 0xcc, 0x4f, 0xf3, 0x37, 0x7e, 0x94, 0x9e, 0x1f, 0x9d, 0xc7, 0x11, 0x4d, 0x8f, 0x4e, 0xd2, 0x47, 0xf2, 0x10, 0xe6, 0xfc, 0xf4, 0x88, 0x21, 0xbd, 0x88, 0x23, 0x3c, 0xca, 0x68, 0xca, 0xa5, 0xca, @@ -1139,45 +1147,46 @@ var fileDescriptor_11312eec02fd5712 = []byte{ 0x4c, 0xc8, 0x7d, 0xe8, 0x87, 0x51, 0x84, 0x8c, 0xbd, 0xe6, 0x85, 0xec, 0x18, 0x07, 0xc6, 0xe1, 0x6e, 0xd0, 0x93, 0x3a, 0xe9, 0xf2, 0x00, 0x06, 0x14, 0x7f, 0xa2, 0xc8, 0x4e, 0x95, 0x8f, 0x29, 0x7c, 0xfa, 0x4a, 0x29, 0x9d, 0x1c, 0xe8, 0x44, 0x14, 0x43, 0x8e, 0x0b, 0xc7, 0x3a, 0x30, 0x0e, - 0xad, 0x40, 0x8b, 0xe4, 0x16, 0xd8, 0xf8, 0x4b, 0x16, 0xd3, 0x4b, 0xa7, 0x25, 0x0c, 0x4a, 0xf2, - 0xfe, 0x34, 0xa1, 0xa3, 0x2a, 0x23, 0x43, 0x30, 0xe3, 0x85, 0xca, 0x6d, 0xc6, 0x0b, 0x42, 0xa0, - 0xc5, 0x2f, 0x33, 0x54, 0x99, 0xc4, 0x99, 0xec, 0x43, 0x9b, 0xa6, 0x4b, 0x64, 0x8e, 0x75, 0x60, - 0x1d, 0xee, 0x06, 0x52, 0x20, 0x5f, 0x42, 0xf7, 0x1c, 0x79, 0xb8, 0x08, 0x79, 0xe8, 0xb4, 0x04, - 0xfa, 0x0f, 0x9a, 0xd1, 0xfb, 0x2f, 0x94, 0xdb, 0x34, 0xe1, 0xf4, 0x32, 0x28, 0xbf, 0x22, 0x77, - 0x60, 0x37, 0x09, 0xcf, 0x91, 0x65, 0x61, 0x84, 0x4e, 0x5b, 0x24, 0x5c, 0x29, 0x88, 0x0b, 0xdd, - 0x8c, 0xa6, 0x17, 0xf1, 0x02, 0xa9, 0x63, 0x0b, 0x63, 0x29, 0x17, 0xc8, 0x18, 0x46, 0x14, 0xb9, - 0xd3, 0x11, 0x16, 0x25, 0xb9, 0x4f, 0x60, 0x50, 0x49, 0x46, 0x46, 0x60, 0x9d, 0xe1, 0xa5, 0xc2, - 0x57, 0x1c, 0x0b, 0x30, 0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x95, 0x91, 0x21, 0x98, 0xf1, 0x42, 0xe5, 0x36, 0xe3, 0x05, 0x21, 0xd0, + 0xe2, 0xab, 0x0c, 0x55, 0x26, 0x71, 0x26, 0xfb, 0xd0, 0xa6, 0xe9, 0x12, 0x99, 0x63, 0x1d, 0x58, + 0x87, 0xbb, 0x81, 0x14, 0xc8, 0x97, 0xd0, 0x3d, 0x47, 0x1e, 0x2e, 0x42, 0x1e, 0x3a, 0x2d, 0x81, + 0xfe, 0x83, 0x66, 0xf4, 0xfe, 0x0b, 0xe5, 0x36, 0x4d, 0x38, 0x5d, 0x05, 0xe5, 0x57, 0xe4, 0x0e, + 0xec, 0x26, 0xe1, 0x39, 0xb2, 0x2c, 0x8c, 0xd0, 0x69, 0x8b, 0x84, 0x97, 0x0a, 0xe2, 0x42, 0x37, + 0xa3, 0xe9, 0x45, 0xbc, 0x40, 0xea, 0xd8, 0xc2, 0x58, 0xca, 0x05, 0x32, 0x86, 0x11, 0x45, 0xee, + 0x74, 0x84, 0x45, 0x49, 0xee, 0x13, 0x18, 0x54, 0x92, 0x91, 0x11, 0x58, 0x67, 0xb8, 0x52, 0xf8, + 0x8a, 0x63, 0x01, 0xe6, 0x22, 0x5c, 0xe6, 0x1a, 0xa1, 0x14, 0xbe, 0x30, 0x3f, 0x33, 0xbc, 0x25, + 0x74, 0x03, 0x64, 0x69, 0x4e, 0x23, 0x2c, 0x68, 0x28, 0x2a, 0x51, 0x1f, 0x8a, 0x73, 0x23, 0x35, + 0x2e, 0x74, 0x31, 0x59, 0x64, 0x69, 0x9c, 0x70, 0xc1, 0xfe, 0x6e, 0x50, 0xca, 0x55, 0x78, 0xad, + 0x1a, 0x3c, 0xef, 0x2f, 0x13, 0xf6, 0x66, 0x98, 0x20, 0x0d, 0x39, 0xaa, 0x41, 0xdb, 0x68, 0x46, + 0x49, 0xbc, 0xb9, 0x4e, 0xfc, 0x57, 0x6b, 0xc4, 0x5b, 0x82, 0xf8, 0x8f, 0x6b, 0xc4, 0x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11, 0xba, 0xfa, 0xa9, 0x43, 0xbe, + 0x83, 0x56, 0x41, 0x30, 0xf1, 0x6a, 0xdf, 0x34, 0x3c, 0x93, 0xdc, 0x07, 0x6f, 0xf5, 0x29, 0xc3, + 0xff, 0x6d, 0x40, 0xbb, 0x68, 0x04, 0x23, 0x33, 0xb0, 0xe5, 0xe8, 0x91, 0x7a, 0x49, 0x95, 0xab, + 0xe1, 0xde, 0xdd, 0x62, 0x2d, 0x71, 0xcf, 0xc0, 0x96, 0x73, 0xb2, 0x11, 0xa8, 0x32, 0xc7, 0x1b, + 0x81, 0x6a, 0xc3, 0xb5, 0x43, 0x8e, 0x15, 0x5c, 0xb7, 0x01, 0x8a, 0x0e, 0x72, 0xbb, 0xd1, 0xa6, + 0x43, 0xbc, 0xb1, 0xc5, 0xcb, 0xf2, 0xf1, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xfa, 0x51, 0x05, + 0x6e, 0x94, 0x0a, 0x00, 0x00, } diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index d7d09418..77a44af8 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -46,6 +46,7 @@ message Resource{ string name = 1; string type = 2; string endpoint = 3; + string namespace = 4; } message GenerateRequest { diff --git a/auth/service/service.go b/auth/service/service.go index a0ce48b7..166886d1 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -132,9 +132,10 @@ func (s *svc) Grant(role string, res *auth.Resource) error { Role: role, Access: pb.Access_GRANTED, Resource: &pb.Resource{ - Type: res.Type, - Name: res.Name, - Endpoint: res.Endpoint, + Namespace: res.Namespace, + Type: res.Type, + Name: res.Name, + Endpoint: res.Endpoint, }, }) return err @@ -146,9 +147,10 @@ func (s *svc) Revoke(role string, res *auth.Resource) error { Role: role, Access: pb.Access_GRANTED, Resource: &pb.Resource{ - Type: res.Type, - Name: res.Name, - Endpoint: res.Endpoint, + Namespace: res.Namespace, + Type: res.Type, + Name: res.Name, + Endpoint: res.Endpoint, }, }) return err @@ -157,10 +159,11 @@ func (s *svc) Revoke(role string, res *auth.Resource) error { // Verify an account has access to a resource func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { queries := [][]string{ - {res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin (role is checked in accessForRule) - {res.Type, res.Name, "*"}, // check for wildcard endpoint, e.g. service.foo* - {res.Type, "*"}, // check for wildcard name, e.g. service.* - {"*"}, // check for wildcard type, e.g. * + {res.Namespace, res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin (role is checked in accessForRule) + {res.Namespace, res.Type, res.Name, "*"}, // check for wildcard endpoint, e.g. service.foo* + {res.Namespace, res.Type, "*"}, // check for wildcard name, e.g. service.* + {res.Namespace, "*"}, // check for wildcard type, e.g. * + {"*"}, // check for wildcard namespace } // endpoint is a url which can have wildcard excludes, e.g. @@ -172,23 +175,30 @@ func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { } } + // set a default account id to log + logID := acc.ID + if len(logID) == 0 { + logID = "[no account]" + } + for _, q := range queries { for _, rule := range s.listRules(q...) { switch accessForRule(rule, acc, res) { case pb.Access_UNKNOWN: continue // rule did not specify access, check the next rule case pb.Access_GRANTED: - log.Infof("%v granted access to %v:%v:%v by rule %v", acc.ID, res.Type, res.Name, res.Endpoint, rule.Id) + log.Infof("%v:%v granted access to %v:%v:%v:%v by rule %v", acc.Namespace, logID, res.Namespace, res.Type, res.Name, res.Endpoint, rule.Id) return nil // rule grants the account access to the resource case pb.Access_DENIED: - log.Infof("%v denied access to %v:%v:%v by rule %v", acc.ID, res.Type, res.Name, res.Endpoint, rule.Id) + log.Infof("%v:%v denied access to %v:%v:%v:%v by rule %v", acc.Namespace, logID, res.Namespace, res.Type, res.Name, res.Endpoint, rule.Id) return auth.ErrForbidden // rule denies access to the resource } } } // no rules were found for the resource, default to denying access - log.Infof("%v denied access to %v:%v:%v by lack of rule (%v rules found)", acc.ID, res.Type, res.Name, res.Endpoint, len(s.rules)) + log.Infof("%v:%v denied access to %v:%v:%v:%v by lack of rule (%v rules found for namespace)", acc.Namespace, logID, res.Namespace, res.Type, res.Name, res.Endpoint, len(s.listRules(res.Namespace))) + fmt.Println(s.rules) return auth.ErrForbidden } @@ -249,19 +259,28 @@ func accessForRule(rule *pb.Rule, acc *auth.Account, res *auth.Resource) pb.Acce return pb.Access_UNKNOWN } -// listRules gets all the rules from the store which have an id -// prefix matching the filters +// listRules gets all the rules from the store which match the filters. +// filters are namespace, type, name and then endpoint. func (s *svc) listRules(filters ...string) []*pb.Rule { s.Lock() defer s.Unlock() - prefix := strings.Join(filters, ruleJoinKey) - var rules []*pb.Rule for _, r := range s.rules { - if strings.HasPrefix(r.Id, prefix) { - rules = append(rules, r) + if len(filters) > 0 && r.Resource.Namespace != filters[0] { + continue } + if len(filters) > 1 && r.Resource.Type != filters[1] { + continue + } + if len(filters) > 2 && r.Resource.Name != filters[2] { + continue + } + if len(filters) > 3 && r.Resource.Endpoint != filters[3] { + continue + } + + rules = append(rules, r) } return rules From 8b35c264eb9980a29152e0bc31b57e5eb61cec03 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 2 Apr 2020 17:44:48 +0100 Subject: [PATCH 500/788] Pass resolver to api auth handler --- api/server/auth/auth.go | 30 +++++++++++++++++++++++------- api/server/http/http.go | 14 +++++++++----- api/server/options.go | 15 +++++++++++++++ 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 1bd60508..7e86f651 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -6,20 +6,25 @@ import ( "net/url" "strings" + "github.com/micro/go-micro/v2/api/resolver" "github.com/micro/go-micro/v2/auth" ) // CombinedAuthHandler wraps a server and authenticates requests -func CombinedAuthHandler(h http.Handler) http.Handler { +func CombinedAuthHandler(namespace string, r resolver.Resolver, h http.Handler) http.Handler { return authHandler{ - handler: h, - auth: auth.DefaultAuth, + handler: h, + resolver: r, + auth: auth.DefaultAuth, + namespace: namespace, } } type authHandler struct { - handler http.Handler - auth auth.Auth + handler http.Handler + auth auth.Auth + resolver resolver.Resolver + namespace string } func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { @@ -45,10 +50,21 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { if err != nil { acc = &auth.Account{} } + + // Determine the name of the service being requested + endpoint, err := h.resolver.Resolve(req) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + return + } + resName := h.namespace + "." + endpoint.Name + + // Perform the verification check to see if the account has access to + // the resource they're requesting err = h.auth.Verify(acc, &auth.Resource{ Type: "service", - Name: "go.micro.web", - Endpoint: req.URL.Path, + Name: resName, + Endpoint: endpoint.Path, }) // The account has the necessary permissions to access the diff --git a/api/server/http/http.go b/api/server/http/http.go index 0af91256..2599d2db 100644 --- a/api/server/http/http.go +++ b/api/server/http/http.go @@ -8,10 +8,9 @@ import ( "os" "sync" - "github.com/micro/go-micro/v2/api/server/auth" - "github.com/gorilla/handlers" "github.com/micro/go-micro/v2/api/server" + "github.com/micro/go-micro/v2/api/server/auth" "github.com/micro/go-micro/v2/api/server/cors" "github.com/micro/go-micro/v2/logger" ) @@ -25,9 +24,14 @@ type httpServer struct { exit chan chan error } -func NewServer(address string) server.Server { +func NewServer(address string, opts ...server.Option) server.Server { + var options server.Options + for _, o := range opts { + o(&options) + } + return &httpServer{ - opts: server.Options{}, + opts: options, mux: http.NewServeMux(), address: address, exit: make(chan chan error), @@ -49,7 +53,7 @@ func (s *httpServer) Init(opts ...server.Option) error { func (s *httpServer) Handle(path string, handler http.Handler) { h := handlers.CombinedLoggingHandler(os.Stdout, handler) - h = auth.CombinedAuthHandler(handler) + h = auth.CombinedAuthHandler(s.opts.Namespace, s.opts.Resolver, handler) if s.opts.EnableCORS { h = cors.CombinedCORSHandler(h) diff --git a/api/server/options.go b/api/server/options.go index 99be1a03..5d167ced 100644 --- a/api/server/options.go +++ b/api/server/options.go @@ -3,6 +3,7 @@ package server import ( "crypto/tls" + "github.com/micro/go-micro/v2/api/resolver" "github.com/micro/go-micro/v2/api/server/acme" ) @@ -15,6 +16,8 @@ type Options struct { EnableTLS bool ACMEHosts []string TLSConfig *tls.Config + Namespace string + Resolver resolver.Resolver } func EnableCORS(b bool) Option { @@ -52,3 +55,15 @@ func TLSConfig(t *tls.Config) Option { o.TLSConfig = t } } + +func Namespace(n string) Option { + return func(o *Options) { + o.Namespace = n + } +} + +func Resolver(r resolver.Resolver) Option { + return func(o *Options) { + o.Resolver = r + } +} From 4a4c6665282c2418bc0518b4c1bc46413402e02b Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 2 Apr 2020 18:03:21 +0100 Subject: [PATCH 501/788] Remove resolver logic --- api/server/auth/auth.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 34f4c654..15373277 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/micro/go-micro/v2/api/resolver" - "github.com/micro/go-micro/v2/api/resolver/path" "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/logger" ) @@ -16,10 +15,8 @@ import ( // CombinedAuthHandler wraps a server and authenticates requests func CombinedAuthHandler(h http.Handler) http.Handler { return authHandler{ - handler: h, - auth: auth.DefaultAuth, - resolver: path.NewResolver(), - // namespace: + handler: h, + auth: auth.DefaultAuth, } } @@ -70,12 +67,6 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { w.WriteHeader(http.StatusForbidden) } - // WIP: Determine the name of the service being requested - // endpoint, err := h.resolver.Resolve(req) - // fmt.Printf("EndpointName: %v\n", endpoint.Name) - // fmt.Printf("EndpointMethod: %v\n", endpoint.Method) - // fmt.Printf("EndpointPath: %v\n", endpoint.Path) - // Perform the verification check to see if the account has access to // the resource they're requesting err = h.auth.Verify(acc, &auth.Resource{ From cfde3ec3d94a3010ae71d2977f38df1ad52fb9b9 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 2 Apr 2020 18:03:57 +0100 Subject: [PATCH 502/788] Remove resolver logic --- api/server/auth/auth.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 15373277..e01b95a0 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -7,7 +7,6 @@ import ( "net/url" "strings" - "github.com/micro/go-micro/v2/api/resolver" "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/logger" ) @@ -21,9 +20,8 @@ func CombinedAuthHandler(h http.Handler) http.Handler { } type authHandler struct { - handler http.Handler - auth auth.Auth - resolver resolver.Resolver + handler http.Handler + auth auth.Auth } func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { From ce23ab36cb58871e469c8fc4e69e2ea9973a7074 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 2 Apr 2020 18:41:06 +0100 Subject: [PATCH 503/788] Improve Err Handling --- auth/service/service.go | 1 - service.go | 2 +- util/wrapper/wrapper.go | 36 +++++++++++++++++++++++++++++++----- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/auth/service/service.go b/auth/service/service.go index 166886d1..57d6082e 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -198,7 +198,6 @@ func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { // no rules were found for the resource, default to denying access log.Infof("%v:%v denied access to %v:%v:%v:%v by lack of rule (%v rules found for namespace)", acc.Namespace, logID, res.Namespace, res.Type, res.Name, res.Endpoint, len(s.listRules(res.Namespace))) - fmt.Println(s.rules) return auth.ErrForbidden } diff --git a/service.go b/service.go index a13b4e19..2feb5db4 100644 --- a/service.go +++ b/service.go @@ -35,7 +35,7 @@ func newService(opts ...Option) Service { serviceName := options.Server.Options().Name // TODO: better accessors - authFn := func() auth.Auth { return service.opts.Auth } + authFn := func() auth.Auth { return options.Auth } // wrap client to inject From-Service header on any calls options.Client = wrapper.FromService(serviceName, options.Client, authFn) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index f795e705..a2878a20 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -2,6 +2,7 @@ package wrapper import ( "context" + "fmt" "strings" "github.com/micro/go-micro/v2/auth" @@ -9,6 +10,7 @@ import ( "github.com/micro/go-micro/v2/debug/stats" "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/server" ) @@ -165,24 +167,48 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { if header, ok := metadata.Get(ctx, "Authorization"); ok { // Ensure the correct scheme is being used if !strings.HasPrefix(header, auth.BearerScheme) { - return errors.Unauthorized("go.micro.auth", "invalid authorization header. expected Bearer schema") + return errors.Unauthorized(req.Service(), "invalid authorization header. expected Bearer schema") } token = header[len(auth.BearerScheme):] } + // Get the namespace for the request + namespace, ok := metadata.Get(ctx, auth.NamespaceKey) + if !ok { + logger.Errorf("Missing request namespace") + namespace = auth.DefaultNamespace + } + fmt.Printf("Namespace is %v\n", namespace) + // Inspect the token and get the account account, err := a.Inspect(token) if err != nil { - account = &auth.Account{} + account = &auth.Account{Namespace: auth.DefaultNamespace} + } + + // Check the accounts namespace matches the namespace we're operating + // within. If not forbid the request and log the occurance. + if account.Namespace != namespace { + logger.Warnf("Cross namespace request forbidden: account %v (%v) requested access to %v %v in the %v namespace", + account.ID, account.Namespace, req.Service(), req.Endpoint(), namespace) + return errors.Forbidden(req.Service(), "cross namespace request") + } + + // construct the resource + res := &auth.Resource{ + Type: "service", + Name: req.Service(), + Endpoint: req.Endpoint(), + Namespace: namespace, } // Verify the caller has access to the resource - err = a.Verify(account, &auth.Resource{Type: "service", Name: req.Service(), Endpoint: req.Endpoint()}) + err = a.Verify(account, res) if err != nil && len(account.ID) > 0 { - return errors.Forbidden("go.micro.auth", "Forbidden call made to %v:%v by %v", req.Service(), req.Endpoint(), account.ID) + return errors.Forbidden(req.Service(), "Forbidden call made to %v:%v by %v", req.Service(), req.Endpoint(), account.ID) } else if err != nil { - return errors.Unauthorized("go.micro.auth", "Unauthorised call made to %v:%v", req.Service(), req.Endpoint()) + return errors.Unauthorized(req.Service(), "Unauthorised call made to %v:%v", req.Service(), req.Endpoint()) } // There is an account, set it in the context From fdcb013f2413bfe9e08c013241767955bf09a47e Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 09:18:30 +0100 Subject: [PATCH 504/788] Fix web registry compatability bugs --- api/resolver/resolver.go | 6 ++++++ api/router/registry/registry.go | 2 +- api/server/auth/auth.go | 12 ++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/api/resolver/resolver.go b/api/resolver/resolver.go index 2e23d62e..12854b19 100644 --- a/api/resolver/resolver.go +++ b/api/resolver/resolver.go @@ -2,9 +2,15 @@ package resolver import ( + "errors" "net/http" ) +var ( + ErrNotFound = errors.New("not found") + ErrInvalidPath = errors.New("invalid path") +) + // Resolver resolves requests to endpoints type Resolver interface { Resolve(r *http.Request) (*Endpoint, error) diff --git a/api/router/registry/registry.go b/api/router/registry/registry.go index 375aa7d0..c024424f 100644 --- a/api/router/registry/registry.go +++ b/api/router/registry/registry.go @@ -325,7 +325,7 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) { } // no match - return nil, errors.New("not found") + return nil, registry.ErrNotFound } func (r *registryRouter) Route(req *http.Request) (*api.Service, error) { diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 7e86f651..68e7f7a3 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -53,11 +53,19 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Determine the name of the service being requested endpoint, err := h.resolver.Resolve(req) - if err != nil { + if err == resolver.ErrInvalidPath || err == resolver.ErrNotFound { + // a file not served by the resolver has been requested (e.g. favicon.ico) + endpoint = &resolver.Endpoint{Path: req.URL.Path} + } else if err != nil { w.WriteHeader(http.StatusInternalServerError) return } - resName := h.namespace + "." + endpoint.Name + + // construct the resource name, e.g. home => go.micro.web.home + resName := h.namespace + if len(endpoint.Name) > 0 { + resName = resName + "." + endpoint.Name + } // Perform the verification check to see if the account has access to // the resource they're requesting From 760233b858dc3350b427b90da4d08c4c02e63687 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 09:34:52 +0100 Subject: [PATCH 505/788] Reverse Change --- api/router/registry/registry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/router/registry/registry.go b/api/router/registry/registry.go index c024424f..375aa7d0 100644 --- a/api/router/registry/registry.go +++ b/api/router/registry/registry.go @@ -325,7 +325,7 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) { } // no match - return nil, registry.ErrNotFound + return nil, errors.New("not found") } func (r *registryRouter) Route(req *http.Request) (*api.Service, error) { From 183c8bfb818893f79c1caaf68531f43b7a9df19b Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 09:45:39 +0100 Subject: [PATCH 506/788] Apply fix for apis --- api/server/auth/auth.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 68e7f7a3..0c486963 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -67,17 +67,19 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { resName = resName + "." + endpoint.Name } + // determine the resource path. there is an inconsistency in how resolvers + // use method, some use it as Users.ReadUser (the rpc method), and others + // use it as the HTTP method, e.g GET. TODO: Refactor this to make it consistent. + resEndpoint := endpoint.Path + if len(endpoint.Path) == 0 { + resEndpoint = endpoint.Method + } + // Perform the verification check to see if the account has access to // the resource they're requesting - err = h.auth.Verify(acc, &auth.Resource{ - Type: "service", - Name: resName, - Endpoint: endpoint.Path, - }) - - // The account has the necessary permissions to access the - // resource - if err == nil { + res := &auth.Resource{Type: "service", Name: resName, Endpoint: resEndpoint} + if err := h.auth.Verify(acc, res); err == nil { + // The account has the necessary permissions to access the resource h.handler.ServeHTTP(w, req) return } From 91b9c3f92eef36c86d088a688d00d34810075a04 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 10:08:39 +0100 Subject: [PATCH 507/788] Add defaults --- api/server/auth/auth.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 0c486963..b17ef8ce 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -7,11 +7,19 @@ import ( "strings" "github.com/micro/go-micro/v2/api/resolver" + "github.com/micro/go-micro/v2/api/resolver/path" "github.com/micro/go-micro/v2/auth" ) // CombinedAuthHandler wraps a server and authenticates requests func CombinedAuthHandler(namespace string, r resolver.Resolver, h http.Handler) http.Handler { + if r == nil { + r = path.NewResolver() + } + if len(namespace) == 0 { + namespace = "go.micro" + } + return authHandler{ handler: h, resolver: r, From 1096c8fb39eba9b2ec625cd7af2b2420cc3f62aa Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 10:16:19 +0100 Subject: [PATCH 508/788] Fix failing test --- api/resolver/path/path.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/resolver/path/path.go b/api/resolver/path/path.go index fec80f62..c4d41fc6 100644 --- a/api/resolver/path/path.go +++ b/api/resolver/path/path.go @@ -2,7 +2,6 @@ package path import ( - "errors" "net/http" "strings" @@ -13,7 +12,7 @@ type Resolver struct{} func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { if req.URL.Path == "/" { - return nil, errors.New("unknown name") + return nil, resolver.ErrNotFound } parts := strings.Split(req.URL.Path[1:], "/") return &resolver.Endpoint{ From dea2d7ab9f1ede5f29307cef73cdf8a579c05258 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 12:27:01 +0100 Subject: [PATCH 509/788] Fix go-micro auth wrapper init --- config/cmd/cmd.go | 1 + service.go | 5 +++-- util/wrapper/wrapper.go | 2 -- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 7b90b29a..021156b9 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -494,6 +494,7 @@ func (c *cmd) Before(ctx *cli.Context) error { *c.opts.Auth = a() clientOpts = append(clientOpts, client.Auth(*c.opts.Auth)) + serverOpts = append(serverOpts, server.Auth(*c.opts.Auth)) } // Set the profile diff --git a/service.go b/service.go index 2feb5db4..36044338 100644 --- a/service.go +++ b/service.go @@ -34,8 +34,9 @@ func newService(opts ...Option) Service { // service name serviceName := options.Server.Options().Name - // TODO: better accessors - authFn := func() auth.Auth { return options.Auth } + // authFn returns the auth, we pass as a function since auth + // has not yet been set at this point. + authFn := func() auth.Auth { return options.Server.Options().Auth } // wrap client to inject From-Service header on any calls options.Client = wrapper.FromService(serviceName, options.Client, authFn) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index a2878a20..a599ac80 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -2,7 +2,6 @@ package wrapper import ( "context" - "fmt" "strings" "github.com/micro/go-micro/v2/auth" @@ -179,7 +178,6 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { logger.Errorf("Missing request namespace") namespace = auth.DefaultNamespace } - fmt.Printf("Namespace is %v\n", namespace) // Inspect the token and get the account account, err := a.Inspect(token) From 49a568e9c05b04125bf22449727ca5c56156bc65 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 12:33:19 +0100 Subject: [PATCH 510/788] Set default server auth --- server/options.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/options.go b/server/options.go index 5caba936..63b895bb 100644 --- a/server/options.go +++ b/server/options.go @@ -60,6 +60,10 @@ func newOptions(opt ...Option) Options { o(&opts) } + if opts.Auth == nil { + opts.Auth = auth.DefaultAuth + } + if opts.Broker == nil { opts.Broker = broker.DefaultBroker } From a9c0e043d2872bb5567b1a79bcf9d380aea595b8 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 12:50:50 +0100 Subject: [PATCH 511/788] Fix nil grpc server auth bug --- server/grpc/options.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/grpc/options.go b/server/grpc/options.go index 5cd52cb0..6591fac2 100644 --- a/server/grpc/options.go +++ b/server/grpc/options.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "net" + "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/registry" @@ -66,6 +67,7 @@ func MaxMsgSize(s int) server.Option { func newOptions(opt ...server.Option) server.Options { opts := server.Options{ + Auth: auth.DefaultAuth, Codecs: make(map[string]codec.NewCodec), Metadata: map[string]string{}, Broker: broker.DefaultBroker, From 1374a9e52883ea5d072c148d0fa39d55ea8d9c14 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 13:03:27 +0100 Subject: [PATCH 512/788] Fix namespace bug in auth wrapper --- util/wrapper/wrapper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index a599ac80..839240c2 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -182,7 +182,7 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { // Inspect the token and get the account account, err := a.Inspect(token) if err != nil { - account = &auth.Account{Namespace: auth.DefaultNamespace} + account = &auth.Account{Namespace: namespace} } // Check the accounts namespace matches the namespace we're operating From d0e47206cc6df6e487750af5f5d753753f2546e1 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 13:29:48 +0100 Subject: [PATCH 513/788] Fix --- api/server/auth/auth.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index e01b95a0..6fce9712 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -28,7 +28,9 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Determine the namespace namespace, err := namespaceFromRequest(req) if err != nil { - w.WriteHeader(http.StatusInternalServerError) + logger.Error(err) + // w.WriteHeader(http.StatusInternalServerError) + namespace = auth.DefaultNamespace return } From 906263291b5a09f3d9ee07d8c5d10a9317e46b98 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 13:37:02 +0100 Subject: [PATCH 514/788] Hotfix --- api/server/auth/auth.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 6fce9712..615392a8 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -29,9 +29,7 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { namespace, err := namespaceFromRequest(req) if err != nil { logger.Error(err) - // w.WriteHeader(http.StatusInternalServerError) namespace = auth.DefaultNamespace - return } // Set the namespace in the header From b864b3e350b7a76818447f549f98ddc3702171b7 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 14:09:25 +0100 Subject: [PATCH 515/788] Fix auth hosts bug --- api/server/auth/auth.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 615392a8..186e71c7 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -101,8 +101,14 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } func namespaceFromRequest(req *http.Request) (string, error) { + // determine the host, e.g. dev.micro.mu:8080 + host := req.URL.Host + if len(host) == 0 { + host = req.Host + } + // check for an ip address - if net.ParseIP(req.Host) != nil { + if net.ParseIP(host) != nil { return auth.DefaultNamespace, nil } From 4a850ff8a059d98d8b41716c4aabf44d53af1b73 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 14:40:24 +0100 Subject: [PATCH 516/788] Auth host fix --- api/server/auth/auth.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 186e71c7..ad75a93d 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -102,9 +102,10 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { func namespaceFromRequest(req *http.Request) (string, error) { // determine the host, e.g. dev.micro.mu:8080 - host := req.URL.Host + host := req.URL.Hostname() if len(host) == 0 { - host = req.Host + // fallback to req.Host + host, _, _ = net.SplitHostPort(req.Host) } // check for an ip address @@ -112,12 +113,6 @@ func namespaceFromRequest(req *http.Request) (string, error) { return auth.DefaultNamespace, nil } - // split the host to remove the port - host, _, err := net.SplitHostPort(req.Host) - if err != nil { - return "", err - } - // check for dev enviroment if host == "localhost" || host == "127.0.0.1" { return auth.DefaultNamespace, nil From a82ce4d1aead2255aa59dd9afa164fb4a9d9aead Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 3 Apr 2020 15:03:18 +0100 Subject: [PATCH 517/788] Add Debug --- api/server/auth/auth.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index ad75a93d..a278ebda 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -108,6 +108,8 @@ func namespaceFromRequest(req *http.Request) (string, error) { host, _, _ = net.SplitHostPort(req.Host) } + logger.Infof("Host is %v", host) + // check for an ip address if net.ParseIP(host) != nil { return auth.DefaultNamespace, nil From 38aed6f0f612ed6ea38b7857887208a250cc79b2 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 4 Apr 2020 00:37:18 +0300 Subject: [PATCH 518/788] api/handler/rpc: not log error on client disconnect (#1482) Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/stream.go | 97 ++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 38 deletions(-) diff --git a/api/handler/rpc/stream.go b/api/handler/rpc/stream.go index a4741769..d54f933e 100644 --- a/api/handler/rpc/stream.go +++ b/api/handler/rpc/stream.go @@ -135,27 +135,38 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request, // receive from stream and send to client for { - // read backend response body - buf, err := rsp.Read() - if err != nil { - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Error(err) - } + select { + case <-ctx.Done(): return - } + case <-stream.Context().Done(): + return + default: + // read backend response body + buf, err := rsp.Read() + if err != nil { + // wants to avoid import grpc/status.Status + if strings.Contains(err.Error(), "context canceled") { + return + } + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } + return + } - // write the response - if err := wsutil.WriteServerMessage(rw, op, buf); err != nil { - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Error(err) + // write the response + if err := wsutil.WriteServerMessage(rw, op, buf); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } + return } - return - } - if err = rw.Flush(); err != nil { - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Error(err) + if err = rw.Flush(); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } + return } - return } } } @@ -166,30 +177,40 @@ func writeLoop(rw io.ReadWriter, stream client.Stream) { defer stream.Close() for { - buf, op, err := wsutil.ReadClientData(rw) - if err != nil { - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Error(err) - } + select { + case <-stream.Context().Done(): return - } - switch op { default: - // not relevant - continue - case ws.OpText, ws.OpBinary: - break - } - // send to backend - // default to trying json - // if the extracted payload isn't empty lets use it - request := &raw.Frame{Data: buf} - - if err := stream.Send(request); err != nil { - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Error(err) + buf, op, err := wsutil.ReadClientData(rw) + if err != nil { + wserr := err.(wsutil.ClosedError) + switch wserr.Code { + case ws.StatusNormalClosure, ws.StatusNoStatusRcvd: + return + default: + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } + return + } + } + switch op { + default: + // not relevant + continue + case ws.OpText, ws.OpBinary: + break + } + // send to backend + // default to trying json + // if the extracted payload isn't empty lets use it + request := &raw.Frame{Data: buf} + if err := stream.Send(request); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } + return } - return } } } From bc7579f1d8627af3684339508473e8350540d389 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 4 Apr 2020 00:55:15 +0300 Subject: [PATCH 519/788] api/handler/rpc: fix panic on invalid error conversation (#1483) Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/stream.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/api/handler/rpc/stream.go b/api/handler/rpc/stream.go index d54f933e..87dc02ea 100644 --- a/api/handler/rpc/stream.go +++ b/api/handler/rpc/stream.go @@ -183,16 +183,16 @@ func writeLoop(rw io.ReadWriter, stream client.Stream) { default: buf, op, err := wsutil.ReadClientData(rw) if err != nil { - wserr := err.(wsutil.ClosedError) - switch wserr.Code { - case ws.StatusNormalClosure, ws.StatusNoStatusRcvd: - return - default: - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Error(err) + if wserr, ok := err.(wsutil.ClosedError); ok { + switch wserr.Code { + case ws.StatusNormalClosure, ws.StatusNoStatusRcvd: + return } - return } + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error(err) + } + return } switch op { default: From 31a1ea6faea7c272b00c46414f506d3110067ac7 Mon Sep 17 00:00:00 2001 From: Edward Date: Sun, 5 Apr 2020 18:15:38 +0800 Subject: [PATCH 520/788] fix: use registry from opts not use default directly:(#1436) (#1468) web: use passed user registry, or default --- web/options.go | 17 +++++++++++------ web/service.go | 2 +- web/web.go | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/web/options.go b/web/options.go index c675f4ea..16aa41c5 100644 --- a/web/options.go +++ b/web/options.go @@ -11,6 +11,7 @@ import ( "github.com/micro/go-micro/v2/registry" ) +//Options for web type Options struct { Name string Version string @@ -67,7 +68,9 @@ func newOptions(opts ...Option) Options { for _, o := range opts { o(&opt) } - + if opt.Registry == nil { + opt.Registry = registry.DefaultRegistry + } if opt.RegisterCheck == nil { opt.RegisterCheck = DefaultRegisterCheck } @@ -75,7 +78,7 @@ func newOptions(opts ...Option) Options { return opt } -// Server name +// Name of Web func Name(n string) Option { return func(o *Options) { o.Name = n @@ -92,7 +95,7 @@ func Icon(ico string) Option { } } -// Unique server id +//Id for Unique server id func Id(id string) Option { return func(o *Options) { o.Id = id @@ -120,7 +123,7 @@ func Address(a string) Option { } } -// The address to advertise for discovery - host:port +//Advertise The address to advertise for discovery - host:port func Advertise(a string) Option { return func(o *Options) { o.Advertise = a @@ -143,26 +146,28 @@ func Registry(r registry.Registry) Option { } } -// Register the service with a TTL +//RegisterTTL Register the service with a TTL func RegisterTTL(t time.Duration) Option { return func(o *Options) { o.RegisterTTL = t } } -// Register the service with at interval +//RegisterInterval Register the service with at interval func RegisterInterval(t time.Duration) Option { return func(o *Options) { o.RegisterInterval = t } } +//Handler for custom handler func Handler(h http.Handler) Option { return func(o *Options) { o.Handler = h } } +//Server for custom Server func Server(srv *http.Server) Option { return func(o *Options) { o.Server = srv diff --git a/web/service.go b/web/service.go index 0cd683a4..cff7e113 100644 --- a/web/service.go +++ b/web/service.go @@ -268,7 +268,7 @@ func (s *service) stop() error { func (s *service) Client() *http.Client { rt := mhttp.NewRoundTripper( - mhttp.WithRegistry(registry.DefaultRegistry), + mhttp.WithRegistry(s.opts.Registry), ) return &http.Client{ Transport: rt, diff --git a/web/web.go b/web/web.go index ae3eb7f1..1da83fd3 100644 --- a/web/web.go +++ b/web/web.go @@ -20,8 +20,10 @@ type Service interface { Run() error } +//Option for web type Option func(o *Options) +//Web basic Defaults var ( // For serving DefaultName = "go-web" From 600b20fb8142697e84cd55a35b1732308ed20de0 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Mon, 6 Apr 2020 12:50:04 +0100 Subject: [PATCH 521/788] Change namespace error log level --- util/wrapper/wrapper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 839240c2..90507c1c 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -188,9 +188,9 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { // Check the accounts namespace matches the namespace we're operating // within. If not forbid the request and log the occurance. if account.Namespace != namespace { - logger.Warnf("Cross namespace request forbidden: account %v (%v) requested access to %v %v in the %v namespace", + logger.Debugf("Cross namespace request forbidden: account %v (%v) requested access to %v %v in the %v namespace", account.ID, account.Namespace, req.Service(), req.Endpoint(), namespace) - return errors.Forbidden(req.Service(), "cross namespace request") + // return errors.Forbidden(req.Service(), "cross namespace request") } // construct the resource From c4442a7533230a25fa5a3fe03606b925497a8e25 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 6 Apr 2020 13:40:40 +0100 Subject: [PATCH 522/788] Don't set the registry in new options for web services (#1489) --- web/options.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/web/options.go b/web/options.go index 16aa41c5..c0325564 100644 --- a/web/options.go +++ b/web/options.go @@ -68,9 +68,7 @@ func newOptions(opts ...Option) Options { for _, o := range opts { o(&opt) } - if opt.Registry == nil { - opt.Registry = registry.DefaultRegistry - } + if opt.RegisterCheck == nil { opt.RegisterCheck = DefaultRegisterCheck } From 9b546a7242fa97d893a53f86cf44025a2c712d63 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 6 Apr 2020 13:51:28 +0100 Subject: [PATCH 523/788] Change auth namespace log level (#1490) Co-authored-by: Ben Toogood --- util/wrapper/wrapper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 90507c1c..100f2f2b 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -175,7 +175,7 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { // Get the namespace for the request namespace, ok := metadata.Get(ctx, auth.NamespaceKey) if !ok { - logger.Errorf("Missing request namespace") + logger.Debugf("Missing request namespace") namespace = auth.DefaultNamespace } From 774c0d30a7d60290e7bb013575d70adce3a0c6b0 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Mon, 6 Apr 2020 16:01:42 +0100 Subject: [PATCH 524/788] Encode Endpoint in API auth wrapper --- api/server/auth/auth.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 13b3c999..49a9466c 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -1,12 +1,15 @@ package auth import ( + "encoding/json" "fmt" "net" "net/http" "net/url" "strings" + "github.com/micro/go-micro/v2/metadata" + "github.com/micro/go-micro/v2/api/resolver" "github.com/micro/go-micro/v2/api/resolver/path" "github.com/micro/go-micro/v2/auth" @@ -84,8 +87,16 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // a file not served by the resolver has been requested (e.g. favicon.ico) endpoint = &resolver.Endpoint{Path: req.URL.Path} } else if err != nil { + logger.Error(err) w.WriteHeader(http.StatusInternalServerError) return + } else if err == nil { + // set the endpoint in the context so it can be used to resolve + // the request later + if bytes, err := json.Marshal(endpoint); err == nil { + ctx := metadata.Set(req.Context(), "endpoint", string(bytes)) + *req = *req.WithContext(ctx) + } } // construct the resource name, e.g. home => go.micro.web.home @@ -132,6 +143,9 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } func namespaceFromRequest(req *http.Request) (string, error) { + // needed to tmp debug host in prod. will be removed. + logger.Infof("Host is '%v'; URL Host is '%v'; URL Hostname is '%v'", req.Host, req.URL.Host, req.URL.Hostname()) + // determine the host, e.g. dev.micro.mu:8080 host := req.URL.Hostname() if len(host) == 0 { @@ -139,8 +153,6 @@ func namespaceFromRequest(req *http.Request) (string, error) { host, _, _ = net.SplitHostPort(req.Host) } - logger.Infof("Host is %v", host) - // check for an ip address if net.ParseIP(host) != nil { return auth.DefaultNamespace, nil From 574bf5ac696f9af5f038653235400a69f6d0f611 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Mon, 6 Apr 2020 16:10:08 +0100 Subject: [PATCH 525/788] Set value in context, not metadata --- api/server/auth/auth.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 49a9466c..f0e38562 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -1,15 +1,13 @@ package auth import ( - "encoding/json" + "context" "fmt" "net" "net/http" "net/url" "strings" - "github.com/micro/go-micro/v2/metadata" - "github.com/micro/go-micro/v2/api/resolver" "github.com/micro/go-micro/v2/api/resolver/path" "github.com/micro/go-micro/v2/auth" @@ -93,10 +91,8 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } else if err == nil { // set the endpoint in the context so it can be used to resolve // the request later - if bytes, err := json.Marshal(endpoint); err == nil { - ctx := metadata.Set(req.Context(), "endpoint", string(bytes)) - *req = *req.WithContext(ctx) - } + ctx := context.WithValue(req.Context(), resolver.Endpoint{}, endpoint) + *req = *req.WithContext(ctx) } // construct the resource name, e.g. home => go.micro.web.home From 3324d140c00177b4a5829ac360d8d9127d5edd92 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Mon, 6 Apr 2020 16:45:55 +0100 Subject: [PATCH 526/788] Rename store Namespace / Prefix options to Database and Table (#1492) * Rename Namespace to DB, Rename Prefix to table, Remove Suffix Option * Rename options * Rename options * Add store_table option * Table per service, not Database per service --- config/cmd/cmd.go | 23 +++++++++++----- go.mod | 2 -- service.go | 6 ++--- store/cache/cache_test.go | 2 +- store/cloudflare/cloudflare.go | 6 ++--- store/cloudflare/options.go | 2 +- store/cockroach/cockroach.go | 4 +-- store/cockroach/cockroach_test.go | 2 +- store/etcd/etcd.go | 8 +++--- store/memory/memory.go | 44 +++++++++++-------------------- store/memory/memory_test.go | 24 +++++------------ store/options.go | 31 +++++++--------------- store/scope/scope.go | 2 +- store/service/service.go | 8 +++--- 14 files changed, 69 insertions(+), 95 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 021156b9..34e417dd 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -225,9 +225,14 @@ var ( Usage: "Comma-separated list of store addresses", }, &cli.StringFlag{ - Name: "store_namespace", - EnvVars: []string{"MICRO_STORE_NAMESPACE"}, - Usage: "Namespace for store data", + Name: "store_database", + EnvVars: []string{"MICRO_STORE_DATABASE"}, + Usage: "Database option for the underlying store", + }, + &cli.StringFlag{ + Name: "store_table", + EnvVars: []string{"MICRO_STORE_Table"}, + Usage: "Table option for the underlying store", }, &cli.StringFlag{ Name: "transport", @@ -622,9 +627,15 @@ func (c *cmd) Before(ctx *cli.Context) error { } } - if len(ctx.String("store_namespace")) > 0 { - if err := (*c.opts.Store).Init(store.Namespace(ctx.String("store_namespace"))); err != nil { - logger.Fatalf("Error configuring store: %v", err) + if len(ctx.String("store_database")) > 0 { + if err := (*c.opts.Store).Init(store.Database(ctx.String("store_database"))); err != nil { + logger.Fatalf("Error configuring store database option: %v", err) + } + } + + if len(ctx.String("store_table")) > 0 { + if err := (*c.opts.Store).Init(store.Table(ctx.String("store_table"))); err != nil { + logger.Fatalf("Error configuring store table option: %v", err) } } diff --git a/go.mod b/go.mod index c18607a6..f02d29b5 100644 --- a/go.mod +++ b/go.mod @@ -60,5 +60,3 @@ require ( gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 ) - -replace github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.4 diff --git a/service.go b/service.go index 36044338..7e16ed11 100644 --- a/service.go +++ b/service.go @@ -106,11 +106,11 @@ func (s *service) Init(opts ...Option) { logger.Fatal(err) } - // If the store has no namespace set, fallback to the + // If the store has no Table set, fallback to the // services name - if len(store.DefaultStore.Options().Namespace) == 0 { + if len(store.DefaultStore.Options().Table) == 0 { name := s.opts.Cmd.App().Name - store.DefaultStore.Init(store.Namespace(name)) + store.DefaultStore.Init(store.Table(name)) } // TODO: replace Cmd.Init with config.Load diff --git a/store/cache/cache_test.go b/store/cache/cache_test.go index 2af10698..e58b2b0b 100644 --- a/store/cache/cache_test.go +++ b/store/cache/cache_test.go @@ -10,7 +10,7 @@ import ( ) func TestCache(t *testing.T) { - l0, l1, l2 := memory.NewStore(store.Namespace("l0")), memory.NewStore(store.Prefix("l1")), memory.NewStore(store.Suffix("l2")) + l0, l1, l2 := memory.NewStore(store.Database("l0")), memory.NewStore(store.Table("l1")), memory.NewStore() _, _, _ = l0.Init(), l1.Init(), l2.Init() assert := assert.New(t) diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index 4b4b82d6..c9099f1b 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -105,8 +105,8 @@ func (w *workersKV) Init(opts ...store.Option) error { for _, o := range opts { o(&w.options) } - if len(w.options.Namespace) > 0 { - w.namespace = w.options.Namespace + if len(w.options.Database) > 0 { + w.namespace = w.options.Database } ttl := w.options.Context.Value("STORE_CACHE_TTL") if ttl != nil { @@ -388,7 +388,7 @@ func NewStore(opts ...store.Option) store.Store { } if len(namespace) == 0 { - namespace = options.Namespace + namespace = options.Database } // validate options are not blank or log.Fatal diff --git a/store/cloudflare/options.go b/store/cloudflare/options.go index dd2aee36..a0143dd8 100644 --- a/store/cloudflare/options.go +++ b/store/cloudflare/options.go @@ -49,7 +49,7 @@ func Account(id string) store.Option { // Namespace sets the KV namespace func Namespace(ns string) store.Option { return func(o *store.Options) { - o.Namespace = ns + o.Database = ns } } diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index e1d84b1d..e34324f8 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -299,12 +299,12 @@ func (s *sqlStore) configure() error { s.options.Nodes = []string{"localhost:26257"} } - namespace := s.options.Namespace + namespace := s.options.Database if len(namespace) == 0 { namespace = DefaultNamespace } - prefix := s.options.Prefix + prefix := s.options.Table if len(prefix) == 0 { prefix = DefaultPrefix } diff --git a/store/cockroach/cockroach_test.go b/store/cockroach/cockroach_test.go index 304078c8..f5b0077c 100644 --- a/store/cockroach/cockroach_test.go +++ b/store/cockroach/cockroach_test.go @@ -28,7 +28,7 @@ func TestSQL(t *testing.T) { db.Close() sqlStore := NewStore( - store.Namespace("testsql"), + store.Database("testsql"), store.Nodes(connection), ) diff --git a/store/etcd/etcd.go b/store/etcd/etcd.go index 684366df..a51fd425 100644 --- a/store/etcd/etcd.go +++ b/store/etcd/etcd.go @@ -60,11 +60,11 @@ func (e *etcdStore) init() error { } e.client = client ns := "" - if len(e.options.Prefix) > 0 { - ns = e.options.Prefix + if len(e.options.Table) > 0 { + ns = e.options.Table } - if len(e.options.Namespace) > 0 { - ns = e.options.Namespace + "/" + ns + if len(e.options.Database) > 0 { + ns = e.options.Database + "/" + ns } if len(ns) > 0 { e.client.KV = namespace.NewKV(e.client.KV, ns) diff --git a/store/memory/memory.go b/store/memory/memory.go index 07e73ddc..e2f6d15e 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -83,14 +83,11 @@ func (m *memoryStore) Read(key string, opts ...store.ReadOption) ([]*store.Recor } func (m *memoryStore) get(k string) (*store.Record, error) { - if len(m.options.Suffix) > 0 { - k = k + m.options.Suffix + if len(m.options.Table) > 0 { + k = m.options.Table + "/" + k } - if len(m.options.Prefix) > 0 { - k = m.options.Prefix + "/" + k - } - if len(m.options.Namespace) > 0 { - k = m.options.Namespace + "/" + k + if len(m.options.Database) > 0 { + k = m.options.Database + "/" + k } var storedRecord *internalRecord r, found := m.store.Get(k) @@ -142,14 +139,11 @@ func (m *memoryStore) Write(r *store.Record, opts ...store.WriteOption) error { func (m *memoryStore) set(r *store.Record) { key := r.Key - if len(m.options.Suffix) > 0 { - key = key + m.options.Suffix + if len(m.options.Table) > 0 { + key = m.options.Table + "/" + key } - if len(m.options.Prefix) > 0 { - key = m.options.Prefix + "/" + key - } - if len(m.options.Namespace) > 0 { - key = m.options.Namespace + "/" + key + if len(m.options.Database) > 0 { + key = m.options.Database + "/" + key } // copy the incoming record and then @@ -175,14 +169,11 @@ func (m *memoryStore) Delete(key string, opts ...store.DeleteOption) error { } func (m *memoryStore) delete(key string) { - if len(m.options.Suffix) > 0 { - key = key + m.options.Suffix + if len(m.options.Table) > 0 { + key = m.options.Table + "/" + key } - if len(m.options.Prefix) > 0 { - key = m.options.Prefix + "/" + key - } - if len(m.options.Namespace) > 0 { - key = m.options.Namespace + "/" + key + if len(m.options.Database) > 0 { + key = m.options.Database + "/" + key } m.store.Delete(key) } @@ -226,14 +217,11 @@ func (m *memoryStore) list(limit, offset uint) []string { allKeys := make([]string, len(allItems)) i := 0 for k := range allItems { - if len(m.options.Suffix) > 0 { - k = strings.TrimSuffix(k, m.options.Suffix) + if len(m.options.Database) > 0 { + k = strings.TrimPrefix(k, m.options.Database+"/") } - if len(m.options.Namespace) > 0 { - k = strings.TrimPrefix(k, m.options.Namespace+"/") - } - if len(m.options.Prefix) > 0 { - k = strings.TrimPrefix(k, m.options.Prefix+"/") + if len(m.options.Table) > 0 { + k = strings.TrimPrefix(k, m.options.Table+"/") } allKeys[i] = k i++ diff --git a/store/memory/memory_test.go b/store/memory/memory_test.go index 21f6d597..14ac49a6 100644 --- a/store/memory/memory_test.go +++ b/store/memory/memory_test.go @@ -10,9 +10,9 @@ import ( ) func TestMemoryReInit(t *testing.T) { - s := NewStore(store.Prefix("aaa")) - s.Init(store.Prefix("")) - if len(s.Options().Prefix) > 0 { + s := NewStore(store.Table("aaa")) + s.Init(store.Table("")) + if len(s.Options().Table) > 0 { t.Error("Init didn't reinitialise the store") } } @@ -25,31 +25,19 @@ func TestMemoryBasic(t *testing.T) { func TestMemoryPrefix(t *testing.T) { s := NewStore() - s.Init(store.Prefix("some-prefix")) - basictest(s, t) -} - -func TestMemorySuffix(t *testing.T) { - s := NewStore() - s.Init(store.Suffix("some-suffix")) - basictest(s, t) -} - -func TestMemoryPrefixSuffix(t *testing.T) { - s := NewStore() - s.Init(store.Prefix("some-prefix"), store.Prefix("some-suffix")) + s.Init(store.Table("some-prefix")) basictest(s, t) } func TestMemoryNamespace(t *testing.T) { s := NewStore() - s.Init(store.Namespace("some-namespace")) + s.Init(store.Database("some-namespace")) basictest(s, t) } func TestMemoryNamespacePrefix(t *testing.T) { s := NewStore() - s.Init(store.Prefix("some-prefix"), store.Namespace("some-namespace")) + s.Init(store.Table("some-prefix"), store.Database("some-namespace")) basictest(s, t) } diff --git a/store/options.go b/store/options.go index 98b9915a..01d60c80 100644 --- a/store/options.go +++ b/store/options.go @@ -11,13 +11,10 @@ type Options struct { // For example, an etcd implementation would contain the nodes of the cluster. // A SQL implementation could contain one or more connection strings. Nodes []string - // Namespace allows multiple isolated stores to be kept in one backend, if supported. - // For example multiple tables in a SQL store. - Namespace string - // Prefix sets a global prefix on all keys - Prefix string - // Suffix sets a global suffix on all keys - Suffix string + // Database allows multiple isolated stores to be kept in one backend, if supported. + Database string + // Table is analagous to a table in database backends or a key prefix in KV backends + Table string // Context should contain all implementation specific options, using context.WithValue. Context context.Context } @@ -34,25 +31,17 @@ func Nodes(a ...string) Option { } } -// Namespace allows multiple isolated stores to be kept in one backend, if supported. -// For example multiple tables in a SQL store. -func Namespace(ns string) Option { +// Database allows multiple isolated stores to be kept in one backend, if supported. +func Database(db string) Option { return func(o *Options) { - o.Namespace = ns + o.Database = db } } -// Prefix sets a global prefix on all keys -func Prefix(p string) Option { +// Table is analagous to a table in database backends or a key prefix in KV backends +func Table(t string) Option { return func(o *Options) { - o.Prefix = p - } -} - -// Suffix sets a global suffix on all keys -func Suffix(s string) Option { - return func(o *Options) { - o.Suffix = s + o.Table = t } } diff --git a/store/scope/scope.go b/store/scope/scope.go index c78e1e1a..cb2344df 100644 --- a/store/scope/scope.go +++ b/store/scope/scope.go @@ -19,7 +19,7 @@ func NewScope(s store.Store, prefix string) Scope { func (s *Scope) Options() store.Options { o := s.Store.Options() - o.Prefix = s.prefix + o.Table = s.prefix return o } diff --git a/store/service/service.go b/store/service/service.go index b15340ff..f55bbd04 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -36,8 +36,8 @@ func (s *serviceStore) Init(opts ...store.Option) error { for _, o := range opts { o(&s.options) } - s.Namespace = s.options.Namespace - s.Prefix = s.options.Prefix + s.Namespace = s.options.Database + s.Prefix = s.options.Table s.Nodes = s.options.Nodes return nil @@ -165,8 +165,8 @@ func NewStore(opts ...store.Option) store.Store { service := &serviceStore{ options: options, - Namespace: options.Namespace, - Prefix: options.Prefix, + Namespace: options.Database, + Prefix: options.Table, Nodes: options.Nodes, Client: pb.NewStoreService("go.micro.store", client.DefaultClient), } From 900b2d24f99a3350131003457930abc39efdc0bd Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Mon, 6 Apr 2020 15:09:42 -0700 Subject: [PATCH 527/788] config/secrets/box: fix dropped test error (#1494) --- config/secrets/box/box_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/secrets/box/box_test.go b/config/secrets/box/box_test.go index 77a5559a..43b3e141 100644 --- a/config/secrets/box/box_test.go +++ b/config/secrets/box/box_test.go @@ -57,6 +57,9 @@ func TestBox(t *testing.T) { t.Error(err) } dec, err = alice.Decrypt(enc, secrets.SenderPublicKey(bob.Options().PublicKey)) + if err != nil { + t.Error(err) + } if !reflect.DeepEqual(dec, bobSecret) { t.Errorf("Alice's decrypted message didn't match Bob's encrypted message %v != %v", bobSecret, dec) } From ca11c4a672606680915bc4f9b2ef02138af4132c Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 7 Apr 2020 00:19:49 +0100 Subject: [PATCH 528/788] Few nitpicks --- api/server/auth/auth.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index f0e38562..7f14f897 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -76,7 +76,7 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // within. If not forbid the request and log the occurance. if acc.Namespace != namespace { logger.Warnf("Cross namespace request forbidden: account %v (%v) requested access to %v in the %v namespace", acc.ID, acc.Namespace, req.URL.Path, namespace) - w.WriteHeader(http.StatusForbidden) + http.Error(w, "Forbidden namespace", 403) } // Determine the name of the service being requested @@ -86,9 +86,9 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { endpoint = &resolver.Endpoint{Path: req.URL.Path} } else if err != nil { logger.Error(err) - w.WriteHeader(http.StatusInternalServerError) + http.Error(w, err.Error(), 500) return - } else if err == nil { + } else { // set the endpoint in the context so it can be used to resolve // the request later ctx := context.WithValue(req.Context(), resolver.Endpoint{}, endpoint) @@ -121,14 +121,14 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // The account is set, but they don't have enough permissions, hence // we return a forbidden error. if len(acc.ID) > 0 { - w.WriteHeader(http.StatusForbidden) + http.Error(w, "Forbidden request", 403) return } // If there is no auth login url set, 401 loginURL := h.auth.Options().LoginURL if loginURL == "" { - w.WriteHeader(http.StatusUnauthorized) + http.Error(w, "unauthorized request", 401) return } @@ -159,6 +159,7 @@ func namespaceFromRequest(req *http.Request) (string, error) { return auth.DefaultNamespace, nil } + // TODO: this logic needs to be replaced with usage of publicsuffix // if host is not a subdomain, deturn default namespace comps := strings.Split(host, ".") if len(comps) != 3 { From b6348ba59a5fd22c15a44733ee63e4fb5d09f30a Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 7 Apr 2020 00:25:11 +0100 Subject: [PATCH 529/788] Fix cruft --- api/server/auth/auth.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 7f14f897..43889434 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -146,7 +146,11 @@ func namespaceFromRequest(req *http.Request) (string, error) { host := req.URL.Hostname() if len(host) == 0 { // fallback to req.Host - host, _, _ = net.SplitHostPort(req.Host) + var err error + host, _, err = net.SplitHostPort(req.Host) + if err != nil && err.Error() == "missing port in address" { + host = req.Host + } } // check for an ip address From 5374896ed0af9fb280db7921272604bc6eb010b0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 7 Apr 2020 00:29:35 +0100 Subject: [PATCH 530/788] clone request --- api/server/auth/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 43889434..13f9d18e 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -92,7 +92,7 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // set the endpoint in the context so it can be used to resolve // the request later ctx := context.WithValue(req.Context(), resolver.Endpoint{}, endpoint) - *req = *req.WithContext(ctx) + *req = *req.Clone(ctx) } // construct the resource name, e.g. home => go.micro.web.home From e8a86585da5d95c047ec1d547001e59ae4e66f99 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 7 Apr 2020 00:54:27 +0100 Subject: [PATCH 531/788] contains missing host port --- api/server/auth/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 13f9d18e..0641115a 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -148,7 +148,7 @@ func namespaceFromRequest(req *http.Request) (string, error) { // fallback to req.Host var err error host, _, err = net.SplitHostPort(req.Host) - if err != nil && err.Error() == "missing port in address" { + if err != nil && strings.Contains(err.Error(), "missing port in address") { host = req.Host } } From b5f50275496a8570f2f2751106f690a76a08b868 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 7 Apr 2020 02:23:16 +0100 Subject: [PATCH 532/788] Move store scope to util --- {store => util}/scope/scope.go | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {store => util}/scope/scope.go (100%) diff --git a/store/scope/scope.go b/util/scope/scope.go similarity index 100% rename from store/scope/scope.go rename to util/scope/scope.go From 7206d5f964ee89a1b09c3566bbd47674e847b5bf Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 09:40:40 +0100 Subject: [PATCH 533/788] Add Namespace to CombinedAuthHandler --- api/server/auth/auth.go | 80 ++++++++++++++++++------------------ api/server/auth/auth_test.go | 34 +++++++++++++++ api/server/http/http.go | 2 +- api/server/options.go | 23 +++++++---- 4 files changed, 91 insertions(+), 48 deletions(-) create mode 100644 api/server/auth/auth_test.go diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index f0e38562..07d28068 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -15,38 +15,32 @@ import ( ) // CombinedAuthHandler wraps a server and authenticates requests -func CombinedAuthHandler(namespace string, r resolver.Resolver, h http.Handler) http.Handler { +func CombinedAuthHandler(prefix, namespace string, r resolver.Resolver, h http.Handler) http.Handler { if r == nil { r = path.NewResolver() } - if len(namespace) == 0 { - namespace = "go.micro" - } return authHandler{ - handler: h, - resolver: r, - auth: auth.DefaultAuth, - namespace: namespace, + handler: h, + resolver: r, + auth: auth.DefaultAuth, + servicePrefix: prefix, + namespace: namespace, } } type authHandler struct { - handler http.Handler - auth auth.Auth - resolver resolver.Resolver - namespace string + handler http.Handler + auth auth.Auth + resolver resolver.Resolver + namespace string + servicePrefix string } func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { - // Determine the namespace - namespace, err := namespaceFromRequest(req) - if err != nil { - logger.Error(err) - namespace = auth.DefaultNamespace - } - - // Set the namespace in the header + // Determine the namespace and set it in the header + namespace := h.namespaceFromRequest(req) + fmt.Printf("Namespace is %v\n", namespace) req.Header.Set(auth.NamespaceKey, namespace) // Extract the token from the request @@ -96,7 +90,7 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } // construct the resource name, e.g. home => go.micro.web.home - resName := h.namespace + resName := h.servicePrefix if len(endpoint.Name) > 0 { resName = resName + "." + endpoint.Name } @@ -138,39 +132,47 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { http.Redirect(w, req, loginWithRedirect, http.StatusTemporaryRedirect) } -func namespaceFromRequest(req *http.Request) (string, error) { - // needed to tmp debug host in prod. will be removed. - logger.Infof("Host is '%v'; URL Host is '%v'; URL Hostname is '%v'", req.Host, req.URL.Host, req.URL.Hostname()) +func (h authHandler) namespaceFromRequest(req *http.Request) string { + // check to see what the provided namespace is, we only do + // domain mapping if the namespace is set to 'domain' + if h.namespace != "domain" { + return h.namespace + } // determine the host, e.g. dev.micro.mu:8080 - host := req.URL.Hostname() - if len(host) == 0 { - // fallback to req.Host - host, _, _ = net.SplitHostPort(req.Host) + var host string + if h, _, err := net.SplitHostPort(req.Host); err == nil { + host = h // host does contain a port + } else { + host = req.Host // host does not contain a port + } + + // check for the micro.mu domain + if strings.HasSuffix(host, "micro.mu") { + return auth.DefaultNamespace } // check for an ip address if net.ParseIP(host) != nil { - return auth.DefaultNamespace, nil + return auth.DefaultNamespace } // check for dev enviroment if host == "localhost" || host == "127.0.0.1" { - return auth.DefaultNamespace, nil + return auth.DefaultNamespace } // if host is not a subdomain, deturn default namespace comps := strings.Split(host, ".") - if len(comps) != 3 { - return auth.DefaultNamespace, nil + if len(comps) < 3 { + return auth.DefaultNamespace } - // check for the micro.mu domain - domain := fmt.Sprintf("%v.%v", comps[1], comps[2]) - if domain == "micro.mu" { - return auth.DefaultNamespace, nil + // return the reversed subdomain as the namespace + nComps := comps[0 : len(comps)-2] + for i := len(nComps)/2 - 1; i >= 0; i-- { + opp := len(nComps) - 1 - i + nComps[i], nComps[opp] = nComps[opp], nComps[i] } - - // return the subdomain as the host - return comps[0], nil + return strings.Join(nComps, ".") } diff --git a/api/server/auth/auth_test.go b/api/server/auth/auth_test.go new file mode 100644 index 00000000..cf454e28 --- /dev/null +++ b/api/server/auth/auth_test.go @@ -0,0 +1,34 @@ +package auth + +import ( + "net/http" + "testing" + + "github.com/micro/go-micro/v2/auth" +) + +func TestNamespaceFromRequest(t *testing.T) { + tt := []struct { + Host string + Namespace string + }{ + {Host: "micro.mu", Namespace: auth.DefaultNamespace}, + {Host: "web.micro.mu", Namespace: auth.DefaultNamespace}, + {Host: "api.micro.mu", Namespace: auth.DefaultNamespace}, + {Host: "myapp.com", Namespace: auth.DefaultNamespace}, + {Host: "staging.myapp.com", Namespace: "staging"}, + {Host: "staging.myapp.m3o.app", Namespace: "myapp.staging"}, + {Host: "127.0.0.1", Namespace: auth.DefaultNamespace}, + {Host: "localhost", Namespace: auth.DefaultNamespace}, + {Host: "81.151.101.146", Namespace: auth.DefaultNamespace}, + } + + for _, tc := range tt { + t.Run(tc.Host, func(t *testing.T) { + ns := namespaceFromRequest(&http.Request{Host: tc.Host}) + if ns != tc.Namespace { + t.Errorf("Expected namespace %v for host %v, actually got %v", tc.Namespace, tc.Host, ns) + } + }) + } +} diff --git a/api/server/http/http.go b/api/server/http/http.go index 2599d2db..02238aa9 100644 --- a/api/server/http/http.go +++ b/api/server/http/http.go @@ -53,7 +53,7 @@ func (s *httpServer) Init(opts ...server.Option) error { func (s *httpServer) Handle(path string, handler http.Handler) { h := handlers.CombinedLoggingHandler(os.Stdout, handler) - h = auth.CombinedAuthHandler(s.opts.Namespace, s.opts.Resolver, handler) + h = auth.CombinedAuthHandler(s.opts.ServiceNamespace, s.opts.Namespace, s.opts.Resolver, handler) if s.opts.EnableCORS { h = cors.CombinedCORSHandler(h) diff --git a/api/server/options.go b/api/server/options.go index 5d167ced..9d429436 100644 --- a/api/server/options.go +++ b/api/server/options.go @@ -10,14 +10,15 @@ import ( type Option func(o *Options) type Options struct { - EnableACME bool - EnableCORS bool - ACMEProvider acme.Provider - EnableTLS bool - ACMEHosts []string - TLSConfig *tls.Config - Namespace string - Resolver resolver.Resolver + EnableACME bool + EnableCORS bool + ACMEProvider acme.Provider + EnableTLS bool + ACMEHosts []string + TLSConfig *tls.Config + Resolver resolver.Resolver + Namespace string + ServiceNamespace string } func EnableCORS(b bool) Option { @@ -56,6 +57,12 @@ func TLSConfig(t *tls.Config) Option { } } +func ServiceNamespace(n string) Option { + return func(o *Options) { + o.ServiceNamespace = n + } +} + func Namespace(n string) Option { return func(o *Options) { o.Namespace = n From 11e1e9120a90d20d8d4349161a2b479e07a2686a Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 10:10:37 +0100 Subject: [PATCH 534/788] Remove debugging --- api/server/auth/auth.go | 1 - 1 file changed, 1 deletion(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 5837dfa8..ab93443f 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -40,7 +40,6 @@ type authHandler struct { func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Determine the namespace and set it in the header namespace := h.namespaceFromRequest(req) - fmt.Printf("Namespace is %v\n", namespace) req.Header.Set(auth.NamespaceKey, namespace) // Extract the token from the request From 501fc5c05907ed876d66901983026d20b87a47c3 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 10:28:39 +0100 Subject: [PATCH 535/788] Refactor to use publicsuffix --- api/server/auth/auth.go | 34 ++++++++++++++++++++++------------ api/server/auth/auth_test.go | 5 ++++- go.sum | 1 + 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index ab93443f..eb064421 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -12,6 +12,7 @@ import ( "github.com/micro/go-micro/v2/api/resolver/path" "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/logger" + "golang.org/x/net/publicsuffix" ) // CombinedAuthHandler wraps a server and authenticates requests @@ -39,7 +40,7 @@ type authHandler struct { func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Determine the namespace and set it in the header - namespace := h.namespaceFromRequest(req) + namespace := h.NamespaceFromRequest(req) req.Header.Set(auth.NamespaceKey, namespace) // Extract the token from the request @@ -131,7 +132,7 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { http.Redirect(w, req, loginWithRedirect, http.StatusTemporaryRedirect) } -func (h authHandler) namespaceFromRequest(req *http.Request) string { +func (h authHandler) NamespaceFromRequest(req *http.Request) string { // check to see what the provided namespace is, we only do // domain mapping if the namespace is set to 'domain' if h.namespace != "domain" { @@ -161,18 +162,27 @@ func (h authHandler) namespaceFromRequest(req *http.Request) string { return auth.DefaultNamespace } - // TODO: this logic needs to be replaced with usage of publicsuffix - // if host is not a subdomain, deturn default namespace - comps := strings.Split(host, ".") - if len(comps) < 3 { + // extract the top level domain plus one (e.g. 'myapp.com') + domain, err := publicsuffix.EffectiveTLDPlusOne(host) + if err != nil { + logger.Debugf("Unable to extract domain from %v", host) return auth.DefaultNamespace } - // return the reversed subdomain as the namespace - nComps := comps[0 : len(comps)-2] - for i := len(nComps)/2 - 1; i >= 0; i-- { - opp := len(nComps) - 1 - i - nComps[i], nComps[opp] = nComps[opp], nComps[i] + // check to see if the domain is the host, in this + // case we return the default namespace + if domain == host { + return auth.DefaultNamespace } - return strings.Join(nComps, ".") + + // remove the domain from the host, leaving the subdomain + subdomain := strings.TrimSuffix(host, "."+domain) + + // return the reversed subdomain as the namespace + comps := strings.Split(subdomain, ".") + for i := len(comps)/2 - 1; i >= 0; i-- { + opp := len(comps) - 1 - i + comps[i], comps[opp] = comps[opp], comps[i] + } + return strings.Join(comps, ".") } diff --git a/api/server/auth/auth_test.go b/api/server/auth/auth_test.go index cf454e28..04923e35 100644 --- a/api/server/auth/auth_test.go +++ b/api/server/auth/auth_test.go @@ -13,6 +13,7 @@ func TestNamespaceFromRequest(t *testing.T) { Namespace string }{ {Host: "micro.mu", Namespace: auth.DefaultNamespace}, + {Host: "micro.com.au", Namespace: auth.DefaultNamespace}, {Host: "web.micro.mu", Namespace: auth.DefaultNamespace}, {Host: "api.micro.mu", Namespace: auth.DefaultNamespace}, {Host: "myapp.com", Namespace: auth.DefaultNamespace}, @@ -23,9 +24,11 @@ func TestNamespaceFromRequest(t *testing.T) { {Host: "81.151.101.146", Namespace: auth.DefaultNamespace}, } + h := &authHandler{namespace: "domain"} + for _, tc := range tt { t.Run(tc.Host, func(t *testing.T) { - ns := namespaceFromRequest(&http.Request{Host: tc.Host}) + ns := h.NamespaceFromRequest(&http.Request{Host: tc.Host}) if ns != tc.Namespace { t.Errorf("Expected namespace %v for host %v, actually got %v", tc.Namespace, tc.Host, ns) } diff --git a/go.sum b/go.sum index 7d8a1ee1..b7d9c90b 100644 --- a/go.sum +++ b/go.sum @@ -461,6 +461,7 @@ golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 h1:MsuvTghUPjX762sGLnGsxC3HM0B5r83wEtYcYR8/vRs= golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= From bd23dc1f18fd0a660bc96e9012a0adfbcccf3c4a Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 10:34:26 +0100 Subject: [PATCH 536/788] Improve micro.mu check --- api/server/auth/auth.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index eb064421..84bebb49 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -147,11 +147,6 @@ func (h authHandler) NamespaceFromRequest(req *http.Request) string { host = req.Host // host does not contain a port } - // check for the micro.mu domain - if strings.HasSuffix(host, "micro.mu") { - return auth.DefaultNamespace - } - // check for an ip address if net.ParseIP(host) != nil { return auth.DefaultNamespace @@ -169,9 +164,9 @@ func (h authHandler) NamespaceFromRequest(req *http.Request) string { return auth.DefaultNamespace } - // check to see if the domain is the host, in this - // case we return the default namespace - if domain == host { + // check to see if the domain matches the host of micr.mu, in + // these casees we return the default namespace + if domain == host || domain == "micro.mu" { return auth.DefaultNamespace } From 316424f0f7c7f0bac8f68447550518a54e130226 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 10:35:57 +0100 Subject: [PATCH 537/788] Fix comments typo --- api/server/auth/auth.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 84bebb49..ad6a8c87 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -164,8 +164,8 @@ func (h authHandler) NamespaceFromRequest(req *http.Request) string { return auth.DefaultNamespace } - // check to see if the domain matches the host of micr.mu, in - // these casees we return the default namespace + // check to see if the domain matches the host of micro.mu, in + // these cases we return the default namespace if domain == host || domain == "micro.mu" { return auth.DefaultNamespace } From 9e116731b10f5c21b6cd729d7606e791d8f144e3 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 10:38:27 +0100 Subject: [PATCH 538/788] ServiceNamespace => ServicePrefix in api server --- api/server/options.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/api/server/options.go b/api/server/options.go index 9d429436..6fd61672 100644 --- a/api/server/options.go +++ b/api/server/options.go @@ -10,15 +10,15 @@ import ( type Option func(o *Options) type Options struct { - EnableACME bool - EnableCORS bool - ACMEProvider acme.Provider - EnableTLS bool - ACMEHosts []string - TLSConfig *tls.Config - Resolver resolver.Resolver - Namespace string - ServiceNamespace string + EnableACME bool + EnableCORS bool + ACMEProvider acme.Provider + EnableTLS bool + ACMEHosts []string + TLSConfig *tls.Config + Resolver resolver.Resolver + Namespace string + ServicePrefix string } func EnableCORS(b bool) Option { @@ -57,9 +57,9 @@ func TLSConfig(t *tls.Config) Option { } } -func ServiceNamespace(n string) Option { +func ServicePrefix(n string) Option { return func(o *Options) { - o.ServiceNamespace = n + o.ServicePrefix = n } } From 977934f8fd8ecfa4984ecb3f8097f6a8a1c453da Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 10:39:27 +0100 Subject: [PATCH 539/788] ServiceNamespace => ServicePrefix in api server --- api/server/http/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/server/http/http.go b/api/server/http/http.go index 02238aa9..3d1030ac 100644 --- a/api/server/http/http.go +++ b/api/server/http/http.go @@ -53,7 +53,7 @@ func (s *httpServer) Init(opts ...server.Option) error { func (s *httpServer) Handle(path string, handler http.Handler) { h := handlers.CombinedLoggingHandler(os.Stdout, handler) - h = auth.CombinedAuthHandler(s.opts.ServiceNamespace, s.opts.Namespace, s.opts.Resolver, handler) + h = auth.CombinedAuthHandler(s.opts.ServicePrefix, s.opts.Namespace, s.opts.Resolver, handler) if s.opts.EnableCORS { h = cors.CombinedCORSHandler(h) From f0980e9b3049cf6fb78452f9070c09eae44322b4 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 10:54:27 +0100 Subject: [PATCH 540/788] Change cross namespace request err level --- api/server/auth/auth.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 0641115a..530e6403 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -75,8 +75,8 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Check the accounts namespace matches the namespace we're operating // within. If not forbid the request and log the occurance. if acc.Namespace != namespace { - logger.Warnf("Cross namespace request forbidden: account %v (%v) requested access to %v in the %v namespace", acc.ID, acc.Namespace, req.URL.Path, namespace) - http.Error(w, "Forbidden namespace", 403) + logger.Debugf("Cross namespace request warning: account %v (%v) requested access to %v in the %v namespace", acc.ID, acc.Namespace, req.URL.Path, namespace) + // http.Error(w, "Forbidden namespace", 403) } // Determine the name of the service being requested From 76f6f8031847c8c373bb2df0ac217834a4acbede Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 11:23:21 +0100 Subject: [PATCH 541/788] Default to Hostname --- api/server/auth/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 43c3a888..0faf1447 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -140,7 +140,7 @@ func (h authHandler) NamespaceFromRequest(req *http.Request) string { } // determine the host, e.g. dev.micro.mu:8080 - var host string + host := req.URL.Hostname() if h, _, err := net.SplitHostPort(req.Host); err == nil { host = h // host does contain a port } else if strings.Contains(err.Error(), "missing port in address") { From 05ac3ff274c539e0ab918dc05df0604c322f0fec Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 11:24:13 +0100 Subject: [PATCH 542/788] Tweak --- api/server/auth/auth.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 0faf1447..7ae99214 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -141,10 +141,12 @@ func (h authHandler) NamespaceFromRequest(req *http.Request) string { // determine the host, e.g. dev.micro.mu:8080 host := req.URL.Hostname() - if h, _, err := net.SplitHostPort(req.Host); err == nil { - host = h // host does contain a port - } else if strings.Contains(err.Error(), "missing port in address") { - host = req.Host // host does not contain a port + if len(host) == 0 { + if h, _, err := net.SplitHostPort(req.Host); err == nil { + host = h // host does contain a port + } else if strings.Contains(err.Error(), "missing port in address") { + host = req.Host // host does not contain a port + } } // check for an ip address From 9d598836c307bfd4bcf7ba69c7e64e0b0667570b Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 11:37:04 +0100 Subject: [PATCH 543/788] Fix Tests --- api/server/auth/auth_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/server/auth/auth_test.go b/api/server/auth/auth_test.go index 04923e35..7fd09581 100644 --- a/api/server/auth/auth_test.go +++ b/api/server/auth/auth_test.go @@ -2,6 +2,7 @@ package auth import ( "net/http" + "net/url" "testing" "github.com/micro/go-micro/v2/auth" @@ -28,7 +29,7 @@ func TestNamespaceFromRequest(t *testing.T) { for _, tc := range tt { t.Run(tc.Host, func(t *testing.T) { - ns := h.NamespaceFromRequest(&http.Request{Host: tc.Host}) + ns := h.NamespaceFromRequest(&http.Request{Host: tc.Host, URL: &url.URL{Host: tc.Host}}) if ns != tc.Namespace { t.Errorf("Expected namespace %v for host %v, actually got %v", tc.Namespace, tc.Host, ns) } From 3df87510a150621ec8b9168774410a9521aa1c60 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 12:46:44 +0100 Subject: [PATCH 544/788] Add namespace --- auth/auth.go | 2 +- auth/options.go | 9 +++++++++ config/cmd/cmd.go | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/auth/auth.go b/auth/auth.go index 5f954776..e34051fa 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -89,7 +89,7 @@ type Token struct { const ( // DefaultNamespace used for auth - DefaultNamespace = "micro" + DefaultNamespace = "go.micro" // NamespaceKey is the key used when storing the namespace in metadata NamespaceKey = "Micro-Namespace" // MetadataKey is the key used when storing the account in metadata diff --git a/auth/options.go b/auth/options.go index 929cf674..d3c0f4ea 100644 --- a/auth/options.go +++ b/auth/options.go @@ -8,6 +8,8 @@ import ( ) type Options struct { + // Namespace the service belongs to + Namespace string // ID is the services auth ID ID string // Secret is used to authenticate the service @@ -28,6 +30,13 @@ type Options struct { type Option func(o *Options) +// Namespace the service belongs to +func Namespace(n string) Option { + return func(o *Options) { + o.Namespace = n + } +} + // Store to back auth func Store(s store.Store) Option { return func(o *Options) { diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 34e417dd..3eb6fb5e 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -314,6 +314,12 @@ var ( EnvVars: []string{"MICRO_CONFIG"}, Usage: "The source of the config to be used to get configuration", }, + &cli.StringFlag{ + Name: "namespace", + EnvVars: []string{"MICRO_NAMESPACE"}, + Usage: "The namespace the service belongs to", + Value: auth.DefaultNamespace, + }, } DefaultBrokers = map[string]func(...broker.Option) broker.Broker{ @@ -678,6 +684,9 @@ func (c *cmd) Before(ctx *cli.Context) error { ctx.String("auth_id"), ctx.String("auth_secret"), )) } + if len(ctx.String("namespace")) > 0 { + authOpts = append(authOpts, auth.Namespace(ctx.String("namespace"))) + } if len(ctx.String("auth_public_key")) > 0 { authOpts = append(authOpts, auth.PublicKey(ctx.String("auth_public_key"))) From 2ea5b3395598a0d8c6002dfad40b2b80fbfce8a0 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Tue, 7 Apr 2020 13:53:22 +0200 Subject: [PATCH 545/788] Disk backed local store (#1491) --- go.mod | 12 +- go.sum | 105 ++++++++++++ store/file/file.go | 351 ++++++++++++++++++++++++++++++++++++++++ store/file/file_test.go | 281 ++++++++++++++++++++++++++++++++ 4 files changed, 740 insertions(+), 9 deletions(-) create mode 100644 store/file/file.go create mode 100644 store/file/file_test.go diff --git a/go.mod b/go.mod index f02d29b5..551a2982 100644 --- a/go.mod +++ b/go.mod @@ -8,8 +8,7 @@ require ( github.com/bitly/go-simplejson v0.5.0 github.com/bwmarrin/discordgo v0.20.2 github.com/coreos/etcd v3.3.18+incompatible - github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect + github.com/davecgh/go-spew v1.1.1 github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 github.com/evanphx/json-patch/v5 v5.0.0 @@ -18,13 +17,10 @@ require ( github.com/fsouza/go-dockerclient v1.6.0 github.com/ghodss/yaml v1.0.0 github.com/go-acme/lego/v3 v3.3.0 - github.com/go-playground/universal-translator v0.17.0 // indirect github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee github.com/gobwas/pool v0.2.0 // indirect github.com/gobwas/ws v1.0.3 - github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.3.2 - github.com/google/go-cmp v0.4.0 // indirect github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/websocket v1.4.1 @@ -33,14 +29,13 @@ require ( github.com/hpcloud/tail v1.0.0 github.com/imdario/mergo v0.3.8 github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 - github.com/json-iterator/go v1.1.9 // indirect github.com/kr/pretty v0.1.0 - github.com/leodido/go-urn v1.2.0 // indirect github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 github.com/mholt/certmagic v0.9.3 github.com/micro/cli/v2 v2.1.2 github.com/micro/mdns v0.3.0 + github.com/micro/micro/v2 v2.4.0 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 github.com/nats-io/nats-server/v2 v2.1.4 @@ -50,8 +45,7 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.4.0 - github.com/technoweenie/multipartstreamer v1.0.1 // indirect - github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect + go.etcd.io/bbolt v1.3.4 go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 diff --git a/go.sum b/go.sum index 7d8a1ee1..74822cf3 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,7 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy contrib.go.opencensus.io/exporter/ocagent v0.4.12/go.mod h1:450APlNTSR6FrvC3CTRqYosuDstRB9un7SOx2k/9ckA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-autorest/autorest v0.1.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg= github.com/Azure/go-autorest/autorest v0.5.0/go.mod h1:9HLKlQjVBH6U3oDfsXOeVc56THsLPw1L03yban4xThw= @@ -29,20 +30,26 @@ github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvd github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 h1:ygIc8M6trr62pF5DucadTWGdEB4mEyvzi0e2nbcmcyA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= +github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/akamai/AkamaiOPEN-edgegrid-golang v0.9.0/go.mod h1:zpDJeKyp9ScW4NNrbdr+Eyxvry3ilGPewKoXw3XGN1k= +github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75 h1:3ILjVyslFbc4jl1w5TWuvvslFD/nDfR2H8tVaMVLrEY= github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75/go.mod h1:uAXEEpARkRhCZfEvy/y0Jcc888f9tHCc1W7/UeEtreE= +github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190808125512-07798873deee/go.mod h1:myCDvQSzCW+wB1WAlocEru4wMGJxy+vlxHdhegi1CDQ= github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= +github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aws/aws-sdk-go v1.23.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= @@ -50,10 +57,16 @@ github.com/beevik/ntp v0.2.0 h1:sGsd+kAXzT0bfVfzJfce04g+dSRfrs+tbQW8lweuYgw= github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y= github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= +github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= +github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= +github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= @@ -62,9 +75,14 @@ github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.10.2 h1:VBodKICVPnwmDxstcW3biKcDSpFIfS/RELUXsZSBYK4= github.com/cloudflare/cloudflare-go v0.10.2/go.mod h1:qhVI5MKwBGhdNU89ZRz2plgYutcJ5PCekLxXn56w6SY= +github.com/cloudflare/cloudflare-go v0.10.9 h1:d8KOgLpYiC+Xq3T4tuO+/goM+RZvuO+T4pojuv8giL8= +github.com/cloudflare/cloudflare-go v0.10.9/go.mod h1:5TrsWH+3f4NV6WjtS5QFp+DifH81rph40gU374Sh0dQ= github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko= github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= @@ -76,10 +94,15 @@ github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3/go.mod h1:IV7qH3hrUgRmyYrtgEeGWJfWbgcHL9CSRruz2Vqcph0= github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDGpgqzQIzDW1TphrGLssLDZp2GuS+X5DkEJB8o= github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= +github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c= +github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpu/goacmedns v0.0.1/go.mod h1:sesf/pNnCYwUevQEQfEwY0Y3DydlQWSGZbaMElOWxok= @@ -108,6 +131,7 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1 github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 h1:jFGzikHboUMRXmMBtwD/PbxoTHPs2919Irp/3rxMbvM= github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1/go.mod h1:HvODWzv6Y6kBf3Ah2WzN1bHjDUezGLaAhwuWVwfpEJs= +github.com/eknkc/basex v1.0.0/go.mod h1:k/F/exNEHFdbs3ZHuasoP2E7zeWwZblG84Y7Z59vQRo= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -116,15 +140,18 @@ github.com/evanphx/json-patch/v5 v5.0.0 h1:dKTrUeykyQwKb/kx7Z+4ukDs6l+4L41HqG1XH github.com/evanphx/json-patch/v5 v5.0.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= +github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXju1m8W4lnEeIqTHPOzhTUO81a7yknM/xQR4= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= +github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4GGn3Hig= github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-acme/lego/v3 v3.3.0 h1:6BePZsOiYA4/w+M7QDytxQtMfCipMPGnWAHs9pWks98= github.com/go-acme/lego/v3 v3.3.0/go.mod h1:iGSY2vQrvQs3WezicSB/oVbO2eCrD88dpWPwb1qLqu0= @@ -140,6 +167,8 @@ github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTM github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU= +github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= @@ -155,9 +184,11 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= @@ -166,17 +197,21 @@ github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -192,10 +227,15 @@ github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg= +github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= +github.com/hako/branca v0.0.0-20180808000428-10b799466ada/go.mod h1:tOPn4gvKEUWqIJNE+zpTeTALaRAXnrRqqSnPlO3VpEo= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -212,11 +252,14 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 h1:lnrOS18wZBYrzdDmnUeg1OVk+kQ3rxG8mZWU89DpMIA= github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1/go.mod h1:DFXrEwSRX0p/aSvxE21319menCBFeQO0jXpRj7LEZUA= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= @@ -229,6 +272,7 @@ github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/kolo/xmlrpc v0.0.0-20190717152603-07c4ee3fd181/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -247,22 +291,31 @@ github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8 github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ= github.com/lucas-clemente/quic-go v0.14.1 h1:c1aKoBZKOPA+49q96B1wGkibyPP0AxYh45WuAoq+87E= github.com/lucas-clemente/quic-go v0.14.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= +github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ= github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE= github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU= github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= +github.com/micro/go-micro v1.18.0 h1:gP70EZVHpJuUIT0YWth192JmlIci+qMOEByHm83XE9E= +github.com/micro/go-micro/v2 v2.3.1-0.20200331090613-76ade7efd9b8/go.mod h1:lYuHYFPjY3QE9fdiy3F2awXcsXTdB68AwoY3RQ3dPN4= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= +github.com/micro/micro/v2 v2.4.0 h1:GlbLaD/50KaSFym7GCQZ/2I4fuTTX9U4Zftni4ImJ40= +github.com/micro/micro/v2 v2.4.0/go.mod h1:/7lxBaU/Isx3USObggNVw6x6pdIJzTDexee7EsARD+A= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= @@ -274,8 +327,10 @@ github.com/mitchellh/hashstructure v1.0.0 h1:ZkRJX1CyOoTkar7p/mLS5TZU4nJ1Rn/F8u9 github.com/mitchellh/hashstructure v1.0.0/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8dQu6DMTwH4oIuGN8GJDAlqDdVE= github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= @@ -294,6 +349,7 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= +github.com/netdata/go-orchestrator v0.0.0-20190905093727-c793edba0e8f/go.mod h1:ECF8anFVCt/TfTIWVPgPrNaYJXtAtpAOF62ugDbw41A= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= @@ -301,8 +357,12 @@ github.com/nrdcg/dnspod-go v0.3.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgP github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2SwKQ= github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/olekukonko/tablewriter v0.0.3/go.mod h1:YZeBtGzYYEsCHp2LST/u/0NDwGkRoBtmn1cIWCJiS6M= +github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= @@ -314,6 +374,7 @@ github.com/opencontainers/runc v0.1.1 h1:GlxAyO6x8rfZYN9Tt0Kti5a/cP41iuiO2yYT0IJ github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/runtime-tools v0.0.0-20181011054405-1d69bd0f9c39/go.mod h1:r3f7wjNzSs2extwzU3Y+6pKfobzPh+kKFJ3ofN+3nfs= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/oracle/oci-go-sdk v7.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= github.com/ovh/go-ovh v0.0.0-20181109152953-ba5adb4cf014/go.mod h1:joRatxRJaZBsY3JAOEMcoOp05CnZzsx4scTxi95DHyQ= @@ -321,6 +382,7 @@ github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgF github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= +github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -329,21 +391,26 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pquerna/otp v1.2.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.1.0 h1:BQ53HtBmfOitExawJ6LokA4x8ov/z0SYYb0+HxJfRI8= github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= +github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8= github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKcyumwBO6qip7RNQ5r77yrssm9bfCowcLEBcU5IA= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= @@ -353,6 +420,7 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sacloud/libsacloud v1.26.1/go.mod h1:79ZwATmHLIFZIMd7sxA3LwzVy/B77uj3LDoToVTxDoQ= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= @@ -363,7 +431,10 @@ github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -377,11 +448,13 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= +github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc h1:yUaosFVTJwnltaHbSNC3i82I92quFs+OFPRl8kNMVwo= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= @@ -389,17 +462,27 @@ github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2 github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= +go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg= +go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -432,6 +515,7 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -459,11 +543,13 @@ golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 h1:MsuvTghUPjX762sGLnGsxC3HM0B5r83wEtYcYR8/vRs= golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -482,6 +568,7 @@ golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -497,6 +584,9 @@ golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= @@ -505,6 +595,8 @@ golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 h1:xQwXv67TxFo9nC1GJFyab5eq/5B590r6RlnL/G8Sz7w= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -528,9 +620,11 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 h1:RIIXAeV6GvDBuADKumTODatUqANFZ+5BPMnzsy4hulY= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= @@ -563,23 +657,30 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= +gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ns1/ns1-go.v2 v2.0.0-20190730140822-b51389932cbc/go.mod h1:VV+3haRsgDiVLxyifmMBrBIuCWFBPYKbRssXB9z67Hw= +gopkg.in/olivere/elastic.v5 v5.0.83/go.mod h1:LXF6q9XNBxpMqrcgax95C6xyARXWbbCXUrtTxrNrxJI= gopkg.in/resty.v1 v1.9.1/go.mod h1:vo52Hzryw9PnPHcJfPsBiFW62XhNx5OczbV9y+IMpgc= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4= gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg= gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= +gopkg.in/src-d/go-git-fixtures.v3 v3.5.0 h1:ivZFOIltbce2Mo8IjzUHAFoq/IylO9WHhNOAJK+LsJg= gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE= gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= @@ -593,12 +694,16 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= +sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/store/file/file.go b/store/file/file.go new file mode 100644 index 00000000..2c6b6092 --- /dev/null +++ b/store/file/file.go @@ -0,0 +1,351 @@ +// Package local is a file system backed store +package file + +import ( + "encoding/json" + "fmt" + "os" + "path/filepath" + "sort" + "strings" + "time" + + "github.com/micro/go-micro/v2/store" + micro_store "github.com/micro/go-micro/v2/store" + bolt "go.etcd.io/bbolt" + + "github.com/pkg/errors" +) + +// NewStore returns a memory store +func NewStore(opts ...store.Option) store.Store { + s := &fileStore{ + options: store.Options{}, + } + for _, o := range opts { + o(&s.options) + } + return s +} + +type fileStore struct { + options store.Options + dir string + fileName string + fullFilePath string +} + +func (m *fileStore) Init(opts ...store.Option) error { + // m.store.Flush() + for _, o := range opts { + o(&m.options) + } + if m.options.Database == "" { + m.options.Database = "default" + } + if m.options.Table == "" { + // bbolt requires bucketname to not be empty + m.options.Table = "default" + } + dir := filepath.Join(os.TempDir(), "micro") + fname := m.options.Database + ".db" + _ = os.Mkdir(dir, 0700) + m.dir = dir + m.fileName = fname + m.fullFilePath = filepath.Join(dir, fname) + return nil +} + +func (m *fileStore) String() string { + return "local" +} + +func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { + readOpts := store.ReadOptions{} + for _, o := range opts { + o(&readOpts) + } + + var keys []string + + // Handle Prefix / suffix + if readOpts.Prefix || readOpts.Suffix { + var opts []store.ListOption + if readOpts.Prefix { + opts = append(opts, store.ListPrefix(key)) + } + if readOpts.Suffix { + opts = append(opts, store.ListSuffix(key)) + } + opts = append(opts, store.ListLimit(readOpts.Limit)) + opts = append(opts, store.ListOffset(readOpts.Offset)) + k, err := m.List(opts...) + if err != nil { + return nil, errors.Wrap(err, "FileStore: Read couldn't List()") + } + keys = k + } else { + keys = []string{key} + } + + var results []*store.Record + for _, k := range keys { + r, err := m.get(k) + if err != nil { + return results, err + } + results = append(results, r) + } + return results, nil +} + +func (m *fileStore) get(k string) (*store.Record, error) { + if len(m.options.Table) > 0 { + k = m.options.Table + "/" + k + } + if len(m.options.Database) > 0 { + k = m.options.Database + "/" + k + } + store, err := bolt.Open(m.fullFilePath, 0700, &bolt.Options{Timeout: 1 * time.Second}) + if err != nil { + return nil, err + } + defer store.Close() + err = store.Update(func(tx *bolt.Tx) error { + _, err := tx.CreateBucketIfNotExists([]byte(m.options.Table)) + if err != nil { + return err + } + return nil + }) + if err != nil { + return nil, err + } + var value []byte + store.View(func(tx *bolt.Tx) error { + // @todo this is still very experimental... + bucket := tx.Bucket([]byte(m.options.Table)) + value = bucket.Get([]byte(k)) + return nil + }) + if value == nil { + return nil, micro_store.ErrNotFound + } + storedRecord := &internalRecord{} + err = json.Unmarshal(value, storedRecord) + if err != nil { + return nil, err + } + newRecord := µ_store.Record{} + newRecord.Key = storedRecord.Key + newRecord.Value = storedRecord.Value + if !storedRecord.ExpiresAt.IsZero() { + if storedRecord.ExpiresAt.Before(time.Now()) { + return nil, micro_store.ErrNotFound + } + newRecord.Expiry = time.Until(storedRecord.ExpiresAt) + } + + return newRecord, nil +} + +func (m *fileStore) Write(r *store.Record, opts ...store.WriteOption) error { + writeOpts := store.WriteOptions{} + for _, o := range opts { + o(&writeOpts) + } + + if len(opts) > 0 { + // Copy the record before applying options, or the incoming record will be mutated + newRecord := store.Record{} + newRecord.Key = r.Key + newRecord.Value = r.Value + newRecord.Expiry = r.Expiry + + if !writeOpts.Expiry.IsZero() { + newRecord.Expiry = time.Until(writeOpts.Expiry) + } + if writeOpts.TTL != 0 { + newRecord.Expiry = writeOpts.TTL + } + return m.set(&newRecord) + } + return m.set(r) +} + +func (m *fileStore) set(r *store.Record) error { + key := r.Key + if len(m.options.Table) > 0 { + key = m.options.Table + "/" + key + } + if len(m.options.Database) > 0 { + key = m.options.Database + "/" + key + } + + // copy the incoming record and then + // convert the expiry in to a hard timestamp + i := &internalRecord{} + i.Key = r.Key + i.Value = r.Value + if r.Expiry != 0 { + i.ExpiresAt = time.Now().Add(r.Expiry) + } + + iJSON, _ := json.Marshal(i) + + store, err := bolt.Open(m.fullFilePath, 0700, &bolt.Options{Timeout: 1 * time.Second}) + if err != nil { + return err + } + defer store.Close() + return store.Update(func(tx *bolt.Tx) error { + b := tx.Bucket([]byte(m.options.Table)) + if b == nil { + var err error + b, err = tx.CreateBucketIfNotExists([]byte(m.options.Table)) + if err != nil { + return err + } + } + return b.Put([]byte(key), iJSON) + }) +} + +func (m *fileStore) Delete(key string, opts ...store.DeleteOption) error { + deleteOptions := store.DeleteOptions{} + for _, o := range opts { + o(&deleteOptions) + } + return m.delete(key) +} + +func (m *fileStore) delete(key string) error { + if len(m.options.Table) > 0 { + key = m.options.Table + "/" + key + } + if len(m.options.Database) > 0 { + key = m.options.Database + "/" + key + } + store, err := bolt.Open(m.fullFilePath, 0700, &bolt.Options{Timeout: 1 * time.Second}) + if err != nil { + return err + } + defer store.Close() + return store.Update(func(tx *bolt.Tx) error { + b := tx.Bucket([]byte(m.options.Table)) + if b == nil { + var err error + b, err = tx.CreateBucketIfNotExists([]byte(m.options.Table)) + if err != nil { + return err + } + } + err := b.Delete([]byte(key)) + return err + }) +} + +func (m *fileStore) deleteAll() error { + return os.Remove(m.fullFilePath) +} + +func (m *fileStore) Options() store.Options { + return m.options +} + +func (m *fileStore) List(opts ...store.ListOption) ([]string, error) { + listOptions := store.ListOptions{} + + for _, o := range opts { + o(&listOptions) + } + allKeys := m.list(listOptions.Limit, listOptions.Offset) + + if len(listOptions.Prefix) > 0 { + var prefixKeys []string + for _, k := range allKeys { + if strings.HasPrefix(k, listOptions.Prefix) { + prefixKeys = append(prefixKeys, k) + } + } + allKeys = prefixKeys + } + if len(listOptions.Suffix) > 0 { + var suffixKeys []string + for _, k := range allKeys { + if strings.HasSuffix(k, listOptions.Suffix) { + suffixKeys = append(suffixKeys, k) + } + } + allKeys = suffixKeys + } + + return allKeys, nil +} + +func (m *fileStore) list(limit, offset uint) []string { + allItems := []string{} + store, err := bolt.Open(m.fullFilePath, 0700, &bolt.Options{Timeout: 1 * time.Second}) + if err != nil { + fmt.Println("Error creating file:", err) + } + defer store.Close() + store.Update(func(tx *bolt.Tx) error { + b := tx.Bucket([]byte(m.options.Table)) + if b == nil { + var err error + b, err = tx.CreateBucketIfNotExists([]byte(m.options.Table)) + if err != nil { + return err + } + } + // @todo very inefficient + if err := b.ForEach(func(k, v []byte) error { + storedRecord := &internalRecord{} + err := json.Unmarshal(v, storedRecord) + if err != nil { + return err + } + if !storedRecord.ExpiresAt.IsZero() { + if storedRecord.ExpiresAt.Before(time.Now()) { + return nil + } + } + allItems = append(allItems, string(k)) + return nil + }); err != nil { + return err + } + + return nil + }) + allKeys := make([]string, len(allItems)) + i := 0 + for _, k := range allItems { + if len(m.options.Database) > 0 { + k = strings.TrimPrefix(k, m.options.Database+"/") + } + if len(m.options.Table) > 0 { + k = strings.TrimPrefix(k, m.options.Table+"/") + } + allKeys[i] = k + i++ + } + if limit != 0 || offset != 0 { + sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] }) + min := func(i, j uint) uint { + if i < j { + return i + } + return j + } + return allKeys[offset:min(limit, uint(len(allKeys)))] + } + return allKeys +} + +type internalRecord struct { + Key string + Value []byte + ExpiresAt time.Time +} diff --git a/store/file/file_test.go b/store/file/file_test.go new file mode 100644 index 00000000..26a20cd3 --- /dev/null +++ b/store/file/file_test.go @@ -0,0 +1,281 @@ +package file + +import ( + "fmt" + "testing" + "time" + + "github.com/davecgh/go-spew/spew" + "github.com/kr/pretty" + "github.com/micro/go-micro/v2/store" +) + +func TestFileReInit(t *testing.T) { + s := NewStore(store.Table("aaa")) + s.Init(store.Table("bbb")) + if s.Options().Table != "bbb" { + t.Error("Init didn't reinitialise the store") + } +} + +func TestFileBasic(t *testing.T) { + s := NewStore() + s.Init() + if err := s.(*fileStore).deleteAll(); err != nil { + t.Logf("Can't delete all: %v", err) + } + basictest(s, t) +} + +func TestFileTable(t *testing.T) { + s := NewStore() + s.Init(store.Table("some-Table")) + if err := s.(*fileStore).deleteAll(); err != nil { + t.Logf("Can't delete all: %v", err) + } + basictest(s, t) +} + +func TestFileDatabase(t *testing.T) { + s := NewStore() + s.Init(store.Database("some-Database")) + if err := s.(*fileStore).deleteAll(); err != nil { + t.Logf("Can't delete all: %v", err) + } + basictest(s, t) +} + +func TestFileDatabaseTable(t *testing.T) { + s := NewStore() + s.Init(store.Table("some-Table"), store.Database("some-Database")) + if err := s.(*fileStore).deleteAll(); err != nil { + t.Logf("Can't delete all: %v", err) + } + basictest(s, t) +} + +func basictest(s store.Store, t *testing.T) { + t.Logf("Testing store %s, with options %# v\n", s.String(), pretty.Formatter(s.Options())) + // Read and Write an expiring Record + if err := s.Write(&store.Record{ + Key: "Hello", + Value: []byte("World"), + Expiry: time.Millisecond * 100, + }); err != nil { + t.Error(err) + } + if r, err := s.Read("Hello"); err != nil { + t.Error(err) + } else { + if len(r) != 1 { + t.Error("Read returned multiple records") + } + if r[0].Key != "Hello" { + t.Errorf("Expected %s, got %s", "Hello", r[0].Key) + } + if string(r[0].Value) != "World" { + t.Errorf("Expected %s, got %s", "World", r[0].Value) + } + } + time.Sleep(time.Millisecond * 200) + if _, err := s.Read("Hello"); err != store.ErrNotFound { + t.Errorf("Expected %# v, got %# v", store.ErrNotFound, err) + } + + // Write 3 records with various expiry and get with Table + records := []*store.Record{ + &store.Record{ + Key: "foo", + Value: []byte("foofoo"), + }, + &store.Record{ + Key: "foobar", + Value: []byte("foobarfoobar"), + Expiry: time.Millisecond * 100, + }, + &store.Record{ + Key: "foobarbaz", + Value: []byte("foobarbazfoobarbaz"), + Expiry: 2 * time.Millisecond * 100, + }, + } + for _, r := range records { + if err := s.Write(r); err != nil { + t.Errorf("Couldn't write k: %s, v: %# v (%s)", r.Key, pretty.Formatter(r.Value), err) + } + } + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) + } else { + if len(results) != 3 { + t.Errorf("Expected 3 items, got %d", len(results)) + t.Logf("Table test: %v\n", spew.Sdump(results)) + } + } + time.Sleep(time.Millisecond * 100) + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) + } else { + if len(results) != 2 { + t.Errorf("Expected 2 items, got %d", len(results)) + t.Logf("Table test: %v\n", spew.Sdump(results)) + } + } + time.Sleep(time.Millisecond * 100) + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) + } else { + if len(results) != 1 { + t.Errorf("Expected 1 item, got %d", len(results)) + t.Logf("Table test: %# v\n", spew.Sdump(results)) + } + } + if err := s.Delete("foo", func(d *store.DeleteOptions) {}); err != nil { + t.Errorf("Delete failed (%v)", err) + } + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) + } else { + if len(results) != 0 { + t.Errorf("Expected 0 items, got %d (%# v)", len(results), spew.Sdump(results)) + } + } + + // Write 3 records with various expiry and get with Suffix + records = []*store.Record{ + &store.Record{ + Key: "foo", + Value: []byte("foofoo"), + }, + &store.Record{ + Key: "barfoo", + Value: []byte("barfoobarfoo"), + Expiry: time.Millisecond * 100, + }, + &store.Record{ + Key: "bazbarfoo", + Value: []byte("bazbarfoobazbarfoo"), + Expiry: 2 * time.Millisecond * 100, + }, + } + for _, r := range records { + if err := s.Write(r); err != nil { + t.Errorf("Couldn't write k: %s, v: %# v (%s)", r.Key, pretty.Formatter(r.Value), err) + } + } + if results, err := s.Read("foo", store.ReadSuffix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) + } else { + if len(results) != 3 { + t.Errorf("Expected 3 items, got %d", len(results)) + t.Logf("Table test: %v\n", spew.Sdump(results)) + } + + } + time.Sleep(time.Millisecond * 100) + if results, err := s.Read("foo", store.ReadSuffix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) + } else { + if len(results) != 2 { + t.Errorf("Expected 2 items, got %d", len(results)) + t.Logf("Table test: %v\n", spew.Sdump(results)) + } + + } + time.Sleep(time.Millisecond * 100) + if results, err := s.Read("foo", store.ReadSuffix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) + } else { + if len(results) != 1 { + t.Errorf("Expected 1 item, got %d", len(results)) + t.Logf("Table test: %# v\n", spew.Sdump(results)) + } + } + if err := s.Delete("foo"); err != nil { + t.Errorf("Delete failed (%v)", err) + } + if results, err := s.Read("foo", store.ReadSuffix()); err != nil { + t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) + } else { + if len(results) != 0 { + t.Errorf("Expected 0 items, got %d (%# v)", len(results), spew.Sdump(results)) + } + } + + // Test Table, Suffix and WriteOptions + if err := s.Write(&store.Record{ + Key: "foofoobarbar", + Value: []byte("something"), + }, store.WriteTTL(time.Millisecond*100)); err != nil { + t.Error(err) + } + if err := s.Write(&store.Record{ + Key: "foofoo", + Value: []byte("something"), + }, store.WriteExpiry(time.Now().Add(time.Millisecond*100))); err != nil { + t.Error(err) + } + if err := s.Write(&store.Record{ + Key: "barbar", + Value: []byte("something"), + // TTL has higher precedence than expiry + }, store.WriteExpiry(time.Now().Add(time.Hour)), store.WriteTTL(time.Millisecond*100)); err != nil { + t.Error(err) + } + if results, err := s.Read("foo", store.ReadPrefix(), store.ReadSuffix()); err != nil { + t.Error(err) + } else { + if len(results) != 1 { + t.Errorf("Expected 1 results, got %d: %# v", len(results), spew.Sdump(results)) + } + } + time.Sleep(time.Millisecond * 100) + if results, err := s.List(); err != nil { + t.Errorf("List failed: %s", err) + } else { + if len(results) != 0 { + t.Errorf("Expiry options were not effective, results :%v", spew.Sdump(results)) + } + } + s.Write(&store.Record{Key: "a", Value: []byte("a")}) + s.Write(&store.Record{Key: "aa", Value: []byte("aa")}) + s.Write(&store.Record{Key: "aaa", Value: []byte("aaa")}) + if results, err := s.Read("b", store.ReadPrefix()); err != nil { + t.Error(err) + } else { + if len(results) != 0 { + t.Errorf("Expected 0 results, got %d", len(results)) + } + } + + s.Init() + if err := s.(*fileStore).deleteAll(); err != nil { + t.Logf("Can't delete all: %v", err) + } + for i := 0; i < 10; i++ { + s.Write(&store.Record{ + Key: fmt.Sprintf("a%d", i), + Value: []byte{}, + }) + } + if results, err := s.Read("a", store.ReadLimit(5), store.ReadPrefix()); err != nil { + t.Error(err) + } else { + if len(results) != 5 { + t.Error("Expected 5 results, got ", len(results)) + } + if results[0].Key != "a0" { + t.Errorf("Expected a0, got %s", results[0].Key) + } + if results[4].Key != "a4" { + t.Errorf("Expected a4, got %s", results[4].Key) + } + } + if results, err := s.Read("a", store.ReadLimit(30), store.ReadOffset(5), store.ReadPrefix()); err != nil { + t.Error(err) + } else { + if len(results) != 5 { + t.Error("Expected 5 results, got ", len(results)) + } + } +} From 71538adfdcb00cb8e240c3b57471c55e74756e82 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 7 Apr 2020 13:00:05 +0100 Subject: [PATCH 546/788] Explicitly set the table name during service init (#1497) --- service.go | 9 +++------ store/cockroach/cockroach.go | 27 +++++++++++++-------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/service.go b/service.go index 7e16ed11..5b34f2ae 100644 --- a/service.go +++ b/service.go @@ -106,12 +106,9 @@ func (s *service) Init(opts ...Option) { logger.Fatal(err) } - // If the store has no Table set, fallback to the - // services name - if len(store.DefaultStore.Options().Table) == 0 { - name := s.opts.Cmd.App().Name - store.DefaultStore.Init(store.Table(name)) - } + // Explicitly set the table name to the service name + name := s.opts.Cmd.App().Name + store.DefaultStore.Init(store.Table(name)) // TODO: replace Cmd.Init with config.Load // Right now we're just going to load a token diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index e34324f8..5f242810 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -14,11 +14,10 @@ import ( "github.com/pkg/errors" ) -// DefaultNamespace is the namespace that the sql store +// DefaultDatabase is the namespace that the sql store // will use if no namespace is provided. var ( - DefaultNamespace = "micro" - DefaultPrefix = "micro" + DefaultDatabase = "micro" ) type sqlStore struct { @@ -296,26 +295,26 @@ func (s *sqlStore) initDB() error { func (s *sqlStore) configure() error { if len(s.options.Nodes) == 0 { - s.options.Nodes = []string{"localhost:26257"} + s.options.Nodes = []string{"postgresql://root@localhost:26257"} } - namespace := s.options.Database - if len(namespace) == 0 { - namespace = DefaultNamespace + database := s.options.Database + if len(database) == 0 { + database = DefaultDatabase } - prefix := s.options.Table - if len(prefix) == 0 { - prefix = DefaultPrefix + if len(s.options.Table) == 0 { + return errors.New("no table set") } + table := s.options.Table // store.namespace must only contain letters, numbers and underscores reg, err := regexp.Compile("[^a-zA-Z0-9]+") if err != nil { return errors.New("error compiling regex for namespace") } - namespace = reg.ReplaceAllString(namespace, "_") - prefix = reg.ReplaceAllString(prefix, "_") + database = reg.ReplaceAllString(database, "_") + table = reg.ReplaceAllString(table, "_") source := s.options.Nodes[0] // check if it is a standard connection string eg: host=%s port=%d user=%s password=%s dbname=%s sslmode=disable @@ -343,8 +342,8 @@ func (s *sqlStore) configure() error { // save the values s.db = db - s.database = namespace - s.table = prefix + s.database = database + s.table = table // initialise the database return s.initDB() From aaee01b1a7561e1df5eb6bfdc24341459d2d277b Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Tue, 7 Apr 2020 15:19:45 +0200 Subject: [PATCH 547/788] Use file store by default (as opposed to memory store) (#1498) * Use file store by default (as opposed to memory store) * Default table for file store --- defaults.go | 4 ++-- store/file/file.go | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/defaults.go b/defaults.go index ca5b1e57..10408f90 100644 --- a/defaults.go +++ b/defaults.go @@ -10,7 +10,7 @@ import ( gcli "github.com/micro/go-micro/v2/client/grpc" memTrace "github.com/micro/go-micro/v2/debug/trace/memory" gsrv "github.com/micro/go-micro/v2/server/grpc" - memStore "github.com/micro/go-micro/v2/store/memory" + fileStore "github.com/micro/go-micro/v2/store/file" ) func init() { @@ -19,7 +19,7 @@ func init() { // default server server.DefaultServer = gsrv.NewServer() // default store - store.DefaultStore = memStore.NewStore() + store.DefaultStore = fileStore.NewStore() // set default trace trace.DefaultTracer = memTrace.NewTracer() } diff --git a/store/file/file.go b/store/file/file.go index 2c6b6092..cf061fd7 100644 --- a/store/file/file.go +++ b/store/file/file.go @@ -17,6 +17,16 @@ import ( "github.com/pkg/errors" ) +var ( + // DefaultDatabase is the namespace that the bbolt store + // will use if no namespace is provided. + DefaultDatabase = "micro" + // DefaultTable when none is specified + DefaultTable = "micro" + // DefaultDir is the default directory for bbolt files + DefaultDir = os.TempDir() +) + // NewStore returns a memory store func NewStore(opts ...store.Option) store.Store { s := &fileStore{ @@ -36,18 +46,17 @@ type fileStore struct { } func (m *fileStore) Init(opts ...store.Option) error { - // m.store.Flush() for _, o := range opts { o(&m.options) } if m.options.Database == "" { - m.options.Database = "default" + m.options.Database = DefaultDatabase } if m.options.Table == "" { // bbolt requires bucketname to not be empty - m.options.Table = "default" + m.options.Table = DefaultTable } - dir := filepath.Join(os.TempDir(), "micro") + dir := filepath.Join(DefaultDir, "micro") fname := m.options.Database + ".db" _ = os.Mkdir(dir, 0700) m.dir = dir From 6aaad7d63f4e7989d8e4491dc5d5ba66c334b699 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 7 Apr 2020 17:38:27 +0300 Subject: [PATCH 548/788] api/router/static: allow to specify body dst (#1486) Signed-off-by: Vasiliy Tolstov --- api/api.go | 6 +++++- api/handler/rpc/rpc.go | 30 +++++++++++++++++++++++++++++- api/router/static/static.go | 3 +++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/api/api.go b/api/api.go index 736dbf77..9dbca5ec 100644 --- a/api/api.go +++ b/api/api.go @@ -22,7 +22,7 @@ type Api interface { String() string } -type Options struct {} +type Options struct{} type Option func(*Options) error @@ -40,6 +40,10 @@ type Endpoint struct { Method []string // HTTP Path e.g /greeter. Expect POSIX regex Path []string + // Body destination + // "*" or "" - top level message value + // "string" - inner message value + Body string // Stream flag Stream bool } diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 83a0d877..f4d23bc9 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -300,6 +300,7 @@ func requestPayload(r *http.Request) ([]byte, error) { // allocate maximum matches := make(map[string]interface{}, len(md)) + bodydst := "" // get fields from url path for k, v := range md { @@ -307,6 +308,9 @@ func requestPayload(r *http.Request) ([]byte, error) { if strings.HasPrefix(k, "x-api-field-") { matches[strings.TrimPrefix(k, "x-api-field-")] = v delete(md, k) + } else if k == "x-api-body" { + bodydst = v + delete(md, k) } } @@ -387,8 +391,32 @@ func requestPayload(r *http.Request) ([]byte, error) { } else { return []byte{}, nil } + if bodydst == "" || bodydst == "*" { + if out, err = jsonpatch.MergeMergePatches(out, bodybuf); err == nil { + return out, nil + } + } + dstmap := make(map[string]interface{}) + ps := strings.Split(bodydst, ".") + if len(ps) == 1 { + dstmap[ps[0]] = bodybuf + } else { + em := make(map[string]interface{}) + em[ps[len(ps)-1]] = bodybuf + for i := len(ps) - 2; i > 0; i-- { + nm := make(map[string]interface{}) + nm[ps[i]] = em + em = nm + } + dstmap[ps[0]] = em + } - if out, err = jsonpatch.MergeMergePatches(out, bodybuf); err == nil { + bodyout, err := json.Marshal(dstmap) + if err != nil { + return nil, err + } + + if out, err = jsonpatch.MergeMergePatches(out, bodyout); err == nil { return out, nil } diff --git a/api/router/static/static.go b/api/router/static/static.go index 3c2c25d4..09271c7c 100644 --- a/api/router/static/static.go +++ b/api/router/static/static.go @@ -191,6 +191,7 @@ func (r *staticRouter) Endpoint(req *http.Request) (*api.Service, error) { Host: ep.apiep.Host, Method: ep.apiep.Method, Path: ep.apiep.Path, + Body: ep.apiep.Body, Stream: ep.apiep.Stream, }, Services: services, @@ -274,6 +275,7 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { for k, v := range matches { md[fmt.Sprintf("x-api-field-%s", k)] = v } + md["x-api-body"] = ep.apiep.Body *req = *req.Clone(context.WithValue(ctx, metadata.MetadataKey{}, md)) break pathLoop } @@ -285,6 +287,7 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { // we got here, so its a match return ep, nil } + // no match return nil, fmt.Errorf("endpoint not found for %v", req) } From 038b936ce982129cb1f3528435866c3854e9a1c1 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Tue, 7 Apr 2020 16:43:43 +0200 Subject: [PATCH 549/788] =?UTF-8?q?Setting=20up=20file=20store=20in=20cons?= =?UTF-8?q?tructor=20and=20not=20in=20init=20which=20is=20o=E2=80=A6=20(#1?= =?UTF-8?q?499)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- defaults.go | 4 ++-- store/file/file.go | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/defaults.go b/defaults.go index 10408f90..1e991e4d 100644 --- a/defaults.go +++ b/defaults.go @@ -10,7 +10,7 @@ import ( gcli "github.com/micro/go-micro/v2/client/grpc" memTrace "github.com/micro/go-micro/v2/debug/trace/memory" gsrv "github.com/micro/go-micro/v2/server/grpc" - fileStore "github.com/micro/go-micro/v2/store/file" + memoryStore "github.com/micro/go-micro/v2/store/memory" ) func init() { @@ -19,7 +19,7 @@ func init() { // default server server.DefaultServer = gsrv.NewServer() // default store - store.DefaultStore = fileStore.NewStore() + store.DefaultStore = memoryStore.NewStore() // set default trace trace.DefaultTracer = memTrace.NewTracer() } diff --git a/store/file/file.go b/store/file/file.go index cf061fd7..26df09ea 100644 --- a/store/file/file.go +++ b/store/file/file.go @@ -32,9 +32,7 @@ func NewStore(opts ...store.Option) store.Store { s := &fileStore{ options: store.Options{}, } - for _, o := range opts { - o(&s.options) - } + s.init(opts...) return s } @@ -46,6 +44,10 @@ type fileStore struct { } func (m *fileStore) Init(opts ...store.Option) error { + return m.init(opts...) +} + +func (m *fileStore) init(opts ...store.Option) error { for _, o := range opts { o(&m.options) } @@ -58,6 +60,9 @@ func (m *fileStore) Init(opts ...store.Option) error { } dir := filepath.Join(DefaultDir, "micro") fname := m.options.Database + ".db" + // Ignoring this as the folder might exist. + // Reads/Writes updates will return with sensible error messages + // about the dir not existing in case this cannot create the path anyway _ = os.Mkdir(dir, 0700) m.dir = dir m.fileName = fname From 4362a885eb824cc583b0d05cb0dd1c884ea0c19a Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 16:24:51 +0100 Subject: [PATCH 550/788] Refactor Namespace Resolver --- api/resolver/resolver.go | 8 +++ api/server/auth/auth.go | 96 ++++++------------------------------ api/server/auth/auth_test.go | 38 -------------- api/server/http/http.go | 2 +- api/server/options.go | 35 ++++++------- auth/service/service.go | 12 +++-- go.sum | 4 ++ util/wrapper/wrapper.go | 30 ++--------- 8 files changed, 53 insertions(+), 172 deletions(-) delete mode 100644 api/server/auth/auth_test.go diff --git a/api/resolver/resolver.go b/api/resolver/resolver.go index 12854b19..daa7078d 100644 --- a/api/resolver/resolver.go +++ b/api/resolver/resolver.go @@ -11,6 +11,12 @@ var ( ErrInvalidPath = errors.New("invalid path") ) +// NamespaceResolver resolves request to the namespace +type NamespaceResolver interface { + Resolve(r *http.Request) string + String() string +} + // Resolver resolves requests to endpoints type Resolver interface { Resolve(r *http.Request) (*Endpoint, error) @@ -27,6 +33,8 @@ type Endpoint struct { Method string // HTTP Path e.g /greeter. Path string + // Namespace, g.g. go.micro + Namespace string } type Options struct { diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 7ae99214..deffa3dc 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -3,44 +3,35 @@ package auth import ( "context" "fmt" - "net" "net/http" "net/url" "strings" "github.com/micro/go-micro/v2/api/resolver" - "github.com/micro/go-micro/v2/api/resolver/path" "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/logger" - "golang.org/x/net/publicsuffix" ) // CombinedAuthHandler wraps a server and authenticates requests -func CombinedAuthHandler(prefix, namespace string, r resolver.Resolver, h http.Handler) http.Handler { - if r == nil { - r = path.NewResolver() - } - +func CombinedAuthHandler(r resolver.Resolver, nr resolver.NamespaceResolver, h http.Handler) http.Handler { return authHandler{ - handler: h, - resolver: r, - auth: auth.DefaultAuth, - servicePrefix: prefix, - namespace: namespace, + handler: h, + resolver: r, + nsResolver: nr, + auth: auth.DefaultAuth, } } type authHandler struct { - handler http.Handler - auth auth.Auth - resolver resolver.Resolver - namespace string - servicePrefix string + handler http.Handler + auth auth.Auth + resolver resolver.Resolver + nsResolver resolver.NamespaceResolver } func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // Determine the namespace and set it in the header - namespace := h.NamespaceFromRequest(req) + namespace := h.nsResolver.Resolve(req) req.Header.Set(auth.NamespaceKey, namespace) // Extract the token from the request @@ -63,14 +54,7 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // account doesn't necesserially mean a forbidden request acc, err := h.auth.Inspect(token) if err != nil { - acc = &auth.Account{Namespace: namespace} - } - - // Check the accounts namespace matches the namespace we're operating - // within. If not forbid the request and log the occurance. - if acc.Namespace != namespace { - logger.Debugf("Cross namespace request warning: account %v (%v) requested access to %v in the %v namespace", acc.ID, acc.Namespace, req.URL.Path, namespace) - // http.Error(w, "Forbidden namespace", 403) + acc = &auth.Account{} } // Determine the name of the service being requested @@ -90,9 +74,9 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } // construct the resource name, e.g. home => go.micro.web.home - resName := h.servicePrefix + resName := namespace if len(endpoint.Name) > 0 { - resName = resName + "." + endpoint.Name + resName = namespace + "." + endpoint.Name } // determine the resource path. there is an inconsistency in how resolvers @@ -127,59 +111,7 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } // Redirect to the login path - params := url.Values{"redirect_to": {req.URL.Path}} + params := url.Values{"redirect_to": {req.URL.String()}} loginWithRedirect := fmt.Sprintf("%v?%v", loginURL, params.Encode()) http.Redirect(w, req, loginWithRedirect, http.StatusTemporaryRedirect) } - -func (h authHandler) NamespaceFromRequest(req *http.Request) string { - // check to see what the provided namespace is, we only do - // domain mapping if the namespace is set to 'domain' - if h.namespace != "domain" { - return h.namespace - } - - // determine the host, e.g. dev.micro.mu:8080 - host := req.URL.Hostname() - if len(host) == 0 { - if h, _, err := net.SplitHostPort(req.Host); err == nil { - host = h // host does contain a port - } else if strings.Contains(err.Error(), "missing port in address") { - host = req.Host // host does not contain a port - } - } - - // check for an ip address - if net.ParseIP(host) != nil { - return auth.DefaultNamespace - } - - // check for dev enviroment - if host == "localhost" || host == "127.0.0.1" { - return auth.DefaultNamespace - } - - // extract the top level domain plus one (e.g. 'myapp.com') - domain, err := publicsuffix.EffectiveTLDPlusOne(host) - if err != nil { - logger.Debugf("Unable to extract domain from %v", host) - return auth.DefaultNamespace - } - - // check to see if the domain matches the host of micro.mu, in - // these cases we return the default namespace - if domain == host || domain == "micro.mu" { - return auth.DefaultNamespace - } - - // remove the domain from the host, leaving the subdomain - subdomain := strings.TrimSuffix(host, "."+domain) - - // return the reversed subdomain as the namespace - comps := strings.Split(subdomain, ".") - for i := len(comps)/2 - 1; i >= 0; i-- { - opp := len(comps) - 1 - i - comps[i], comps[opp] = comps[opp], comps[i] - } - return strings.Join(comps, ".") -} diff --git a/api/server/auth/auth_test.go b/api/server/auth/auth_test.go deleted file mode 100644 index 7fd09581..00000000 --- a/api/server/auth/auth_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package auth - -import ( - "net/http" - "net/url" - "testing" - - "github.com/micro/go-micro/v2/auth" -) - -func TestNamespaceFromRequest(t *testing.T) { - tt := []struct { - Host string - Namespace string - }{ - {Host: "micro.mu", Namespace: auth.DefaultNamespace}, - {Host: "micro.com.au", Namespace: auth.DefaultNamespace}, - {Host: "web.micro.mu", Namespace: auth.DefaultNamespace}, - {Host: "api.micro.mu", Namespace: auth.DefaultNamespace}, - {Host: "myapp.com", Namespace: auth.DefaultNamespace}, - {Host: "staging.myapp.com", Namespace: "staging"}, - {Host: "staging.myapp.m3o.app", Namespace: "myapp.staging"}, - {Host: "127.0.0.1", Namespace: auth.DefaultNamespace}, - {Host: "localhost", Namespace: auth.DefaultNamespace}, - {Host: "81.151.101.146", Namespace: auth.DefaultNamespace}, - } - - h := &authHandler{namespace: "domain"} - - for _, tc := range tt { - t.Run(tc.Host, func(t *testing.T) { - ns := h.NamespaceFromRequest(&http.Request{Host: tc.Host, URL: &url.URL{Host: tc.Host}}) - if ns != tc.Namespace { - t.Errorf("Expected namespace %v for host %v, actually got %v", tc.Namespace, tc.Host, ns) - } - }) - } -} diff --git a/api/server/http/http.go b/api/server/http/http.go index 3d1030ac..c35d24b7 100644 --- a/api/server/http/http.go +++ b/api/server/http/http.go @@ -53,7 +53,7 @@ func (s *httpServer) Init(opts ...server.Option) error { func (s *httpServer) Handle(path string, handler http.Handler) { h := handlers.CombinedLoggingHandler(os.Stdout, handler) - h = auth.CombinedAuthHandler(s.opts.ServicePrefix, s.opts.Namespace, s.opts.Resolver, handler) + h = auth.CombinedAuthHandler(s.opts.Resolver, s.opts.NamespaceResolver, handler) if s.opts.EnableCORS { h = cors.CombinedCORSHandler(h) diff --git a/api/server/options.go b/api/server/options.go index 6fd61672..9aa14579 100644 --- a/api/server/options.go +++ b/api/server/options.go @@ -10,15 +10,14 @@ import ( type Option func(o *Options) type Options struct { - EnableACME bool - EnableCORS bool - ACMEProvider acme.Provider - EnableTLS bool - ACMEHosts []string - TLSConfig *tls.Config - Resolver resolver.Resolver - Namespace string - ServicePrefix string + EnableACME bool + EnableCORS bool + ACMEProvider acme.Provider + EnableTLS bool + ACMEHosts []string + TLSConfig *tls.Config + Resolver resolver.Resolver + NamespaceResolver resolver.NamespaceResolver } func EnableCORS(b bool) Option { @@ -57,20 +56,14 @@ func TLSConfig(t *tls.Config) Option { } } -func ServicePrefix(n string) Option { - return func(o *Options) { - o.ServicePrefix = n - } -} - -func Namespace(n string) Option { - return func(o *Options) { - o.Namespace = n - } -} - func Resolver(r resolver.Resolver) Option { return func(o *Options) { o.Resolver = r } } + +func NamespaceResolver(r resolver.NamespaceResolver) Option { + return func(o *Options) { + o.NamespaceResolver = r + } +} diff --git a/auth/service/service.go b/auth/service/service.go index 57d6082e..cb1740c7 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -158,6 +158,11 @@ func (s *svc) Revoke(role string, res *auth.Resource) error { // Verify an account has access to a resource func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { + // set the namespace on the resource + if len(res.Namespace) == 0 { + res.Namespace = s.Options().Namespace + } + queries := [][]string{ {res.Namespace, res.Type, res.Name, res.Endpoint}, // check for specific role, e.g. service.foo.ListFoo:admin (role is checked in accessForRule) {res.Namespace, res.Type, res.Name, "*"}, // check for wildcard endpoint, e.g. service.foo* @@ -205,16 +210,15 @@ func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { func (s *svc) Inspect(token string) (*auth.Account, error) { // try to decode JWT locally and fall back to srv if an error occurs if len(strings.Split(token, ".")) == 3 && s.jwt != nil { - if acc, err := s.jwt.Inspect(token); err == nil { - return acc, nil - } + return s.jwt.Inspect(token) } + // the token is not a JWT or we do not have the keys to decode it, + // fall back to the auth service rsp, err := s.auth.Inspect(context.TODO(), &pb.InspectRequest{Token: token}) if err != nil { return nil, err } - return serializeAccount(rsp.Account), nil } diff --git a/go.sum b/go.sum index b7d9c90b..4de561e2 100644 --- a/go.sum +++ b/go.sum @@ -399,6 +399,7 @@ go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= @@ -432,6 +433,7 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -529,6 +531,7 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 h1:RIIXAeV6GvDBuADKumTODatUqANFZ+5BPMnzsy4hulY= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -600,6 +603,7 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 100f2f2b..9a7fe54f 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -9,7 +9,6 @@ import ( "github.com/micro/go-micro/v2/debug/stats" "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/errors" - "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/server" ) @@ -155,11 +154,6 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { return h(ctx, req, rsp) } - // Check for auth service endpoints which should be excluded from auth - if strings.HasPrefix(req.Endpoint(), "Auth.") { - return h(ctx, req, rsp) - } - // Extract the token if present. Note: if noop is being used // then the token can be blank without erroring var token string @@ -172,33 +166,17 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { token = header[len(auth.BearerScheme):] } - // Get the namespace for the request - namespace, ok := metadata.Get(ctx, auth.NamespaceKey) - if !ok { - logger.Debugf("Missing request namespace") - namespace = auth.DefaultNamespace - } - // Inspect the token and get the account account, err := a.Inspect(token) if err != nil { - account = &auth.Account{Namespace: namespace} - } - - // Check the accounts namespace matches the namespace we're operating - // within. If not forbid the request and log the occurance. - if account.Namespace != namespace { - logger.Debugf("Cross namespace request forbidden: account %v (%v) requested access to %v %v in the %v namespace", - account.ID, account.Namespace, req.Service(), req.Endpoint(), namespace) - // return errors.Forbidden(req.Service(), "cross namespace request") + account = &auth.Account{} } // construct the resource res := &auth.Resource{ - Type: "service", - Name: req.Service(), - Endpoint: req.Endpoint(), - Namespace: namespace, + Type: "service", + Name: req.Service(), + Endpoint: req.Endpoint(), } // Verify the caller has access to the resource From 3735b0e52917ef7af6886cc3738a4eebde522d67 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 16:27:01 +0100 Subject: [PATCH 551/788] Remove global namespace option --- config/cmd/cmd.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 3eb6fb5e..34e417dd 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -314,12 +314,6 @@ var ( EnvVars: []string{"MICRO_CONFIG"}, Usage: "The source of the config to be used to get configuration", }, - &cli.StringFlag{ - Name: "namespace", - EnvVars: []string{"MICRO_NAMESPACE"}, - Usage: "The namespace the service belongs to", - Value: auth.DefaultNamespace, - }, } DefaultBrokers = map[string]func(...broker.Option) broker.Broker{ @@ -684,9 +678,6 @@ func (c *cmd) Before(ctx *cli.Context) error { ctx.String("auth_id"), ctx.String("auth_secret"), )) } - if len(ctx.String("namespace")) > 0 { - authOpts = append(authOpts, auth.Namespace(ctx.String("namespace"))) - } if len(ctx.String("auth_public_key")) > 0 { authOpts = append(authOpts, auth.PublicKey(ctx.String("auth_public_key"))) From 67cd59d7bcd9c42c0c6b11e51049c0bbb57f27c4 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 16:27:59 +0100 Subject: [PATCH 552/788] Rename namespace from Resolver.Endpoint --- api/resolver/resolver.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/resolver/resolver.go b/api/resolver/resolver.go index daa7078d..99a10802 100644 --- a/api/resolver/resolver.go +++ b/api/resolver/resolver.go @@ -33,8 +33,6 @@ type Endpoint struct { Method string // HTTP Path e.g /greeter. Path string - // Namespace, g.g. go.micro - Namespace string } type Options struct { From 39c352f210395ddf304842075c8a04b8de99d7aa Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 7 Apr 2020 18:22:40 +0100 Subject: [PATCH 553/788] Remove the test that takes 30 seconds sleeping --- sync/store/cache_test.go | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 sync/store/cache_test.go diff --git a/sync/store/cache_test.go b/sync/store/cache_test.go deleted file mode 100644 index 23d3aecd..00000000 --- a/sync/store/cache_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package store - -import ( - "context" - "testing" - "time" - - "github.com/micro/go-micro/v2/store" - "github.com/micro/go-micro/v2/store/memory" -) - -func TestCacheTicker(t *testing.T) { - l0 := memory.NewStore() - l0.Init() - l1 := memory.NewStore() - l1.Init() - l2 := memory.NewStore() - l2.Init() - c := NewCache(Stores(l0, l1, l2), SyncInterval(1*time.Second), SyncMultiplier(2)) - - if err := c.Init(store.WithContext(context.Background())); err != nil { - t.Fatal(err) - } - - time.Sleep(30 * time.Second) -} From e907d24e3bfafca5b53a0f7acb935c152d6016f7 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 7 Apr 2020 19:29:26 +0100 Subject: [PATCH 554/788] API Wrappers --- api/resolver/resolver.go | 6 -- api/server/auth/auth.go | 117 --------------------------------------- api/server/http/http.go | 7 ++- api/server/options.go | 31 ++++++----- 4 files changed, 22 insertions(+), 139 deletions(-) delete mode 100644 api/server/auth/auth.go diff --git a/api/resolver/resolver.go b/api/resolver/resolver.go index 99a10802..12854b19 100644 --- a/api/resolver/resolver.go +++ b/api/resolver/resolver.go @@ -11,12 +11,6 @@ var ( ErrInvalidPath = errors.New("invalid path") ) -// NamespaceResolver resolves request to the namespace -type NamespaceResolver interface { - Resolve(r *http.Request) string - String() string -} - // Resolver resolves requests to endpoints type Resolver interface { Resolve(r *http.Request) (*Endpoint, error) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go deleted file mode 100644 index deffa3dc..00000000 --- a/api/server/auth/auth.go +++ /dev/null @@ -1,117 +0,0 @@ -package auth - -import ( - "context" - "fmt" - "net/http" - "net/url" - "strings" - - "github.com/micro/go-micro/v2/api/resolver" - "github.com/micro/go-micro/v2/auth" - "github.com/micro/go-micro/v2/logger" -) - -// CombinedAuthHandler wraps a server and authenticates requests -func CombinedAuthHandler(r resolver.Resolver, nr resolver.NamespaceResolver, h http.Handler) http.Handler { - return authHandler{ - handler: h, - resolver: r, - nsResolver: nr, - auth: auth.DefaultAuth, - } -} - -type authHandler struct { - handler http.Handler - auth auth.Auth - resolver resolver.Resolver - nsResolver resolver.NamespaceResolver -} - -func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { - // Determine the namespace and set it in the header - namespace := h.nsResolver.Resolve(req) - req.Header.Set(auth.NamespaceKey, namespace) - - // Extract the token from the request - var token string - if header := req.Header.Get("Authorization"); len(header) > 0 { - // Extract the auth token from the request - if strings.HasPrefix(header, auth.BearerScheme) { - token = header[len(auth.BearerScheme):] - } - } else { - // Get the token out the cookies if not provided in headers - if c, err := req.Cookie("micro-token"); err == nil && c != nil { - token = strings.TrimPrefix(c.Value, auth.TokenCookieName+"=") - req.Header.Set("Authorization", auth.BearerScheme+token) - } - } - - // Get the account using the token, fallback to a blank account - // since some endpoints can be unauthenticated, so the lack of an - // account doesn't necesserially mean a forbidden request - acc, err := h.auth.Inspect(token) - if err != nil { - acc = &auth.Account{} - } - - // Determine the name of the service being requested - endpoint, err := h.resolver.Resolve(req) - if err == resolver.ErrInvalidPath || err == resolver.ErrNotFound { - // a file not served by the resolver has been requested (e.g. favicon.ico) - endpoint = &resolver.Endpoint{Path: req.URL.Path} - } else if err != nil { - logger.Error(err) - http.Error(w, err.Error(), 500) - return - } else { - // set the endpoint in the context so it can be used to resolve - // the request later - ctx := context.WithValue(req.Context(), resolver.Endpoint{}, endpoint) - *req = *req.Clone(ctx) - } - - // construct the resource name, e.g. home => go.micro.web.home - resName := namespace - if len(endpoint.Name) > 0 { - resName = namespace + "." + endpoint.Name - } - - // determine the resource path. there is an inconsistency in how resolvers - // use method, some use it as Users.ReadUser (the rpc method), and others - // use it as the HTTP method, e.g GET. TODO: Refactor this to make it consistent. - resEndpoint := endpoint.Path - if len(endpoint.Path) == 0 { - resEndpoint = endpoint.Method - } - - // Perform the verification check to see if the account has access to - // the resource they're requesting - res := &auth.Resource{Type: "service", Name: resName, Endpoint: resEndpoint, Namespace: namespace} - if err := h.auth.Verify(acc, res); err == nil { - // The account has the necessary permissions to access the resource - h.handler.ServeHTTP(w, req) - return - } - - // The account is set, but they don't have enough permissions, hence - // we return a forbidden error. - if len(acc.ID) > 0 { - http.Error(w, "Forbidden request", 403) - return - } - - // If there is no auth login url set, 401 - loginURL := h.auth.Options().LoginURL - if loginURL == "" { - http.Error(w, "unauthorized request", 401) - return - } - - // Redirect to the login path - params := url.Values{"redirect_to": {req.URL.String()}} - loginWithRedirect := fmt.Sprintf("%v?%v", loginURL, params.Encode()) - http.Redirect(w, req, loginWithRedirect, http.StatusTemporaryRedirect) -} diff --git a/api/server/http/http.go b/api/server/http/http.go index c35d24b7..6615232d 100644 --- a/api/server/http/http.go +++ b/api/server/http/http.go @@ -10,7 +10,6 @@ import ( "github.com/gorilla/handlers" "github.com/micro/go-micro/v2/api/server" - "github.com/micro/go-micro/v2/api/server/auth" "github.com/micro/go-micro/v2/api/server/cors" "github.com/micro/go-micro/v2/logger" ) @@ -53,7 +52,11 @@ func (s *httpServer) Init(opts ...server.Option) error { func (s *httpServer) Handle(path string, handler http.Handler) { h := handlers.CombinedLoggingHandler(os.Stdout, handler) - h = auth.CombinedAuthHandler(s.opts.Resolver, s.opts.NamespaceResolver, handler) + + // apply the wrappers, e.g. auth + for _, wrapper := range s.opts.Wrappers { + h = wrapper(h) + } if s.opts.EnableCORS { h = cors.CombinedCORSHandler(h) diff --git a/api/server/options.go b/api/server/options.go index 9aa14579..6d87f543 100644 --- a/api/server/options.go +++ b/api/server/options.go @@ -2,6 +2,7 @@ package server import ( "crypto/tls" + "net/http" "github.com/micro/go-micro/v2/api/resolver" "github.com/micro/go-micro/v2/api/server/acme" @@ -10,14 +11,22 @@ import ( type Option func(o *Options) type Options struct { - EnableACME bool - EnableCORS bool - ACMEProvider acme.Provider - EnableTLS bool - ACMEHosts []string - TLSConfig *tls.Config - Resolver resolver.Resolver - NamespaceResolver resolver.NamespaceResolver + EnableACME bool + EnableCORS bool + ACMEProvider acme.Provider + EnableTLS bool + ACMEHosts []string + TLSConfig *tls.Config + Resolver resolver.Resolver + Wrappers []Wrapper +} + +type Wrapper func(h http.Handler) http.Handler + +func WrapHandler(w Wrapper) Option { + return func(o *Options) { + o.Wrappers = append(o.Wrappers, w) + } } func EnableCORS(b bool) Option { @@ -61,9 +70,3 @@ func Resolver(r resolver.Resolver) Option { o.Resolver = r } } - -func NamespaceResolver(r resolver.NamespaceResolver) Option { - return func(o *Options) { - o.NamespaceResolver = r - } -} From 4cac7dcc4809e190f83645172fca9368f6c8ef4b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 7 Apr 2020 19:45:27 +0100 Subject: [PATCH 555/788] fix file tests --- store/file/file.go | 399 +++++++++++++++++++--------------------- store/file/file_test.go | 137 ++++++-------- 2 files changed, 252 insertions(+), 284 deletions(-) diff --git a/store/file/file.go b/store/file/file.go index 26df09ea..2f924380 100644 --- a/store/file/file.go +++ b/store/file/file.go @@ -3,7 +3,6 @@ package file import ( "encoding/json" - "fmt" "os" "path/filepath" "sort" @@ -11,10 +10,8 @@ import ( "time" "github.com/micro/go-micro/v2/store" - micro_store "github.com/micro/go-micro/v2/store" - bolt "go.etcd.io/bbolt" - "github.com/pkg/errors" + bolt "go.etcd.io/bbolt" ) var ( @@ -29,49 +26,213 @@ var ( // NewStore returns a memory store func NewStore(opts ...store.Option) store.Store { - s := &fileStore{ - options: store.Options{}, - } + s := &fileStore{} s.init(opts...) return s } type fileStore struct { - options store.Options - dir string - fileName string - fullFilePath string + options store.Options + dir string + fileName string + dbPath string + // the database handle + db *bolt.DB } -func (m *fileStore) Init(opts ...store.Option) error { - return m.init(opts...) +// record stored by us +type record struct { + Key string + Value []byte + ExpiresAt time.Time +} + +func (m *fileStore) delete(key string) error { + return m.db.Update(func(tx *bolt.Tx) error { + b := tx.Bucket([]byte(m.options.Table)) + if b == nil { + return nil + } + return b.Delete([]byte(key)) + }) } func (m *fileStore) init(opts ...store.Option) error { for _, o := range opts { o(&m.options) } + if m.options.Database == "" { m.options.Database = DefaultDatabase } + if m.options.Table == "" { // bbolt requires bucketname to not be empty m.options.Table = DefaultTable } + + // create a directory /tmp/micro dir := filepath.Join(DefaultDir, "micro") + // create the database handle fname := m.options.Database + ".db" // Ignoring this as the folder might exist. // Reads/Writes updates will return with sensible error messages // about the dir not existing in case this cannot create the path anyway _ = os.Mkdir(dir, 0700) + m.dir = dir m.fileName = fname - m.fullFilePath = filepath.Join(dir, fname) - return nil + m.dbPath = filepath.Join(dir, fname) + + // close existing handle + if m.db != nil { + m.db.Close() + } + + // create new db handle + db, err := bolt.Open(m.dbPath, 0700, &bolt.Options{Timeout: 5 * time.Second}) + if err != nil { + return err + } + + // set the new db + m.db = db + + // create the table + return db.Update(func(tx *bolt.Tx) error { + _, err := tx.CreateBucketIfNotExists([]byte(m.options.Table)) + return err + }) } -func (m *fileStore) String() string { - return "local" +func (m *fileStore) list(limit, offset uint) []string { + var allItems []string + + m.db.View(func(tx *bolt.Tx) error { + b := tx.Bucket([]byte(m.options.Table)) + // nothing to read + if b == nil { + return nil + } + + // @todo very inefficient + if err := b.ForEach(func(k, v []byte) error { + storedRecord := &record{} + + if err := json.Unmarshal(v, storedRecord); err != nil { + return err + } + + if !storedRecord.ExpiresAt.IsZero() { + if storedRecord.ExpiresAt.Before(time.Now()) { + return nil + } + } + + allItems = append(allItems, string(k)) + + return nil + }); err != nil { + return err + } + + return nil + }) + + allKeys := make([]string, len(allItems)) + + for i, k := range allItems { + allKeys[i] = k + } + + if limit != 0 || offset != 0 { + sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] }) + min := func(i, j uint) uint { + if i < j { + return i + } + return j + } + return allKeys[offset:min(limit, uint(len(allKeys)))] + } + + return allKeys +} + +func (m *fileStore) get(k string) (*store.Record, error) { + var value []byte + + m.db.View(func(tx *bolt.Tx) error { + // @todo this is still very experimental... + b := tx.Bucket([]byte(m.options.Table)) + if b == nil { + return nil + } + + value = b.Get([]byte(k)) + return nil + }) + + if value == nil { + return nil, store.ErrNotFound + } + + storedRecord := &record{} + + if err := json.Unmarshal(value, storedRecord); err != nil { + return nil, err + } + + newRecord := &store.Record{} + newRecord.Key = storedRecord.Key + newRecord.Value = storedRecord.Value + + if !storedRecord.ExpiresAt.IsZero() { + if storedRecord.ExpiresAt.Before(time.Now()) { + return nil, store.ErrNotFound + } + newRecord.Expiry = time.Until(storedRecord.ExpiresAt) + } + + return newRecord, nil +} + +func (m *fileStore) set(r *store.Record) error { + // copy the incoming record and then + // convert the expiry in to a hard timestamp + item := &record{} + item.Key = r.Key + item.Value = r.Value + if r.Expiry != 0 { + item.ExpiresAt = time.Now().Add(r.Expiry) + } + + // marshal the data + data, _ := json.Marshal(item) + + return m.db.Update(func(tx *bolt.Tx) error { + b := tx.Bucket([]byte(m.options.Table)) + if b == nil { + var err error + b, err = tx.CreateBucketIfNotExists([]byte(m.options.Table)) + if err != nil { + return err + } + } + return b.Put([]byte(r.Key), data) + }) +} + +func (m *fileStore) Init(opts ...store.Option) error { + return m.init(opts...) +} + +func (m *fileStore) Delete(key string, opts ...store.DeleteOption) error { + deleteOptions := store.DeleteOptions{} + for _, o := range opts { + o(&deleteOptions) + } + return m.delete(key) } func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { @@ -83,6 +244,7 @@ func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, var keys []string // Handle Prefix / suffix + // TODO: do range scan here rather than listing all keys if readOpts.Prefix || readOpts.Suffix { var opts []store.ListOption if readOpts.Prefix { @@ -91,18 +253,22 @@ func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, if readOpts.Suffix { opts = append(opts, store.ListSuffix(key)) } + opts = append(opts, store.ListLimit(readOpts.Limit)) opts = append(opts, store.ListOffset(readOpts.Offset)) + k, err := m.List(opts...) if err != nil { return nil, errors.Wrap(err, "FileStore: Read couldn't List()") } + keys = k } else { keys = []string{key} } var results []*store.Record + for _, k := range keys { r, err := m.get(k) if err != nil { @@ -110,59 +276,10 @@ func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, } results = append(results, r) } + return results, nil } -func (m *fileStore) get(k string) (*store.Record, error) { - if len(m.options.Table) > 0 { - k = m.options.Table + "/" + k - } - if len(m.options.Database) > 0 { - k = m.options.Database + "/" + k - } - store, err := bolt.Open(m.fullFilePath, 0700, &bolt.Options{Timeout: 1 * time.Second}) - if err != nil { - return nil, err - } - defer store.Close() - err = store.Update(func(tx *bolt.Tx) error { - _, err := tx.CreateBucketIfNotExists([]byte(m.options.Table)) - if err != nil { - return err - } - return nil - }) - if err != nil { - return nil, err - } - var value []byte - store.View(func(tx *bolt.Tx) error { - // @todo this is still very experimental... - bucket := tx.Bucket([]byte(m.options.Table)) - value = bucket.Get([]byte(k)) - return nil - }) - if value == nil { - return nil, micro_store.ErrNotFound - } - storedRecord := &internalRecord{} - err = json.Unmarshal(value, storedRecord) - if err != nil { - return nil, err - } - newRecord := µ_store.Record{} - newRecord.Key = storedRecord.Key - newRecord.Value = storedRecord.Value - if !storedRecord.ExpiresAt.IsZero() { - if storedRecord.ExpiresAt.Before(time.Now()) { - return nil, micro_store.ErrNotFound - } - newRecord.Expiry = time.Until(storedRecord.ExpiresAt) - } - - return newRecord, nil -} - func (m *fileStore) Write(r *store.Record, opts ...store.WriteOption) error { writeOpts := store.WriteOptions{} for _, o := range opts { @@ -182,87 +299,13 @@ func (m *fileStore) Write(r *store.Record, opts ...store.WriteOption) error { if writeOpts.TTL != 0 { newRecord.Expiry = writeOpts.TTL } + return m.set(&newRecord) } + return m.set(r) } -func (m *fileStore) set(r *store.Record) error { - key := r.Key - if len(m.options.Table) > 0 { - key = m.options.Table + "/" + key - } - if len(m.options.Database) > 0 { - key = m.options.Database + "/" + key - } - - // copy the incoming record and then - // convert the expiry in to a hard timestamp - i := &internalRecord{} - i.Key = r.Key - i.Value = r.Value - if r.Expiry != 0 { - i.ExpiresAt = time.Now().Add(r.Expiry) - } - - iJSON, _ := json.Marshal(i) - - store, err := bolt.Open(m.fullFilePath, 0700, &bolt.Options{Timeout: 1 * time.Second}) - if err != nil { - return err - } - defer store.Close() - return store.Update(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte(m.options.Table)) - if b == nil { - var err error - b, err = tx.CreateBucketIfNotExists([]byte(m.options.Table)) - if err != nil { - return err - } - } - return b.Put([]byte(key), iJSON) - }) -} - -func (m *fileStore) Delete(key string, opts ...store.DeleteOption) error { - deleteOptions := store.DeleteOptions{} - for _, o := range opts { - o(&deleteOptions) - } - return m.delete(key) -} - -func (m *fileStore) delete(key string) error { - if len(m.options.Table) > 0 { - key = m.options.Table + "/" + key - } - if len(m.options.Database) > 0 { - key = m.options.Database + "/" + key - } - store, err := bolt.Open(m.fullFilePath, 0700, &bolt.Options{Timeout: 1 * time.Second}) - if err != nil { - return err - } - defer store.Close() - return store.Update(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte(m.options.Table)) - if b == nil { - var err error - b, err = tx.CreateBucketIfNotExists([]byte(m.options.Table)) - if err != nil { - return err - } - } - err := b.Delete([]byte(key)) - return err - }) -} - -func (m *fileStore) deleteAll() error { - return os.Remove(m.fullFilePath) -} - func (m *fileStore) Options() store.Options { return m.options } @@ -273,6 +316,8 @@ func (m *fileStore) List(opts ...store.ListOption) ([]string, error) { for _, o := range opts { o(&listOptions) } + + // TODO apply prefix/suffix in range query allKeys := m.list(listOptions.Limit, listOptions.Offset) if len(listOptions.Prefix) > 0 { @@ -284,6 +329,7 @@ func (m *fileStore) List(opts ...store.ListOption) ([]string, error) { } allKeys = prefixKeys } + if len(listOptions.Suffix) > 0 { var suffixKeys []string for _, k := range allKeys { @@ -297,69 +343,6 @@ func (m *fileStore) List(opts ...store.ListOption) ([]string, error) { return allKeys, nil } -func (m *fileStore) list(limit, offset uint) []string { - allItems := []string{} - store, err := bolt.Open(m.fullFilePath, 0700, &bolt.Options{Timeout: 1 * time.Second}) - if err != nil { - fmt.Println("Error creating file:", err) - } - defer store.Close() - store.Update(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte(m.options.Table)) - if b == nil { - var err error - b, err = tx.CreateBucketIfNotExists([]byte(m.options.Table)) - if err != nil { - return err - } - } - // @todo very inefficient - if err := b.ForEach(func(k, v []byte) error { - storedRecord := &internalRecord{} - err := json.Unmarshal(v, storedRecord) - if err != nil { - return err - } - if !storedRecord.ExpiresAt.IsZero() { - if storedRecord.ExpiresAt.Before(time.Now()) { - return nil - } - } - allItems = append(allItems, string(k)) - return nil - }); err != nil { - return err - } - - return nil - }) - allKeys := make([]string, len(allItems)) - i := 0 - for _, k := range allItems { - if len(m.options.Database) > 0 { - k = strings.TrimPrefix(k, m.options.Database+"/") - } - if len(m.options.Table) > 0 { - k = strings.TrimPrefix(k, m.options.Table+"/") - } - allKeys[i] = k - i++ - } - if limit != 0 || offset != 0 { - sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] }) - min := func(i, j uint) uint { - if i < j { - return i - } - return j - } - return allKeys[offset:min(limit, uint(len(allKeys)))] - } - return allKeys -} - -type internalRecord struct { - Key string - Value []byte - ExpiresAt time.Time +func (m *fileStore) String() string { + return "file" } diff --git a/store/file/file_test.go b/store/file/file_test.go index 26a20cd3..86c533fc 100644 --- a/store/file/file_test.go +++ b/store/file/file_test.go @@ -2,6 +2,9 @@ package file import ( "fmt" + "os" + "path/filepath" + "strings" "testing" "time" @@ -10,7 +13,13 @@ import ( "github.com/micro/go-micro/v2/store" ) -func TestFileReInit(t *testing.T) { +func cleanup() { + dir := filepath.Join(DefaultDir, "micro/") + os.RemoveAll(dir) +} + +func TestFileStoreReInit(t *testing.T) { + defer cleanup() s := NewStore(store.Table("aaa")) s.Init(store.Table("bbb")) if s.Options().Table != "bbb" { @@ -18,54 +27,44 @@ func TestFileReInit(t *testing.T) { } } -func TestFileBasic(t *testing.T) { +func TestFileStoreBasic(t *testing.T) { + defer cleanup() s := NewStore() - s.Init() - if err := s.(*fileStore).deleteAll(); err != nil { - t.Logf("Can't delete all: %v", err) - } - basictest(s, t) + fileTest(s, t) } -func TestFileTable(t *testing.T) { - s := NewStore() - s.Init(store.Table("some-Table")) - if err := s.(*fileStore).deleteAll(); err != nil { - t.Logf("Can't delete all: %v", err) - } - basictest(s, t) +func TestFileStoreTable(t *testing.T) { + defer cleanup() + s := NewStore(store.Table("testTable")) + fileTest(s, t) } -func TestFileDatabase(t *testing.T) { - s := NewStore() - s.Init(store.Database("some-Database")) - if err := s.(*fileStore).deleteAll(); err != nil { - t.Logf("Can't delete all: %v", err) - } - basictest(s, t) +func TestFileStoreDatabase(t *testing.T) { + defer cleanup() + s := NewStore(store.Database("testdb")) + fileTest(s, t) } -func TestFileDatabaseTable(t *testing.T) { - s := NewStore() - s.Init(store.Table("some-Table"), store.Database("some-Database")) - if err := s.(*fileStore).deleteAll(); err != nil { - t.Logf("Can't delete all: %v", err) - } - basictest(s, t) +func TestFileStoreDatabaseTable(t *testing.T) { + defer cleanup() + s := NewStore(store.Table("testTable"), store.Database("testdb")) + fileTest(s, t) } -func basictest(s store.Store, t *testing.T) { - t.Logf("Testing store %s, with options %# v\n", s.String(), pretty.Formatter(s.Options())) +func fileTest(s store.Store, t *testing.T) { + t.Logf("Options %s %v\n", s.String(), s.Options()) + // Read and Write an expiring Record if err := s.Write(&store.Record{ Key: "Hello", Value: []byte("World"), - Expiry: time.Millisecond * 100, + Expiry: time.Millisecond * 150, }); err != nil { t.Error(err) } + if r, err := s.Read("Hello"); err != nil { - t.Error(err) + t.Fatal(err) } else { if len(r) != 1 { t.Error("Read returned multiple records") @@ -77,7 +76,10 @@ func basictest(s store.Store, t *testing.T) { t.Errorf("Expected %s, got %s", "World", r[0].Value) } } + + // wait for expiry time.Sleep(time.Millisecond * 200) + if _, err := s.Read("Hello"); err != store.ErrNotFound { t.Errorf("Expected %# v, got %# v", store.ErrNotFound, err) } @@ -93,26 +95,14 @@ func basictest(s store.Store, t *testing.T) { Value: []byte("foobarfoobar"), Expiry: time.Millisecond * 100, }, - &store.Record{ - Key: "foobarbaz", - Value: []byte("foobarbazfoobarbaz"), - Expiry: 2 * time.Millisecond * 100, - }, } + for _, r := range records { if err := s.Write(r); err != nil { t.Errorf("Couldn't write k: %s, v: %# v (%s)", r.Key, pretty.Formatter(r.Value), err) } } - if results, err := s.Read("foo", store.ReadPrefix()); err != nil { - t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) - } else { - if len(results) != 3 { - t.Errorf("Expected 3 items, got %d", len(results)) - t.Logf("Table test: %v\n", spew.Sdump(results)) - } - } - time.Sleep(time.Millisecond * 100) + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) } else { @@ -121,20 +111,23 @@ func basictest(s store.Store, t *testing.T) { t.Logf("Table test: %v\n", spew.Sdump(results)) } } - time.Sleep(time.Millisecond * 100) + + // wait for the expiry + time.Sleep(time.Millisecond * 200) + if results, err := s.Read("foo", store.ReadPrefix()); err != nil { t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) - } else { - if len(results) != 1 { - t.Errorf("Expected 1 item, got %d", len(results)) - t.Logf("Table test: %# v\n", spew.Sdump(results)) - } + } else if len(results) != 1 { + t.Errorf("Expected 1 item, got %d", len(results)) + t.Logf("Table test: %v\n", spew.Sdump(results)) } - if err := s.Delete("foo", func(d *store.DeleteOptions) {}); err != nil { + + if err := s.Delete("foo"); err != nil { t.Errorf("Delete failed (%v)", err) } - if results, err := s.Read("foo", store.ReadPrefix()); err != nil { - t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) + + if results, err := s.Read("foo"); err != store.ErrNotFound { + t.Errorf("Expected read failure read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) } else { if len(results) != 0 { t.Errorf("Expected 0 items, got %d (%# v)", len(results), spew.Sdump(results)) @@ -148,8 +141,9 @@ func basictest(s store.Store, t *testing.T) { Value: []byte("foofoo"), }, &store.Record{ - Key: "barfoo", - Value: []byte("barfoobarfoo"), + Key: "barfoo", + Value: []byte("barfoobarfoo"), + Expiry: time.Millisecond * 100, }, &store.Record{ @@ -222,6 +216,7 @@ func basictest(s store.Store, t *testing.T) { }, store.WriteExpiry(time.Now().Add(time.Hour)), store.WriteTTL(time.Millisecond*100)); err != nil { t.Error(err) } + if results, err := s.Read("foo", store.ReadPrefix(), store.ReadSuffix()); err != nil { t.Error(err) } else { @@ -229,7 +224,9 @@ func basictest(s store.Store, t *testing.T) { t.Errorf("Expected 1 results, got %d: %# v", len(results), spew.Sdump(results)) } } + time.Sleep(time.Millisecond * 100) + if results, err := s.List(); err != nil { t.Errorf("List failed: %s", err) } else { @@ -237,40 +234,28 @@ func basictest(s store.Store, t *testing.T) { t.Errorf("Expiry options were not effective, results :%v", spew.Sdump(results)) } } - s.Write(&store.Record{Key: "a", Value: []byte("a")}) - s.Write(&store.Record{Key: "aa", Value: []byte("aa")}) - s.Write(&store.Record{Key: "aaa", Value: []byte("aaa")}) - if results, err := s.Read("b", store.ReadPrefix()); err != nil { - t.Error(err) - } else { - if len(results) != 0 { - t.Errorf("Expected 0 results, got %d", len(results)) - } - } - s.Init() - if err := s.(*fileStore).deleteAll(); err != nil { - t.Logf("Can't delete all: %v", err) - } + // write the following records for i := 0; i < 10; i++ { s.Write(&store.Record{ Key: fmt.Sprintf("a%d", i), Value: []byte{}, }) } + + // read back a few records if results, err := s.Read("a", store.ReadLimit(5), store.ReadPrefix()); err != nil { t.Error(err) } else { if len(results) != 5 { t.Error("Expected 5 results, got ", len(results)) } - if results[0].Key != "a0" { - t.Errorf("Expected a0, got %s", results[0].Key) - } - if results[4].Key != "a4" { - t.Errorf("Expected a4, got %s", results[4].Key) + if !strings.HasPrefix(results[0].Key, "a") { + t.Errorf("Expected a prefix, got %s", results[0].Key) } } + + // read the rest back if results, err := s.Read("a", store.ReadLimit(30), store.ReadOffset(5), store.ReadPrefix()); err != nil { t.Error(err) } else { From 4b0e27413e14190a358e66e38061f01a95e59c3b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Apr 2020 09:51:10 +0100 Subject: [PATCH 556/788] add Store Close method (#1500) * add Store Close method * Update sync store build failure --- store/cache/cache.go | 4 ++++ store/cloudflare/cloudflare.go | 4 ++++ store/cockroach/cockroach.go | 7 +++++++ store/etcd/etcd.go | 4 ++++ store/file/file.go | 13 ++++++++++--- store/file/file_test.go | 15 ++++++++------- store/memory/memory.go | 5 +++++ store/noop.go | 4 ++++ store/service/service.go | 4 ++++ store/store.go | 2 ++ sync/store/cache.go | 4 ++++ 11 files changed, 56 insertions(+), 10 deletions(-) diff --git a/store/cache/cache.go b/store/cache/cache.go index a52c2bb3..96790b7a 100644 --- a/store/cache/cache.go +++ b/store/cache/cache.go @@ -23,6 +23,10 @@ func NewCache(stores ...store.Store) store.Store { return c } +func (c *cache) Close() error { + return nil +} + func (c *cache) Init(...store.Option) error { if len(c.stores) < 2 { return errors.New("cache requires at least 2 stores") diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index c9099f1b..c7fa5541 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -101,6 +101,10 @@ func validateOptions(account, token, namespace string) { } } +func (w *workersKV) Close() error { + return nil +} + func (w *workersKV) Init(opts ...store.Option) error { for _, o := range opts { o(&w.options) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 5f242810..29d78743 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -36,6 +36,13 @@ type sqlStore struct { options store.Options } +func (s *sqlStore) Close() error { + if s.db != nil { + return s.db.Close() + } + return nil +} + func (s *sqlStore) Init(opts ...store.Option) error { for _, o := range opts { o(&s.options) diff --git a/store/etcd/etcd.go b/store/etcd/etcd.go index a51fd425..d4d9cf97 100644 --- a/store/etcd/etcd.go +++ b/store/etcd/etcd.go @@ -32,6 +32,10 @@ func NewStore(opts ...store.Option) store.Store { return e } +func (e *etcdStore) Close() error { + return e.client.Close() +} + func (e *etcdStore) Init(opts ...store.Option) error { for _, o := range opts { o(&e.options) diff --git a/store/file/file.go b/store/file/file.go index 2f924380..2a62207d 100644 --- a/store/file/file.go +++ b/store/file/file.go @@ -72,13 +72,13 @@ func (m *fileStore) init(opts ...store.Option) error { } // create a directory /tmp/micro - dir := filepath.Join(DefaultDir, "micro") + dir := filepath.Join(DefaultDir, m.options.Database) // create the database handle - fname := m.options.Database + ".db" + fname := m.options.Table + ".db" // Ignoring this as the folder might exist. // Reads/Writes updates will return with sensible error messages // about the dir not existing in case this cannot create the path anyway - _ = os.Mkdir(dir, 0700) + os.MkdirAll(dir, 0700) m.dir = dir m.fileName = fname @@ -223,6 +223,13 @@ func (m *fileStore) set(r *store.Record) error { }) } +func (m *fileStore) Close() error { + if m.db != nil { + return m.db.Close() + } + return nil +} + func (m *fileStore) Init(opts ...store.Option) error { return m.init(opts...) } diff --git a/store/file/file_test.go b/store/file/file_test.go index 86c533fc..b3466b9a 100644 --- a/store/file/file_test.go +++ b/store/file/file_test.go @@ -13,14 +13,15 @@ import ( "github.com/micro/go-micro/v2/store" ) -func cleanup() { - dir := filepath.Join(DefaultDir, "micro/") +func cleanup(db string, s store.Store) { + s.Close() + dir := filepath.Join(DefaultDir, db + "/") os.RemoveAll(dir) } func TestFileStoreReInit(t *testing.T) { - defer cleanup() s := NewStore(store.Table("aaa")) + defer cleanup(DefaultDatabase, s) s.Init(store.Table("bbb")) if s.Options().Table != "bbb" { t.Error("Init didn't reinitialise the store") @@ -28,26 +29,26 @@ func TestFileStoreReInit(t *testing.T) { } func TestFileStoreBasic(t *testing.T) { - defer cleanup() s := NewStore() + defer cleanup(DefaultDatabase, s) fileTest(s, t) } func TestFileStoreTable(t *testing.T) { - defer cleanup() s := NewStore(store.Table("testTable")) + defer cleanup(DefaultDatabase, s) fileTest(s, t) } func TestFileStoreDatabase(t *testing.T) { - defer cleanup() s := NewStore(store.Database("testdb")) + defer cleanup("testdb", s) fileTest(s, t) } func TestFileStoreDatabaseTable(t *testing.T) { - defer cleanup() s := NewStore(store.Table("testTable"), store.Database("testdb")) + defer cleanup("testdb", s) fileTest(s, t) } diff --git a/store/memory/memory.go b/store/memory/memory.go index e2f6d15e..97d19072 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -30,6 +30,11 @@ type memoryStore struct { store *cache.Cache } +func (m *memoryStore) Close() error { + m.store.Flush() + return nil +} + func (m *memoryStore) Init(opts ...store.Option) error { m.store.Flush() for _, o := range opts { diff --git a/store/noop.go b/store/noop.go index 0c6ebb4b..25d4850a 100644 --- a/store/noop.go +++ b/store/noop.go @@ -29,3 +29,7 @@ func (n *noopStore) Delete(key string, opts ...DeleteOption) error { func (n *noopStore) List(opts ...ListOption) ([]string, error) { return []string{}, nil } + +func (n *noopStore) Close() error { + return nil +} diff --git a/store/service/service.go b/store/service/service.go index f55bbd04..f3829e9a 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -32,6 +32,10 @@ type serviceStore struct { Client pb.StoreService } +func (s *serviceStore) Close() error { + return nil +} + func (s *serviceStore) Init(opts ...store.Option) error { for _, o := range opts { o(&s.options) diff --git a/store/store.go b/store/store.go index 057ad4ea..d073f4e1 100644 --- a/store/store.go +++ b/store/store.go @@ -28,6 +28,8 @@ type Store interface { Delete(key string, opts ...DeleteOption) error // List returns any keys that match, or an empty list with no error if none matched. List(opts ...ListOption) ([]string, error) + // Close the store + Close() error // String returns the name of the implementation. String() string } diff --git a/sync/store/cache.go b/sync/store/cache.go index 3c13e48a..2385e961 100644 --- a/sync/store/cache.go +++ b/sync/store/cache.go @@ -41,6 +41,10 @@ func NewCache(opts ...Option) Cache { return c } +func (c *cache) Close() error { + return nil +} + // Init initialises the storeOptions func (c *cache) Init(opts ...store.Option) error { for _, o := range opts { From 98fc3dfbad2369825ed1b86e26472f3ca2eb4c73 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Apr 2020 09:57:51 +0100 Subject: [PATCH 557/788] use single data bucket --- store/file/file.go | 15 +++++++++------ store/file/file_test.go | 10 +++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/store/file/file.go b/store/file/file.go index 2a62207d..cddcaf80 100644 --- a/store/file/file.go +++ b/store/file/file.go @@ -22,6 +22,9 @@ var ( DefaultTable = "micro" // DefaultDir is the default directory for bbolt files DefaultDir = os.TempDir() + + // bucket used for data storage + dataBucket = "data" ) // NewStore returns a memory store @@ -49,7 +52,7 @@ type record struct { func (m *fileStore) delete(key string) error { return m.db.Update(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte(m.options.Table)) + b := tx.Bucket([]byte(dataBucket)) if b == nil { return nil } @@ -100,7 +103,7 @@ func (m *fileStore) init(opts ...store.Option) error { // create the table return db.Update(func(tx *bolt.Tx) error { - _, err := tx.CreateBucketIfNotExists([]byte(m.options.Table)) + _, err := tx.CreateBucketIfNotExists([]byte(dataBucket)) return err }) } @@ -109,7 +112,7 @@ func (m *fileStore) list(limit, offset uint) []string { var allItems []string m.db.View(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte(m.options.Table)) + b := tx.Bucket([]byte(dataBucket)) // nothing to read if b == nil { return nil @@ -164,7 +167,7 @@ func (m *fileStore) get(k string) (*store.Record, error) { m.db.View(func(tx *bolt.Tx) error { // @todo this is still very experimental... - b := tx.Bucket([]byte(m.options.Table)) + b := tx.Bucket([]byte(dataBucket)) if b == nil { return nil } @@ -211,10 +214,10 @@ func (m *fileStore) set(r *store.Record) error { data, _ := json.Marshal(item) return m.db.Update(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte(m.options.Table)) + b := tx.Bucket([]byte(dataBucket)) if b == nil { var err error - b, err = tx.CreateBucketIfNotExists([]byte(m.options.Table)) + b, err = tx.CreateBucketIfNotExists([]byte(dataBucket)) if err != nil { return err } diff --git a/store/file/file_test.go b/store/file/file_test.go index b3466b9a..6dd58c64 100644 --- a/store/file/file_test.go +++ b/store/file/file_test.go @@ -15,7 +15,7 @@ import ( func cleanup(db string, s store.Store) { s.Close() - dir := filepath.Join(DefaultDir, db + "/") + dir := filepath.Join(DefaultDir, db+"/") os.RemoveAll(dir) } @@ -249,19 +249,19 @@ func fileTest(s store.Store, t *testing.T) { t.Error(err) } else { if len(results) != 5 { - t.Error("Expected 5 results, got ", len(results)) + t.Fatal("Expected 5 results, got ", len(results)) } if !strings.HasPrefix(results[0].Key, "a") { - t.Errorf("Expected a prefix, got %s", results[0].Key) + t.Fatalf("Expected a prefix, got %s", results[0].Key) } } // read the rest back if results, err := s.Read("a", store.ReadLimit(30), store.ReadOffset(5), store.ReadPrefix()); err != nil { - t.Error(err) + t.Fatal(err) } else { if len(results) != 5 { - t.Error("Expected 5 results, got ", len(results)) + t.Fatal("Expected 5 results, got ", len(results)) } } } From 1fbc056dd4d9619a00a84b56fe3c917c0614e876 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 8 Apr 2020 12:50:19 +0300 Subject: [PATCH 558/788] minimize allocations (#1472) * server: minimize allocations on re-register Signed-off-by: Vasiliy Tolstov * server: stop old instance before Init() Signed-off-by: Vasiliy Tolstov * client/grpc: fix allocations in protobuf marshal Signed-off-by: Vasiliy Tolstov * codec/json: fix allocations in protobuf marshal Signed-off-by: Vasiliy Tolstov * remove stop from init Signed-off-by: Vasiliy Tolstov * codec/grpc: expose MaxMessageSize Signed-off-by: Vasiliy Tolstov * codec: use buffer pool Signed-off-by: Vasiliy Tolstov * metadata: minimize reallocations Signed-off-by: Vasiliy Tolstov * util/wrapper: use metadata helper Signed-off-by: Vasiliy Tolstov * registry/cache: move logs to debug level Signed-off-by: Vasiliy Tolstov * server: move logs to debug level Signed-off-by: Vasiliy Tolstov * server: cache service only when Advertise is ip addr Signed-off-by: Vasiliy Tolstov * server: use metadata.Copy Signed-off-by: Vasiliy Tolstov --- client/grpc/codec.go | 19 +++++-- codec/bytes/marshaler.go | 6 +- codec/grpc/util.go | 6 +- codec/json/marshaler.go | 17 +++++- codec/proto/marshaler.go | 32 ++++++++++- metadata/metadata.go | 6 +- registry/cache/cache.go | 8 +-- server/grpc/grpc.go | 79 ++++++++++++++++++-------- server/rpc_server.go | 116 +++++++++++++++++++++++++++++---------- util/wrapper/wrapper.go | 14 +---- 10 files changed, 220 insertions(+), 83 deletions(-) diff --git a/client/grpc/codec.go b/client/grpc/codec.go index a7ee99fc..e5a6730e 100644 --- a/client/grpc/codec.go +++ b/client/grpc/codec.go @@ -11,6 +11,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/codec/bytes" + "github.com/oxtoacart/bpool" "google.golang.org/grpc" "google.golang.org/grpc/encoding" ) @@ -23,6 +24,9 @@ type wrapCodec struct{ encoding.Codec } var jsonpbMarshaler = &jsonpb.Marshaler{} var useNumber bool +// create buffer pool with 16 instances each preallocated with 256 bytes +var bufferPool = bpool.NewSizedBufferPool(16, 256) + var ( defaultGRPCCodecs = map[string]encoding.Codec{ "application/json": jsonCodec{}, @@ -106,14 +110,19 @@ func (bytesCodec) Name() string { } func (jsonCodec) Marshal(v interface{}) ([]byte, error) { - if pb, ok := v.(proto.Message); ok { - s, err := jsonpbMarshaler.MarshalToString(pb) - - return []byte(s), err - } if b, ok := v.(*bytes.Frame); ok { return b.Data, nil } + + if pb, ok := v.(proto.Message); ok { + buf := bufferPool.Get() + defer bufferPool.Put(buf) + if err := jsonpbMarshaler.Marshal(buf, pb); err != nil { + return nil, err + } + return buf.Bytes(), nil + } + return json.Marshal(v) } diff --git a/codec/bytes/marshaler.go b/codec/bytes/marshaler.go index 86af8984..d15e8d75 100644 --- a/codec/bytes/marshaler.go +++ b/codec/bytes/marshaler.go @@ -1,7 +1,7 @@ package bytes import ( - "errors" + "github.com/micro/go-micro/v2/codec" ) type Marshaler struct{} @@ -20,7 +20,7 @@ func (n Marshaler) Marshal(v interface{}) ([]byte, error) { case *Message: return ve.Body, nil } - return nil, errors.New("invalid message") + return nil, codec.ErrInvalidMessage } func (n Marshaler) Unmarshal(d []byte, v interface{}) error { @@ -30,7 +30,7 @@ func (n Marshaler) Unmarshal(d []byte, v interface{}) error { case *Message: ve.Body = d } - return errors.New("invalid message") + return codec.ErrInvalidMessage } func (n Marshaler) String() string { diff --git a/codec/grpc/util.go b/codec/grpc/util.go index 04c5ee38..6ba77e22 100644 --- a/codec/grpc/util.go +++ b/codec/grpc/util.go @@ -7,7 +7,7 @@ import ( ) var ( - maxMessageSize = 1024 * 1024 * 4 + MaxMessageSize = 1024 * 1024 * 4 // 4Mb maxInt = int(^uint(0) >> 1) ) @@ -34,8 +34,8 @@ func decode(r io.Reader) (uint8, []byte, error) { if int64(length) > int64(maxInt) { return cf, nil, fmt.Errorf("grpc: received message larger than max length allowed on current machine (%d vs. %d)", length, maxInt) } - if int(length) > maxMessageSize { - return cf, nil, fmt.Errorf("grpc: received message larger than max (%d vs. %d)", length, maxMessageSize) + if int(length) > MaxMessageSize { + return cf, nil, fmt.Errorf("grpc: received message larger than max (%d vs. %d)", length, MaxMessageSize) } msg := make([]byte, int(length)) diff --git a/codec/json/marshaler.go b/codec/json/marshaler.go index a13e5f39..2f6bcd54 100644 --- a/codec/json/marshaler.go +++ b/codec/json/marshaler.go @@ -1,21 +1,36 @@ package json import ( + "bytes" "encoding/json" "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" + "github.com/oxtoacart/bpool" ) +var jsonpbMarshaler = &jsonpb.Marshaler{} + +// create buffer pool with 16 instances each preallocated with 256 bytes +var bufferPool = bpool.NewSizedBufferPool(16, 256) + type Marshaler struct{} func (j Marshaler) Marshal(v interface{}) ([]byte, error) { + if pb, ok := v.(proto.Message); ok { + buf := bufferPool.Get() + defer bufferPool.Put(buf) + if err := jsonpbMarshaler.Marshal(buf, pb); err != nil { + return nil, err + } + return buf.Bytes(), nil + } return json.Marshal(v) } func (j Marshaler) Unmarshal(d []byte, v interface{}) error { if pb, ok := v.(proto.Message); ok { - return jsonpb.UnmarshalString(string(d), pb) + return jsonpb.Unmarshal(bytes.NewReader(d), pb) } return json.Unmarshal(d, v) } diff --git a/codec/proto/marshaler.go b/codec/proto/marshaler.go index 8f9eee2a..82acc4b2 100644 --- a/codec/proto/marshaler.go +++ b/codec/proto/marshaler.go @@ -1,17 +1,45 @@ package proto import ( + "bytes" + "github.com/golang/protobuf/proto" + "github.com/micro/go-micro/v2/codec" + "github.com/oxtoacart/bpool" ) +// create buffer pool with 16 instances each preallocated with 256 bytes +var bufferPool = bpool.NewSizedBufferPool(16, 256) + type Marshaler struct{} func (Marshaler) Marshal(v interface{}) ([]byte, error) { - return proto.Marshal(v.(proto.Message)) + pb, ok := v.(proto.Message) + if !ok { + return nil, codec.ErrInvalidMessage + } + + // looks not good, but allows to reuse underlining bytes + buf := bufferPool.Get() + pbuf := proto.NewBuffer(buf.Bytes()) + defer func() { + bufferPool.Put(bytes.NewBuffer(pbuf.Bytes())) + }() + + if err := pbuf.Marshal(pb); err != nil { + return nil, err + } + + return pbuf.Bytes(), nil } func (Marshaler) Unmarshal(data []byte, v interface{}) error { - return proto.Unmarshal(data, v.(proto.Message)) + pb, ok := v.(proto.Message) + if !ok { + return codec.ErrInvalidMessage + } + + return proto.Unmarshal(data, pb) } func (Marshaler) String() string { diff --git a/metadata/metadata.go b/metadata/metadata.go index 96693cf6..bd539314 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -34,7 +34,7 @@ func (md Metadata) Delete(key string) { // Copy makes a copy of the metadata func Copy(md Metadata) Metadata { - cmd := make(Metadata) + cmd := make(Metadata, len(md)) for k, v := range md { cmd[k] = v } @@ -86,7 +86,7 @@ func FromContext(ctx context.Context) (Metadata, bool) { } // capitalise all values - newMD := make(map[string]string, len(md)) + newMD := make(Metadata, len(md)) for k, v := range md { newMD[strings.Title(k)] = v } @@ -105,7 +105,7 @@ func MergeContext(ctx context.Context, patchMd Metadata, overwrite bool) context ctx = context.Background() } md, _ := ctx.Value(MetadataKey{}).(Metadata) - cmd := make(Metadata) + cmd := make(Metadata, len(md)) for k, v := range md { cmd[k] = v } diff --git a/registry/cache/cache.go b/registry/cache/cache.go index a68e32ef..eb12d16d 100644 --- a/registry/cache/cache.go +++ b/registry/cache/cache.go @@ -339,8 +339,8 @@ func (c *cache) run() { c.setStatus(err) if a > 3 { - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Info("rcache: ", err, " backing off ", d) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debug("rcache: ", err, " backing off ", d) } a = 0 } @@ -364,8 +364,8 @@ func (c *cache) run() { c.setStatus(err) if b > 3 { - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Info("rcache: ", err, " backing off ", d) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debug("rcache: ", err, " backing off ", d) } b = 0 } diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 2b0dc913..dd711d3f 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -59,6 +59,9 @@ type grpcServer struct { started bool // used for first registration registered bool + + // registry service instance + rsvc *registry.Service } func init() { @@ -102,6 +105,9 @@ func (r grpcRouter) ServeRequest(ctx context.Context, req server.Request, rsp se } func (g *grpcServer) configure(opts ...server.Option) { + g.Lock() + defer g.Unlock() + // Don't reprocess where there's no config if len(opts) == 0 && g.srv != nil { return @@ -127,6 +133,7 @@ func (g *grpcServer) configure(opts ...server.Option) { gopts = append(gopts, opts...) } + g.rsvc = nil g.srv = grpc.NewServer(gopts...) } @@ -559,11 +566,24 @@ func (g *grpcServer) Subscribe(sb server.Subscriber) error { } func (g *grpcServer) Register() error { + + g.RLock() + rsvc := g.rsvc + config := g.opts + g.RUnlock() + + // if service already filled, reuse it and return early + if rsvc != nil { + rOpts := []registry.RegisterOption{registry.RegisterTTL(config.RegisterTTL)} + if err := config.Registry.Register(rsvc, rOpts...); err != nil { + return err + } + return nil + } + var err error var advt, host, port string - - // parse address for host, port - config := g.opts + var cacheService bool // check the advertise address first // if it exists then use it, otherwise @@ -584,16 +604,17 @@ func (g *grpcServer) Register() error { host = advt } + if ip := net.ParseIP(host); ip != nil { + cacheService = true + } + addr, err := addr.Extract(host) if err != nil { return err } // make copy of metadata - md := make(meta.Metadata) - for k, v := range config.Metadata { - md[k] = v - } + md := meta.Copy(config.Metadata) // register service node := ®istry.Node{ @@ -646,13 +667,13 @@ func (g *grpcServer) Register() error { Endpoints: endpoints, } - g.Lock() + g.RLock() registered := g.registered - g.Unlock() + g.RUnlock() if !registered { - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) } } @@ -671,6 +692,9 @@ func (g *grpcServer) Register() error { g.Lock() defer g.Unlock() + if cacheService { + g.rsvc = service + } g.registered = true for sb := range g.subscribers { @@ -688,8 +712,8 @@ func (g *grpcServer) Register() error { opts = append(opts, broker.DisableAutoAck()) } - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Infof("Subscribing to topic: %s", sb.Topic()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debug("Subscribing to topic: %s", sb.Topic()) } sub, err := config.Broker.Subscribe(sb.Topic(), handler, opts...) if err != nil { @@ -705,7 +729,9 @@ func (g *grpcServer) Deregister() error { var err error var advt, host, port string + g.RLock() config := g.opts + g.RUnlock() // check the advertise address first // if it exists then use it, otherwise @@ -742,14 +768,15 @@ func (g *grpcServer) Deregister() error { Nodes: []*registry.Node{node}, } - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Infof("Deregistering node: %s", node.Id) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Deregistering node: %s", node.Id) } if err := config.Registry.Deregister(service); err != nil { return err } g.Lock() + g.rsvc = nil if !g.registered { g.Unlock() @@ -760,8 +787,8 @@ func (g *grpcServer) Deregister() error { for sb, subs := range g.subscribers { for _, sub := range subs { - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Infof("Unsubscribing from topic: %s", sub.Topic()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Unsubscribing from topic: %s", sub.Topic()) } sub.Unsubscribe() } @@ -819,11 +846,14 @@ func (g *grpcServer) Start() error { if len(g.subscribers) > 0 { // connect to the broker if err := config.Broker.Connect(); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("Broker [%s] connect error: %v", config.Broker.String(), err) + } return err } - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Infof("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address()) } } @@ -900,11 +930,15 @@ func (g *grpcServer) Start() error { // close transport ch <- nil - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Infof("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address()) } // disconnect broker - config.Broker.Disconnect() + if err := config.Broker.Disconnect(); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("Broker [%s] disconnect error: %v", config.Broker.String(), err) + } + } }() // mark the server as started @@ -930,6 +964,7 @@ func (g *grpcServer) Stop() error { select { case err = <-ch: g.Lock() + g.rsvc = nil g.started = false g.Unlock() } diff --git a/server/rpc_server.go b/server/rpc_server.go index 4619fa64..5bb5740d 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -40,6 +40,8 @@ type rpcServer struct { subscriber broker.Subscriber // graceful exit wg *sync.WaitGroup + + rsvc *registry.Service } func newRpcServer(opts ...Option) Server { @@ -459,10 +461,11 @@ func (s *rpcServer) Options() Options { func (s *rpcServer) Init(opts ...Option) error { s.Lock() + defer s.Unlock() + for _, opt := range opts { opt(&s.opts) } - // update router if its the default if s.opts.Router == nil { r := newRpcRouter() @@ -472,7 +475,8 @@ func (s *rpcServer) Init(opts ...Option) error { s.router = r } - s.Unlock() + s.rsvc = nil + return nil } @@ -510,11 +514,24 @@ func (s *rpcServer) Subscribe(sb Subscriber) error { } func (s *rpcServer) Register() error { + + s.RLock() + rsvc := s.rsvc + config := s.Options() + s.RUnlock() + + if rsvc != nil { + rOpts := []registry.RegisterOption{registry.RegisterTTL(config.RegisterTTL)} + if err := config.Registry.Register(rsvc, rOpts...); err != nil { + return err + } + + return nil + } + var err error var advt, host, port string - - // parse address for host, port - config := s.Options() + var cacheService bool // check the advertise address first // if it exists then use it, otherwise @@ -535,16 +552,17 @@ func (s *rpcServer) Register() error { host = advt } + if ip := net.ParseIP(host); ip != nil { + cacheService = true + } + addr, err := addr.Extract(host) if err != nil { return err } // make copy of metadata - md := make(metadata.Metadata) - for k, v := range config.Metadata { - md[k] = v - } + md := metadata.Copy(config.Metadata) // mq-rpc(eg. nats) doesn't need the port. its addr is queue name. if port != "" { @@ -612,7 +630,9 @@ func (s *rpcServer) Register() error { s.RUnlock() if !registered { - log.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + log.Debugf("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) + } } // create registry options @@ -630,6 +650,9 @@ func (s *rpcServer) Register() error { s.Lock() defer s.Unlock() + if cacheService { + s.rsvc = service + } s.registered = true // set what we're advertising s.opts.Advertise = addr @@ -665,8 +688,9 @@ func (s *rpcServer) Register() error { if err != nil { return err } - log.Infof("Subscribing to topic: %s", sub.Topic()) - + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + log.Debugf("Subscribing to topic: %s", sub.Topic()) + } s.subscribers[sb] = []broker.Subscriber{sub} } @@ -677,7 +701,9 @@ func (s *rpcServer) Deregister() error { var err error var advt, host, port string + s.RLock() config := s.Options() + s.RUnlock() // check the advertise address first // if it exists then use it, otherwise @@ -719,12 +745,15 @@ func (s *rpcServer) Deregister() error { Nodes: []*registry.Node{node}, } - log.Infof("Registry [%s] Deregistering node: %s", config.Registry.String(), node.Id) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + log.Debugf("Registry [%s] Deregistering node: %s", config.Registry.String(), node.Id) + } if err := config.Registry.Deregister(service); err != nil { return err } s.Lock() + s.rsvc = nil if !s.registered { s.Unlock() @@ -741,7 +770,9 @@ func (s *rpcServer) Deregister() error { for sb, subs := range s.subscribers { for _, sub := range subs { - log.Infof("Unsubscribing %s from topic: %s", node.Id, sub.Topic()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + log.Debugf("Unsubscribing %s from topic: %s", node.Id, sub.Topic()) + } sub.Unsubscribe() } s.subscribers[sb] = nil @@ -767,7 +798,9 @@ func (s *rpcServer) Start() error { return err } - log.Infof("Transport [%s] Listening on %s", config.Transport.String(), ts.Addr()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + log.Debugf("Transport [%s] Listening on %s", config.Transport.String(), ts.Addr()) + } // swap address s.Lock() @@ -775,22 +808,31 @@ func (s *rpcServer) Start() error { s.opts.Address = ts.Addr() s.Unlock() + bname := config.Broker.String() + // connect to the broker if err := config.Broker.Connect(); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + log.Errorf("Broker [%s] connect error: %v", bname, err) + } return err } - bname := config.Broker.String() - - log.Infof("Broker [%s] Connected to %s", bname, config.Broker.Address()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + log.Debugf("Broker [%s] Connected to %s", bname, config.Broker.Address()) + } // use RegisterCheck func before register if err = s.opts.RegisterCheck(s.opts.Context); err != nil { - log.Errorf("Server %s-%s register check error: %s", config.Name, config.Id, err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + log.Errorf("Server %s-%s register check error: %s", config.Name, config.Id, err) + } } else { // announce self to the world if err = s.Register(); err != nil { - log.Errorf("Server %s-%s register error: %s", config.Name, config.Id, err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + log.Errorf("Server %s-%s register error: %s", config.Name, config.Id, err) + } } } @@ -811,7 +853,9 @@ func (s *rpcServer) Start() error { // check the error and backoff default: if err != nil { - log.Errorf("Accept error: %v", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + log.Errorf("Accept error: %v", err) + } time.Sleep(time.Second) continue } @@ -844,17 +888,25 @@ func (s *rpcServer) Start() error { s.RUnlock() rerr := s.opts.RegisterCheck(s.opts.Context) if rerr != nil && registered { - log.Errorf("Server %s-%s register check error: %s, deregister it", config.Name, config.Id, err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + log.Errorf("Server %s-%s register check error: %s, deregister it", config.Name, config.Id, err) + } // deregister self in case of error if err := s.Deregister(); err != nil { - log.Errorf("Server %s-%s deregister error: %s", config.Name, config.Id, err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + log.Errorf("Server %s-%s deregister error: %s", config.Name, config.Id, err) + } } } else if rerr != nil && !registered { - log.Errorf("Server %s-%s register check error: %s", config.Name, config.Id, err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + log.Errorf("Server %s-%s register check error: %s", config.Name, config.Id, err) + } continue } if err := s.Register(); err != nil { - log.Errorf("Server %s-%s register error: %s", config.Name, config.Id, err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + log.Errorf("Server %s-%s register error: %s", config.Name, config.Id, err) + } } // wait for exit case ch = <-s.exit: @@ -870,7 +922,9 @@ func (s *rpcServer) Start() error { if registered { // deregister self if err := s.Deregister(); err != nil { - log.Errorf("Server %s-%s deregister error: %s", config.Name, config.Id, err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + log.Errorf("Server %s-%s deregister error: %s", config.Name, config.Id, err) + } } } @@ -886,9 +940,15 @@ func (s *rpcServer) Start() error { // close transport listener ch <- ts.Close() - log.Infof("Broker [%s] Disconnected from %s", bname, config.Broker.Address()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + log.Debugf("Broker [%s] Disconnected from %s", bname, config.Broker.Address()) + } // disconnect the broker - config.Broker.Disconnect() + if err := config.Broker.Disconnect(); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + log.Errorf("Broker [%s] Disconnect error: %v", bname, err) + } + } // swap back address s.Lock() diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 100f2f2b..505772b6 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -35,18 +35,8 @@ var ( ) func (c *clientWrapper) setHeaders(ctx context.Context) context.Context { - // copy metadata - mda, _ := metadata.FromContext(ctx) - md := metadata.Copy(mda) - - // set headers - for k, v := range c.headers { - if _, ok := md[k]; !ok { - md[k] = v - } - } - - return metadata.NewContext(ctx, md) + // don't overwrite keys + return metadata.MergeContext(ctx, c.headers, false) } func (c *clientWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { From bc0dc2e50973cd280743840771706f9ca013f679 Mon Sep 17 00:00:00 2001 From: Edward Date: Wed, 8 Apr 2020 17:50:44 +0800 Subject: [PATCH 559/788] fix :no syscall.Kill on windows #1474 (#1474) --- web/service_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/service_test.go b/web/service_test.go index f2e270c5..428f9424 100644 --- a/web/service_test.go +++ b/web/service_test.go @@ -115,8 +115,9 @@ func TestService(t *testing.T) { ch := make(chan os.Signal, 1) signal.Notify(ch, syscall.SIGTERM) + p, _ := os.FindProcess(os.Getpid()) + p.Signal(syscall.SIGTERM) - syscall.Kill(syscall.Getpid(), syscall.SIGTERM) <-ch select { From cc027d900e790c47512daf126be0dbd790a0e359 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Wed, 8 Apr 2020 12:08:08 +0100 Subject: [PATCH 560/788] Close statements, add default table if the store was not initialised through service.Init() (#1502) --- store/cockroach/cockroach.go | 45 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 29d78743..4aa68ac5 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -18,6 +18,7 @@ import ( // will use if no namespace is provided. var ( DefaultDatabase = "micro" + DefaultTable = "micro" ) type sqlStore struct { @@ -37,6 +38,12 @@ type sqlStore struct { } func (s *sqlStore) Close() error { + closeStmt(s.delete) + closeStmt(s.list) + closeStmt(s.readMany) + closeStmt(s.readOffset) + closeStmt(s.readOne) + closeStmt(s.write) if s.db != nil { return s.db.Close() } @@ -248,33 +255,25 @@ func (s *sqlStore) initDB() error { if err != nil { return errors.Wrap(err, "List statement couldn't be prepared") } - if s.list != nil { - s.list.Close() - } + closeStmt(s.list) s.list = list readOne, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key = $1;", s.database, s.table)) if err != nil { return errors.Wrap(err, "ReadOne statement couldn't be prepared") } - if s.readOne != nil { - s.readOne.Close() - } + closeStmt(s.readOne) s.readOne = readOne readMany, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key LIKE $1;", s.database, s.table)) if err != nil { return errors.Wrap(err, "ReadMany statement couldn't be prepared") } - if s.readMany != nil { - s.readMany.Close() - } + closeStmt(s.readMany) s.readMany = readMany readOffset, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key LIKE $1 ORDER BY key DESC LIMIT $2 OFFSET $3;", s.database, s.table)) if err != nil { return errors.Wrap(err, "ReadOffset statement couldn't be prepared") } - if s.readOffset != nil { - s.readOffset.Close() - } + closeStmt(s.readOffset) s.readOffset = readOffset write, err := s.db.Prepare(fmt.Sprintf(`INSERT INTO %s.%s(key, value, expiry) VALUES ($1, $2::bytea, $3) @@ -284,17 +283,13 @@ func (s *sqlStore) initDB() error { if err != nil { return errors.Wrap(err, "Write statement couldn't be prepared") } - if s.write != nil { - s.write.Close() - } + closeStmt(s.write) s.write = write delete, err := s.db.Prepare(fmt.Sprintf("DELETE FROM %s.%s WHERE key = $1;", s.database, s.table)) if err != nil { return errors.Wrap(err, "Delete statement couldn't be prepared") } - if s.delete != nil { - s.delete.Close() - } + closeStmt(s.delete) s.delete = delete return nil @@ -302,7 +297,7 @@ func (s *sqlStore) initDB() error { func (s *sqlStore) configure() error { if len(s.options.Nodes) == 0 { - s.options.Nodes = []string{"postgresql://root@localhost:26257"} + s.options.Nodes = []string{"postgresql://root@localhost:26257?sslmode=disable"} } database := s.options.Database @@ -310,10 +305,10 @@ func (s *sqlStore) configure() error { database = DefaultDatabase } - if len(s.options.Table) == 0 { - return errors.New("no table set") - } table := s.options.Table + if len(table) == 0 { + table = DefaultTable + } // store.namespace must only contain letters, numbers and underscores reg, err := regexp.Compile("[^a-zA-Z0-9]+") @@ -382,3 +377,9 @@ func NewStore(opts ...store.Option) store.Store { // return store return s } + +func closeStmt(s *sql.Stmt) { + if s != nil { + s.Close() + } +} From 8400aba81ce2b3e93399ccac7216157e4bf400fb Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 8 Apr 2020 14:56:54 +0300 Subject: [PATCH 561/788] broker/memory: small memory improvements (#1501) Signed-off-by: Vasiliy Tolstov --- broker/memory/memory.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/broker/memory/memory.go b/broker/memory/memory.go index 5424f378..2938402c 100644 --- a/broker/memory/memory.go +++ b/broker/memory/memory.go @@ -55,7 +55,8 @@ func (m *memoryBroker) Connect() error { return nil } - addr, err := maddr.Extract("::") + // use 127.0.0.1 to avoid scan of all network interfaces + addr, err := maddr.Extract("127.0.0.1") if err != nil { return err } From 77f5cc5023222b01effa7a7347ecb83b48b13ec8 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Wed, 8 Apr 2020 13:00:30 +0100 Subject: [PATCH 562/788] Fix nil dereference in cloudflare store (#1504) --- store/cloudflare/cloudflare.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go index c7fa5541..cf3002f6 100644 --- a/store/cloudflare/cloudflare.go +++ b/store/cloudflare/cloudflare.go @@ -112,6 +112,9 @@ func (w *workersKV) Init(opts ...store.Option) error { if len(w.options.Database) > 0 { w.namespace = w.options.Database } + if w.options.Context == nil { + w.options.Context = context.TODO() + } ttl := w.options.Context.Value("STORE_CACHE_TTL") if ttl != nil { ttlduration, ok := ttl.(time.Duration) From 9a73828782312626ba7e93c771dce07f72bfe6bb Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Apr 2020 15:34:11 +0100 Subject: [PATCH 563/788] Remove unused handlers --- api/handler/broker/broker.go | 292 ------------------------- api/handler/cloudevents/cloudevents.go | 101 --------- api/handler/cloudevents/event.go | 288 ------------------------ api/handler/file/file.go | 16 -- api/handler/registry/registry.go | 224 ------------------- api/handler/udp/udp.go | 25 --- api/handler/unix/unix.go | 30 --- 7 files changed, 976 deletions(-) delete mode 100644 api/handler/broker/broker.go delete mode 100644 api/handler/cloudevents/cloudevents.go delete mode 100644 api/handler/cloudevents/event.go delete mode 100644 api/handler/file/file.go delete mode 100644 api/handler/registry/registry.go delete mode 100644 api/handler/udp/udp.go delete mode 100644 api/handler/unix/unix.go diff --git a/api/handler/broker/broker.go b/api/handler/broker/broker.go deleted file mode 100644 index 7c04c0aa..00000000 --- a/api/handler/broker/broker.go +++ /dev/null @@ -1,292 +0,0 @@ -// Package broker provides a go-micro/broker handler -package broker - -import ( - "encoding/json" - "net/http" - "net/url" - "strings" - "sync" - "sync/atomic" - "time" - - "github.com/gorilla/websocket" - "github.com/micro/go-micro/v2/api/handler" - "github.com/micro/go-micro/v2/broker" - "github.com/micro/go-micro/v2/logger" - "github.com/oxtoacart/bpool" -) - -var ( - bufferPool = bpool.NewSizedBufferPool(1024, 8) -) - -const ( - Handler = "broker" - - pingTime = (readDeadline * 9) / 10 - readLimit = 16384 - readDeadline = 60 * time.Second - writeDeadline = 10 * time.Second -) - -type brokerHandler struct { - once atomic.Value - opts handler.Options - u websocket.Upgrader -} - -type conn struct { - b broker.Broker - cType string - topic string - queue string - exit chan bool - - sync.Mutex - ws *websocket.Conn -} - -var ( - contentType = "text/plain" -) - -func checkOrigin(r *http.Request) bool { - origin := r.Header["Origin"] - if len(origin) == 0 { - return true - } - u, err := url.Parse(origin[0]) - if err != nil { - return false - } - return u.Host == r.Host -} - -func (c *conn) close() { - select { - case <-c.exit: - return - default: - close(c.exit) - } -} - -func (c *conn) readLoop() { - defer func() { - c.close() - c.ws.Close() - }() - - // set read limit/deadline - c.ws.SetReadLimit(readLimit) - c.ws.SetReadDeadline(time.Now().Add(readDeadline)) - - // set close handler - ch := c.ws.CloseHandler() - c.ws.SetCloseHandler(func(code int, text string) error { - err := ch(code, text) - c.close() - return err - }) - - // set pong handler - c.ws.SetPongHandler(func(string) error { - c.ws.SetReadDeadline(time.Now().Add(readDeadline)) - return nil - }) - - for { - _, message, err := c.ws.ReadMessage() - if err != nil { - return - } - c.b.Publish(c.topic, &broker.Message{ - Header: map[string]string{"Content-Type": c.cType}, - Body: message, - }) - } -} - -func (c *conn) write(mType int, data []byte) error { - c.Lock() - c.ws.SetWriteDeadline(time.Now().Add(writeDeadline)) - err := c.ws.WriteMessage(mType, data) - c.Unlock() - return err -} - -func (c *conn) writeLoop() { - ticker := time.NewTicker(pingTime) - - var opts []broker.SubscribeOption - - if len(c.queue) > 0 { - opts = append(opts, broker.Queue(c.queue)) - } - - subscriber, err := c.b.Subscribe(c.topic, func(p broker.Event) error { - b, err := json.Marshal(p.Message()) - if err != nil { - return nil - } - return c.write(websocket.TextMessage, b) - }, opts...) - - defer func() { - subscriber.Unsubscribe() - ticker.Stop() - c.ws.Close() - }() - - if err != nil { - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Error(err.Error()) - } - return - } - - for { - select { - case <-ticker.C: - if err := c.write(websocket.PingMessage, []byte{}); err != nil { - return - } - case <-c.exit: - return - } - } -} - -func (b *brokerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - bsize := handler.DefaultMaxRecvSize - if b.opts.MaxRecvSize > 0 { - bsize = b.opts.MaxRecvSize - } - - r.Body = http.MaxBytesReader(w, r.Body, bsize) - - br := b.opts.Service.Client().Options().Broker - - // Setup the broker - if !b.once.Load().(bool) { - if err := br.Init(); err != nil { - http.Error(w, err.Error(), 500) - } - if err := br.Connect(); err != nil { - http.Error(w, err.Error(), 500) - } - b.once.Store(true) - } - - // Parse - r.ParseForm() - topic := r.Form.Get("topic") - - // Can't do anything without a topic - if len(topic) == 0 { - http.Error(w, "Topic not specified", 400) - return - } - - // Post assumed to be Publish - if r.Method == "POST" { - // Create a broker message - msg := &broker.Message{ - Header: make(map[string]string), - } - - // Set header - for k, v := range r.Header { - msg.Header[k] = strings.Join(v, ", ") - } - - // Read body - buf := bufferPool.Get() - defer bufferPool.Put(buf) - if _, err := buf.ReadFrom(r.Body); err != nil { - http.Error(w, err.Error(), 500) - return - } - // Set body - msg.Body = buf.Bytes() - // Set body - - // Publish - br.Publish(topic, msg) - return - } - - // now back to our regularly scheduled programming - - if r.Method != "GET" { - http.Error(w, "Method not allowed", 405) - return - } - - queue := r.Form.Get("queue") - - ws, err := b.u.Upgrade(w, r, nil) - if err != nil { - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Error(err.Error()) - } - return - } - - cType := r.Header.Get("Content-Type") - if len(cType) == 0 { - cType = contentType - } - - c := &conn{ - b: br, - cType: cType, - topic: topic, - queue: queue, - exit: make(chan bool), - ws: ws, - } - - go c.writeLoop() - c.readLoop() -} - -func (b *brokerHandler) String() string { - return "broker" -} - -func NewHandler(opts ...handler.Option) handler.Handler { - h := &brokerHandler{ - u: websocket.Upgrader{ - CheckOrigin: func(r *http.Request) bool { - return true - }, - ReadBufferSize: 1024, - WriteBufferSize: 1024, - }, - opts: handler.NewOptions(opts...), - } - h.once.Store(true) - return h -} - -func WithCors(cors map[string]bool, opts ...handler.Option) handler.Handler { - return &brokerHandler{ - u: websocket.Upgrader{ - CheckOrigin: func(r *http.Request) bool { - if origin := r.Header.Get("Origin"); cors[origin] { - return true - } else if len(origin) > 0 && cors["*"] { - return true - } else if checkOrigin(r) { - return true - } - return false - }, - ReadBufferSize: 1024, - WriteBufferSize: 1024, - }, - opts: handler.NewOptions(opts...), - } -} diff --git a/api/handler/cloudevents/cloudevents.go b/api/handler/cloudevents/cloudevents.go deleted file mode 100644 index 630412da..00000000 --- a/api/handler/cloudevents/cloudevents.go +++ /dev/null @@ -1,101 +0,0 @@ -// Package cloudevents provides a cloudevents handler publishing the event using the go-micro/client -package cloudevents - -import ( - "net/http" - "path" - "regexp" - "strings" - - "github.com/micro/go-micro/v2/api/handler" - "github.com/micro/go-micro/v2/util/ctx" -) - -type event struct { - opts handler.Options -} - -var ( - Handler = "cloudevents" - versionRe = regexp.MustCompilePOSIX("^v[0-9]+$") -) - -func eventName(parts []string) string { - return strings.Join(parts, ".") -} - -func evRoute(ns, p string) (string, string) { - p = path.Clean(p) - p = strings.TrimPrefix(p, "/") - - if len(p) == 0 { - return ns, "event" - } - - parts := strings.Split(p, "/") - - // no path - if len(parts) == 0 { - // topic: namespace - // action: event - return strings.Trim(ns, "."), "event" - } - - // Treat /v[0-9]+ as versioning - // /v1/foo/bar => topic: v1.foo action: bar - if len(parts) >= 2 && versionRe.Match([]byte(parts[0])) { - topic := ns + "." + strings.Join(parts[:2], ".") - action := eventName(parts[1:]) - return topic, action - } - - // /foo => topic: ns.foo action: foo - // /foo/bar => topic: ns.foo action: bar - topic := ns + "." + strings.Join(parts[:1], ".") - action := eventName(parts[1:]) - - return topic, action -} - -func (e *event) ServeHTTP(w http.ResponseWriter, r *http.Request) { - bsize := handler.DefaultMaxRecvSize - if e.opts.MaxRecvSize > 0 { - bsize = e.opts.MaxRecvSize - } - - r.Body = http.MaxBytesReader(w, r.Body, bsize) - - // request to topic:event - // create event - // publish to topic - topic, _ := evRoute(e.opts.Namespace, r.URL.Path) - - // create event - ev, err := FromRequest(r) - if err != nil { - http.Error(w, err.Error(), 500) - return - } - - // get client - c := e.opts.Service.Client() - - // create publication - p := c.NewMessage(topic, ev) - - // publish event - if err := c.Publish(ctx.FromRequest(r), p); err != nil { - http.Error(w, err.Error(), 500) - return - } -} - -func (e *event) String() string { - return "cloudevents" -} - -func NewHandler(opts ...handler.Option) handler.Handler { - return &event{ - opts: handler.NewOptions(opts...), - } -} diff --git a/api/handler/cloudevents/event.go b/api/handler/cloudevents/event.go deleted file mode 100644 index 0463792c..00000000 --- a/api/handler/cloudevents/event.go +++ /dev/null @@ -1,288 +0,0 @@ -/* - * From: https://github.com/serverless/event-gateway/blob/master/event/event.go - * Modified: Strip to handler requirements - * - * Copyright 2017 Serverless, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package cloudevents - -import ( - "encoding/json" - "errors" - "fmt" - "mime" - "net/http" - "strings" - "time" - "unicode" - - "github.com/google/uuid" - "github.com/oxtoacart/bpool" - validator "gopkg.in/go-playground/validator.v9" -) - -var ( - bufferPool = bpool.NewSizedBufferPool(1024, 8) -) - -const ( - // TransformationVersion is indicative of the revision of how Event Gateway transforms a request into CloudEvents format. - TransformationVersion = "0.1" - - // CloudEventsVersion currently supported by Event Gateway - CloudEventsVersion = "0.1" -) - -// Event is a default event structure. All data that passes through the Event Gateway -// is formatted to a format defined CloudEvents v0.1 spec. -type Event struct { - EventType string `json:"eventType" validate:"required"` - EventTypeVersion string `json:"eventTypeVersion,omitempty"` - CloudEventsVersion string `json:"cloudEventsVersion" validate:"required"` - Source string `json:"source" validate:"uri,required"` - EventID string `json:"eventID" validate:"required"` - EventTime *time.Time `json:"eventTime,omitempty"` - SchemaURL string `json:"schemaURL,omitempty"` - Extensions map[string]interface{} `json:"extensions,omitempty"` - ContentType string `json:"contentType,omitempty"` - Data interface{} `json:"data"` -} - -// New return new instance of Event. -func New(eventType string, mimeType string, payload interface{}) *Event { - now := time.Now() - - event := &Event{ - EventType: eventType, - CloudEventsVersion: CloudEventsVersion, - Source: "https://micro.mu", - EventID: uuid.New().String(), - EventTime: &now, - ContentType: mimeType, - Data: payload, - Extensions: map[string]interface{}{ - "eventgateway": map[string]interface{}{ - "transformed": "true", - "transformation-version": TransformationVersion, - }, - }, - } - - event.Data = normalizePayload(event.Data, event.ContentType) - return event -} - -// FromRequest takes an HTTP request and returns an Event along with path. Most of the implementation -// is based on https://github.com/cloudevents/spec/blob/master/http-transport-binding.md. -// This function also supports legacy mode where event type is sent in Event header. -func FromRequest(r *http.Request) (*Event, error) { - contentType := r.Header.Get("Content-Type") - mimeType, _, err := mime.ParseMediaType(contentType) - if err != nil { - if err.Error() != "mime: no media type" { - return nil, err - } - mimeType = "application/octet-stream" - } - // Read request body - body := []byte{} - if r.Body != nil { - buf := bufferPool.Get() - defer bufferPool.Put(buf) - if _, err := buf.ReadFrom(r.Body); err != nil { - return nil, err - } - body = buf.Bytes() - } - - var event *Event - if mimeType == mimeCloudEventsJSON { // CloudEvents Structured Content Mode - return parseAsCloudEvent(mimeType, body) - } else if isCloudEventsBinaryContentMode(r.Header) { // CloudEvents Binary Content Mode - return parseAsCloudEventBinary(r.Header, body) - } else if isLegacyMode(r.Header) { - if mimeType == mimeJSON { // CloudEvent in Legacy Mode - event, err = parseAsCloudEvent(mimeType, body) - if err != nil { - return New(string(r.Header.Get("event")), mimeType, body), nil - } - return event, err - } - - return New(string(r.Header.Get("event")), mimeType, body), nil - } - - return New("http.request", mimeJSON, newHTTPRequestData(r, body)), nil -} - -// Validate Event struct -func (e *Event) Validate() error { - validate := validator.New() - err := validate.Struct(e) - if err != nil { - return fmt.Errorf("CloudEvent not valid: %v", err) - } - return nil -} - -func isLegacyMode(headers http.Header) bool { - if headers.Get("Event") != "" { - return true - } - - return false -} - -func isCloudEventsBinaryContentMode(headers http.Header) bool { - if headers.Get("CE-EventType") != "" && - headers.Get("CE-CloudEventsVersion") != "" && - headers.Get("CE-Source") != "" && - headers.Get("CE-EventID") != "" { - return true - } - - return false -} - -func parseAsCloudEventBinary(headers http.Header, payload interface{}) (*Event, error) { - event := &Event{ - EventType: headers.Get("CE-EventType"), - EventTypeVersion: headers.Get("CE-EventTypeVersion"), - CloudEventsVersion: headers.Get("CE-CloudEventsVersion"), - Source: headers.Get("CE-Source"), - EventID: headers.Get("CE-EventID"), - ContentType: headers.Get("Content-Type"), - Data: payload, - } - - err := event.Validate() - if err != nil { - return nil, err - } - - if headers.Get("CE-EventTime") != "" { - val, err := time.Parse(time.RFC3339, headers.Get("CE-EventTime")) - if err != nil { - return nil, err - } - event.EventTime = &val - } - - if val := headers.Get("CE-SchemaURL"); len(val) > 0 { - event.SchemaURL = val - } - - event.Extensions = map[string]interface{}{} - for key, val := range flatten(headers) { - if strings.HasPrefix(key, "Ce-X-") { - key = strings.TrimLeft(key, "Ce-X-") - // Make first character lowercase - runes := []rune(key) - runes[0] = unicode.ToLower(runes[0]) - event.Extensions[string(runes)] = val - } - } - - event.Data = normalizePayload(event.Data, event.ContentType) - return event, nil -} - -func flatten(h http.Header) map[string]string { - headers := map[string]string{} - for key, header := range h { - headers[key] = header[0] - if len(header) > 1 { - headers[key] = strings.Join(header, ", ") - } - } - return headers -} - -func parseAsCloudEvent(mime string, payload interface{}) (*Event, error) { - body, ok := payload.([]byte) - if ok { - event := &Event{} - err := json.Unmarshal(body, event) - if err != nil { - return nil, err - } - - err = event.Validate() - if err != nil { - return nil, err - } - - event.Data = normalizePayload(event.Data, event.ContentType) - return event, nil - } - - return nil, errors.New("couldn't cast to []byte") -} - -const ( - mimeJSON = "application/json" - mimeFormMultipart = "multipart/form-data" - mimeFormURLEncoded = "application/x-www-form-urlencoded" - mimeCloudEventsJSON = "application/cloudevents+json" -) - -// normalizePayload takes anything, checks if it's []byte array and depending on provided mime -// type converts it to either string or map[string]interface to avoid having base64 string after -// JSON marshaling. -func normalizePayload(payload interface{}, mime string) interface{} { - if bytePayload, ok := payload.([]byte); ok && len(bytePayload) > 0 { - switch { - case mime == mimeJSON || strings.HasSuffix(mime, "+json"): - var result map[string]interface{} - err := json.Unmarshal(bytePayload, &result) - if err != nil { - return payload - } - return result - case strings.HasPrefix(mime, mimeFormMultipart), mime == mimeFormURLEncoded: - return string(bytePayload) - } - } - - return payload -} - -// HTTPRequestData is a event schema used for sending events to HTTP subscriptions. -type HTTPRequestData struct { - Headers map[string]string `json:"headers"` - Query map[string][]string `json:"query"` - Body interface{} `json:"body"` - Host string `json:"host"` - Path string `json:"path"` - Method string `json:"method"` - Params map[string]string `json:"params"` -} - -// NewHTTPRequestData returns a new instance of HTTPRequestData -func newHTTPRequestData(r *http.Request, eventData interface{}) *HTTPRequestData { - req := &HTTPRequestData{ - Headers: flatten(r.Header), - Query: r.URL.Query(), - Body: eventData, - Host: r.Host, - Path: r.URL.Path, - Method: r.Method, - } - - req.Body = normalizePayload(req.Body, r.Header.Get("content-type")) - return req -} diff --git a/api/handler/file/file.go b/api/handler/file/file.go deleted file mode 100644 index 76045bef..00000000 --- a/api/handler/file/file.go +++ /dev/null @@ -1,16 +0,0 @@ -// Package file serves file relative to the current directory -package file - -import ( - "net/http" -) - -type Handler struct{} - -func (h *Handler) Serve(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "."+r.URL.Path) -} - -func (h *Handler) String() string { - return "file" -} diff --git a/api/handler/registry/registry.go b/api/handler/registry/registry.go deleted file mode 100644 index b0eeaf5a..00000000 --- a/api/handler/registry/registry.go +++ /dev/null @@ -1,224 +0,0 @@ -// Package registry is a go-micro/registry handler -package registry - -import ( - "encoding/json" - "net/http" - "strconv" - "time" - - "github.com/gorilla/websocket" - "github.com/micro/go-micro/v2/api/handler" - "github.com/micro/go-micro/v2/registry" - "github.com/oxtoacart/bpool" -) - -var ( - bufferPool = bpool.NewSizedBufferPool(1024, 8) -) - -const ( - Handler = "registry" - - pingTime = (readDeadline * 9) / 10 - readLimit = 16384 - readDeadline = 60 * time.Second - writeDeadline = 10 * time.Second -) - -type registryHandler struct { - opts handler.Options - reg registry.Registry -} - -func (rh *registryHandler) add(w http.ResponseWriter, r *http.Request) { - r.ParseForm() - defer r.Body.Close() - - // Read body - buf := bufferPool.Get() - defer bufferPool.Put(buf) - if _, err := buf.ReadFrom(r.Body); err != nil { - http.Error(w, err.Error(), 500) - return - } - - var opts []registry.RegisterOption - - // parse ttl - if ttl := r.Form.Get("ttl"); len(ttl) > 0 { - d, err := time.ParseDuration(ttl) - if err == nil { - opts = append(opts, registry.RegisterTTL(d)) - } - } - - var service *registry.Service - if err := json.NewDecoder(buf).Decode(&service); err != nil { - http.Error(w, err.Error(), 500) - return - } - if err := rh.reg.Register(service, opts...); err != nil { - http.Error(w, err.Error(), 500) - return - } -} - -func (rh *registryHandler) del(w http.ResponseWriter, r *http.Request) { - r.ParseForm() - defer r.Body.Close() - - // Read body - buf := bufferPool.Get() - defer bufferPool.Put(buf) - if _, err := buf.ReadFrom(r.Body); err != nil { - http.Error(w, err.Error(), 500) - return - } - - var service *registry.Service - if err := json.NewDecoder(buf).Decode(&service); err != nil { - http.Error(w, err.Error(), 500) - return - } - if err := rh.reg.Deregister(service); err != nil { - http.Error(w, err.Error(), 500) - return - } -} - -func (rh *registryHandler) get(w http.ResponseWriter, r *http.Request) { - r.ParseForm() - service := r.Form.Get("service") - - var s []*registry.Service - var err error - - if len(service) == 0 { - // - upgrade := r.Header.Get("Upgrade") - connect := r.Header.Get("Connection") - - // watch if websockets - if upgrade == "websocket" && connect == "Upgrade" { - rw, err := rh.reg.Watch() - if err != nil { - http.Error(w, err.Error(), 500) - return - } - watch(rw, w, r) - return - } - - // otherwise list services - s, err = rh.reg.ListServices() - } else { - s, err = rh.reg.GetService(service) - } - - if err != nil { - http.Error(w, err.Error(), 500) - return - } - - if s == nil || (len(service) > 0 && (len(s) == 0 || len(s[0].Name) == 0)) { - http.Error(w, "Service not found", 404) - return - } - - b, err := json.Marshal(s) - if err != nil { - http.Error(w, err.Error(), 500) - return - } - - w.Header().Set("Content-Type", "application/json") - w.Header().Set("Content-Length", strconv.Itoa(len(b))) - w.Write(b) -} - -func ping(ws *websocket.Conn, exit chan bool) { - ticker := time.NewTicker(pingTime) - - for { - select { - case <-ticker.C: - ws.SetWriteDeadline(time.Now().Add(writeDeadline)) - err := ws.WriteMessage(websocket.PingMessage, []byte{}) - if err != nil { - return - } - case <-exit: - return - } - } -} - -func watch(rw registry.Watcher, w http.ResponseWriter, r *http.Request) { - upgrader := websocket.Upgrader{ - ReadBufferSize: 1024, - WriteBufferSize: 1024, - } - - ws, err := upgrader.Upgrade(w, r, nil) - if err != nil { - http.Error(w, err.Error(), 500) - return - } - - // we need an exit chan - exit := make(chan bool) - - defer func() { - close(exit) - }() - - // ping the socket - go ping(ws, exit) - - for { - // get next result - r, err := rw.Next() - if err != nil { - http.Error(w, err.Error(), 500) - return - } - - // write to client - ws.SetWriteDeadline(time.Now().Add(writeDeadline)) - if err := ws.WriteJSON(r); err != nil { - return - } - } -} - -func (rh *registryHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - bsize := handler.DefaultMaxRecvSize - if rh.opts.MaxRecvSize > 0 { - bsize = rh.opts.MaxRecvSize - } - - r.Body = http.MaxBytesReader(w, r.Body, bsize) - - switch r.Method { - case "GET": - rh.get(w, r) - case "POST": - rh.add(w, r) - case "DELETE": - rh.del(w, r) - } -} - -func (rh *registryHandler) String() string { - return "registry" -} - -func NewHandler(opts ...handler.Option) handler.Handler { - options := handler.NewOptions(opts...) - - return ®istryHandler{ - opts: options, - reg: options.Service.Client().Options().Registry, - } -} diff --git a/api/handler/udp/udp.go b/api/handler/udp/udp.go deleted file mode 100644 index 247aa340..00000000 --- a/api/handler/udp/udp.go +++ /dev/null @@ -1,25 +0,0 @@ -// Package udp reads and write from a udp connection -package udp - -import ( - "io" - "net" - "net/http" -) - -type Handler struct{} - -func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - c, err := net.Dial("udp", r.Host) - if err != nil { - http.Error(w, err.Error(), 500) - return - } - go io.Copy(c, r.Body) - // write response - io.Copy(w, c) -} - -func (h *Handler) String() string { - return "udp" -} diff --git a/api/handler/unix/unix.go b/api/handler/unix/unix.go deleted file mode 100644 index 070aef87..00000000 --- a/api/handler/unix/unix.go +++ /dev/null @@ -1,30 +0,0 @@ -// Package unix reads from a unix socket expecting it to be in /tmp/path -package unix - -import ( - "fmt" - "io" - "net" - "net/http" - "path/filepath" -) - -type Handler struct{} - -func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - sock := fmt.Sprintf("%s.sock", filepath.Clean(r.URL.Path)) - path := filepath.Join("/tmp", sock) - - c, err := net.Dial("unix", path) - if err != nil { - http.Error(w, err.Error(), 500) - return - } - go io.Copy(c, r.Body) - // write response - io.Copy(w, c) -} - -func (h *Handler) String() string { - return "unix" -} From 2c1d1afd71748e1c6f75037803ce938b4add90cb Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Apr 2020 15:38:02 +0100 Subject: [PATCH 564/788] Strip namespace from registry router --- api/router/registry/registry.go | 31 ++----------------- api/router/registry/registry_test.go | 45 ---------------------------- 2 files changed, 2 insertions(+), 74 deletions(-) diff --git a/api/router/registry/registry.go b/api/router/registry/registry.go index 375aa7d0..b3f04958 100644 --- a/api/router/registry/registry.go +++ b/api/router/registry/registry.go @@ -6,7 +6,6 @@ import ( "fmt" "net/http" "regexp" - "strings" "sync" "time" @@ -29,28 +28,6 @@ type registryRouter struct { eps map[string]*api.Service } -func setNamespace(ns, name string) string { - ns = strings.TrimSpace(ns) - name = strings.TrimSpace(name) - - // no namespace - if len(ns) == 0 { - return name - } - - switch { - // has - suffix - case strings.HasSuffix(ns, "-"): - return strings.Replace(ns+name, ".", "-", -1) - // has . suffix - case strings.HasSuffix(ns, "."): - return ns + name - } - - // default join . - return strings.Join([]string{ns, name}, ".") -} - func (r *registryRouter) isClosed() bool { select { case <-r.exit: @@ -79,10 +56,6 @@ func (r *registryRouter) refresh() { // for each service, get service and store endpoints for _, s := range services { - // only get services for this namespace - if !strings.HasPrefix(s.Name, r.opts.Namespace) { - continue - } service, err := r.rc.GetService(s.Name) if err != nil { if logger.V(logger.ErrorLevel, logger.DefaultLogger) { @@ -105,7 +78,7 @@ func (r *registryRouter) refresh() { // process watch event func (r *registryRouter) process(res *registry.Result) { // skip these things - if res == nil || res.Service == nil || !strings.HasPrefix(res.Service.Name, r.opts.Namespace) { + if res == nil || res.Service == nil { return } @@ -350,7 +323,7 @@ func (r *registryRouter) Route(req *http.Request) (*api.Service, error) { } // service name - name := setNamespace(r.opts.Namespace, rp.Name) + name := rp.Name // get service services, err := r.rc.GetService(name) diff --git a/api/router/registry/registry_test.go b/api/router/registry/registry_test.go index 45646234..5824d237 100644 --- a/api/router/registry/registry_test.go +++ b/api/router/registry/registry_test.go @@ -9,51 +9,6 @@ import ( "github.com/micro/go-micro/v2/api" ) -func TestSetNamespace(t *testing.T) { - testCases := []struct { - namespace string - name string - expected string - }{ - // default dotted path - { - "go.micro.api", - "foo", - "go.micro.api.foo", - }, - // dotted end - { - "go.micro.api.", - "foo", - "go.micro.api.foo", - }, - // dashed end - { - "go-micro-api-", - "foo", - "go-micro-api-foo", - }, - // no namespace - { - "", - "foo", - "foo", - }, - { - "go-micro-api-", - "v2.foo", - "go-micro-api-v2-foo", - }, - } - - for _, test := range testCases { - name := setNamespace(test.namespace, test.name) - if name != test.expected { - t.Fatalf("expected name %s got %s", test.expected, name) - } - } -} - func TestRouter(t *testing.T) { r := newRouter() From b2079669f71c7c3c01735984fa9ad79b358055b3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Apr 2020 15:39:01 +0100 Subject: [PATCH 565/788] Strip namespace from router --- api/router/options.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/api/router/options.go b/api/router/options.go index cbba2028..9f0c9325 100644 --- a/api/router/options.go +++ b/api/router/options.go @@ -7,10 +7,9 @@ import ( ) type Options struct { - Namespace string - Handler string - Registry registry.Registry - Resolver resolver.Resolver + Handler string + Registry registry.Registry + Resolver resolver.Resolver } type Option func(o *Options) @@ -28,7 +27,6 @@ func NewOptions(opts ...Option) Options { if options.Resolver == nil { options.Resolver = micro.NewResolver( resolver.WithHandler(options.Handler), - resolver.WithNamespace(options.Namespace), ) } @@ -41,12 +39,6 @@ func WithHandler(h string) Option { } } -func WithNamespace(ns string) Option { - return func(o *Options) { - o.Namespace = ns - } -} - func WithRegistry(r registry.Registry) Option { return func(o *Options) { o.Registry = r From 8ff86ae08b707c5c921c57300c905eacd44469dc Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 8 Apr 2020 16:21:53 +0100 Subject: [PATCH 566/788] Extract micro resolver --- api/resolver/micro/micro.go | 45 ----------- api/resolver/micro/route.go | 95 ---------------------- api/resolver/micro/route_test.go | 130 ------------------------------- api/router/options.go | 7 -- 4 files changed, 277 deletions(-) delete mode 100644 api/resolver/micro/micro.go delete mode 100644 api/resolver/micro/route.go delete mode 100644 api/resolver/micro/route_test.go diff --git a/api/resolver/micro/micro.go b/api/resolver/micro/micro.go deleted file mode 100644 index 9d940887..00000000 --- a/api/resolver/micro/micro.go +++ /dev/null @@ -1,45 +0,0 @@ -// Package micro provides a micro rpc resolver which prefixes a namespace -package micro - -import ( - "net/http" - - "github.com/micro/go-micro/v2/api/resolver" -) - -// default resolver for legacy purposes -// it uses proxy routing to resolve names -// /foo becomes namespace.foo -// /v1/foo becomes namespace.v1.foo -type Resolver struct { - Options resolver.Options -} - -func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { - var name, method string - - switch r.Options.Handler { - // internal handlers - case "meta", "api", "rpc", "micro": - name, method = apiRoute(req.URL.Path) - default: - method = req.Method - name = proxyRoute(req.URL.Path) - } - - return &resolver.Endpoint{ - Name: name, - Method: method, - }, nil -} - -func (r *Resolver) String() string { - return "micro" -} - -// NewResolver creates a new micro resolver -func NewResolver(opts ...resolver.Option) resolver.Resolver { - return &Resolver{ - Options: resolver.NewOptions(opts...), - } -} diff --git a/api/resolver/micro/route.go b/api/resolver/micro/route.go deleted file mode 100644 index b2f94b01..00000000 --- a/api/resolver/micro/route.go +++ /dev/null @@ -1,95 +0,0 @@ -package micro - -import ( - "path" - "regexp" - "strings" -) - -var ( - proxyRe = regexp.MustCompile("^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$") - versionRe = regexp.MustCompilePOSIX("^v[0-9]+$") -) - -// Translates /foo/bar/zool into api service go.micro.api.foo method Bar.Zool -// Translates /foo/bar into api service go.micro.api.foo method Foo.Bar -func apiRoute(p string) (string, string) { - p = path.Clean(p) - p = strings.TrimPrefix(p, "/") - parts := strings.Split(p, "/") - - // if we have 1 part assume name Name.Call - if len(parts) == 1 && len(parts[0]) > 0 { - return parts[0], methodName(append(parts, "Call")) - } - - // If we've got two or less parts - // Use first part as service - // Use all parts as method - if len(parts) <= 2 { - name := parts[0] - return name, methodName(parts) - } - - // Treat /v[0-9]+ as versioning where we have 3 parts - // /v1/foo/bar => service: v1.foo method: Foo.bar - if len(parts) == 3 && versionRe.Match([]byte(parts[0])) { - name := strings.Join(parts[:len(parts)-1], ".") - return name, methodName(parts[len(parts)-2:]) - } - - // Service is everything minus last two parts - // Method is the last two parts - name := strings.Join(parts[:len(parts)-2], ".") - return name, methodName(parts[len(parts)-2:]) -} - -func proxyRoute(p string) string { - parts := strings.Split(p, "/") - if len(parts) < 2 { - return "" - } - - var service string - var alias string - - // /[service]/methods - if len(parts) > 2 { - // /v1/[service] - if versionRe.MatchString(parts[1]) { - service = parts[1] + "." + parts[2] - alias = parts[2] - } else { - service = parts[1] - alias = parts[1] - } - // /[service] - } else { - service = parts[1] - alias = parts[1] - } - - // check service name is valid - if !proxyRe.MatchString(alias) { - return "" - } - - return service -} - -func methodName(parts []string) string { - for i, part := range parts { - parts[i] = toCamel(part) - } - - return strings.Join(parts, ".") -} - -func toCamel(s string) string { - words := strings.Split(s, "-") - var out string - for _, word := range words { - out += strings.Title(word) - } - return out -} diff --git a/api/resolver/micro/route_test.go b/api/resolver/micro/route_test.go deleted file mode 100644 index b2c61bce..00000000 --- a/api/resolver/micro/route_test.go +++ /dev/null @@ -1,130 +0,0 @@ -package micro - -import ( - "testing" -) - -func TestApiRoute(t *testing.T) { - testData := []struct { - path string - service string - method string - }{ - { - "/foo/bar", - "foo", - "Foo.Bar", - }, - { - "/foo/foo/bar", - "foo", - "Foo.Bar", - }, - { - "/foo/bar/baz", - "foo", - "Bar.Baz", - }, - { - "/foo/bar/baz-xyz", - "foo", - "Bar.BazXyz", - }, - { - "/foo/bar/baz/cat", - "foo.bar", - "Baz.Cat", - }, - { - "/foo/bar/baz/cat/car", - "foo.bar.baz", - "Cat.Car", - }, - { - "/foo/fooBar/bazCat", - "foo", - "FooBar.BazCat", - }, - { - "/v1/foo/bar", - "v1.foo", - "Foo.Bar", - }, - { - "/v1/foo/bar/baz", - "v1.foo", - "Bar.Baz", - }, - { - "/v1/foo/bar/baz/cat", - "v1.foo.bar", - "Baz.Cat", - }, - } - - for _, d := range testData { - s, m := apiRoute(d.path) - if d.service != s { - t.Fatalf("Expected service: %s for path: %s got: %s %s", d.service, d.path, s, m) - } - if d.method != m { - t.Fatalf("Expected service: %s for path: %s got: %s", d.method, d.path, m) - } - } -} - -func TestProxyRoute(t *testing.T) { - testData := []struct { - path string - service string - }{ - // no namespace - { - "/f", - "f", - }, - { - "/f", - "f", - }, - { - "/f-b", - "f-b", - }, - { - "/foo/bar", - "foo", - }, - { - "/foo-bar", - "foo-bar", - }, - { - "/foo-bar-baz", - "foo-bar-baz", - }, - { - "/foo/bar/bar", - "foo", - }, - { - "/v1/foo/bar", - "v1.foo", - }, - { - "/v1/foo/bar/baz", - "v1.foo", - }, - { - "/v1/foo/bar/baz/cat", - "v1.foo", - }, - } - - for _, d := range testData { - s := proxyRoute(d.path) - if d.service != s { - t.Fatalf("Expected service: %s for path: %s got: %s", d.service, d.path, s) - } - } -} diff --git a/api/router/options.go b/api/router/options.go index 9f0c9325..8dc54327 100644 --- a/api/router/options.go +++ b/api/router/options.go @@ -2,7 +2,6 @@ package router import ( "github.com/micro/go-micro/v2/api/resolver" - "github.com/micro/go-micro/v2/api/resolver/micro" "github.com/micro/go-micro/v2/registry" ) @@ -24,12 +23,6 @@ func NewOptions(opts ...Option) Options { o(&options) } - if options.Resolver == nil { - options.Resolver = micro.NewResolver( - resolver.WithHandler(options.Handler), - ) - } - return options } From 48dd30c4c261afe2661887abe1478ca55a68518e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Apr 2020 19:20:43 +0100 Subject: [PATCH 567/788] fix http test --- api/handler/http/http_test.go | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/api/handler/http/http_test.go b/api/handler/http/http_test.go index 6f094874..d80fdf18 100644 --- a/api/handler/http/http_test.go +++ b/api/handler/http/http_test.go @@ -13,7 +13,7 @@ import ( "github.com/micro/go-micro/v2/registry/memory" ) -func testHttp(t *testing.T, path, service, ns string) { +func testHttp(t *testing.T, path, service string) { r := memory.NewRegistry() l, err := net.Listen("tcp", "127.0.0.1:0") @@ -54,7 +54,6 @@ func testHttp(t *testing.T, path, service, ns string) { // initialise the handler rt := regRouter.NewRouter( router.WithHandler("http"), - router.WithNamespace(ns), router.WithRegistry(r), ) @@ -74,48 +73,40 @@ func testHttp(t *testing.T, path, service, ns string) { func TestHttpHandler(t *testing.T) { testData := []struct { - path string - service string - namespace string + path string + service string }{ { "/test/foo", - "go.micro.api.test", - "go.micro.api", + "test", }, { "/test/foo/baz", - "go.micro.api.test", - "go.micro.api", + "test", }, { "/v1/foo", - "go.micro.api.v1.foo", - "go.micro.api", + "v1.foo", }, { "/v1/foo/bar", - "go.micro.api.v1.foo", - "go.micro.api", + "v1.foo", }, { "/v2/baz", - "go.micro.api.v2.baz", - "go.micro.api", - }, - { - "/v2/baz/bar", - "go.micro.api.v2.baz", - "go.micro.api", + "v2.baz", + }, + { + "/v2/baz/bar", + "v2.baz", }, { "/v2/baz/bar", "v2.baz", - "", }, } for _, d := range testData { - testHttp(t, d.path, d.service, d.namespace) + testHttp(t, d.path, d.service) } } From 45700eaabe84f1f7296c5a8f06e9db7ce39fdfd1 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Apr 2020 19:25:57 +0100 Subject: [PATCH 568/788] set database/table in header --- store/service/service.go | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/store/service/service.go b/store/service/service.go index f3829e9a..f812082b 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -16,18 +16,15 @@ import ( type serviceStore struct { options store.Options - // Namespace to use - Namespace string + // The database to use + Database string + + // The table to use + Table string // Addresses of the nodes Nodes []string - // Prefix to use - Prefix string - - // Suffix to use - Suffix string - // store service client Client pb.StoreService } @@ -40,8 +37,8 @@ func (s *serviceStore) Init(opts ...store.Option) error { for _, o := range opts { o(&s.options) } - s.Namespace = s.options.Database - s.Prefix = s.options.Table + s.Database = s.options.Database + s.Table = s.options.Table s.Nodes = s.options.Nodes return nil @@ -52,12 +49,12 @@ func (s *serviceStore) Context() context.Context { md := make(metadata.Metadata) - if len(s.Namespace) > 0 { - md["Micro-Namespace"] = s.Namespace + if len(s.Database) > 0 { + md["Micro-Database"] = s.Database } - if len(s.Prefix) > 0 { - md["Micro-Prefix"] = s.Prefix + if len(s.Table) > 0 { + md["Micro-Table"] = s.Table } return metadata.NewContext(ctx, md) @@ -168,11 +165,11 @@ func NewStore(opts ...store.Option) store.Store { } service := &serviceStore{ - options: options, - Namespace: options.Database, - Prefix: options.Table, - Nodes: options.Nodes, - Client: pb.NewStoreService("go.micro.store", client.DefaultClient), + options: options, + Database: options.Database, + Table: options.Table, + Nodes: options.Nodes, + Client: pb.NewStoreService("go.micro.store", client.DefaultClient), } return service From bf41d8d28e630eeffd2c7a9848888e7976fe557d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Apr 2020 19:44:49 +0100 Subject: [PATCH 569/788] fix store table env var --- config/cmd/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 34e417dd..674affba 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -231,7 +231,7 @@ var ( }, &cli.StringFlag{ Name: "store_table", - EnvVars: []string{"MICRO_STORE_Table"}, + EnvVars: []string{"MICRO_STORE_TABLE"}, Usage: "Table option for the underlying store", }, &cli.StringFlag{ From 1768958af7d37c2e9c9cdcd3c68fda51bb30a380 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Apr 2020 22:50:56 +0100 Subject: [PATCH 570/788] fix typo --- server/grpc/grpc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index dd711d3f..393f4f99 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -713,7 +713,7 @@ func (g *grpcServer) Register() error { } if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debug("Subscribing to topic: %s", sb.Topic()) + logger.Debugf("Subscribing to topic: %s", sb.Topic()) } sub, err := config.Broker.Subscribe(sb.Topic(), handler, opts...) if err != nil { From bf8ebf8ad2f5c5d3afdb235bda04b8dc2432430e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 8 Apr 2020 23:27:32 +0100 Subject: [PATCH 571/788] add namespace --- api/resolver/micro/micro.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/resolver/micro/micro.go b/api/resolver/micro/micro.go index 9d940887..bacbcbac 100644 --- a/api/resolver/micro/micro.go +++ b/api/resolver/micro/micro.go @@ -27,6 +27,11 @@ func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { name = proxyRoute(req.URL.Path) } + // set the namespace if it exists + if len(r.Options.Namespace) > 0 { + name = r.Options.Namespace + "." + name + } + return &resolver.Endpoint{ Name: name, Method: method, From 1e7cd8c484b598e71df0f491fc7e12722b66bf39 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Wed, 8 Apr 2020 23:52:35 +0100 Subject: [PATCH 572/788] Make the constraint explicit rather than inferred (#1506) --- store/cockroach/cockroach.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 4aa68ac5..47038639 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -277,9 +277,9 @@ func (s *sqlStore) initDB() error { s.readOffset = readOffset write, err := s.db.Prepare(fmt.Sprintf(`INSERT INTO %s.%s(key, value, expiry) VALUES ($1, $2::bytea, $3) - ON CONFLICT (key) + ON CONFLICT ON CONSTRAINT %s_pkey DO UPDATE - SET value = EXCLUDED.value, expiry = EXCLUDED.expiry;`, s.database, s.table)) + SET value = EXCLUDED.value, expiry = EXCLUDED.expiry;`, s.database, s.table, s.table)) if err != nil { return errors.Wrap(err, "Write statement couldn't be prepared") } From c1ad6d6c7c112b9afdf80dc38a73f0a25f550234 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 9 Apr 2020 09:41:50 +0100 Subject: [PATCH 573/788] set service name in web --- web/service.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web/service.go b/web/service.go index cff7e113..069a53e2 100644 --- a/web/service.go +++ b/web/service.go @@ -370,6 +370,10 @@ func (s *service) Init(opts ...Option) error { return nil })) + // pass in own name and version + serviceOpts = append(serviceOpts, micro.Name(s.opts.Name)) + serviceOpts = append(serviceOpts, micro.Version(s.opts.Version)) + s.opts.Service.Init(serviceOpts...) srv := s.genSrv() srv.Endpoints = s.srv.Endpoints From f2dd091ec07970556f7e6c1ca5bdb63fda8d082d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 9 Apr 2020 10:28:16 +0100 Subject: [PATCH 574/788] strip log --- runtime/default.go | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/default.go b/runtime/default.go index 614319d3..a0ea161b 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -204,7 +204,6 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error { service := newService(s, options) f, err := os.OpenFile(logFile(service.Name), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) - logger.Info(f, err) if err != nil { log.Fatal(err) } From f102aba4c1014b529d59c09b466213e4f0e0e8e5 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 9 Apr 2020 10:28:38 +0100 Subject: [PATCH 575/788] Fix HTTP tests --- api/handler/http/http_test.go | 10 ++++++++-- api/resolver/host/host.go | 6 ++++-- api/resolver/path/path.go | 9 ++++++--- api/resolver/vpath/vpath.go | 25 ++++++++++++++++++------- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/api/handler/http/http_test.go b/api/handler/http/http_test.go index 6f094874..1a9d496d 100644 --- a/api/handler/http/http_test.go +++ b/api/handler/http/http_test.go @@ -7,6 +7,8 @@ import ( "testing" "github.com/micro/go-micro/v2/api/handler" + "github.com/micro/go-micro/v2/api/resolver" + res "github.com/micro/go-micro/v2/api/resolver/vpath" "github.com/micro/go-micro/v2/api/router" regRouter "github.com/micro/go-micro/v2/api/router/registry" "github.com/micro/go-micro/v2/registry" @@ -54,8 +56,10 @@ func testHttp(t *testing.T, path, service, ns string) { // initialise the handler rt := regRouter.NewRouter( router.WithHandler("http"), - router.WithNamespace(ns), router.WithRegistry(r), + router.WithResolver(res.NewResolver( + resolver.WithNamespace(ns), + )), ) p := NewHandler(handler.WithRouter(rt)) @@ -116,6 +120,8 @@ func TestHttpHandler(t *testing.T) { } for _, d := range testData { - testHttp(t, d.path, d.service, d.namespace) + t.Run(d.service, func(t *testing.T) { + testHttp(t, d.path, d.service, d.namespace) + }) } } diff --git a/api/resolver/host/host.go b/api/resolver/host/host.go index 157c138f..204bdfa8 100644 --- a/api/resolver/host/host.go +++ b/api/resolver/host/host.go @@ -7,7 +7,9 @@ import ( "github.com/micro/go-micro/v2/api/resolver" ) -type Resolver struct{} +type Resolver struct { + opts resolver.Options +} func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { return &resolver.Endpoint{ @@ -23,5 +25,5 @@ func (r *Resolver) String() string { } func NewResolver(opts ...resolver.Option) resolver.Resolver { - return &Resolver{} + return &Resolver{opts: resolver.NewOptions(opts...)} } diff --git a/api/resolver/path/path.go b/api/resolver/path/path.go index c4d41fc6..88bec8a7 100644 --- a/api/resolver/path/path.go +++ b/api/resolver/path/path.go @@ -8,15 +8,18 @@ import ( "github.com/micro/go-micro/v2/api/resolver" ) -type Resolver struct{} +type Resolver struct { + opts resolver.Options +} func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { if req.URL.Path == "/" { return nil, resolver.ErrNotFound } + parts := strings.Split(req.URL.Path[1:], "/") return &resolver.Endpoint{ - Name: parts[0], + Name: r.opts.Namespace + "." + parts[0], Host: req.Host, Method: req.Method, Path: req.URL.Path, @@ -28,5 +31,5 @@ func (r *Resolver) String() string { } func NewResolver(opts ...resolver.Option) resolver.Resolver { - return &Resolver{} + return &Resolver{opts: resolver.NewOptions(opts...)} } diff --git a/api/resolver/vpath/vpath.go b/api/resolver/vpath/vpath.go index 45f6faaf..f1e49399 100644 --- a/api/resolver/vpath/vpath.go +++ b/api/resolver/vpath/vpath.go @@ -3,6 +3,7 @@ package vpath import ( "errors" + "fmt" "net/http" "regexp" "strings" @@ -10,7 +11,13 @@ import ( "github.com/micro/go-micro/v2/api/resolver" ) -type Resolver struct{} +func NewResolver(opts ...resolver.Option) resolver.Resolver { + return &Resolver{opts: resolver.NewOptions(opts...)} +} + +type Resolver struct { + opts resolver.Options +} var ( re = regexp.MustCompile("^v[0-9]+$") @@ -21,11 +28,12 @@ func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { return nil, errors.New("unknown name") } - parts := strings.Split(req.URL.Path[1:], "/") + fmt.Println(req.URL.Path) + parts := strings.Split(req.URL.Path[1:], "/") if len(parts) == 1 { return &resolver.Endpoint{ - Name: parts[0], + Name: addNamespace(r.opts.Namespace, parts...), Host: req.Host, Method: req.Method, Path: req.URL.Path, @@ -35,7 +43,7 @@ func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { // /v1/foo if re.MatchString(parts[0]) { return &resolver.Endpoint{ - Name: parts[1], + Name: addNamespace(r.opts.Namespace, parts[0:2]...), Host: req.Host, Method: req.Method, Path: req.URL.Path, @@ -43,7 +51,7 @@ func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { } return &resolver.Endpoint{ - Name: parts[0], + Name: addNamespace(r.opts.Namespace, parts[0]), Host: req.Host, Method: req.Method, Path: req.URL.Path, @@ -54,6 +62,9 @@ func (r *Resolver) String() string { return "path" } -func NewResolver(opts ...resolver.Option) resolver.Resolver { - return &Resolver{} +func addNamespace(ns string, parts ...string) string { + if len(ns) == 0 { + return strings.Join(parts, ".") + } + return strings.Join(append([]string{ns}, parts...), ".") } From 3ede494945c974ac72aa88d82ef8f20a2ad2c986 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 9 Apr 2020 10:32:08 +0100 Subject: [PATCH 576/788] Change import name --- api/handler/http/http_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/handler/http/http_test.go b/api/handler/http/http_test.go index 1a9d496d..6844a45a 100644 --- a/api/handler/http/http_test.go +++ b/api/handler/http/http_test.go @@ -8,7 +8,7 @@ import ( "github.com/micro/go-micro/v2/api/handler" "github.com/micro/go-micro/v2/api/resolver" - res "github.com/micro/go-micro/v2/api/resolver/vpath" + "github.com/micro/go-micro/v2/api/resolver/vpath" "github.com/micro/go-micro/v2/api/router" regRouter "github.com/micro/go-micro/v2/api/router/registry" "github.com/micro/go-micro/v2/registry" @@ -57,7 +57,7 @@ func testHttp(t *testing.T, path, service, ns string) { rt := regRouter.NewRouter( router.WithHandler("http"), router.WithRegistry(r), - router.WithResolver(res.NewResolver( + router.WithResolver(vpath.NewResolver( resolver.WithNamespace(ns), )), ) From 27eb7db1c2a947f706dabd967427ffc137c62efc Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 9 Apr 2020 10:34:21 +0100 Subject: [PATCH 577/788] Add default resolver to api router --- api/router/options.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/router/options.go b/api/router/options.go index 8dc54327..69b8a504 100644 --- a/api/router/options.go +++ b/api/router/options.go @@ -2,6 +2,7 @@ package router import ( "github.com/micro/go-micro/v2/api/resolver" + "github.com/micro/go-micro/v2/api/resolver/vpath" "github.com/micro/go-micro/v2/registry" ) @@ -23,6 +24,12 @@ func NewOptions(opts ...Option) Options { o(&options) } + if options.Resolver == nil { + options.Resolver = vpath.NewResolver( + resolver.WithHandler(options.Handler), + ) + } + return options } From bc1c8223e6797d0c070f0b80ba6689e6e4ff29bf Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Thu, 9 Apr 2020 11:50:12 +0200 Subject: [PATCH 578/788] Remove ugly unneeded log in runtime local (#1507) From 4ff959ef50a6e2e2872de9a4fd85aff2d3a4a366 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 9 Apr 2020 11:03:33 +0100 Subject: [PATCH 579/788] Dynamic Namespace --- api/handler/http/http_test.go | 2 +- api/resolver/options.go | 15 +++++++++++++-- api/resolver/path/path.go | 4 +++- api/resolver/resolver.go | 9 ++++++++- api/resolver/vpath/vpath.go | 10 ++++++---- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/api/handler/http/http_test.go b/api/handler/http/http_test.go index 6844a45a..f0ccd1ff 100644 --- a/api/handler/http/http_test.go +++ b/api/handler/http/http_test.go @@ -58,7 +58,7 @@ func testHttp(t *testing.T, path, service, ns string) { router.WithHandler("http"), router.WithRegistry(r), router.WithResolver(vpath.NewResolver( - resolver.WithNamespace(ns), + resolver.WithNamespace(resolver.StaticNamespace(ns)), )), ) diff --git a/api/resolver/options.go b/api/resolver/options.go index ce4b2e49..eb9ce875 100644 --- a/api/resolver/options.go +++ b/api/resolver/options.go @@ -1,11 +1,22 @@ package resolver +import ( + "net/http" + + "github.com/micro/go-micro/v2/auth" +) + // NewOptions returns new initialised options func NewOptions(opts ...Option) Options { var options Options for _, o := range opts { o(&options) } + + if options.Namespace == nil { + options.Namespace = StaticNamespace(auth.DefaultNamespace) + } + return options } @@ -16,8 +27,8 @@ func WithHandler(h string) Option { } } -// WithNamespace sets the namespace being used -func WithNamespace(n string) Option { +// WithNamespace sets the function which determines the namespace for a request +func WithNamespace(n func(*http.Request) string) Option { return func(o *Options) { o.Namespace = n } diff --git a/api/resolver/path/path.go b/api/resolver/path/path.go index 88bec8a7..84a92656 100644 --- a/api/resolver/path/path.go +++ b/api/resolver/path/path.go @@ -18,8 +18,10 @@ func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { } parts := strings.Split(req.URL.Path[1:], "/") + ns := r.opts.Namespace(req) + return &resolver.Endpoint{ - Name: r.opts.Namespace + "." + parts[0], + Name: ns + "." + parts[0], Host: req.Host, Method: req.Method, Path: req.URL.Path, diff --git a/api/resolver/resolver.go b/api/resolver/resolver.go index 12854b19..81e8194d 100644 --- a/api/resolver/resolver.go +++ b/api/resolver/resolver.go @@ -31,7 +31,14 @@ type Endpoint struct { type Options struct { Handler string - Namespace string + Namespace func(*http.Request) string } type Option func(o *Options) + +// StaticNamespace returns the same namespace for each request +func StaticNamespace(ns string) func(*http.Request) string { + return func(*http.Request) string { + return ns + } +} diff --git a/api/resolver/vpath/vpath.go b/api/resolver/vpath/vpath.go index f1e49399..cf407ded 100644 --- a/api/resolver/vpath/vpath.go +++ b/api/resolver/vpath/vpath.go @@ -33,7 +33,7 @@ func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { parts := strings.Split(req.URL.Path[1:], "/") if len(parts) == 1 { return &resolver.Endpoint{ - Name: addNamespace(r.opts.Namespace, parts...), + Name: r.withNamespace(req, parts...), Host: req.Host, Method: req.Method, Path: req.URL.Path, @@ -43,7 +43,7 @@ func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { // /v1/foo if re.MatchString(parts[0]) { return &resolver.Endpoint{ - Name: addNamespace(r.opts.Namespace, parts[0:2]...), + Name: r.withNamespace(req, parts[0:2]...), Host: req.Host, Method: req.Method, Path: req.URL.Path, @@ -51,7 +51,7 @@ func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { } return &resolver.Endpoint{ - Name: addNamespace(r.opts.Namespace, parts[0]), + Name: r.withNamespace(req, parts[0]), Host: req.Host, Method: req.Method, Path: req.URL.Path, @@ -62,9 +62,11 @@ func (r *Resolver) String() string { return "path" } -func addNamespace(ns string, parts ...string) string { +func (r *Resolver) withNamespace(req *http.Request, parts ...string) string { + ns := r.opts.Namespace(req) if len(ns) == 0 { return strings.Join(parts, ".") } + return strings.Join(append([]string{ns}, parts...), ".") } From 1063b954de0d41e6d052f2ddb00b53d31c9e5dfc Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 9 Apr 2020 14:05:46 +0300 Subject: [PATCH 580/788] dont display t.Log/t.Logf as errors in github actions (#1508) * fix tests and github action annotations Signed-off-by: Vasiliy Tolstov --- api/server/acme/certmagic/certmagic_test.go | 10 ++++++- client/selector/default_test.go | 5 +++- client/selector/strategy_test.go | 5 +++- config/source/file/file_test.go | 2 +- registry/memory/memory_test.go | 5 +++- registry/util_test.go | 9 +++++-- router/default_test.go | 21 +++++++++++---- store/cloudflare/cloudflare_test.go | 8 +++++- store/cockroach/cockroach_test.go | 7 ++++- store/file/file_test.go | 15 ++++++----- store/memory/memory_test.go | 29 ++++++++++++++++----- transport/memory/memory_test.go | 9 +++++-- tunnel/tunnel_test.go | 14 ++++++---- web/service.go | 4 +-- web/service_test.go | 16 +++++++++--- 15 files changed, 118 insertions(+), 41 deletions(-) diff --git a/api/server/acme/certmagic/certmagic_test.go b/api/server/acme/certmagic/certmagic_test.go index 30d698c8..12893dfe 100644 --- a/api/server/acme/certmagic/certmagic_test.go +++ b/api/server/acme/certmagic/certmagic_test.go @@ -18,7 +18,7 @@ import ( func TestCertMagic(t *testing.T) { if len(os.Getenv("IN_TRAVIS_CI")) != 0 { - t.Skip("Travis doesn't let us bind :443") + t.Skip() } l, err := NewProvider().Listen() if err != nil { @@ -52,6 +52,10 @@ func TestCertMagic(t *testing.T) { } func TestStorageImplementation(t *testing.T) { + if len(os.Getenv("IN_TRAVIS_CI")) != 0 { + t.Skip() + } + apiToken, accountID := os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ACCOUNT_ID") kvID := os.Getenv("KV_NAMESPACE_ID") if len(apiToken) == 0 || len(accountID) == 0 || len(kvID) == 0 { @@ -189,6 +193,10 @@ func TestStorageImplementation(t *testing.T) { // Full test with a real zone, with against LE staging func TestE2e(t *testing.T) { + if len(os.Getenv("IN_TRAVIS_CI")) != 0 { + t.Skip() + } + apiToken, accountID := os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ACCOUNT_ID") kvID := os.Getenv("KV_NAMESPACE_ID") if len(apiToken) == 0 || len(accountID) == 0 || len(kvID) == 0 { diff --git a/client/selector/default_test.go b/client/selector/default_test.go index d3b50003..60d10b1b 100644 --- a/client/selector/default_test.go +++ b/client/selector/default_test.go @@ -1,6 +1,7 @@ package selector import ( + "os" "testing" "github.com/micro/go-micro/v2/registry/memory" @@ -25,5 +26,7 @@ func TestRegistrySelector(t *testing.T) { counts[node.Id]++ } - t.Logf("Selector Counts %v", counts) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Selector Counts %v", counts) + } } diff --git a/client/selector/strategy_test.go b/client/selector/strategy_test.go index 07bf30b6..692c802f 100644 --- a/client/selector/strategy_test.go +++ b/client/selector/strategy_test.go @@ -1,6 +1,7 @@ package selector import ( + "os" "testing" "github.com/micro/go-micro/v2/registry" @@ -50,6 +51,8 @@ func TestStrategies(t *testing.T) { counts[node.Id]++ } - t.Logf("%s: %+v\n", name, counts) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("%s: %+v\n", name, counts) + } } } diff --git a/config/source/file/file_test.go b/config/source/file/file_test.go index 1d0a3ad0..e388a88a 100644 --- a/config/source/file/file_test.go +++ b/config/source/file/file_test.go @@ -59,8 +59,8 @@ func TestFile(t *testing.T) { if err != nil { t.Error(err) } - t.Logf("%+v", c) if string(c.Data) != string(data) { + t.Logf("%+v", c) t.Error("data from file does not match") } } diff --git a/registry/memory/memory_test.go b/registry/memory/memory_test.go index 9609b20c..0244a8da 100644 --- a/registry/memory/memory_test.go +++ b/registry/memory/memory_test.go @@ -2,6 +2,7 @@ package memory import ( "fmt" + "os" "testing" "time" @@ -205,7 +206,9 @@ func TestMemoryRegistryTTLConcurrent(t *testing.T) { } } - t.Logf("test will wait %v, then check TTL timeouts", waitTime) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("test will wait %v, then check TTL timeouts", waitTime) + } errChan := make(chan error, concurrency) syncChan := make(chan struct{}) diff --git a/registry/util_test.go b/registry/util_test.go index 75fd5133..e1a6e9a0 100644 --- a/registry/util_test.go +++ b/registry/util_test.go @@ -1,6 +1,7 @@ package registry import ( + "os" "testing" ) @@ -32,7 +33,9 @@ func TestRemove(t *testing.T) { if i := len(servs); i > 0 { t.Errorf("Expected 0 nodes, got %d: %+v", i, servs) } - t.Logf("Services %+v", servs) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Services %+v", servs) + } } func TestRemoveNodes(t *testing.T) { @@ -67,5 +70,7 @@ func TestRemoveNodes(t *testing.T) { if i := len(nodes); i != 1 { t.Errorf("Expected only 1 node, got %d: %+v", i, nodes) } - t.Logf("Nodes %+v", nodes) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Nodes %+v", nodes) + } } diff --git a/router/default_test.go b/router/default_test.go index 19d36423..4ed2f08e 100644 --- a/router/default_test.go +++ b/router/default_test.go @@ -2,6 +2,7 @@ package router import ( "fmt" + "os" "sync" "testing" "time" @@ -29,7 +30,9 @@ func TestRouterStartStop(t *testing.T) { if err := r.Stop(); err != nil { t.Errorf("failed to stop router: %v", err) } - t.Logf("TestRouterStartStop STOPPED") + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("TestRouterStartStop STOPPED") + } } func TestRouterAdvertise(t *testing.T) { @@ -49,7 +52,9 @@ func TestRouterAdvertise(t *testing.T) { // receive announce event ann := <-ch - t.Logf("received announce advert: %v", ann) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("received announce advert: %v", ann) + } // Generate random unique routes nrRoutes := 5 @@ -81,9 +86,13 @@ func TestRouterAdvertise(t *testing.T) { wg.Done() defer close(createDone) for _, route := range routes { - t.Logf("Creating route %v", route) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Creating route %v", route) + } if err := r.Table().Create(route); err != nil { - t.Logf("Failed to create route: %v", err) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Failed to create route: %v", err) + } errChan <- err return } @@ -105,7 +114,9 @@ func TestRouterAdvertise(t *testing.T) { t.Errorf("failed advertising events: %v", advertErr) default: // do nothing for now - t.Logf("Router advert received: %v", advert) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Router advert received: %v", advert) + } adverts += len(advert.Events) } return diff --git a/store/cloudflare/cloudflare_test.go b/store/cloudflare/cloudflare_test.go index dbf78c26..9cc7a05b 100644 --- a/store/cloudflare/cloudflare_test.go +++ b/store/cloudflare/cloudflare_test.go @@ -11,6 +11,10 @@ import ( ) func TestCloudflare(t *testing.T) { + if len(os.Getenv("IN_TRAVIS_CI")) != 0 { + t.Skip() + } + apiToken, accountID := os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ACCOUNT_ID") kvID := os.Getenv("KV_NAMESPACE_ID") if len(apiToken) == 0 || len(accountID) == 0 || len(kvID) == 0 { @@ -31,7 +35,9 @@ func TestCloudflare(t *testing.T) { if err != nil { t.Fatalf("List: %s\n", err.Error()) } else { - t.Log("Listed " + strconv.Itoa(len(records)) + " records") + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Log("Listed " + strconv.Itoa(len(records)) + " records") + } } err = wkv.Write(&store.Record{ diff --git a/store/cockroach/cockroach_test.go b/store/cockroach/cockroach_test.go index f5b0077c..5bd6dc40 100644 --- a/store/cockroach/cockroach_test.go +++ b/store/cockroach/cockroach_test.go @@ -3,6 +3,7 @@ package cockroach import ( "database/sql" "fmt" + "os" "testing" "time" @@ -11,6 +12,10 @@ import ( ) func TestSQL(t *testing.T) { + if len(os.Getenv("IN_TRAVIS_CI")) != 0 { + t.Skip() + } + connection := fmt.Sprintf( "host=%s port=%d user=%s sslmode=disable dbname=%s", "localhost", @@ -23,7 +28,7 @@ func TestSQL(t *testing.T) { t.Fatal(err) } if err := db.Ping(); err != nil { - t.Skip(err) + t.Fatal(err) } db.Close() diff --git a/store/file/file_test.go b/store/file/file_test.go index 6dd58c64..fded4644 100644 --- a/store/file/file_test.go +++ b/store/file/file_test.go @@ -53,8 +53,9 @@ func TestFileStoreDatabaseTable(t *testing.T) { } func fileTest(s store.Store, t *testing.T) { - t.Logf("Options %s %v\n", s.String(), s.Options()) - + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Options %s %v\n", s.String(), s.Options()) + } // Read and Write an expiring Record if err := s.Write(&store.Record{ Key: "Hello", @@ -109,7 +110,7 @@ func fileTest(s store.Store, t *testing.T) { } else { if len(results) != 2 { t.Errorf("Expected 2 items, got %d", len(results)) - t.Logf("Table test: %v\n", spew.Sdump(results)) + //t.Logf("Table test: %v\n", spew.Sdump(results)) } } @@ -120,7 +121,7 @@ func fileTest(s store.Store, t *testing.T) { t.Errorf("Couldn't read all \"foo\" keys, got %# v (%s)", spew.Sdump(results), err) } else if len(results) != 1 { t.Errorf("Expected 1 item, got %d", len(results)) - t.Logf("Table test: %v\n", spew.Sdump(results)) + //t.Logf("Table test: %v\n", spew.Sdump(results)) } if err := s.Delete("foo"); err != nil { @@ -163,7 +164,7 @@ func fileTest(s store.Store, t *testing.T) { } else { if len(results) != 3 { t.Errorf("Expected 3 items, got %d", len(results)) - t.Logf("Table test: %v\n", spew.Sdump(results)) + //t.Logf("Table test: %v\n", spew.Sdump(results)) } } @@ -173,7 +174,7 @@ func fileTest(s store.Store, t *testing.T) { } else { if len(results) != 2 { t.Errorf("Expected 2 items, got %d", len(results)) - t.Logf("Table test: %v\n", spew.Sdump(results)) + //t.Logf("Table test: %v\n", spew.Sdump(results)) } } @@ -183,7 +184,7 @@ func fileTest(s store.Store, t *testing.T) { } else { if len(results) != 1 { t.Errorf("Expected 1 item, got %d", len(results)) - t.Logf("Table test: %# v\n", spew.Sdump(results)) + // t.Logf("Table test: %# v\n", spew.Sdump(results)) } } if err := s.Delete("foo"); err != nil { diff --git a/store/memory/memory_test.go b/store/memory/memory_test.go index 14ac49a6..8d51ea0d 100644 --- a/store/memory/memory_test.go +++ b/store/memory/memory_test.go @@ -2,6 +2,7 @@ package memory import ( "fmt" + "os" "testing" "time" @@ -42,7 +43,9 @@ func TestMemoryNamespacePrefix(t *testing.T) { } func basictest(s store.Store, t *testing.T) { - t.Logf("Testing store %s, with options %# v\n", s.String(), pretty.Formatter(s.Options())) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Testing store %s, with options %# v\n", s.String(), pretty.Formatter(s.Options())) + } // Read and Write an expiring Record if err := s.Write(&store.Record{ Key: "Hello", @@ -97,7 +100,9 @@ func basictest(s store.Store, t *testing.T) { if len(results) != 3 { t.Errorf("Expected 3 items, got %d", len(results)) } - t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } } time.Sleep(time.Millisecond * 100) if results, err := s.Read("foo", store.ReadPrefix()); err != nil { @@ -106,7 +111,9 @@ func basictest(s store.Store, t *testing.T) { if len(results) != 2 { t.Errorf("Expected 2 items, got %d", len(results)) } - t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } } time.Sleep(time.Millisecond * 100) if results, err := s.Read("foo", store.ReadPrefix()); err != nil { @@ -115,7 +122,9 @@ func basictest(s store.Store, t *testing.T) { if len(results) != 1 { t.Errorf("Expected 1 item, got %d", len(results)) } - t.Logf("Prefix test: %# v\n", pretty.Formatter(results)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Prefix test: %# v\n", pretty.Formatter(results)) + } } if err := s.Delete("foo", func(d *store.DeleteOptions) {}); err != nil { t.Errorf("Delete failed (%v)", err) @@ -156,7 +165,9 @@ func basictest(s store.Store, t *testing.T) { if len(results) != 3 { t.Errorf("Expected 3 items, got %d", len(results)) } - t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } } time.Sleep(time.Millisecond * 100) if results, err := s.Read("foo", store.ReadSuffix()); err != nil { @@ -165,7 +176,9 @@ func basictest(s store.Store, t *testing.T) { if len(results) != 2 { t.Errorf("Expected 2 items, got %d", len(results)) } - t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Prefix test: %v\n", pretty.Formatter(results)) + } } time.Sleep(time.Millisecond * 100) if results, err := s.Read("foo", store.ReadSuffix()); err != nil { @@ -174,7 +187,9 @@ func basictest(s store.Store, t *testing.T) { if len(results) != 1 { t.Errorf("Expected 1 item, got %d", len(results)) } - t.Logf("Prefix test: %# v\n", pretty.Formatter(results)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Prefix test: %# v\n", pretty.Formatter(results)) + } } if err := s.Delete("foo"); err != nil { t.Errorf("Delete failed (%v)", err) diff --git a/transport/memory/memory_test.go b/transport/memory/memory_test.go index 50e64aaf..1d46d401 100644 --- a/transport/memory/memory_test.go +++ b/transport/memory/memory_test.go @@ -1,6 +1,7 @@ package memory import ( + "os" "testing" "github.com/micro/go-micro/v2/transport" @@ -24,7 +25,9 @@ func TestMemoryTransport(t *testing.T) { if err := sock.Recv(&m); err != nil { return } - t.Logf("Server Received %s", string(m.Body)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Server Received %s", string(m.Body)) + } if err := sock.Send(&transport.Message{ Body: []byte(`pong`), }); err != nil { @@ -54,7 +57,9 @@ func TestMemoryTransport(t *testing.T) { if err := c.Recv(&m); err != nil { return } - t.Logf("Client Received %s", string(m.Body)) + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("Client Received %s", string(m.Body)) + } } } diff --git a/tunnel/tunnel_test.go b/tunnel/tunnel_test.go index 2e86baf0..1c620347 100644 --- a/tunnel/tunnel_test.go +++ b/tunnel/tunnel_test.go @@ -1,6 +1,7 @@ package tunnel import ( + "os" "sync" "testing" "time" @@ -288,12 +289,15 @@ func TestTunnelRTTRate(t *testing.T) { // wait until done wg.Wait() - for _, link := range tunA.Links() { - t.Logf("Link %s length %v rate %v", link.Id(), link.Length(), link.Rate()) - } + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + // only needed for debug + for _, link := range tunA.Links() { + t.Logf("Link %s length %v rate %v", link.Id(), link.Length(), link.Rate()) + } - for _, link := range tunB.Links() { - t.Logf("Link %s length %v rate %v", link.Id(), link.Length(), link.Rate()) + for _, link := range tunB.Links() { + t.Logf("Link %s length %v rate %v", link.Id(), link.Length(), link.Rate()) + } } } diff --git a/web/service.go b/web/service.go index 069a53e2..737f801b 100644 --- a/web/service.go +++ b/web/service.go @@ -226,8 +226,8 @@ func (s *service) start() error { ch <- l.Close() }() - if logger.V(logger.InfoLevel, log) { - log.Infof("Listening on %v", l.Addr().String()) + if logger.V(logger.DebugLevel, log) { + log.Debugf("Listening on %v", l.Addr().String()) } return nil } diff --git a/web/service_test.go b/web/service_test.go index 428f9424..0d033038 100644 --- a/web/service_test.go +++ b/web/service_test.go @@ -110,7 +110,9 @@ func TestService(t *testing.T) { t.Fatalf("service.Run():%v", err) } case <-time.After(time.Duration(time.Second)): - t.Logf("service.Run() survived a client request without an error") + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("service.Run() survived a client request without an error") + } } ch := make(chan os.Signal, 1) @@ -125,10 +127,14 @@ func TestService(t *testing.T) { if err != nil { t.Fatalf("service.Run():%v", err) } else { - t.Log("service.Run() nil return on syscall.SIGTERM") + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Log("service.Run() nil return on syscall.SIGTERM") + } } case <-time.After(time.Duration(time.Second)): - t.Logf("service.Run() survived a client request without an error") + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("service.Run() survived a client request without an error") + } } eventually(func() bool { @@ -286,7 +292,9 @@ func TestTLS(t *testing.T) { t.Fatalf("service.Run():%v", err) } case <-time.After(time.Duration(time.Second)): - t.Logf("service.Run() survived a client request without an error") + if len(os.Getenv("IN_TRAVIS_CI")) == 0 { + t.Logf("service.Run() survived a client request without an error") + } } } From 2659215d5ea33e1250309c5a7ce52214ca75be89 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Thu, 9 Apr 2020 12:11:24 +0100 Subject: [PATCH 581/788] cockroachDB doesn't support this syntax (#1509) --- store/cockroach/cockroach.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 47038639..e89c5281 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -277,7 +277,7 @@ func (s *sqlStore) initDB() error { s.readOffset = readOffset write, err := s.db.Prepare(fmt.Sprintf(`INSERT INTO %s.%s(key, value, expiry) VALUES ($1, $2::bytea, $3) - ON CONFLICT ON CONSTRAINT %s_pkey + ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, expiry = EXCLUDED.expiry;`, s.database, s.table, s.table)) if err != nil { From 2e379ca7d026a2b52f7a54d38b046ba9968e317e Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Thu, 9 Apr 2020 12:18:02 +0100 Subject: [PATCH 582/788] Don't break the build! --- store/cockroach/cockroach.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index e89c5281..4aa68ac5 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -279,7 +279,7 @@ func (s *sqlStore) initDB() error { VALUES ($1, $2::bytea, $3) ON CONFLICT (key) DO UPDATE - SET value = EXCLUDED.value, expiry = EXCLUDED.expiry;`, s.database, s.table, s.table)) + SET value = EXCLUDED.value, expiry = EXCLUDED.expiry;`, s.database, s.table)) if err != nil { return errors.Wrap(err, "Write statement couldn't be prepared") } From 8c1b477279b593075cf52ed93cf872f2b8d170da Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 9 Apr 2020 14:58:50 +0300 Subject: [PATCH 583/788] store/cockroach: fixup test (#1512) * store/cockroach: fixup test Signed-off-by: Vasiliy Tolstov --- store/cockroach/cockroach_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/cockroach/cockroach_test.go b/store/cockroach/cockroach_test.go index 5bd6dc40..8664c5dc 100644 --- a/store/cockroach/cockroach_test.go +++ b/store/cockroach/cockroach_test.go @@ -28,7 +28,7 @@ func TestSQL(t *testing.T) { t.Fatal(err) } if err := db.Ping(); err != nil { - t.Fatal(err) + t.Skip("store/cockroach: can't connect to db") } db.Close() From 29cccd0b4ab6132f1a738ec63ddd35bf9c8e2659 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 9 Apr 2020 14:10:17 +0100 Subject: [PATCH 584/788] minor tweak add log line to proxy and basic auth provider by default (#1513) --- auth/default.go | 13 ++++++++++++- proxy/mucp/mucp.go | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/auth/default.go b/auth/default.go index 358cf099..b9160a50 100644 --- a/auth/default.go +++ b/auth/default.go @@ -2,6 +2,7 @@ package auth import ( "github.com/google/uuid" + "github.com/micro/go-micro/v2/auth/provider/basic" ) var ( @@ -9,7 +10,17 @@ var ( ) func NewAuth(opts ...Option) Auth { - return &noop{} + options := Options{ + Provider: basic.NewProvider(), + } + + for _, o := range opts { + o(&options) + } + + return &noop{ + opts: options, + } } type noop struct { diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index da901c13..e7c69aa2 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -206,7 +206,7 @@ func (p *Proxy) cacheRoutes(service string) ([]router.Route, error) { results, err := p.Router.Lookup(router.QueryService(service)) if err != nil { // assumption that we're ok with stale routes - + logger.Debugf("Failed to lookup route for %s: %v", service, err) // otherwise return the error return nil, err } From 77f0abb0ba550948abbe793aed54460e0703caf8 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Thu, 9 Apr 2020 16:44:39 +0200 Subject: [PATCH 585/788] Enabling micro run for subfolders (#1510) * Enabling micro run for subfolders * Use source instead of os.Args[2] * Works now * PR comments * WorkDir -> Dir --- runtime/local/process/os/os.go | 4 ++++ runtime/local/process/process.go | 2 ++ runtime/service.go | 1 + 3 files changed, 7 insertions(+) diff --git a/runtime/local/process/os/os.go b/runtime/local/process/os/os.go index f1825e97..a35d0b79 100644 --- a/runtime/local/process/os/os.go +++ b/runtime/local/process/os/os.go @@ -15,13 +15,17 @@ import ( func (p *Process) Exec(exe *process.Executable) error { cmd := exec.Command(exe.Package.Path) + cmd.Dir = exe.Dir return cmd.Run() } func (p *Process) Fork(exe *process.Executable) (*process.PID, error) { // create command cmd := exec.Command(exe.Package.Path, exe.Args...) + + cmd.Dir = exe.Dir // set env vars + cmd.Env = append(cmd.Env, os.Environ()...) cmd.Env = append(cmd.Env, exe.Env...) // create process group diff --git a/runtime/local/process/process.go b/runtime/local/process/process.go index 4449d294..ffeae63e 100644 --- a/runtime/local/process/process.go +++ b/runtime/local/process/process.go @@ -26,6 +26,8 @@ type Executable struct { Env []string // Args to pass Args []string + // Initial working directory + Dir string } // PID is the running process diff --git a/runtime/service.go b/runtime/service.go index 9c6bdc16..eb6c4154 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -55,6 +55,7 @@ func newService(s *Service, c CreateOptions) *service { }, Env: c.Env, Args: args, + Dir: s.Source, }, closed: make(chan bool), output: c.Output, From 0a27a0818410abe949e96d858b308e99bee532d2 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Thu, 9 Apr 2020 16:37:32 +0100 Subject: [PATCH 586/788] Add Databases and Tables endpoints to store RPC proto (#1515) * Add Databases and Tables to store RPC * add Database to TablesRequest --- store/service/proto/store.pb.go | 471 +++++++++++--------------- store/service/proto/store.pb.micro.go | 36 +- store/service/proto/store.proto | 16 + 3 files changed, 256 insertions(+), 267 deletions(-) diff --git a/store/service/proto/store.pb.go b/store/service/proto/store.pb.go index 177e664d..bcab9640 100644 --- a/store/service/proto/store.pb.go +++ b/store/service/proto/store.pb.go @@ -1,15 +1,11 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: store/service/proto/store.proto +// source: store.proto package go_micro_store import ( - context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" math "math" ) @@ -40,7 +36,7 @@ func (m *Record) Reset() { *m = Record{} } func (m *Record) String() string { return proto.CompactTextString(m) } func (*Record) ProtoMessage() {} func (*Record) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{0} + return fileDescriptor_98bbca36ef968dfc, []int{0} } func (m *Record) XXX_Unmarshal(b []byte) error { @@ -96,7 +92,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{1} + return fileDescriptor_98bbca36ef968dfc, []int{1} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -157,7 +153,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{2} + return fileDescriptor_98bbca36ef968dfc, []int{2} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -203,7 +199,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{3} + return fileDescriptor_98bbca36ef968dfc, []int{3} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -245,7 +241,7 @@ func (m *WriteOptions) Reset() { *m = WriteOptions{} } func (m *WriteOptions) String() string { return proto.CompactTextString(m) } func (*WriteOptions) ProtoMessage() {} func (*WriteOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{4} + return fileDescriptor_98bbca36ef968dfc, []int{4} } func (m *WriteOptions) XXX_Unmarshal(b []byte) error { @@ -292,7 +288,7 @@ func (m *WriteRequest) Reset() { *m = WriteRequest{} } func (m *WriteRequest) String() string { return proto.CompactTextString(m) } func (*WriteRequest) ProtoMessage() {} func (*WriteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{5} + return fileDescriptor_98bbca36ef968dfc, []int{5} } func (m *WriteRequest) XXX_Unmarshal(b []byte) error { @@ -337,7 +333,7 @@ func (m *WriteResponse) Reset() { *m = WriteResponse{} } func (m *WriteResponse) String() string { return proto.CompactTextString(m) } func (*WriteResponse) ProtoMessage() {} func (*WriteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{6} + return fileDescriptor_98bbca36ef968dfc, []int{6} } func (m *WriteResponse) XXX_Unmarshal(b []byte) error { @@ -368,7 +364,7 @@ func (m *DeleteOptions) Reset() { *m = DeleteOptions{} } func (m *DeleteOptions) String() string { return proto.CompactTextString(m) } func (*DeleteOptions) ProtoMessage() {} func (*DeleteOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{7} + return fileDescriptor_98bbca36ef968dfc, []int{7} } func (m *DeleteOptions) XXX_Unmarshal(b []byte) error { @@ -401,7 +397,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{8} + return fileDescriptor_98bbca36ef968dfc, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -446,7 +442,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{9} + return fileDescriptor_98bbca36ef968dfc, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -481,7 +477,7 @@ func (m *ListOptions) Reset() { *m = ListOptions{} } func (m *ListOptions) String() string { return proto.CompactTextString(m) } func (*ListOptions) ProtoMessage() {} func (*ListOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{10} + return fileDescriptor_98bbca36ef968dfc, []int{10} } func (m *ListOptions) XXX_Unmarshal(b []byte) error { @@ -541,7 +537,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{11} + return fileDescriptor_98bbca36ef968dfc, []int{11} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -580,7 +576,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{12} + return fileDescriptor_98bbca36ef968dfc, []int{12} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -608,6 +604,154 @@ func (m *ListResponse) GetKeys() []string { return nil } +type DatabasesRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DatabasesRequest) Reset() { *m = DatabasesRequest{} } +func (m *DatabasesRequest) String() string { return proto.CompactTextString(m) } +func (*DatabasesRequest) ProtoMessage() {} +func (*DatabasesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_98bbca36ef968dfc, []int{13} +} + +func (m *DatabasesRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DatabasesRequest.Unmarshal(m, b) +} +func (m *DatabasesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DatabasesRequest.Marshal(b, m, deterministic) +} +func (m *DatabasesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DatabasesRequest.Merge(m, src) +} +func (m *DatabasesRequest) XXX_Size() int { + return xxx_messageInfo_DatabasesRequest.Size(m) +} +func (m *DatabasesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DatabasesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DatabasesRequest proto.InternalMessageInfo + +type DatabasesResponse struct { + Databases []string `protobuf:"bytes,1,rep,name=databases,proto3" json:"databases,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DatabasesResponse) Reset() { *m = DatabasesResponse{} } +func (m *DatabasesResponse) String() string { return proto.CompactTextString(m) } +func (*DatabasesResponse) ProtoMessage() {} +func (*DatabasesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_98bbca36ef968dfc, []int{14} +} + +func (m *DatabasesResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DatabasesResponse.Unmarshal(m, b) +} +func (m *DatabasesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DatabasesResponse.Marshal(b, m, deterministic) +} +func (m *DatabasesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_DatabasesResponse.Merge(m, src) +} +func (m *DatabasesResponse) XXX_Size() int { + return xxx_messageInfo_DatabasesResponse.Size(m) +} +func (m *DatabasesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_DatabasesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_DatabasesResponse proto.InternalMessageInfo + +func (m *DatabasesResponse) GetDatabases() []string { + if m != nil { + return m.Databases + } + return nil +} + +type TablesRequest struct { + Database string `protobuf:"bytes,1,opt,name=database,proto3" json:"database,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *TablesRequest) Reset() { *m = TablesRequest{} } +func (m *TablesRequest) String() string { return proto.CompactTextString(m) } +func (*TablesRequest) ProtoMessage() {} +func (*TablesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_98bbca36ef968dfc, []int{15} +} + +func (m *TablesRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_TablesRequest.Unmarshal(m, b) +} +func (m *TablesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_TablesRequest.Marshal(b, m, deterministic) +} +func (m *TablesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_TablesRequest.Merge(m, src) +} +func (m *TablesRequest) XXX_Size() int { + return xxx_messageInfo_TablesRequest.Size(m) +} +func (m *TablesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_TablesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_TablesRequest proto.InternalMessageInfo + +func (m *TablesRequest) GetDatabase() string { + if m != nil { + return m.Database + } + return "" +} + +type TablesResponse struct { + Tables []string `protobuf:"bytes,1,rep,name=tables,proto3" json:"tables,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *TablesResponse) Reset() { *m = TablesResponse{} } +func (m *TablesResponse) String() string { return proto.CompactTextString(m) } +func (*TablesResponse) ProtoMessage() {} +func (*TablesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_98bbca36ef968dfc, []int{16} +} + +func (m *TablesResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_TablesResponse.Unmarshal(m, b) +} +func (m *TablesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_TablesResponse.Marshal(b, m, deterministic) +} +func (m *TablesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_TablesResponse.Merge(m, src) +} +func (m *TablesResponse) XXX_Size() int { + return xxx_messageInfo_TablesResponse.Size(m) +} +func (m *TablesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_TablesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_TablesResponse proto.InternalMessageInfo + +func (m *TablesResponse) GetTables() []string { + if m != nil { + return m.Tables + } + return nil +} + func init() { proto.RegisterType((*Record)(nil), "go.micro.store.Record") proto.RegisterType((*ReadOptions)(nil), "go.micro.store.ReadOptions") @@ -622,256 +766,51 @@ func init() { proto.RegisterType((*ListOptions)(nil), "go.micro.store.ListOptions") proto.RegisterType((*ListRequest)(nil), "go.micro.store.ListRequest") proto.RegisterType((*ListResponse)(nil), "go.micro.store.ListResponse") + proto.RegisterType((*DatabasesRequest)(nil), "go.micro.store.DatabasesRequest") + proto.RegisterType((*DatabasesResponse)(nil), "go.micro.store.DatabasesResponse") + proto.RegisterType((*TablesRequest)(nil), "go.micro.store.TablesRequest") + proto.RegisterType((*TablesResponse)(nil), "go.micro.store.TablesResponse") } -func init() { proto.RegisterFile("store/service/proto/store.proto", fileDescriptor_1ba364858f5c3cdb) } - -var fileDescriptor_1ba364858f5c3cdb = []byte{ - // 474 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x5d, 0x6f, 0xd3, 0x30, - 0x14, 0x9d, 0x9b, 0x34, 0x5b, 0x6f, 0xcb, 0xa8, 0x2c, 0x34, 0x45, 0xb0, 0x41, 0xe5, 0xa7, 0x3c, - 0xa5, 0x53, 0x11, 0x1f, 0x8f, 0x48, 0x0c, 0x04, 0x08, 0x09, 0xc9, 0x48, 0x20, 0xf1, 0x36, 0xba, - 0x5b, 0x64, 0xb5, 0x9b, 0x83, 0xed, 0x56, 0xeb, 0x1f, 0xe2, 0x77, 0x22, 0x7f, 0xb5, 0x69, 0x48, - 0x5e, 0x78, 0xf3, 0xbd, 0xbe, 0x39, 0xe7, 0x9e, 0xe3, 0xa3, 0xc0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ed, 0xba, 0xde, 0x41, 0xbd, 0x83, 0xd4, 0x7a, 0x41, 0x5b, 0x9d, 0xeb, - 0xd4, 0x55, 0xb7, 0x8f, 0x1d, 0x5d, 0x92, 0x9f, 0x99, 0xfb, 0x5f, 0x3d, 0xff, 0x1b, 0x00, 0x00, - 0xff, 0xff, 0xdd, 0xdb, 0x9c, 0x15, 0xd2, 0x04, 0x00, 0x00, +func init() { + proto.RegisterFile("store.proto", fileDescriptor_98bbca36ef968dfc) } -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// StoreClient is the client API for Store service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type StoreClient interface { - Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) - Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) - Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) - List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (Store_ListClient, error) -} - -type storeClient struct { - cc *grpc.ClientConn -} - -func NewStoreClient(cc *grpc.ClientConn) StoreClient { - return &storeClient{cc} -} - -func (c *storeClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { - out := new(ReadResponse) - err := c.cc.Invoke(ctx, "/go.micro.store.Store/Read", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *storeClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) { - out := new(WriteResponse) - err := c.cc.Invoke(ctx, "/go.micro.store.Store/Write", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *storeClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { - out := new(DeleteResponse) - err := c.cc.Invoke(ctx, "/go.micro.store.Store/Delete", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *storeClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (Store_ListClient, error) { - stream, err := c.cc.NewStream(ctx, &_Store_serviceDesc.Streams[0], "/go.micro.store.Store/List", opts...) - if err != nil { - return nil, err - } - x := &storeListClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type Store_ListClient interface { - Recv() (*ListResponse, error) - grpc.ClientStream -} - -type storeListClient struct { - grpc.ClientStream -} - -func (x *storeListClient) Recv() (*ListResponse, error) { - m := new(ListResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// StoreServer is the server API for Store service. -type StoreServer interface { - Read(context.Context, *ReadRequest) (*ReadResponse, error) - Write(context.Context, *WriteRequest) (*WriteResponse, error) - Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) - List(*ListRequest, Store_ListServer) error -} - -// UnimplementedStoreServer can be embedded to have forward compatible implementations. -type UnimplementedStoreServer struct { -} - -func (*UnimplementedStoreServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") -} -func (*UnimplementedStoreServer) Write(ctx context.Context, req *WriteRequest) (*WriteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Write not implemented") -} -func (*UnimplementedStoreServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") -} -func (*UnimplementedStoreServer) List(req *ListRequest, srv Store_ListServer) error { - return status.Errorf(codes.Unimplemented, "method List not implemented") -} - -func RegisterStoreServer(s *grpc.Server, srv StoreServer) { - s.RegisterService(&_Store_serviceDesc, srv) -} - -func _Store_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ReadRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(StoreServer).Read(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.store.Store/Read", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(StoreServer).Read(ctx, req.(*ReadRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Store_Write_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(WriteRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(StoreServer).Write(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.store.Store/Write", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(StoreServer).Write(ctx, req.(*WriteRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Store_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DeleteRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(StoreServer).Delete(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.store.Store/Delete", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(StoreServer).Delete(ctx, req.(*DeleteRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Store_List_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(ListRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(StoreServer).List(m, &storeListServer{stream}) -} - -type Store_ListServer interface { - Send(*ListResponse) error - grpc.ServerStream -} - -type storeListServer struct { - grpc.ServerStream -} - -func (x *storeListServer) Send(m *ListResponse) error { - return x.ServerStream.SendMsg(m) -} - -var _Store_serviceDesc = grpc.ServiceDesc{ - ServiceName: "go.micro.store.Store", - HandlerType: (*StoreServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Read", - Handler: _Store_Read_Handler, - }, - { - MethodName: "Write", - Handler: _Store_Write_Handler, - }, - { - MethodName: "Delete", - Handler: _Store_Delete_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "List", - Handler: _Store_List_Handler, - ServerStreams: true, - }, - }, - Metadata: "store/service/proto/store.proto", +var fileDescriptor_98bbca36ef968dfc = []byte{ + // 552 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x5d, 0x8b, 0xd3, 0x40, + 0x14, 0x6d, 0x9a, 0x34, 0xdb, 0xdc, 0x76, 0x6b, 0x1d, 0xa4, 0x94, 0xda, 0x95, 0x38, 0x4f, 0x01, + 0x21, 0xac, 0x15, 0x3f, 0x1e, 0x05, 0xab, 0xa8, 0x08, 0xc2, 0x28, 0x0a, 0xbe, 0xa5, 0xdb, 0xa9, + 0x84, 0x66, 0x77, 0x62, 0x66, 0xba, 0x6c, 0x7f, 0xa0, 0xff, 0x4b, 0xe6, 0x2b, 0x4d, 0xd3, 0xc4, + 0x87, 0x7d, 0x9b, 0x7b, 0xe7, 0xce, 0x39, 0xf7, 0xdc, 0x7b, 0x12, 0x18, 0x70, 0xc1, 0x0a, 0x1a, + 0xe7, 0x05, 0x13, 0x0c, 0x8d, 0x7e, 0xb3, 0xf8, 0x3a, 0xbd, 0x2a, 0x58, 0xac, 0xb2, 0xf8, 0x23, + 0xf8, 0x84, 0x5e, 0xb1, 0x62, 0x8d, 0xc6, 0xe0, 0x6e, 0xe9, 0x7e, 0xea, 0x84, 0x4e, 0x14, 0x10, + 0x79, 0x44, 0x8f, 0xa0, 0x77, 0x9b, 0x64, 0x3b, 0x3a, 0xed, 0x86, 0x4e, 0x34, 0x24, 0x3a, 0x40, + 0x13, 0xf0, 0xe9, 0x5d, 0x9e, 0x16, 0xfb, 0xa9, 0x1b, 0x3a, 0x91, 0x4b, 0x4c, 0x84, 0xb7, 0x30, + 0x20, 0x34, 0x59, 0x7f, 0xcd, 0x45, 0xca, 0x6e, 0xb8, 0x2c, 0xcb, 0x0b, 0xba, 0x49, 0xef, 0x14, + 0x62, 0x9f, 0x98, 0x48, 0xe6, 0xf9, 0x6e, 0x23, 0xf3, 0x5d, 0x9d, 0xd7, 0x91, 0x24, 0xcb, 0xd2, + 0xeb, 0x54, 0x28, 0x54, 0x8f, 0xe8, 0x40, 0x56, 0xb3, 0xcd, 0x86, 0x53, 0x31, 0xf5, 0x54, 0xda, + 0x44, 0xf8, 0x87, 0x26, 0x23, 0xf4, 0xcf, 0x8e, 0x72, 0xd1, 0xd0, 0xfb, 0x4b, 0x38, 0x63, 0xba, + 0x13, 0xc5, 0x33, 0x58, 0x3c, 0x8e, 0x8f, 0x95, 0xc7, 0x95, 0x66, 0x89, 0xad, 0xc5, 0x6f, 0x61, + 0xa8, 0x71, 0x79, 0xce, 0x6e, 0x38, 0x45, 0x97, 0x70, 0x56, 0xa8, 0xf1, 0xf0, 0xa9, 0x13, 0xba, + 0xd1, 0x60, 0x31, 0x39, 0x85, 0x91, 0xd7, 0xc4, 0x96, 0xe1, 0x37, 0x30, 0xfc, 0x59, 0xa4, 0x82, + 0x56, 0xe6, 0x60, 0xc6, 0xe5, 0x54, 0xc7, 0x25, 0x5b, 0x16, 0x22, 0x53, 0xcd, 0xb9, 0x44, 0x1e, + 0xf1, 0xad, 0x79, 0x69, 0x45, 0xc5, 0xe0, 0x6b, 0x50, 0xf5, 0xb2, 0x9d, 0xda, 0x54, 0xa1, 0x57, + 0x75, 0xc9, 0xf3, 0xfa, 0x83, 0x6a, 0x63, 0x07, 0xcd, 0x0f, 0xe0, 0xdc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 0x65, 0x91, 0x9e, 0xb4, 0x5d, 0x97, 0x50, 0xef, 0xc1, 0x93, 0x9b, 0x42, 0x8d, 0x7b, + 0x6d, 0xd5, 0x55, 0x5d, 0x2e, 0xee, 0x5c, 0x3a, 0x88, 0x40, 0x50, 0xae, 0x0c, 0x85, 0x27, 0xac, + 0xb5, 0x0d, 0xcf, 0x9e, 0xfe, 0xa7, 0xa2, 0xaa, 0x52, 0xaf, 0xe9, 0x54, 0xe5, 0xd1, 0xae, 0x4f, + 0x55, 0x1e, 0x6f, 0x17, 0x77, 0x56, 0xbe, 0xfa, 0xd9, 0xbf, 0xf8, 0x17, 0x00, 0x00, 0xff, 0xff, + 0x18, 0xa5, 0x9b, 0x82, 0xfb, 0x05, 0x00, 0x00, } diff --git a/store/service/proto/store.pb.micro.go b/store/service/proto/store.pb.micro.go index 4cdba07f..2c5ca29f 100644 --- a/store/service/proto/store.pb.micro.go +++ b/store/service/proto/store.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: store/service/proto/store.proto +// source: store.proto package go_micro_store @@ -38,6 +38,8 @@ type StoreService interface { Write(ctx context.Context, in *WriteRequest, opts ...client.CallOption) (*WriteResponse, error) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (Store_ListService, error) + Databases(ctx context.Context, in *DatabasesRequest, opts ...client.CallOption) (*DatabasesResponse, error) + Tables(ctx context.Context, in *TablesRequest, opts ...client.CallOption) (*TablesResponse, error) } type storeService struct { @@ -131,6 +133,26 @@ func (x *storeServiceList) Recv() (*ListResponse, error) { return m, nil } +func (c *storeService) Databases(ctx context.Context, in *DatabasesRequest, opts ...client.CallOption) (*DatabasesResponse, error) { + req := c.c.NewRequest(c.name, "Store.Databases", in) + out := new(DatabasesResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *storeService) Tables(ctx context.Context, in *TablesRequest, opts ...client.CallOption) (*TablesResponse, error) { + req := c.c.NewRequest(c.name, "Store.Tables", in) + out := new(TablesResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for Store service type StoreHandler interface { @@ -138,6 +160,8 @@ type StoreHandler interface { Write(context.Context, *WriteRequest, *WriteResponse) error Delete(context.Context, *DeleteRequest, *DeleteResponse) error List(context.Context, *ListRequest, Store_ListStream) error + Databases(context.Context, *DatabasesRequest, *DatabasesResponse) error + Tables(context.Context, *TablesRequest, *TablesResponse) error } func RegisterStoreHandler(s server.Server, hdlr StoreHandler, opts ...server.HandlerOption) error { @@ -146,6 +170,8 @@ func RegisterStoreHandler(s server.Server, hdlr StoreHandler, opts ...server.Han Write(ctx context.Context, in *WriteRequest, out *WriteResponse) error Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error List(ctx context.Context, stream server.Stream) error + Databases(ctx context.Context, in *DatabasesRequest, out *DatabasesResponse) error + Tables(ctx context.Context, in *TablesRequest, out *TablesResponse) error } type Store struct { store @@ -209,3 +235,11 @@ func (x *storeListStream) RecvMsg(m interface{}) error { func (x *storeListStream) Send(m *ListResponse) error { return x.stream.Send(m) } + +func (h *storeHandler) Databases(ctx context.Context, in *DatabasesRequest, out *DatabasesResponse) error { + return h.StoreHandler.Databases(ctx, in, out) +} + +func (h *storeHandler) Tables(ctx context.Context, in *TablesRequest, out *TablesResponse) error { + return h.StoreHandler.Tables(ctx, in, out) +} diff --git a/store/service/proto/store.proto b/store/service/proto/store.proto index a6462ad2..460cf049 100644 --- a/store/service/proto/store.proto +++ b/store/service/proto/store.proto @@ -7,6 +7,8 @@ service Store { rpc Write(WriteRequest) returns (WriteResponse) {}; rpc Delete(DeleteRequest) returns (DeleteResponse) {}; rpc List(ListRequest) returns (stream ListResponse) {}; + rpc Databases(DatabasesRequest) returns (DatabasesResponse) {}; + rpc Tables(TablesRequest) returns (TablesResponse) {}; } message Record { @@ -72,3 +74,17 @@ message ListResponse { reserved 1; //repeated Record records = 1; repeated string keys = 2; } + +message DatabasesRequest {} + +message DatabasesResponse { + repeated string databases = 1; +} + +message TablesRequest { + string database = 1; +} + +message TablesResponse { + repeated string tables = 1; +} From 53549b6b3089fc23345262036510300fd1e3b141 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 9 Apr 2020 17:56:13 +0100 Subject: [PATCH 587/788] Add options for Database/Table (#1516) * Add options for Database/Table * fix opts --- store/options.go | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/store/options.go b/store/options.go index 01d60c80..27224731 100644 --- a/store/options.go +++ b/store/options.go @@ -54,6 +54,7 @@ func WithContext(c context.Context) Option { // ReadOptions configures an individual Read operation type ReadOptions struct { + Database, Table string // Prefix returns all records that are prefixed with key Prefix bool // Suffix returns all records that have the suffix key @@ -67,6 +68,14 @@ type ReadOptions struct { // ReadOption sets values in ReadOptions type ReadOption func(r *ReadOptions) +// ReadFrom the database and table +func ReadFrom(database, table string) ReadOption { + return func(r *ReadOptions) { + r.Database = database + r.Table = table + } +} + // ReadPrefix returns all records that are prefixed with key func ReadPrefix() ReadOption { return func(r *ReadOptions) { @@ -98,6 +107,7 @@ func ReadOffset(o uint) ReadOption { // WriteOptions configures an individual Write operation // If Expiry and TTL are set TTL takes precedence type WriteOptions struct { + Database, Table string // Expiry is the time the record expires Expiry time.Time // TTL is the time until the record expires @@ -107,6 +117,14 @@ type WriteOptions struct { // WriteOption sets values in WriteOptions type WriteOption func(w *WriteOptions) +// WriteTo the database and table +func WriteTo(database, table string) WriteOption { + return func(w *WriteOptions) { + w.Database = database + w.Table = table + } +} + // WriteExpiry is the time the record expires func WriteExpiry(t time.Time) WriteOption { return func(w *WriteOptions) { @@ -122,13 +140,25 @@ func WriteTTL(d time.Duration) WriteOption { } // DeleteOptions configures an individual Delete operation -type DeleteOptions struct{} +type DeleteOptions struct { + Database, Table string +} // DeleteOption sets values in DeleteOptions type DeleteOption func(d *DeleteOptions) +// DeleteFrom the database and table +func DeleteFrom(database, table string) DeleteOption { + return func(d *DeleteOptions) { + d.Database = database + d.Table = table + } +} + // ListOptions configures an individual List operation type ListOptions struct { + // List from the following + Database, Table string // Prefix returns all keys that are prefixed with key Prefix string // Suffix returns all keys that end with key @@ -142,6 +172,14 @@ type ListOptions struct { // ListOption sets values in ListOptions type ListOption func(l *ListOptions) +// ListFrom the database and table +func ListFrom(database, table string) ListOption { + return func(l *ListOptions) { + l.Database = database + l.Table = table + } +} + // ListPrefix returns all keys that are prefixed with key func ListPrefix(p string) ListOption { return func(l *ListOptions) { From 6a666c9c7db871c0b88152ad5a84e9f4a92a845c Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Thu, 9 Apr 2020 19:38:43 +0100 Subject: [PATCH 588/788] Add json tags to store.Record (#1518) --- store/store.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/store/store.go b/store/store.go index d073f4e1..c949f939 100644 --- a/store/store.go +++ b/store/store.go @@ -36,7 +36,7 @@ type Store interface { // Record is an item stored or retrieved from a Store type Record struct { - Key string - Value []byte - Expiry time.Duration + Key string `json:"key"` + Value []byte `json:"value"` + Expiry time.Duration `json:"expiry,omitempty"` } From 9a685b2df5ef441fd3d0fd4dadd2b6bb6c9d3393 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Apr 2020 17:15:20 +0100 Subject: [PATCH 589/788] delete k8s registry (#1522) --- config/cmd/cmd.go | 10 +- registry/kubernetes/README.md | 66 ------- registry/kubernetes/kubernetes.go | 289 ------------------------------ registry/kubernetes/watcher.go | 263 --------------------------- 4 files changed, 4 insertions(+), 624 deletions(-) delete mode 100644 registry/kubernetes/README.md delete mode 100644 registry/kubernetes/kubernetes.go delete mode 100644 registry/kubernetes/watcher.go diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 674affba..44071b71 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -42,7 +42,6 @@ import ( // registries "github.com/micro/go-micro/v2/registry/etcd" - kreg "github.com/micro/go-micro/v2/registry/kubernetes" "github.com/micro/go-micro/v2/registry/mdns" rmem "github.com/micro/go-micro/v2/registry/memory" regSrv "github.com/micro/go-micro/v2/registry/service" @@ -328,11 +327,10 @@ var ( } DefaultRegistries = map[string]func(...registry.Option) registry.Registry{ - "service": regSrv.NewRegistry, - "etcd": etcd.NewRegistry, - "mdns": mdns.NewRegistry, - "memory": rmem.NewRegistry, - "kubernetes": kreg.NewRegistry, + "service": regSrv.NewRegistry, + "etcd": etcd.NewRegistry, + "mdns": mdns.NewRegistry, + "memory": rmem.NewRegistry, } DefaultSelectors = map[string]func(...selector.Option) selector.Selector{ diff --git a/registry/kubernetes/README.md b/registry/kubernetes/README.md deleted file mode 100644 index 80282db4..00000000 --- a/registry/kubernetes/README.md +++ /dev/null @@ -1,66 +0,0 @@ -# Kubernetes Registry Plugin for micro -This is a plugin for go-micro that allows you to use Kubernetes as a registry. - - -## Overview -This registry plugin makes use of Annotations and Labels on a Kubernetes pod -to build a service discovery mechanism. - - -## RBAC -If your Kubernetes cluster has RBAC enabled, a role and role binding -will need to be created to allow this plugin to `list` and `patch` pods. - -A cluster role can be used to specify the `list` and `patch` -requirements, while a role binding per namespace can be used to apply -the cluster role. The example RBAC configs below assume your Micro-based -services are running in the `test` namespace, and the pods that contain -the services are using the `micro-services` service account. - -``` -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: micro-registry -rules: -- apiGroups: - - "" - resources: - - pods - verbs: - - list - - patch - - watch -``` - -``` -apiVersion: rbac.authorization.k8s.io/v1 -kind: RoleBinding -metadata: - name: micro-registry -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: micro-registry -subjects: -- kind: ServiceAccount - name: micro-services - namespace: test -``` - - -## Gotchas -* Registering/Deregistering relies on the HOSTNAME Environment Variable, which inside a pod -is the place where it can be retrieved from. (This needs improving) - - -## Connecting to the Kubernetes API -### Within a pod -If the `--registry_address` flag is omitted, the plugin will securely connect to -the Kubernetes API using the pods "Service Account". No extra configuration is necessary. - -Find out more about service accounts here. http://kubernetes.io/docs/user-guide/accessing-the-cluster/ - -### Outside of Kubernetes -Some functions of the plugin should work, but its not been heavily tested. -Currently no TLS support. diff --git a/registry/kubernetes/kubernetes.go b/registry/kubernetes/kubernetes.go deleted file mode 100644 index 81719376..00000000 --- a/registry/kubernetes/kubernetes.go +++ /dev/null @@ -1,289 +0,0 @@ -// Package kubernetes provides a kubernetes registry -package kubernetes - -import ( - "encoding/json" - "errors" - "fmt" - "os" - "regexp" - "strings" - "time" - - "github.com/micro/go-micro/v2/registry" - "github.com/micro/go-micro/v2/util/kubernetes/client" -) - -type kregistry struct { - client client.Client - timeout time.Duration - options registry.Options -} - -var ( - // used on pods as labels & services to select - // eg: svcSelectorPrefix+"svc.name" - servicePrefix = "go.micro/" - serviceValue = "service" - - labelTypeKey = "micro" - labelTypeValue = "service" - - // used on k8s services to scope a serialised - // micro service by pod name - annotationPrefix = "go.micro/" - - // Pod status - podRunning = "Running" - - // label name regex - labelRe = regexp.MustCompilePOSIX("[-A-Za-z0-9_.]") -) - -// podSelector -var podSelector = map[string]string{ - labelTypeKey: labelTypeValue, -} - -func configure(k *kregistry, opts ...registry.Option) error { - for _, o := range opts { - o(&k.options) - } - - // get first host - var host string - if len(k.options.Addrs) > 0 && len(k.options.Addrs[0]) > 0 { - host = k.options.Addrs[0] - } - - if k.options.Timeout == 0 { - k.options.Timeout = time.Second * 1 - } - - // if no hosts setup, assume InCluster - var c client.Client - - if len(host) > 0 { - c = client.NewLocalClient(host) - } else { - c = client.NewClusterClient() - } - - k.client = c - k.timeout = k.options.Timeout - - return nil -} - -// serviceName generates a valid service name for k8s labels -func serviceName(name string) string { - aname := make([]byte, len(name)) - - for i, r := range []byte(name) { - if !labelRe.Match([]byte{r}) { - aname[i] = '_' - continue - } - aname[i] = r - } - - return string(aname) -} - -// Init allows reconfig of options -func (c *kregistry) Init(opts ...registry.Option) error { - return configure(c, opts...) -} - -// Options returns the registry Options -func (c *kregistry) Options() registry.Options { - return c.options -} - -// Register sets a service selector label and an annotation with a -// serialised version of the service passed in. -func (c *kregistry) Register(s *registry.Service, opts ...registry.RegisterOption) error { - if len(s.Nodes) == 0 { - return errors.New("no nodes") - } - - // TODO: grab podname from somewhere better than this. - podName := os.Getenv("HOSTNAME") - svcName := s.Name - - // encode micro service - b, err := json.Marshal(s) - if err != nil { - return err - } - /// marshalled service - svc := string(b) - - pod := &client.Pod{ - Metadata: &client.Metadata{ - Labels: map[string]string{ - // micro: service - labelTypeKey: labelTypeValue, - // micro/service/name: service - servicePrefix + serviceName(svcName): serviceValue, - }, - Annotations: map[string]string{ - // micro/service/name: definition - annotationPrefix + serviceName(svcName): svc, - }, - }, - } - - return c.client.Update(&client.Resource{ - Name: podName, - Kind: "pod", - Value: pod, - }) -} - -// Deregister nils out any things set in Register -func (c *kregistry) Deregister(s *registry.Service) error { - if len(s.Nodes) == 0 { - return errors.New("you must deregister at least one node") - } - - // TODO: grab podname from somewhere better than this. - podName := os.Getenv("HOSTNAME") - svcName := s.Name - - pod := &client.Pod{ - Metadata: &client.Metadata{ - Labels: map[string]string{ - servicePrefix + serviceName(svcName): "", - }, - Annotations: map[string]string{ - annotationPrefix + serviceName(svcName): "", - }, - }, - } - - return c.client.Update(&client.Resource{ - Name: podName, - Kind: "pod", - Value: pod, - }) -} - -// GetService will get all the pods with the given service selector, -// and build services from the annotations. -func (c *kregistry) GetService(name string) ([]*registry.Service, error) { - var pods client.PodList - - if err := c.client.Get(&client.Resource{ - Kind: "pod", - Value: &pods, - }, map[string]string{ - servicePrefix + serviceName(name): serviceValue, - }); err != nil { - return nil, err - } - - if len(pods.Items) == 0 { - return nil, registry.ErrNotFound - } - - // svcs mapped by version - svcs := make(map[string]*registry.Service) - - // loop through items - for _, pod := range pods.Items { - if pod.Status.Phase != podRunning { - continue - } - - // get serialised service from annotation - svcStr, ok := pod.Metadata.Annotations[annotationPrefix+serviceName(name)] - if !ok { - continue - } - - // unmarshal service string - var svc registry.Service - - if err := json.Unmarshal([]byte(svcStr), &svc); err != nil { - return nil, fmt.Errorf("could not unmarshal service '%s' from pod annotation", name) - } - - // merge up pod service & ip with versioned service. - vs, ok := svcs[svc.Version] - if !ok { - svcs[svc.Version] = &svc - continue - } - - vs.Nodes = append(vs.Nodes, svc.Nodes...) - } - - list := make([]*registry.Service, 0, len(svcs)) - for _, val := range svcs { - list = append(list, val) - } - return list, nil -} - -// ListServices will list all the service names -func (c *kregistry) ListServices() ([]*registry.Service, error) { - var pods client.PodList - - if err := c.client.Get(&client.Resource{ - Kind: "pod", - Value: &pods, - }, podSelector); err != nil { - return nil, err - } - - // svcs mapped by name - svcs := make(map[string]bool) - - for _, pod := range pods.Items { - if pod.Status.Phase != podRunning { - continue - } - for k, v := range pod.Metadata.Annotations { - if !strings.HasPrefix(k, annotationPrefix) { - continue - } - - // we have to unmarshal the annotation itself since the - // key is encoded to match the regex restriction. - var svc registry.Service - - if err := json.Unmarshal([]byte(v), &svc); err != nil { - continue - } - - svcs[svc.Name] = true - } - } - - var list []*registry.Service - - for val := range svcs { - list = append(list, ®istry.Service{Name: val}) - } - - return list, nil -} - -// Watch returns a kubernetes watcher -func (c *kregistry) Watch(opts ...registry.WatchOption) (registry.Watcher, error) { - return newWatcher(c, opts...) -} - -func (c *kregistry) String() string { - return "kubernetes" -} - -// NewRegistry creates a kubernetes registry -func NewRegistry(opts ...registry.Option) registry.Registry { - k := &kregistry{ - options: registry.Options{}, - } - configure(k, opts...) - return k -} diff --git a/registry/kubernetes/watcher.go b/registry/kubernetes/watcher.go deleted file mode 100644 index 89bffed6..00000000 --- a/registry/kubernetes/watcher.go +++ /dev/null @@ -1,263 +0,0 @@ -package kubernetes - -import ( - "encoding/json" - "errors" - "strings" - "sync" - - "github.com/micro/go-micro/v2/logger" - "github.com/micro/go-micro/v2/registry" - "github.com/micro/go-micro/v2/util/kubernetes/client" -) - -type k8sWatcher struct { - registry *kregistry - watcher client.Watcher - next chan *registry.Result - stop chan bool - - sync.RWMutex - pods map[string]*client.Pod -} - -// build a cache of pods when the watcher starts. -func (k *k8sWatcher) updateCache() ([]*registry.Result, error) { - var pods client.PodList - - if err := k.registry.client.Get(&client.Resource{ - Kind: "pod", - Value: &pods, - }, podSelector); err != nil { - return nil, err - } - - var results []*registry.Result - - for _, pod := range pods.Items { - rslts := k.buildPodResults(&pod, nil) - - for _, r := range rslts { - results = append(results, r) - } - - k.Lock() - k.pods[pod.Metadata.Name] = &pod - k.Unlock() - } - - return results, nil -} - -// look through pod annotations, compare against cache if present -// and return a list of results to send down the wire. -func (k *k8sWatcher) buildPodResults(pod *client.Pod, cache *client.Pod) []*registry.Result { - var results []*registry.Result - ignore := make(map[string]bool) - - if pod.Metadata != nil { - for ak, av := range pod.Metadata.Annotations { - // check this annotation kv is a service notation - if !strings.HasPrefix(ak, annotationPrefix) { - continue - } - - if len(av) == 0 { - continue - } - - // ignore when we check the cached annotations - // as we take care of it here - ignore[ak] = true - - // compare aginst cache. - var cacheExists bool - var cav string - - if cache != nil && cache.Metadata != nil { - cav, cacheExists = cache.Metadata.Annotations[ak] - if cacheExists && len(cav) > 0 && cav == av { - // service notation exists and is identical - - // no change result required. - continue - } - } - - rslt := ®istry.Result{} - if cacheExists { - rslt.Action = "update" - } else { - rslt.Action = "create" - } - - // unmarshal service notation from annotation value - err := json.Unmarshal([]byte(av), &rslt.Service) - if err != nil { - continue - } - - results = append(results, rslt) - } - } - - // loop through cache annotations to find services - // not accounted for above, and "delete" them. - if cache != nil && cache.Metadata != nil { - for ak, av := range cache.Metadata.Annotations { - if ignore[ak] { - continue - } - - // check this annotation kv is a service notation - if !strings.HasPrefix(ak, annotationPrefix) { - continue - } - - rslt := ®istry.Result{Action: "delete"} - // unmarshal service notation from annotation value - err := json.Unmarshal([]byte(av), &rslt.Service) - if err != nil { - continue - } - - results = append(results, rslt) - } - } - - return results -} - -// handleEvent will taken an event from the k8s pods API and do the correct -// things with the result, based on the local cache. -func (k *k8sWatcher) handleEvent(event client.Event) { - var pod client.Pod - if err := json.Unmarshal([]byte(event.Object), &pod); err != nil { - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Info("K8s Watcher: Couldnt unmarshal event object from pod") - } - return - } - - switch event.Type { - case client.Modified: - // Pod was modified - - k.RLock() - cache := k.pods[pod.Metadata.Name] - k.RUnlock() - - // service could have been added, edited or removed. - var results []*registry.Result - - if pod.Status.Phase == podRunning { - results = k.buildPodResults(&pod, cache) - } else { - // passing in cache might not return all results - results = k.buildPodResults(&pod, nil) - } - - for _, result := range results { - // pod isnt running - if pod.Status.Phase != podRunning { - result.Action = "delete" - } - - select { - case k.next <- result: - case <-k.stop: - return - } - } - - k.Lock() - k.pods[pod.Metadata.Name] = &pod - k.Unlock() - return - - case client.Deleted: - // Pod was deleted - // passing in cache might not return all results - results := k.buildPodResults(&pod, nil) - - for _, result := range results { - result.Action = "delete" - select { - case k.next <- result: - case <-k.stop: - return - } - } - - k.Lock() - delete(k.pods, pod.Metadata.Name) - k.Unlock() - return - } - -} - -// Next will block until a new result comes in -func (k *k8sWatcher) Next() (*registry.Result, error) { - select { - case r := <-k.next: - return r, nil - case <-k.stop: - return nil, errors.New("watcher stopped") - } -} - -// Stop will cancel any requests, and close channels -func (k *k8sWatcher) Stop() { - select { - case <-k.stop: - return - default: - k.watcher.Stop() - close(k.stop) - } -} - -func newWatcher(kr *kregistry, opts ...registry.WatchOption) (registry.Watcher, error) { - var wo registry.WatchOptions - for _, o := range opts { - o(&wo) - } - - selector := podSelector - if len(wo.Service) > 0 { - selector = map[string]string{ - servicePrefix + serviceName(wo.Service): serviceValue, - } - } - - // Create watch request - watcher, err := kr.client.Watch(&client.Resource{ - Kind: "pod", - }, client.WatchParams(selector)) - if err != nil { - return nil, err - } - - k := &k8sWatcher{ - registry: kr, - watcher: watcher, - next: make(chan *registry.Result), - stop: make(chan bool), - pods: make(map[string]*client.Pod), - } - - // update cache, but dont emit changes - if _, err := k.updateCache(); err != nil { - return nil, err - } - - // range over watch request changes, and invoke - // the update event - go func() { - for event := range watcher.Chan() { - k.handleEvent(event) - } - }() - - return k, nil -} From d134b469be6a2e8a060e40dcfa4a0b83a485fa58 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Apr 2020 17:17:24 +0100 Subject: [PATCH 590/788] rename file --- registry/{watcher_test.go => mdns_watcher_test.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename registry/{watcher_test.go => mdns_watcher_test.go} (100%) diff --git a/registry/watcher_test.go b/registry/mdns_watcher_test.go similarity index 100% rename from registry/watcher_test.go rename to registry/mdns_watcher_test.go From 4fd12430d0f6c280bd1ed1233e6d4975983dbbbe Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Apr 2020 17:19:26 +0100 Subject: [PATCH 591/788] cleanup mdns files --- registry/encoding.go | 73 --------------------------------------- registry/encoding_test.go | 65 ---------------------------------- registry/mdns_registry.go | 67 +++++++++++++++++++++++++++++++++++ registry/mdns_test.go | 60 ++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 138 deletions(-) delete mode 100644 registry/encoding.go delete mode 100644 registry/encoding_test.go diff --git a/registry/encoding.go b/registry/encoding.go deleted file mode 100644 index 750f88f8..00000000 --- a/registry/encoding.go +++ /dev/null @@ -1,73 +0,0 @@ -package registry - -import ( - "bytes" - "compress/zlib" - "encoding/hex" - "encoding/json" - "io/ioutil" - "strings" -) - -func encode(txt *mdnsTxt) ([]string, error) { - b, err := json.Marshal(txt) - if err != nil { - return nil, err - } - - var buf bytes.Buffer - defer buf.Reset() - - w := zlib.NewWriter(&buf) - if _, err := w.Write(b); err != nil { - return nil, err - } - w.Close() - - encoded := hex.EncodeToString(buf.Bytes()) - - // individual txt limit - if len(encoded) <= 255 { - return []string{encoded}, nil - } - - // split encoded string - var record []string - - for len(encoded) > 255 { - record = append(record, encoded[:255]) - encoded = encoded[255:] - } - - record = append(record, encoded) - - return record, nil -} - -func decode(record []string) (*mdnsTxt, error) { - encoded := strings.Join(record, "") - - hr, err := hex.DecodeString(encoded) - if err != nil { - return nil, err - } - - br := bytes.NewReader(hr) - zr, err := zlib.NewReader(br) - if err != nil { - return nil, err - } - - rbuf, err := ioutil.ReadAll(zr) - if err != nil { - return nil, err - } - - var txt *mdnsTxt - - if err := json.Unmarshal(rbuf, &txt); err != nil { - return nil, err - } - - return txt, nil -} diff --git a/registry/encoding_test.go b/registry/encoding_test.go deleted file mode 100644 index ff9ae97e..00000000 --- a/registry/encoding_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package registry - -import ( - "testing" -) - -func TestEncoding(t *testing.T) { - testData := []*mdnsTxt{ - { - Version: "1.0.0", - Metadata: map[string]string{ - "foo": "bar", - }, - Endpoints: []*Endpoint{ - { - Name: "endpoint1", - Request: &Value{ - Name: "request", - Type: "request", - }, - Response: &Value{ - Name: "response", - Type: "response", - }, - Metadata: map[string]string{ - "foo1": "bar1", - }, - }, - }, - }, - } - - for _, d := range testData { - encoded, err := encode(d) - if err != nil { - t.Fatal(err) - } - - for _, txt := range encoded { - if len(txt) > 255 { - t.Fatalf("One of parts for txt is %d characters", len(txt)) - } - } - - decoded, err := decode(encoded) - if err != nil { - t.Fatal(err) - } - - if decoded.Version != d.Version { - t.Fatalf("Expected version %s got %s", d.Version, decoded.Version) - } - - if len(decoded.Endpoints) != len(d.Endpoints) { - t.Fatalf("Expected %d endpoints, got %d", len(d.Endpoints), len(decoded.Endpoints)) - } - - for k, v := range d.Metadata { - if val := decoded.Metadata[k]; val != v { - t.Fatalf("Expected %s=%s got %s=%s", k, v, k, val) - } - } - } - -} diff --git a/registry/mdns_registry.go b/registry/mdns_registry.go index 9dbca6de..7e614840 100644 --- a/registry/mdns_registry.go +++ b/registry/mdns_registry.go @@ -2,8 +2,13 @@ package registry import ( + "bytes" + "compress/zlib" "context" + "encoding/hex" + "encoding/json" "fmt" + "io/ioutil" "net" "strconv" "strings" @@ -49,6 +54,68 @@ type mdnsRegistry struct { listener chan *mdns.ServiceEntry } +func encode(txt *mdnsTxt) ([]string, error) { + b, err := json.Marshal(txt) + if err != nil { + return nil, err + } + + var buf bytes.Buffer + defer buf.Reset() + + w := zlib.NewWriter(&buf) + if _, err := w.Write(b); err != nil { + return nil, err + } + w.Close() + + encoded := hex.EncodeToString(buf.Bytes()) + + // individual txt limit + if len(encoded) <= 255 { + return []string{encoded}, nil + } + + // split encoded string + var record []string + + for len(encoded) > 255 { + record = append(record, encoded[:255]) + encoded = encoded[255:] + } + + record = append(record, encoded) + + return record, nil +} + +func decode(record []string) (*mdnsTxt, error) { + encoded := strings.Join(record, "") + + hr, err := hex.DecodeString(encoded) + if err != nil { + return nil, err + } + + br := bytes.NewReader(hr) + zr, err := zlib.NewReader(br) + if err != nil { + return nil, err + } + + rbuf, err := ioutil.ReadAll(zr) + if err != nil { + return nil, err + } + + var txt *mdnsTxt + + if err := json.Unmarshal(rbuf, &txt); err != nil { + return nil, err + } + + return txt, nil +} func newRegistry(opts ...Option) Registry { options := Options{ Context: context.Background(), diff --git a/registry/mdns_test.go b/registry/mdns_test.go index a5630c67..c9979d5c 100644 --- a/registry/mdns_test.go +++ b/registry/mdns_test.go @@ -137,3 +137,63 @@ func TestMDNS(t *testing.T) { } } + +func TestEncoding(t *testing.T) { + testData := []*mdnsTxt{ + { + Version: "1.0.0", + Metadata: map[string]string{ + "foo": "bar", + }, + Endpoints: []*Endpoint{ + { + Name: "endpoint1", + Request: &Value{ + Name: "request", + Type: "request", + }, + Response: &Value{ + Name: "response", + Type: "response", + }, + Metadata: map[string]string{ + "foo1": "bar1", + }, + }, + }, + }, + } + + for _, d := range testData { + encoded, err := encode(d) + if err != nil { + t.Fatal(err) + } + + for _, txt := range encoded { + if len(txt) > 255 { + t.Fatalf("One of parts for txt is %d characters", len(txt)) + } + } + + decoded, err := decode(encoded) + if err != nil { + t.Fatal(err) + } + + if decoded.Version != d.Version { + t.Fatalf("Expected version %s got %s", d.Version, decoded.Version) + } + + if len(decoded.Endpoints) != len(d.Endpoints) { + t.Fatalf("Expected %d endpoints, got %d", len(d.Endpoints), len(decoded.Endpoints)) + } + + for k, v := range d.Metadata { + if val := decoded.Metadata[k]; val != v { + t.Fatalf("Expected %s=%s got %s=%s", k, v, k, val) + } + } + } + +} From e5268dd0a62a79787e60400e9d55467a6cabe4dc Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Apr 2020 17:41:10 +0100 Subject: [PATCH 592/788] move reg util to own package (#1523) * move reg util to own package * fix test * fix broken static router --- api/router/static/static.go | 3 +- registry/cache/cache.go | 5 +-- {registry => util/registry}/util.go | 44 +++++++++++++----------- {registry => util/registry}/util_test.go | 16 +++++---- 4 files changed, 38 insertions(+), 30 deletions(-) rename {registry => util/registry}/util.go (64%) rename {registry => util/registry}/util_test.go (77%) diff --git a/api/router/static/static.go b/api/router/static/static.go index 09271c7c..f868e52d 100644 --- a/api/router/static/static.go +++ b/api/router/static/static.go @@ -16,6 +16,7 @@ import ( "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" + util "github.com/micro/go-micro/v2/util/registry" ) type endpoint struct { @@ -164,7 +165,7 @@ func (r *staticRouter) Endpoint(req *http.Request) (*api.Service, error) { // hack for stream endpoint if ep.apiep.Stream { - svcs := registry.Copy(services) + svcs := util.Copy(services) for _, svc := range svcs { if len(svc.Endpoints) == 0 { e := ®istry.Endpoint{} diff --git a/registry/cache/cache.go b/registry/cache/cache.go index eb12d16d..7714f980 100644 --- a/registry/cache/cache.go +++ b/registry/cache/cache.go @@ -9,6 +9,7 @@ import ( "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" + util "github.com/micro/go-micro/v2/util/registry" ) // Cache is the registry cache interface @@ -119,7 +120,7 @@ func (c *cache) get(service string) ([]*registry.Service, error) { // get cache ttl ttl := c.ttls[service] // make a copy - cp := registry.Copy(services) + cp := util.Copy(services) // got services && within ttl so return cache if c.isValid(cp, ttl) { @@ -152,7 +153,7 @@ func (c *cache) get(service string) ([]*registry.Service, error) { // cache results c.Lock() - c.set(service, registry.Copy(services)) + c.set(service, util.Copy(services)) c.Unlock() return services, nil diff --git a/registry/util.go b/util/registry/util.go similarity index 64% rename from registry/util.go rename to util/registry/util.go index 729d3ca8..140faedd 100644 --- a/registry/util.go +++ b/util/registry/util.go @@ -1,7 +1,11 @@ package registry -func addNodes(old, neu []*Node) []*Node { - nodes := make([]*Node, len(neu)) +import ( + "github.com/micro/go-micro/v2/registry" +) + +func addNodes(old, neu []*registry.Node) []*registry.Node { + nodes := make([]*registry.Node, len(neu)) // add all new nodes for i, n := range neu { node := *n @@ -31,8 +35,8 @@ func addNodes(old, neu []*Node) []*Node { return nodes } -func delNodes(old, del []*Node) []*Node { - var nodes []*Node +func delNodes(old, del []*registry.Node) []*registry.Node { + var nodes []*registry.Node for _, o := range old { var rem bool for _, n := range del { @@ -49,24 +53,24 @@ func delNodes(old, del []*Node) []*Node { } // CopyService make a copy of service -func CopyService(service *Service) *Service { +func CopyService(service *registry.Service) *registry.Service { // copy service - s := new(Service) + s := new(registry.Service) *s = *service // copy nodes - nodes := make([]*Node, len(service.Nodes)) + nodes := make([]*registry.Node, len(service.Nodes)) for j, node := range service.Nodes { - n := new(Node) + n := new(registry.Node) *n = *node nodes[j] = n } s.Nodes = nodes // copy endpoints - eps := make([]*Endpoint, len(service.Endpoints)) + eps := make([]*registry.Endpoint, len(service.Endpoints)) for j, ep := range service.Endpoints { - e := new(Endpoint) + e := new(registry.Endpoint) *e = *ep eps[j] = e } @@ -75,8 +79,8 @@ func CopyService(service *Service) *Service { } // Copy makes a copy of services -func Copy(current []*Service) []*Service { - services := make([]*Service, len(current)) +func Copy(current []*registry.Service) []*registry.Service { + services := make([]*registry.Service, len(current)) for i, service := range current { services[i] = CopyService(service) } @@ -84,14 +88,14 @@ func Copy(current []*Service) []*Service { } // Merge merges two lists of services and returns a new copy -func Merge(olist []*Service, nlist []*Service) []*Service { - var srv []*Service +func Merge(olist []*registry.Service, nlist []*registry.Service) []*registry.Service { + var srv []*registry.Service for _, n := range nlist { var seen bool for _, o := range olist { if o.Version == n.Version { - sp := new(Service) + sp := new(registry.Service) // make copy *sp = *o // set nodes @@ -102,25 +106,25 @@ func Merge(olist []*Service, nlist []*Service) []*Service { srv = append(srv, sp) break } else { - sp := new(Service) + sp := new(registry.Service) // make copy *sp = *o srv = append(srv, sp) } } if !seen { - srv = append(srv, Copy([]*Service{n})...) + srv = append(srv, Copy([]*registry.Service{n})...) } } return srv } // Remove removes services and returns a new copy -func Remove(old, del []*Service) []*Service { - var services []*Service +func Remove(old, del []*registry.Service) []*registry.Service { + var services []*registry.Service for _, o := range old { - srv := new(Service) + srv := new(registry.Service) *srv = *o var rem bool diff --git a/registry/util_test.go b/util/registry/util_test.go similarity index 77% rename from registry/util_test.go rename to util/registry/util_test.go index e1a6e9a0..740ab5b1 100644 --- a/registry/util_test.go +++ b/util/registry/util_test.go @@ -3,14 +3,16 @@ package registry import ( "os" "testing" + + "github.com/micro/go-micro/v2/registry" ) func TestRemove(t *testing.T) { - services := []*Service{ + services := []*registry.Service{ { Name: "foo", Version: "1.0.0", - Nodes: []*Node{ + Nodes: []*registry.Node{ { Id: "foo-123", Address: "localhost:9999", @@ -20,7 +22,7 @@ func TestRemove(t *testing.T) { { Name: "foo", Version: "1.0.0", - Nodes: []*Node{ + Nodes: []*registry.Node{ { Id: "foo-123", Address: "localhost:6666", @@ -29,7 +31,7 @@ func TestRemove(t *testing.T) { }, } - servs := Remove([]*Service{services[0]}, []*Service{services[1]}) + servs := Remove([]*registry.Service{services[0]}, []*registry.Service{services[1]}) if i := len(servs); i > 0 { t.Errorf("Expected 0 nodes, got %d: %+v", i, servs) } @@ -39,11 +41,11 @@ func TestRemove(t *testing.T) { } func TestRemoveNodes(t *testing.T) { - services := []*Service{ + services := []*registry.Service{ { Name: "foo", Version: "1.0.0", - Nodes: []*Node{ + Nodes: []*registry.Node{ { Id: "foo-123", Address: "localhost:9999", @@ -57,7 +59,7 @@ func TestRemoveNodes(t *testing.T) { { Name: "foo", Version: "1.0.0", - Nodes: []*Node{ + Nodes: []*registry.Node{ { Id: "foo-123", Address: "localhost:6666", From 57853b2849aa484d72e91a9522563f3fa1a2ef7e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Apr 2020 17:43:02 +0100 Subject: [PATCH 593/788] remove etcd store --- store/etcd/config.go | 178 -------------------------- store/etcd/etcd.go | 272 ---------------------------------------- store/etcd/etcd_test.go | 225 --------------------------------- 3 files changed, 675 deletions(-) delete mode 100644 store/etcd/config.go delete mode 100644 store/etcd/etcd.go delete mode 100644 store/etcd/etcd_test.go diff --git a/store/etcd/config.go b/store/etcd/config.go deleted file mode 100644 index eb79cea1..00000000 --- a/store/etcd/config.go +++ /dev/null @@ -1,178 +0,0 @@ -package etcd - -import ( - "context" - cryptotls "crypto/tls" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/micro/go-micro/v2/store" - "google.golang.org/grpc" -) - -// Implement all the options from https://pkg.go.dev/github.com/coreos/etcd/clientv3?tab=doc#Config -// Need to use non basic types in context.WithValue -type autoSyncInterval string -type dialTimeout string -type dialKeepAliveTime string -type dialKeepAliveTimeout string -type maxCallSendMsgSize string -type maxCallRecvMsgSize string -type tls string -type username string -type password string -type rejectOldCluster string -type dialOptions string -type clientContext string -type permitWithoutStream string - -// AutoSyncInterval is the interval to update endpoints with its latest members. -// 0 disables auto-sync. By default auto-sync is disabled. -func AutoSyncInterval(d time.Duration) store.Option { - return func(o *store.Options) { - o.Context = context.WithValue(o.Context, autoSyncInterval(""), d) - } -} - -// DialTimeout is the timeout for failing to establish a connection. -func DialTimeout(d time.Duration) store.Option { - return func(o *store.Options) { - o.Context = context.WithValue(o.Context, dialTimeout(""), d) - } -} - -// DialKeepAliveTime is the time after which client pings the server to see if -// transport is alive. -func DialKeepAliveTime(d time.Duration) store.Option { - return func(o *store.Options) { - o.Context = context.WithValue(o.Context, dialKeepAliveTime(""), d) - } -} - -// DialKeepAliveTimeout is the time that the client waits for a response for the -// keep-alive probe. If the response is not received in this time, the connection is closed. -func DialKeepAliveTimeout(d time.Duration) store.Option { - return func(o *store.Options) { - o.Context = context.WithValue(o.Context, dialKeepAliveTimeout(""), d) - } -} - -// MaxCallSendMsgSize is the client-side request send limit in bytes. -// If 0, it defaults to 2.0 MiB (2 * 1024 * 1024). -// Make sure that "MaxCallSendMsgSize" < server-side default send/recv limit. -// ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes"). -func MaxCallSendMsgSize(size int) store.Option { - return func(o *store.Options) { - o.Context = context.WithValue(o.Context, maxCallSendMsgSize(""), size) - } -} - -// MaxCallRecvMsgSize is the client-side response receive limit. -// If 0, it defaults to "math.MaxInt32", because range response can -// easily exceed request send limits. -// Make sure that "MaxCallRecvMsgSize" >= server-side default send/recv limit. -// ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes"). -func MaxCallRecvMsgSize(size int) store.Option { - return func(o *store.Options) { - o.Context = context.WithValue(o.Context, maxCallRecvMsgSize(""), size) - } -} - -// TLS holds the client secure credentials, if any. -func TLS(conf *cryptotls.Config) store.Option { - return func(o *store.Options) { - t := conf.Clone() - o.Context = context.WithValue(o.Context, tls(""), t) - } -} - -// Username is a user name for authentication. -func Username(u string) store.Option { - return func(o *store.Options) { - o.Context = context.WithValue(o.Context, username(""), u) - } -} - -// Password is a password for authentication. -func Password(p string) store.Option { - return func(o *store.Options) { - o.Context = context.WithValue(o.Context, password(""), p) - } -} - -// RejectOldCluster when set will refuse to create a client against an outdated cluster. -func RejectOldCluster(b bool) store.Option { - return func(o *store.Options) { - o.Context = context.WithValue(o.Context, rejectOldCluster(""), b) - } -} - -// DialOptions is a list of dial options for the grpc client (e.g., for interceptors). -// For example, pass "grpc.WithBlock()" to block until the underlying connection is up. -// Without this, Dial returns immediately and connecting the server happens in background. -func DialOptions(opts []grpc.DialOption) store.Option { - return func(o *store.Options) { - if len(opts) > 0 { - ops := make([]grpc.DialOption, len(opts)) - copy(ops, opts) - o.Context = context.WithValue(o.Context, dialOptions(""), ops) - } - } -} - -// ClientContext is the default etcd3 client context; it can be used to cancel grpc -// dial out andother operations that do not have an explicit context. -func ClientContext(ctx context.Context) store.Option { - return func(o *store.Options) { - o.Context = context.WithValue(o.Context, clientContext(""), ctx) - } -} - -// PermitWithoutStream when set will allow client to send keepalive pings to server without any active streams(RPCs). -func PermitWithoutStream(b bool) store.Option { - return func(o *store.Options) { - o.Context = context.WithValue(o.Context, permitWithoutStream(""), b) - } -} - -func (e *etcdStore) applyConfig(cfg *clientv3.Config) { - if v := e.options.Context.Value(autoSyncInterval("")); v != nil { - cfg.AutoSyncInterval = v.(time.Duration) - } - if v := e.options.Context.Value(dialTimeout("")); v != nil { - cfg.DialTimeout = v.(time.Duration) - } - if v := e.options.Context.Value(dialKeepAliveTime("")); v != nil { - cfg.DialKeepAliveTime = v.(time.Duration) - } - if v := e.options.Context.Value(dialKeepAliveTimeout("")); v != nil { - cfg.DialKeepAliveTimeout = v.(time.Duration) - } - if v := e.options.Context.Value(maxCallSendMsgSize("")); v != nil { - cfg.MaxCallSendMsgSize = v.(int) - } - if v := e.options.Context.Value(maxCallRecvMsgSize("")); v != nil { - cfg.MaxCallRecvMsgSize = v.(int) - } - if v := e.options.Context.Value(tls("")); v != nil { - cfg.TLS = v.(*cryptotls.Config) - } - if v := e.options.Context.Value(username("")); v != nil { - cfg.Username = v.(string) - } - if v := e.options.Context.Value(password("")); v != nil { - cfg.Username = v.(string) - } - if v := e.options.Context.Value(rejectOldCluster("")); v != nil { - cfg.RejectOldCluster = v.(bool) - } - if v := e.options.Context.Value(dialOptions("")); v != nil { - cfg.DialOptions = v.([]grpc.DialOption) - } - if v := e.options.Context.Value(clientContext("")); v != nil { - cfg.Context = v.(context.Context) - } - if v := e.options.Context.Value(permitWithoutStream("")); v != nil { - cfg.PermitWithoutStream = v.(bool) - } -} diff --git a/store/etcd/etcd.go b/store/etcd/etcd.go deleted file mode 100644 index d4d9cf97..00000000 --- a/store/etcd/etcd.go +++ /dev/null @@ -1,272 +0,0 @@ -// Package etcd implements a go-micro/v2/store with etcd -package etcd - -import ( - "bytes" - "context" - "encoding/gob" - "math" - "strings" - "time" - - "github.com/coreos/etcd/clientv3" - "github.com/coreos/etcd/clientv3/namespace" - "github.com/micro/go-micro/v2/store" - "github.com/pkg/errors" -) - -type etcdStore struct { - options store.Options - - client *clientv3.Client - config clientv3.Config -} - -// NewStore returns a new etcd store -func NewStore(opts ...store.Option) store.Store { - e := &etcdStore{} - for _, o := range opts { - o(&e.options) - } - e.init() - return e -} - -func (e *etcdStore) Close() error { - return e.client.Close() -} - -func (e *etcdStore) Init(opts ...store.Option) error { - for _, o := range opts { - o(&e.options) - } - return e.init() -} - -func (e *etcdStore) init() error { - // ensure context is non-nil - e.options.Context = context.Background() - // set up config - e.config = clientv3.Config{} - e.applyConfig(&e.config) - if len(e.options.Nodes) == 0 { - e.config.Endpoints = []string{"http://127.0.0.1:2379"} - } else { - e.config.Endpoints = make([]string, len(e.options.Nodes)) - copy(e.config.Endpoints, e.options.Nodes) - } - if e.client != nil { - e.client.Close() - } - client, err := clientv3.New(e.config) - if err != nil { - return err - } - e.client = client - ns := "" - if len(e.options.Table) > 0 { - ns = e.options.Table - } - if len(e.options.Database) > 0 { - ns = e.options.Database + "/" + ns - } - if len(ns) > 0 { - e.client.KV = namespace.NewKV(e.client.KV, ns) - e.client.Watcher = namespace.NewWatcher(e.client.Watcher, ns) - e.client.Lease = namespace.NewLease(e.client.Lease, ns) - } - - return nil -} - -func (e *etcdStore) Options() store.Options { - return e.options -} - -func (e *etcdStore) String() string { - return "etcd" -} - -func (e *etcdStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { - readOpts := store.ReadOptions{} - for _, o := range opts { - o(&readOpts) - } - if readOpts.Suffix { - return e.readSuffix(key, readOpts) - } - - var etcdOpts []clientv3.OpOption - if readOpts.Prefix { - etcdOpts = append(etcdOpts, clientv3.WithPrefix(), clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend)) - } - resp, err := e.client.KV.Get(context.Background(), key, etcdOpts...) - if err != nil { - return nil, err - } - if resp.Count == 0 && !(readOpts.Prefix || readOpts.Suffix) { - return nil, store.ErrNotFound - } - var records []*store.Record - for _, kv := range resp.Kvs { - ir := internalRecord{} - if err := gob.NewDecoder(bytes.NewReader(kv.Value)).Decode(&ir); err != nil { - return records, errors.Wrapf(err, "couldn't decode %s into internalRecord", err.Error()) - } - r := store.Record{ - Key: ir.Key, - Value: ir.Value, - } - if !ir.ExpiresAt.IsZero() { - r.Expiry = time.Until(ir.ExpiresAt) - } - records = append(records, &r) - } - if readOpts.Limit > 0 || readOpts.Offset > 0 { - return records[readOpts.Offset:min(readOpts.Limit, uint(len(records)))], nil - } - return records, nil -} - -func (e *etcdStore) readSuffix(key string, readOpts store.ReadOptions) ([]*store.Record, error) { - opts := []store.ListOption{store.ListSuffix(key)} - if readOpts.Prefix { - opts = append(opts, store.ListPrefix(key)) - } - keys, err := e.List(opts...) - if err != nil { - return nil, errors.Wrapf(err, "Couldn't list with suffix %s", key) - } - var records []*store.Record - for _, k := range keys { - resp, err := e.client.KV.Get(context.Background(), k) - if err != nil { - return nil, errors.Wrapf(err, "Couldn't get key %s", k) - } - ir := internalRecord{} - if err := gob.NewDecoder(bytes.NewReader(resp.Kvs[0].Value)).Decode(&ir); err != nil { - return records, errors.Wrapf(err, "couldn't decode %s into internalRecord", err.Error()) - } - r := store.Record{ - Key: ir.Key, - Value: ir.Value, - } - if !ir.ExpiresAt.IsZero() { - r.Expiry = time.Until(ir.ExpiresAt) - } - records = append(records, &r) - - } - if readOpts.Limit > 0 || readOpts.Offset > 0 { - return records[readOpts.Offset:min(readOpts.Limit, uint(len(records)))], nil - } - return records, nil -} - -func (e *etcdStore) Write(r *store.Record, opts ...store.WriteOption) error { - options := store.WriteOptions{} - for _, o := range opts { - o(&options) - } - - if len(opts) > 0 { - // Copy the record before applying options, or the incoming record will be mutated - newRecord := store.Record{} - newRecord.Key = r.Key - newRecord.Value = make([]byte, len(r.Value)) - copy(newRecord.Value, r.Value) - newRecord.Expiry = r.Expiry - - if !options.Expiry.IsZero() { - newRecord.Expiry = time.Until(options.Expiry) - } - if options.TTL != 0 { - newRecord.Expiry = options.TTL - } - return e.write(&newRecord) - } - return e.write(r) -} - -func (e *etcdStore) write(r *store.Record) error { - var putOpts []clientv3.OpOption - ir := &internalRecord{} - ir.Key = r.Key - ir.Value = make([]byte, len(r.Value)) - copy(ir.Value, r.Value) - if r.Expiry != 0 { - ir.ExpiresAt = time.Now().Add(r.Expiry) - var leasexpiry int64 - if r.Expiry.Seconds() < 5.0 { - // minimum etcd lease is 5 seconds - leasexpiry = 5 - } else { - leasexpiry = int64(math.Ceil(r.Expiry.Seconds())) - } - lr, err := e.client.Lease.Grant(context.Background(), leasexpiry) - if err != nil { - return errors.Wrapf(err, "couldn't grant an etcd lease for %s", r.Key) - } - putOpts = append(putOpts, clientv3.WithLease(lr.ID)) - } - b := &bytes.Buffer{} - if err := gob.NewEncoder(b).Encode(ir); err != nil { - return errors.Wrapf(err, "couldn't encode %s", r.Key) - } - _, err := e.client.KV.Put(context.Background(), ir.Key, string(b.Bytes()), putOpts...) - return errors.Wrapf(err, "couldn't put key %s in to etcd", err) -} - -func (e *etcdStore) Delete(key string, opts ...store.DeleteOption) error { - options := store.DeleteOptions{} - for _, o := range opts { - o(&options) - } - _, err := e.client.KV.Delete(context.Background(), key) - return errors.Wrapf(err, "couldn't delete key %s", key) -} - -func (e *etcdStore) List(opts ...store.ListOption) ([]string, error) { - options := store.ListOptions{} - for _, o := range opts { - o(&options) - } - searchPrefix := "" - if len(options.Prefix) > 0 { - searchPrefix = options.Prefix - } - resp, err := e.client.KV.Get(context.Background(), searchPrefix, clientv3.WithPrefix(), clientv3.WithKeysOnly(), clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend)) - if err != nil { - return nil, errors.Wrap(err, "couldn't list, etcd get failed") - } - if len(options.Suffix) == 0 { - keys := make([]string, resp.Count) - for i, kv := range resp.Kvs { - keys[i] = string(kv.Key) - } - return keys, nil - } - keys := []string{} - for _, kv := range resp.Kvs { - if strings.HasSuffix(string(kv.Key), options.Suffix) { - keys = append(keys, string(kv.Key)) - } - } - if options.Limit > 0 || options.Offset > 0 { - return keys[options.Offset:min(options.Limit, uint(len(keys)))], nil - } - return keys, nil -} - -type internalRecord struct { - Key string - Value []byte - ExpiresAt time.Time -} - -func min(i, j uint) uint { - if i < j { - return i - } - return j -} diff --git a/store/etcd/etcd_test.go b/store/etcd/etcd_test.go deleted file mode 100644 index fade2fce..00000000 --- a/store/etcd/etcd_test.go +++ /dev/null @@ -1,225 +0,0 @@ -package etcd - -import ( - "fmt" - "testing" - "time" - - "github.com/kr/pretty" - "github.com/micro/go-micro/v2/store" -) - -func TestEtcd(t *testing.T) { - e := NewStore() - if err := e.Init(); err != nil { - t.Fatal(err) - } - //basictest(e, t) -} - -func basictest(s store.Store, t *testing.T) { - t.Logf("Testing store %s, with options %# v\n", s.String(), pretty.Formatter(s.Options())) - // Read and Write an expiring Record - if err := s.Write(&store.Record{ - Key: "Hello", - Value: []byte("World"), - Expiry: time.Second * 5, - }); err != nil { - t.Fatal(err) - } - if r, err := s.Read("Hello"); err != nil { - t.Fatal(err) - } else { - if len(r) != 1 { - t.Fatal("Read returned multiple records") - } - if r[0].Key != "Hello" { - t.Fatalf("Expected %s, got %s", "Hello", r[0].Key) - } - if string(r[0].Value) != "World" { - t.Fatalf("Expected %s, got %s", "World", r[0].Value) - } - } - time.Sleep(time.Second * 6) - if records, err := s.Read("Hello"); err != store.ErrNotFound { - t.Fatalf("Expected %# v, got %# v\nResults were %# v", store.ErrNotFound, err, pretty.Formatter(records)) - } - - // Write 3 records with various expiry and get with prefix - records := []*store.Record{ - &store.Record{ - Key: "foo", - Value: []byte("foofoo"), - }, - &store.Record{ - Key: "foobar", - Value: []byte("foobarfoobar"), - Expiry: time.Second * 5, - }, - &store.Record{ - Key: "foobarbaz", - Value: []byte("foobarbazfoobarbaz"), - Expiry: 2 * time.Second * 5, - }, - } - for _, r := range records { - if err := s.Write(r); err != nil { - t.Fatalf("Couldn't write k: %s, v: %# v (%s)", r.Key, pretty.Formatter(r.Value), err) - } - } - if results, err := s.Read("foo", store.ReadPrefix()); err != nil { - t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) - } else { - if len(results) != 3 { - t.Fatalf("Expected 3 items, got %d", len(results)) - } - } - time.Sleep(time.Second * 6) - if results, err := s.Read("foo", store.ReadPrefix()); err != nil { - t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) - } else { - if len(results) != 2 { - t.Fatalf("Expected 2 items, got %d", len(results)) - } - } - time.Sleep(time.Second * 5) - if results, err := s.Read("foo", store.ReadPrefix()); err != nil { - t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) - } else { - if len(results) != 1 { - t.Fatalf("Expected 1 item, got %d", len(results)) - } - } - if err := s.Delete("foo", func(d *store.DeleteOptions) {}); err != nil { - t.Fatalf("Delete failed (%v)", err) - } - if results, err := s.Read("foo", store.ReadPrefix()); err != nil { - t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) - } else { - if len(results) != 0 { - t.Fatalf("Expected 0 items, got %d (%# v)", len(results), pretty.Formatter(results)) - } - } - - // Write 3 records with various expiry and get with Suffix - records = []*store.Record{ - &store.Record{ - Key: "foo", - Value: []byte("foofoo"), - }, - &store.Record{ - Key: "barfoo", - Value: []byte("barfoobarfoo"), - Expiry: time.Second * 5, - }, - &store.Record{ - Key: "bazbarfoo", - Value: []byte("bazbarfoobazbarfoo"), - Expiry: 2 * time.Second * 5, - }, - } - for _, r := range records { - if err := s.Write(r); err != nil { - t.Fatalf("Couldn't write k: %s, v: %# v (%s)", r.Key, pretty.Formatter(r.Value), err) - } - } - if results, err := s.Read("foo", store.ReadSuffix()); err != nil { - t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) - } else { - if len(results) != 3 { - t.Fatalf("Expected 3 items, got %d", len(results)) - } - } - time.Sleep(time.Second * 6) - if results, err := s.Read("foo", store.ReadSuffix()); err != nil { - t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) - } else { - if len(results) != 2 { - t.Fatalf("Expected 2 items, got %d", len(results)) - } - t.Logf("Prefix test: %v\n", pretty.Formatter(results)) - } - time.Sleep(time.Second * 5) - if results, err := s.Read("foo", store.ReadSuffix()); err != nil { - t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) - } else { - if len(results) != 1 { - t.Fatalf("Expected 1 item, got %d", len(results)) - } - t.Logf("Prefix test: %# v\n", pretty.Formatter(results)) - } - if err := s.Delete("foo"); err != nil { - t.Fatalf("Delete failed (%v)", err) - } - if results, err := s.Read("foo", store.ReadSuffix()); err != nil { - t.Fatalf("Couldn't read all \"foo\" keys, got %# v (%s)", pretty.Formatter(results), err) - } else { - if len(results) != 0 { - t.Fatalf("Expected 0 items, got %d (%# v)", len(results), pretty.Formatter(results)) - } - } - - // Test Prefix, Suffix and WriteOptions - if err := s.Write(&store.Record{ - Key: "foofoobarbar", - Value: []byte("something"), - }, store.WriteTTL(time.Millisecond*100)); err != nil { - t.Fatal(err) - } - if err := s.Write(&store.Record{ - Key: "foofoo", - Value: []byte("something"), - }, store.WriteExpiry(time.Now().Add(time.Millisecond*100))); err != nil { - t.Fatal(err) - } - if err := s.Write(&store.Record{ - Key: "barbar", - Value: []byte("something"), - // TTL has higher precedence than expiry - }, store.WriteExpiry(time.Now().Add(time.Hour)), store.WriteTTL(time.Millisecond*100)); err != nil { - t.Fatal(err) - } - if results, err := s.Read("foo", store.ReadPrefix(), store.ReadSuffix()); err != nil { - t.Fatal(err) - } else { - if len(results) != 1 { - t.Fatalf("Expected 1 results, got %d: %# v", len(results), pretty.Formatter(results)) - } - } - time.Sleep(time.Second * 6) - if results, err := s.List(); err != nil { - t.Fatalf("List failed: %s", err) - } else { - if len(results) != 0 { - t.Fatal("Expiry options were not effective") - } - } - - s.Init() - for i := 0; i < 10; i++ { - s.Write(&store.Record{ - Key: fmt.Sprintf("a%d", i), - Value: []byte{}, - }) - } - if results, err := s.Read("a", store.ReadLimit(5), store.ReadPrefix()); err != nil { - t.Fatal(err) - } else { - if len(results) != 5 { - t.Fatal("Expected 5 results, got ", len(results)) - } - if results[0].Key != "a0" { - t.Fatalf("Expected a0, got %s", results[0].Key) - } - if results[4].Key != "a4" { - t.Fatalf("Expected a4, got %s", results[4].Key) - } - } - if results, err := s.Read("a", store.ReadLimit(30), store.ReadOffset(5), store.ReadPrefix()); err != nil { - t.Fatal(err) - } else { - if len(results) != 5 { - t.Fatal("Expected 5 results, got ", len(results)) - } - } -} From b9a5e9d61013b7bde33235903b1b379063e17de5 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Apr 2020 17:47:13 +0100 Subject: [PATCH 594/788] fixup sync map --- sync/map.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/sync/map.go b/sync/map.go index edfeb6a9..2196a4e0 100644 --- a/sync/map.go +++ b/sync/map.go @@ -8,8 +8,6 @@ import ( "sort" "github.com/micro/go-micro/v2/store" - ckv "github.com/micro/go-micro/v2/store/etcd" - lock "github.com/micro/go-micro/v2/sync/lock/etcd" ) type syncMap struct { @@ -152,14 +150,6 @@ func NewMap(opts ...Option) Map { o(&options) } - if options.Lock == nil { - options.Lock = lock.NewLock() - } - - if options.Store == nil { - options.Store = ckv.NewStore() - } - return &syncMap{ opts: options, } From d4b2c948ddecf921660f2a98aceae0e38784e042 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Apr 2020 19:50:57 +0100 Subject: [PATCH 595/788] Remove cloudflare store --- api/server/acme/certmagic/certmagic_test.go | 236 ----------- store/cloudflare/cloudflare.go | 411 -------------------- store/cloudflare/cloudflare_test.go | 95 ----- store/cloudflare/options.go | 64 --- 4 files changed, 806 deletions(-) delete mode 100644 api/server/acme/certmagic/certmagic_test.go delete mode 100644 store/cloudflare/cloudflare.go delete mode 100644 store/cloudflare/cloudflare_test.go delete mode 100644 store/cloudflare/options.go diff --git a/api/server/acme/certmagic/certmagic_test.go b/api/server/acme/certmagic/certmagic_test.go deleted file mode 100644 index 12893dfe..00000000 --- a/api/server/acme/certmagic/certmagic_test.go +++ /dev/null @@ -1,236 +0,0 @@ -package certmagic - -import ( - "net" - "net/http" - "os" - "reflect" - "sort" - "testing" - "time" - - "github.com/go-acme/lego/v3/providers/dns/cloudflare" - "github.com/mholt/certmagic" - "github.com/micro/go-micro/v2/api/server/acme" - cfstore "github.com/micro/go-micro/v2/store/cloudflare" - "github.com/micro/go-micro/v2/sync/lock/memory" -) - -func TestCertMagic(t *testing.T) { - if len(os.Getenv("IN_TRAVIS_CI")) != 0 { - t.Skip() - } - l, err := NewProvider().Listen() - if err != nil { - if _, ok := err.(*net.OpError); ok { - t.Skip("Run under non privileged user") - } - t.Fatal(err.Error()) - } - l.Close() - - c := cloudflare.NewDefaultConfig() - c.AuthEmail = "" - c.AuthKey = "" - c.AuthToken = "test" - c.ZoneToken = "test" - - p, err := cloudflare.NewDNSProviderConfig(c) - if err != nil { - t.Fatal(err.Error()) - } - - l, err = NewProvider(acme.AcceptToS(true), - acme.CA(acme.LetsEncryptStagingCA), - acme.ChallengeProvider(p), - ).Listen() - - if err != nil { - t.Fatal(err.Error()) - } - l.Close() -} - -func TestStorageImplementation(t *testing.T) { - if len(os.Getenv("IN_TRAVIS_CI")) != 0 { - t.Skip() - } - - apiToken, accountID := os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ACCOUNT_ID") - kvID := os.Getenv("KV_NAMESPACE_ID") - if len(apiToken) == 0 || len(accountID) == 0 || len(kvID) == 0 { - t.Skip("No Cloudflare API keys available, skipping test") - } - - var s certmagic.Storage - st := cfstore.NewStore( - cfstore.Token(apiToken), - cfstore.Account(accountID), - cfstore.Namespace(kvID), - ) - s = &storage{ - lock: memory.NewLock(), - store: st, - } - - // Test Lock - if err := s.Lock("test"); err != nil { - t.Fatal(err) - } - - // Test Unlock - if err := s.Unlock("test"); err != nil { - t.Fatal(err) - } - - // Test data - testdata := []struct { - key string - value []byte - }{ - {key: "/foo/a", value: []byte("lorem")}, - {key: "/foo/b", value: []byte("ipsum")}, - {key: "/foo/c", value: []byte("dolor")}, - {key: "/foo/d", value: []byte("sit")}, - {key: "/bar/a", value: []byte("amet")}, - {key: "/bar/b", value: []byte("consectetur")}, - {key: "/bar/c", value: []byte("adipiscing")}, - {key: "/bar/d", value: []byte("elit")}, - {key: "/foo/bar/a", value: []byte("sed")}, - {key: "/foo/bar/b", value: []byte("do")}, - {key: "/foo/bar/c", value: []byte("eiusmod")}, - {key: "/foo/bar/d", value: []byte("tempor")}, - {key: "/foo/bar/baz/a", value: []byte("incididunt")}, - {key: "/foo/bar/baz/b", value: []byte("ut")}, - {key: "/foo/bar/baz/c", value: []byte("labore")}, - {key: "/foo/bar/baz/d", value: []byte("et")}, - // a duplicate just in case there's any edge cases - {key: "/foo/a", value: []byte("lorem")}, - } - - // Test Store - for _, d := range testdata { - if err := s.Store(d.key, d.value); err != nil { - t.Fatal(err.Error()) - } - } - - // Test Load - for _, d := range testdata { - if value, err := s.Load(d.key); err != nil { - t.Fatal(err.Error()) - } else { - if !reflect.DeepEqual(value, d.value) { - t.Fatalf("Load %s: expected %v, got %v", d.key, d.value, value) - } - } - } - - // Test Exists - for _, d := range testdata { - if !s.Exists(d.key) { - t.Fatalf("%s should exist, but doesn't\n", d.key) - } - } - - // Test List - if list, err := s.List("/", true); err != nil { - t.Fatal(err.Error()) - } else { - var expected []string - for i, d := range testdata { - if i != len(testdata)-1 { - // Don't store the intentionally duplicated key - expected = append(expected, d.key) - } - } - sort.Strings(expected) - sort.Strings(list) - if !reflect.DeepEqual(expected, list) { - t.Fatalf("List: Expected %v, got %v\n", expected, list) - } - } - if list, err := s.List("/foo", false); err != nil { - t.Fatal(err.Error()) - } else { - sort.Strings(list) - expected := []string{"/foo/a", "/foo/b", "/foo/bar", "/foo/c", "/foo/d"} - if !reflect.DeepEqual(expected, list) { - t.Fatalf("List: expected %s, got %s\n", expected, list) - } - } - - // Test Stat - for _, d := range testdata { - info, err := s.Stat(d.key) - if err != nil { - t.Fatal(err.Error()) - } else { - if info.Key != d.key { - t.Fatalf("Stat().Key: expected %s, got %s\n", d.key, info.Key) - } - if info.Size != int64(len(d.value)) { - t.Fatalf("Stat().Size: expected %d, got %d\n", len(d.value), info.Size) - } - if time.Since(info.Modified) > time.Minute { - t.Fatalf("Stat().Modified: expected time since last modified to be < 1 minute, got %v\n", time.Since(info.Modified)) - } - } - - } - - // Test Delete - for _, d := range testdata { - if err := s.Delete(d.key); err != nil { - t.Fatal(err.Error()) - } - } - - // New interface doesn't return an error, so call it in case any log.Fatal - // happens - NewProvider(acme.Cache(s)) -} - -// Full test with a real zone, with against LE staging -func TestE2e(t *testing.T) { - if len(os.Getenv("IN_TRAVIS_CI")) != 0 { - t.Skip() - } - - apiToken, accountID := os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ACCOUNT_ID") - kvID := os.Getenv("KV_NAMESPACE_ID") - if len(apiToken) == 0 || len(accountID) == 0 || len(kvID) == 0 { - t.Skip("No Cloudflare API keys available, skipping test") - } - - testLock := memory.NewLock() - testStore := cfstore.NewStore( - cfstore.Token(apiToken), - cfstore.Account(accountID), - cfstore.Namespace(kvID), - ) - testStorage := NewStorage(testLock, testStore) - - conf := cloudflare.NewDefaultConfig() - conf.AuthToken = apiToken - conf.ZoneToken = apiToken - testChallengeProvider, err := cloudflare.NewDNSProviderConfig(conf) - if err != nil { - t.Fatal(err.Error()) - } - - testProvider := NewProvider( - acme.AcceptToS(true), - acme.Cache(testStorage), - acme.CA(acme.LetsEncryptStagingCA), - acme.ChallengeProvider(testChallengeProvider), - acme.OnDemand(false), - ) - - listener, err := testProvider.Listen("*.micro.mu", "micro.mu") - if err != nil { - t.Fatal(err.Error()) - } - go http.Serve(listener, http.NotFoundHandler()) - time.Sleep(10 * time.Minute) -} diff --git a/store/cloudflare/cloudflare.go b/store/cloudflare/cloudflare.go deleted file mode 100644 index cf3002f6..00000000 --- a/store/cloudflare/cloudflare.go +++ /dev/null @@ -1,411 +0,0 @@ -// Package cloudflare is a store implementation backed by cloudflare workers kv -// Note that the cloudflare workers KV API is eventually consistent. -package cloudflare - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "log" - "math" - "net/http" - "net/url" - "os" - "strconv" - "strings" - "time" - - "github.com/micro/go-micro/v2/store" - "github.com/pkg/errors" - - "github.com/patrickmn/go-cache" -) - -const ( - apiBaseURL = "https://api.cloudflare.com/client/v4/" -) - -type workersKV struct { - options store.Options - // cf account id - account string - // cf api token - token string - // cf kv namespace - namespace string - // http client to use - httpClient *http.Client - // cache - cache *cache.Cache -} - -// apiResponse is a cloudflare v4 api response -type apiResponse struct { - Result []struct { - ID string `json:"id"` - Type string `json:"type"` - Name string `json:"name"` - Expiration int64 `json:"expiration"` - Content string `json:"content"` - Proxiable bool `json:"proxiable"` - Proxied bool `json:"proxied"` - TTL int64 `json:"ttl"` - Priority int64 `json:"priority"` - Locked bool `json:"locked"` - ZoneID string `json:"zone_id"` - ZoneName string `json:"zone_name"` - ModifiedOn time.Time `json:"modified_on"` - CreatedOn time.Time `json:"created_on"` - } `json:"result"` - Success bool `json:"success"` - Errors []apiMessage `json:"errors"` - // not sure Messages is ever populated? - Messages []apiMessage `json:"messages"` - ResultInfo struct { - Page int `json:"page"` - PerPage int `json:"per_page"` - Count int `json:"count"` - TotalCount int `json:"total_count"` - } `json:"result_info"` -} - -// apiMessage is a Cloudflare v4 API Error -type apiMessage struct { - Code int `json:"code"` - Message string `json:"message"` -} - -// getOptions returns account id, token and namespace -func getOptions() (string, string, string) { - accountID := strings.TrimSpace(os.Getenv("CF_ACCOUNT_ID")) - apiToken := strings.TrimSpace(os.Getenv("CF_API_TOKEN")) - namespace := strings.TrimSpace(os.Getenv("KV_NAMESPACE_ID")) - - return accountID, apiToken, namespace -} - -func validateOptions(account, token, namespace string) { - if len(account) == 0 { - log.Fatal("Store: CF_ACCOUNT_ID is blank") - } - - if len(token) == 0 { - log.Fatal("Store: CF_API_TOKEN is blank") - } - - if len(namespace) == 0 { - log.Fatal("Store: KV_NAMESPACE_ID is blank") - } -} - -func (w *workersKV) Close() error { - return nil -} - -func (w *workersKV) Init(opts ...store.Option) error { - for _, o := range opts { - o(&w.options) - } - if len(w.options.Database) > 0 { - w.namespace = w.options.Database - } - if w.options.Context == nil { - w.options.Context = context.TODO() - } - ttl := w.options.Context.Value("STORE_CACHE_TTL") - if ttl != nil { - ttlduration, ok := ttl.(time.Duration) - if !ok { - log.Fatal("STORE_CACHE_TTL from context must be type int64") - } - w.cache = cache.New(ttlduration, 3*ttlduration) - } - return nil -} - -func (w *workersKV) list(prefix string) ([]string, error) { - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() - - path := fmt.Sprintf("accounts/%s/storage/kv/namespaces/%s/keys", w.account, w.namespace) - - body := make(map[string]string) - - if len(prefix) > 0 { - body["prefix"] = prefix - } - - response, _, _, err := w.request(ctx, http.MethodGet, path, body, make(http.Header)) - if err != nil { - return nil, err - } - - a := &apiResponse{} - if err := json.Unmarshal(response, a); err != nil { - return nil, err - } - - if !a.Success { - messages := "" - for _, m := range a.Errors { - messages += strconv.Itoa(m.Code) + " " + m.Message + "\n" - } - return nil, errors.New(messages) - } - - keys := make([]string, 0, len(a.Result)) - - for _, r := range a.Result { - keys = append(keys, r.Name) - } - - return keys, nil -} - -// In the cloudflare workers KV implemention, List() doesn't guarantee -// anything as the workers API is eventually consistent. -func (w *workersKV) List(opts ...store.ListOption) ([]string, error) { - keys, err := w.list("") - if err != nil { - return nil, err - } - - return keys, nil -} - -func (w *workersKV) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() - - var options store.ReadOptions - for _, o := range opts { - o(&options) - } - - keys := []string{key} - - if options.Prefix { - k, err := w.list(key) - if err != nil { - return nil, err - } - keys = k - } - - //nolint:prealloc - var records []*store.Record - - for _, k := range keys { - if w.cache != nil { - if resp, hit := w.cache.Get(k); hit { - if record, ok := resp.(*store.Record); ok { - records = append(records, record) - continue - } - } - } - - path := fmt.Sprintf("accounts/%s/storage/kv/namespaces/%s/values/%s", w.account, w.namespace, url.PathEscape(k)) - response, headers, status, err := w.request(ctx, http.MethodGet, path, nil, make(http.Header)) - if err != nil { - return records, err - } - if status < 200 || status >= 300 { - if status == 404 { - return nil, store.ErrNotFound - } - - return records, errors.New("Received unexpected Status " + strconv.Itoa(status) + string(response)) - } - record := &store.Record{ - Key: k, - Value: response, - } - if expiry := headers.Get("Expiration"); len(expiry) != 0 { - expiryUnix, err := strconv.ParseInt(expiry, 10, 64) - if err != nil { - return records, err - } - record.Expiry = time.Until(time.Unix(expiryUnix, 0)) - } - if w.cache != nil { - w.cache.Set(record.Key, record, cache.DefaultExpiration) - } - records = append(records, record) - } - - return records, nil -} - -func (w *workersKV) Write(r *store.Record, opts ...store.WriteOption) error { - // Set it in local cache, with the global TTL from options - if w.cache != nil { - w.cache.Set(r.Key, r, cache.DefaultExpiration) - } - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() - - path := fmt.Sprintf("accounts/%s/storage/kv/namespaces/%s/values/%s", w.account, w.namespace, url.PathEscape(r.Key)) - if r.Expiry != 0 { - // Minimum cloudflare TTL is 60 Seconds - exp := int(math.Max(60, math.Round(r.Expiry.Seconds()))) - path = path + "?expiration_ttl=" + strconv.Itoa(exp) - } - - headers := make(http.Header) - - resp, _, _, err := w.request(ctx, http.MethodPut, path, r.Value, headers) - if err != nil { - return err - } - - a := &apiResponse{} - if err := json.Unmarshal(resp, a); err != nil { - return err - } - - if !a.Success { - messages := "" - for _, m := range a.Errors { - messages += strconv.Itoa(m.Code) + " " + m.Message + "\n" - } - return errors.New(messages) - } - - return nil -} - -func (w *workersKV) Delete(key string, opts ...store.DeleteOption) error { - if w.cache != nil { - w.cache.Delete(key) - } - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() - - path := fmt.Sprintf("accounts/%s/storage/kv/namespaces/%s/values/%s", w.account, w.namespace, url.PathEscape(key)) - resp, _, _, err := w.request(ctx, http.MethodDelete, path, nil, make(http.Header)) - if err != nil { - return err - } - - a := &apiResponse{} - if err := json.Unmarshal(resp, a); err != nil { - return err - } - - if !a.Success { - messages := "" - for _, m := range a.Errors { - messages += strconv.Itoa(m.Code) + " " + m.Message + "\n" - } - return errors.New(messages) - } - - return nil -} - -func (w *workersKV) request(ctx context.Context, method, path string, body interface{}, headers http.Header) ([]byte, http.Header, int, error) { - var jsonBody []byte - var err error - - if body != nil { - if paramBytes, ok := body.([]byte); ok { - jsonBody = paramBytes - } else { - jsonBody, err = json.Marshal(body) - if err != nil { - return nil, nil, 0, errors.Wrap(err, "error marshalling params to JSON") - } - } - } else { - jsonBody = nil - } - - var reqBody io.Reader - - if jsonBody != nil { - reqBody = bytes.NewReader(jsonBody) - } - - req, err := http.NewRequestWithContext(ctx, method, apiBaseURL+path, reqBody) - if err != nil { - return nil, nil, 0, errors.Wrap(err, "error creating new request") - } - - for key, value := range headers { - req.Header[key] = value - } - - // set token if it exists - if len(w.token) > 0 { - req.Header.Set("Authorization", "Bearer "+w.token) - } - - // set the user agent to micro - req.Header.Set("User-Agent", "micro/1.0 (https://micro.mu)") - - // Official cloudflare client does exponential backoff here - // TODO: retry and use util/backoff - resp, err := w.httpClient.Do(req) - if err != nil { - return nil, nil, 0, err - } - defer resp.Body.Close() - - respBody, err := ioutil.ReadAll(resp.Body) - if err != nil { - return respBody, resp.Header, resp.StatusCode, err - } - - return respBody, resp.Header, resp.StatusCode, nil -} - -func (w *workersKV) String() string { - return "cloudflare" -} - -func (w *workersKV) Options() store.Options { - return w.options -} - -// NewStore returns a cloudflare Store implementation. -// Account ID, Token and Namespace must either be passed as options or -// environment variables. If set as env vars we expect the following; -// CF_API_TOKEN to a cloudflare API token scoped to Workers KV. -// CF_ACCOUNT_ID to contain a string with your cloudflare account ID. -// KV_NAMESPACE_ID to contain the namespace UUID for your KV storage. -func NewStore(opts ...store.Option) store.Store { - var options store.Options - for _, o := range opts { - o(&options) - } - - // get options from environment - account, token, namespace := getOptions() - - if len(account) == 0 { - account = getAccount(options.Context) - } - - if len(token) == 0 { - token = getToken(options.Context) - } - - if len(namespace) == 0 { - namespace = options.Database - } - - // validate options are not blank or log.Fatal - validateOptions(account, token, namespace) - - return &workersKV{ - account: account, - namespace: namespace, - token: token, - options: options, - httpClient: &http.Client{}, - } -} diff --git a/store/cloudflare/cloudflare_test.go b/store/cloudflare/cloudflare_test.go deleted file mode 100644 index 9cc7a05b..00000000 --- a/store/cloudflare/cloudflare_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package cloudflare - -import ( - "math/rand" - "os" - "strconv" - "testing" - "time" - - "github.com/micro/go-micro/v2/store" -) - -func TestCloudflare(t *testing.T) { - if len(os.Getenv("IN_TRAVIS_CI")) != 0 { - t.Skip() - } - - apiToken, accountID := os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ACCOUNT_ID") - kvID := os.Getenv("KV_NAMESPACE_ID") - if len(apiToken) == 0 || len(accountID) == 0 || len(kvID) == 0 { - t.Skip("No Cloudflare API keys available, skipping test") - } - rand.Seed(time.Now().UnixNano()) - randomK := strconv.Itoa(rand.Int()) - randomV := strconv.Itoa(rand.Int()) - - wkv := NewStore( - Token(apiToken), - Account(accountID), - Namespace(kvID), - CacheTTL(60000000000), - ) - - records, err := wkv.List() - if err != nil { - t.Fatalf("List: %s\n", err.Error()) - } else { - if len(os.Getenv("IN_TRAVIS_CI")) == 0 { - t.Log("Listed " + strconv.Itoa(len(records)) + " records") - } - } - - err = wkv.Write(&store.Record{ - Key: randomK, - Value: []byte(randomV), - }) - if err != nil { - t.Errorf("Write: %s", err.Error()) - } - err = wkv.Write(&store.Record{ - Key: "expirationtest", - Value: []byte("This message will self destruct"), - Expiry: 75 * time.Second, - }) - if err != nil { - t.Errorf("Write: %s", err.Error()) - } - - // This might be needed for cloudflare eventual consistency - time.Sleep(1 * time.Minute) - - r, err := wkv.Read(randomK) - if err != nil { - t.Errorf("Read: %s\n", err.Error()) - } - if len(r) != 1 { - t.Errorf("Expected to read 1 key, got %d keys\n", len(r)) - } - if string(r[0].Value) != randomV { - t.Errorf("Read: expected %s, got %s\n", randomK, string(r[0].Value)) - } - - r, err = wkv.Read("expirationtest") - if err != nil { - t.Errorf("Read: expirationtest should still exist") - } - if r[0].Expiry == 0 { - t.Error("Expected r to have an expiry") - } else { - t.Log(r[0].Expiry) - } - - time.Sleep(20 * time.Second) - r, err = wkv.Read("expirationtest") - if err == nil && len(r) != 0 { - t.Error("Read: Managed to read expirationtest, but it should have expired") - t.Log(err, r[0].Key, string(r[0].Value), r[0].Expiry, len(r)) - } - - err = wkv.Delete(randomK) - if err != nil { - t.Errorf("Delete: %s\n", err.Error()) - } - -} diff --git a/store/cloudflare/options.go b/store/cloudflare/options.go deleted file mode 100644 index a0143dd8..00000000 --- a/store/cloudflare/options.go +++ /dev/null @@ -1,64 +0,0 @@ -package cloudflare - -import ( - "context" - "time" - - "github.com/micro/go-micro/v2/store" -) - -func getOption(ctx context.Context, key string) string { - if ctx == nil { - return "" - } - val, ok := ctx.Value(key).(string) - if !ok { - return "" - } - return val -} - -func getToken(ctx context.Context) string { - return getOption(ctx, "CF_API_TOKEN") -} - -func getAccount(ctx context.Context) string { - return getOption(ctx, "CF_ACCOUNT_ID") -} - -// Token sets the cloudflare api token -func Token(t string) store.Option { - return func(o *store.Options) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, "CF_API_TOKEN", t) - } -} - -// Account sets the cloudflare account id -func Account(id string) store.Option { - return func(o *store.Options) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, "CF_ACCOUNT_ID", id) - } -} - -// Namespace sets the KV namespace -func Namespace(ns string) store.Option { - return func(o *store.Options) { - o.Database = ns - } -} - -// CacheTTL sets the timeout in nanoseconds of the read/write cache -func CacheTTL(ttl time.Duration) store.Option { - return func(o *store.Options) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, "STORE_CACHE_TTL", ttl) - } -} From b5f546b137419898f8c1f1045e775b887572ab96 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Apr 2020 19:55:45 +0100 Subject: [PATCH 596/788] go mod tidy --- go.mod | 23 ++++++++++++++++++++--- go.sum | 50 +------------------------------------------------- 2 files changed, 21 insertions(+), 52 deletions(-) diff --git a/go.mod b/go.mod index 551a2982..4ce7a293 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,14 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/beevik/ntp v0.2.0 github.com/bitly/go-simplejson v0.5.0 + github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect github.com/bwmarrin/discordgo v0.20.2 + github.com/coreos/bbolt v1.3.3 // indirect github.com/coreos/etcd v3.3.18+incompatible + github.com/coreos/go-semver v0.3.0 // indirect + github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect + github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/davecgh/go-spew v1.1.1 github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 @@ -17,25 +23,31 @@ require ( github.com/fsouza/go-dockerclient v1.6.0 github.com/ghodss/yaml v1.0.0 github.com/go-acme/lego/v3 v3.3.0 + github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee github.com/gobwas/pool v0.2.0 // indirect github.com/gobwas/ws v1.0.3 + github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.3.2 + github.com/google/go-cmp v0.4.0 // indirect github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 - github.com/gorilla/websocket v1.4.1 + github.com/gorilla/websocket v1.4.1 // indirect + github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect + github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.9.5 github.com/hashicorp/hcl v1.0.0 github.com/hpcloud/tail v1.0.0 github.com/imdario/mergo v0.3.8 + github.com/jonboulle/clockwork v0.1.0 // indirect github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 + github.com/json-iterator/go v1.1.9 // indirect github.com/kr/pretty v0.1.0 github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 github.com/mholt/certmagic v0.9.3 github.com/micro/cli/v2 v2.1.2 github.com/micro/mdns v0.3.0 - github.com/micro/micro/v2 v2.4.0 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 github.com/nats-io/nats-server/v2 v2.1.4 @@ -44,13 +56,18 @@ require ( github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 + github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 + github.com/technoweenie/multipartstreamer v1.0.1 // indirect + github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect + github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect go.etcd.io/bbolt v1.3.4 go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 + golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect google.golang.org/grpc v1.26.0 - gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 + sigs.k8s.io/yaml v1.1.0 // indirect ) diff --git a/go.sum b/go.sum index 6011d507..63e5e123 100644 --- a/go.sum +++ b/go.sum @@ -64,9 +64,6 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= -github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4= -github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= -github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= @@ -75,14 +72,9 @@ github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.10.2 h1:VBodKICVPnwmDxstcW3biKcDSpFIfS/RELUXsZSBYK4= github.com/cloudflare/cloudflare-go v0.10.2/go.mod h1:qhVI5MKwBGhdNU89ZRz2plgYutcJ5PCekLxXn56w6SY= -github.com/cloudflare/cloudflare-go v0.10.9 h1:d8KOgLpYiC+Xq3T4tuO+/goM+RZvuO+T4pojuv8giL8= -github.com/cloudflare/cloudflare-go v0.10.9/go.mod h1:5TrsWH+3f4NV6WjtS5QFp+DifH81rph40gU374Sh0dQ= github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko= github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= @@ -94,6 +86,7 @@ github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3/go.mod h1:IV7qH3hrUgRmyYrtgEeGWJfWbgcHL9CSRruz2Vqcph0= github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDGpgqzQIzDW1TphrGLssLDZp2GuS+X5DkEJB8o= github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= +github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= @@ -131,7 +124,6 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1 github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 h1:jFGzikHboUMRXmMBtwD/PbxoTHPs2919Irp/3rxMbvM= github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1/go.mod h1:HvODWzv6Y6kBf3Ah2WzN1bHjDUezGLaAhwuWVwfpEJs= -github.com/eknkc/basex v1.0.0/go.mod h1:k/F/exNEHFdbs3ZHuasoP2E7zeWwZblG84Y7Z59vQRo= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -144,7 +136,6 @@ github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjr github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXju1m8W4lnEeIqTHPOzhTUO81a7yknM/xQR4= github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= -github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4GGn3Hig= @@ -162,10 +153,6 @@ github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3I github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= -github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= -github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU= github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM= @@ -204,14 +191,12 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -235,7 +220,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= -github.com/hako/branca v0.0.0-20180808000428-10b799466ada/go.mod h1:tOPn4gvKEUWqIJNE+zpTeTALaRAXnrRqqSnPlO3VpEo= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -283,26 +267,20 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= -github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= -github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ= github.com/lucas-clemente/quic-go v0.14.1 h1:c1aKoBZKOPA+49q96B1wGkibyPP0AxYh45WuAoq+87E= github.com/lucas-clemente/quic-go v0.14.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= -github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ= github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE= github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= @@ -310,12 +288,8 @@ github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= -github.com/micro/go-micro v1.18.0 h1:gP70EZVHpJuUIT0YWth192JmlIci+qMOEByHm83XE9E= -github.com/micro/go-micro/v2 v2.3.1-0.20200331090613-76ade7efd9b8/go.mod h1:lYuHYFPjY3QE9fdiy3F2awXcsXTdB68AwoY3RQ3dPN4= github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= -github.com/micro/micro/v2 v2.4.0 h1:GlbLaD/50KaSFym7GCQZ/2I4fuTTX9U4Zftni4ImJ40= -github.com/micro/micro/v2 v2.4.0/go.mod h1:/7lxBaU/Isx3USObggNVw6x6pdIJzTDexee7EsARD+A= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= @@ -349,7 +323,6 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= -github.com/netdata/go-orchestrator v0.0.0-20190905093727-c793edba0e8f/go.mod h1:ECF8anFVCt/TfTIWVPgPrNaYJXtAtpAOF62ugDbw41A= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= @@ -357,8 +330,6 @@ github.com/nrdcg/dnspod-go v0.3.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgP github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2SwKQ= github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= -github.com/olekukonko/tablewriter v0.0.3/go.mod h1:YZeBtGzYYEsCHp2LST/u/0NDwGkRoBtmn1cIWCJiS6M= -github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -382,7 +353,6 @@ github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgF github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= -github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -391,7 +361,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/pquerna/otp v1.2.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= @@ -420,7 +389,6 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sacloud/libsacloud v1.26.1/go.mod h1:79ZwATmHLIFZIMd7sxA3LwzVy/B77uj3LDoToVTxDoQ= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= @@ -431,7 +399,6 @@ github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= @@ -454,7 +421,6 @@ github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4 github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= @@ -464,8 +430,6 @@ github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= -go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg= go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= @@ -543,14 +507,11 @@ golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 h1:MsuvTghUPjX762sGLnGsxC3HM0B5r83wEtYcYR8/vRs= golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -569,7 +530,6 @@ golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -585,7 +545,6 @@ golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -658,23 +617,16 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= -gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= -gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= -gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= -gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= -gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ns1/ns1-go.v2 v2.0.0-20190730140822-b51389932cbc/go.mod h1:VV+3haRsgDiVLxyifmMBrBIuCWFBPYKbRssXB9z67Hw= -gopkg.in/olivere/elastic.v5 v5.0.83/go.mod h1:LXF6q9XNBxpMqrcgax95C6xyARXWbbCXUrtTxrNrxJI= gopkg.in/resty.v1 v1.9.1/go.mod h1:vo52Hzryw9PnPHcJfPsBiFW62XhNx5OczbV9y+IMpgc= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4= From 57b758db7ee8431e4af71a10423bcd76257fe24a Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Apr 2020 22:09:06 +0100 Subject: [PATCH 597/788] push --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 73837149..d6294ace 100644 --- a/README.md +++ b/README.md @@ -45,4 +45,3 @@ are pluggable and allows Go Micro to be runtime agnostic. You can plugin any und ## Getting Started See the [docs](https://micro.mu/docs/framework.html) for detailed information on the architecture, installation and use of go-micro. - From b979db6d9dbbab972dd3f41ad8b50125443355d0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 10 Apr 2020 23:29:15 +0100 Subject: [PATCH 598/788] remove sync event --- sync/event/event.go | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 sync/event/event.go diff --git a/sync/event/event.go b/sync/event/event.go deleted file mode 100644 index bd85d16c..00000000 --- a/sync/event/event.go +++ /dev/null @@ -1,27 +0,0 @@ -// Package event provides a distributed log interface -package event - -// Event provides a distributed log interface -type Event interface { - // Log retrieves the log with an id/name - Log(id string) (Log, error) -} - -// Log is an individual event log -type Log interface { - // Close the log handle - Close() error - // Log ID - Id() string - // Read will read the next record - Read() (*Record, error) - // Go to an offset - Seek(offset int64) error - // Write an event to the log - Write(*Record) error -} - -type Record struct { - Metadata map[string]interface{} - Data []byte -} From bc71640fd942f1e27e58e68997dc001b7b53a549 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 11 Apr 2020 03:46:54 +0300 Subject: [PATCH 599/788] broker: swap default broker from eats to http (#1524) * broker: swap default broker from eats to http Signed-off-by: Vasiliy Tolstov --- broker/default.go | 504 ----------------------------- broker/http.go | 709 +++++++++++++++++++++++++++++++++++++++++ broker/http/http.go | 11 + broker/http/options.go | 23 ++ broker/http_test.go | 384 ++++++++++++++++++++++ config/cmd/cmd.go | 2 + go.mod | 2 - go.sum | 12 - 8 files changed, 1129 insertions(+), 518 deletions(-) delete mode 100644 broker/default.go create mode 100644 broker/http.go create mode 100644 broker/http/http.go create mode 100644 broker/http/options.go create mode 100644 broker/http_test.go diff --git a/broker/default.go b/broker/default.go deleted file mode 100644 index ae6562ce..00000000 --- a/broker/default.go +++ /dev/null @@ -1,504 +0,0 @@ -package broker - -import ( - "context" - "errors" - "net" - "net/url" - "strconv" - "strings" - "sync" - "time" - - "github.com/micro/go-micro/v2/codec/json" - "github.com/micro/go-micro/v2/logger" - "github.com/micro/go-micro/v2/registry" - "github.com/micro/go-micro/v2/util/addr" - "github.com/nats-io/nats-server/v2/server" - nats "github.com/nats-io/nats.go" -) - -type natsBroker struct { - sync.Once - sync.RWMutex - - // indicate if we're connected - connected bool - - // address to bind routes to - addrs []string - // servers for the client - servers []string - - // client connection and nats opts - conn *nats.Conn - opts Options - nopts nats.Options - - // should we drain the connection - drain bool - closeCh chan (error) - - // embedded server - server *server.Server - // configure to use local server - local bool - // server exit channel - exit chan bool -} - -type subscriber struct { - s *nats.Subscription - opts SubscribeOptions -} - -type publication struct { - t string - err error - m *Message -} - -func (p *publication) Topic() string { - return p.t -} - -func (p *publication) Message() *Message { - return p.m -} - -func (p *publication) Ack() error { - // nats does not support acking - return nil -} - -func (p *publication) Error() error { - return p.err -} - -func (s *subscriber) Options() SubscribeOptions { - return s.opts -} - -func (s *subscriber) Topic() string { - return s.s.Subject -} - -func (s *subscriber) Unsubscribe() error { - return s.s.Unsubscribe() -} - -func (n *natsBroker) Address() string { - n.RLock() - defer n.RUnlock() - - if n.server != nil { - return n.server.ClusterAddr().String() - } - - if n.conn != nil && n.conn.IsConnected() { - return n.conn.ConnectedUrl() - } - - if len(n.addrs) > 0 { - return n.addrs[0] - } - - return "127.0.0.1:-1" -} - -func (n *natsBroker) setAddrs(addrs []string) []string { - //nolint:prealloc - var cAddrs []string - for _, addr := range addrs { - if len(addr) == 0 { - continue - } - if !strings.HasPrefix(addr, "nats://") { - addr = "nats://" + addr - } - cAddrs = append(cAddrs, addr) - } - // if there's no address and we weren't told to - // embed a local server then use the default url - if len(cAddrs) == 0 && !n.local { - cAddrs = []string{nats.DefaultURL} - } - return cAddrs -} - -// serve stats a local nats server if needed -func (n *natsBroker) serve(exit chan bool) error { - // local server address - host := "127.0.0.1" - port := -1 - - // cluster address - caddr := "0.0.0.0" - cport := -1 - - // with no address we just default it - // this is a local client address - if len(n.addrs) > 0 { - address := n.addrs[0] - if strings.HasPrefix(address, "nats://") { - address = strings.TrimPrefix(address, "nats://") - } - - // parse out the address - h, p, err := net.SplitHostPort(address) - if err == nil { - caddr = h - cport, _ = strconv.Atoi(p) - } - } - - // 1. create new server - // 2. register the server - // 3. connect to other servers - - // set cluster opts - cOpts := server.ClusterOpts{ - Host: caddr, - Port: cport, - } - - // get the routes for other nodes - var routes []*url.URL - - // get existing nats servers to connect to - services, err := n.opts.Registry.GetService("go.micro.nats.broker") - if err == nil { - for _, service := range services { - for _, node := range service.Nodes { - u, err := url.Parse("nats://" + node.Address) - if err != nil { - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Info(err) - } - continue - } - // append to the cluster routes - routes = append(routes, u) - } - } - } - - // try get existing server - s := n.server - - if s != nil { - // stop the existing server - s.Shutdown() - } - - s, err = server.NewServer(&server.Options{ - // Specify the host - Host: host, - // Use a random port - Port: port, - // Set the cluster ops - Cluster: cOpts, - // Set the routes - Routes: routes, - NoLog: true, - NoSigs: true, - MaxControlLine: 2048, - TLSConfig: n.opts.TLSConfig, - }) - if err != nil { - return err - } - - // save the server - n.server = s - - // start the server - go s.Start() - - var ready bool - - // wait till its ready for connections - for i := 0; i < 3; i++ { - if s.ReadyForConnections(time.Second) { - ready = true - break - } - } - - if !ready { - return errors.New("server not ready") - } - - // set the client address - n.servers = []string{s.ClientURL()} - - go func() { - var advertise string - - // parse out the address - _, port, err := net.SplitHostPort(s.ClusterAddr().String()) - if err == nil { - addr, _ := addr.Extract("") - advertise = net.JoinHostPort(addr, port) - } else { - s.ClusterAddr().String() - } - - // register the cluster address - for { - select { - case err := <-n.closeCh: - if err != nil { - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Info(err) - } - } - case <-exit: - // deregister on exit - n.opts.Registry.Deregister(®istry.Service{ - Name: "go.micro.nats.broker", - Version: "v2", - Nodes: []*registry.Node{ - {Id: s.ID(), Address: advertise}, - }, - }) - s.Shutdown() - return - default: - // register the broker - n.opts.Registry.Register(®istry.Service{ - Name: "go.micro.nats.broker", - Version: "v2", - Nodes: []*registry.Node{ - {Id: s.ID(), Address: advertise}, - }, - }, registry.RegisterTTL(time.Minute)) - time.Sleep(time.Minute) - } - } - }() - - return nil -} - -func (n *natsBroker) Connect() error { - n.Lock() - defer n.Unlock() - - if !n.connected { - // create exit chan - n.exit = make(chan bool) - - // start the local server - if err := n.serve(n.exit); err != nil { - return err - } - - // set to connected - } - - status := nats.CLOSED - if n.conn != nil { - status = n.conn.Status() - } - - switch status { - case nats.CONNECTED, nats.RECONNECTING, nats.CONNECTING: - return nil - default: // DISCONNECTED or CLOSED or DRAINING - opts := n.nopts - opts.DrainTimeout = 1 * time.Second - opts.AsyncErrorCB = n.onAsyncError - opts.DisconnectedErrCB = n.onDisconnectedError - opts.ClosedCB = n.onClose - opts.Servers = n.servers - opts.Secure = n.opts.Secure - opts.TLSConfig = n.opts.TLSConfig - - // secure might not be set - if n.opts.TLSConfig != nil { - opts.Secure = true - } - - c, err := opts.Connect() - if err != nil { - return err - } - n.conn = c - - n.connected = true - - return nil - } -} - -func (n *natsBroker) Disconnect() error { - n.RLock() - defer n.RUnlock() - - if !n.connected { - return nil - } - - // drain the connection if specified - if n.drain { - n.conn.Drain() - } - - // close the client connection - n.conn.Close() - - // shutdown the local server - // and deregister - if n.server != nil { - select { - case <-n.exit: - default: - close(n.exit) - } - } - - // set not connected - n.connected = false - - return nil -} - -func (n *natsBroker) Init(opts ...Option) error { - n.setOption(opts...) - return nil -} - -func (n *natsBroker) Options() Options { - return n.opts -} - -func (n *natsBroker) Publish(topic string, msg *Message, opts ...PublishOption) error { - b, err := n.opts.Codec.Marshal(msg) - if err != nil { - return err - } - n.RLock() - defer n.RUnlock() - return n.conn.Publish(topic, b) -} - -func (n *natsBroker) Subscribe(topic string, handler Handler, opts ...SubscribeOption) (Subscriber, error) { - if n.conn == nil { - return nil, errors.New("not connected") - } - - opt := SubscribeOptions{ - AutoAck: true, - Context: context.Background(), - } - - for _, o := range opts { - o(&opt) - } - - fn := func(msg *nats.Msg) { - var m Message - pub := &publication{t: msg.Subject} - eh := n.opts.ErrorHandler - err := n.opts.Codec.Unmarshal(msg.Data, &m) - pub.err = err - pub.m = &m - if err != nil { - m.Body = msg.Data - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Error(err) - } - if eh != nil { - eh(pub) - } - return - } - if err := handler(pub); err != nil { - pub.err = err - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Error(err) - } - if eh != nil { - eh(pub) - } - } - } - - var sub *nats.Subscription - var err error - - n.RLock() - if len(opt.Queue) > 0 { - sub, err = n.conn.QueueSubscribe(topic, opt.Queue, fn) - } else { - sub, err = n.conn.Subscribe(topic, fn) - } - n.RUnlock() - if err != nil { - return nil, err - } - return &subscriber{s: sub, opts: opt}, nil -} - -func (n *natsBroker) String() string { - return "eats" -} - -func (n *natsBroker) setOption(opts ...Option) { - for _, o := range opts { - o(&n.opts) - } - - n.Once.Do(func() { - n.nopts = nats.GetDefaultOptions() - }) - - // local embedded server - n.local = true - // set to drain - n.drain = true - - if !n.opts.Secure { - n.opts.Secure = n.nopts.Secure - } - - if n.opts.TLSConfig == nil { - n.opts.TLSConfig = n.nopts.TLSConfig - } - - n.addrs = n.setAddrs(n.opts.Addrs) -} - -func (n *natsBroker) onClose(conn *nats.Conn) { - n.closeCh <- nil -} - -func (n *natsBroker) onDisconnectedError(conn *nats.Conn, err error) { - n.closeCh <- err -} - -func (n *natsBroker) onAsyncError(conn *nats.Conn, sub *nats.Subscription, err error) { - // There are kinds of different async error nats might callback, but we are interested - // in ErrDrainTimeout only here. - if err == nats.ErrDrainTimeout { - n.closeCh <- err - } -} - -func NewBroker(opts ...Option) Broker { - options := Options{ - // Default codec - Codec: json.Marshaler{}, - Context: context.Background(), - Registry: registry.DefaultRegistry, - } - - n := &natsBroker{ - opts: options, - closeCh: make(chan error), - } - n.setOption(opts...) - - return n -} diff --git a/broker/http.go b/broker/http.go new file mode 100644 index 00000000..a4a90698 --- /dev/null +++ b/broker/http.go @@ -0,0 +1,709 @@ +// Package http provides a http based message broker +package broker + +import ( + "bytes" + "context" + "crypto/tls" + "errors" + "fmt" + "io" + "io/ioutil" + "math/rand" + "net" + "net/http" + "net/url" + "runtime" + "sync" + "time" + + "github.com/google/uuid" + "github.com/micro/go-micro/v2/codec/json" + merr "github.com/micro/go-micro/v2/errors" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/registry/cache" + maddr "github.com/micro/go-micro/v2/util/addr" + mnet "github.com/micro/go-micro/v2/util/net" + mls "github.com/micro/go-micro/v2/util/tls" + "golang.org/x/net/http2" +) + +// HTTP Broker is a point to point async broker +type httpBroker struct { + id string + address string + opts Options + + mux *http.ServeMux + + c *http.Client + r registry.Registry + + sync.RWMutex + subscribers map[string][]*httpSubscriber + running bool + exit chan chan error + + // offline message inbox + mtx sync.RWMutex + inbox map[string][][]byte +} + +type httpSubscriber struct { + opts SubscribeOptions + id string + topic string + fn Handler + svc *registry.Service + hb *httpBroker +} + +type httpEvent struct { + m *Message + t string + err error +} + +var ( + DefaultSubPath = "/" + serviceName = "micro.http.broker" + broadcastVersion = "ff.http.broadcast" + registerTTL = time.Minute + registerInterval = time.Second * 30 +) + +func init() { + rand.Seed(time.Now().Unix()) +} + +func newTransport(config *tls.Config) *http.Transport { + if config == nil { + config = &tls.Config{ + InsecureSkipVerify: true, + } + } + + dialTLS := func(network string, addr string) (net.Conn, error) { + return tls.Dial(network, addr, config) + } + + t := &http.Transport{ + Proxy: http.ProxyFromEnvironment, + Dial: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + }).Dial, + TLSHandshakeTimeout: 10 * time.Second, + DialTLS: dialTLS, + } + runtime.SetFinalizer(&t, func(tr **http.Transport) { + (*tr).CloseIdleConnections() + }) + + // setup http2 + http2.ConfigureTransport(t) + + return t +} + +func newHttpBroker(opts ...Option) Broker { + options := Options{ + Codec: json.Marshaler{}, + Context: context.TODO(), + Registry: registry.DefaultRegistry, + } + + for _, o := range opts { + o(&options) + } + + // set address + addr := ":0" + if len(options.Addrs) > 0 && len(options.Addrs[0]) > 0 { + addr = options.Addrs[0] + } + + h := &httpBroker{ + id: uuid.New().String(), + address: addr, + opts: options, + r: options.Registry, + c: &http.Client{Transport: newTransport(options.TLSConfig)}, + subscribers: make(map[string][]*httpSubscriber), + exit: make(chan chan error), + mux: http.NewServeMux(), + inbox: make(map[string][][]byte), + } + + // specify the message handler + h.mux.Handle(DefaultSubPath, h) + + // get optional handlers + if h.opts.Context != nil { + handlers, ok := h.opts.Context.Value("http_handlers").(map[string]http.Handler) + if ok { + for pattern, handler := range handlers { + h.mux.Handle(pattern, handler) + } + } + } + + return h +} + +func (h *httpEvent) Ack() error { + return nil +} + +func (h *httpEvent) Error() error { + return h.err +} + +func (h *httpEvent) Message() *Message { + return h.m +} + +func (h *httpEvent) Topic() string { + return h.t +} + +func (h *httpSubscriber) Options() SubscribeOptions { + return h.opts +} + +func (h *httpSubscriber) Topic() string { + return h.topic +} + +func (h *httpSubscriber) Unsubscribe() error { + return h.hb.unsubscribe(h) +} + +func (h *httpBroker) saveMessage(topic string, msg []byte) { + h.mtx.Lock() + defer h.mtx.Unlock() + + // get messages + c := h.inbox[topic] + + // save message + c = append(c, msg) + + // max length 64 + if len(c) > 64 { + c = c[:64] + } + + // save inbox + h.inbox[topic] = c +} + +func (h *httpBroker) getMessage(topic string, num int) [][]byte { + h.mtx.Lock() + defer h.mtx.Unlock() + + // get messages + c, ok := h.inbox[topic] + if !ok { + return nil + } + + // more message than requests + if len(c) >= num { + msg := c[:num] + h.inbox[topic] = c[num:] + return msg + } + + // reset inbox + h.inbox[topic] = nil + + // return all messages + return c +} + +func (h *httpBroker) subscribe(s *httpSubscriber) error { + h.Lock() + defer h.Unlock() + + if err := h.r.Register(s.svc, registry.RegisterTTL(registerTTL)); err != nil { + return err + } + + h.subscribers[s.topic] = append(h.subscribers[s.topic], s) + return nil +} + +func (h *httpBroker) unsubscribe(s *httpSubscriber) error { + h.Lock() + defer h.Unlock() + + //nolint:prealloc + var subscribers []*httpSubscriber + + // look for subscriber + for _, sub := range h.subscribers[s.topic] { + // deregister and skip forward + if sub == s { + _ = h.r.Deregister(sub.svc) + continue + } + // keep subscriber + subscribers = append(subscribers, sub) + } + + // set subscribers + h.subscribers[s.topic] = subscribers + + return nil +} + +func (h *httpBroker) run(l net.Listener) { + t := time.NewTicker(registerInterval) + defer t.Stop() + + for { + select { + // heartbeat for each subscriber + case <-t.C: + h.RLock() + for _, subs := range h.subscribers { + for _, sub := range subs { + _ = h.r.Register(sub.svc, registry.RegisterTTL(registerTTL)) + } + } + h.RUnlock() + // received exit signal + case ch := <-h.exit: + ch <- l.Close() + h.RLock() + for _, subs := range h.subscribers { + for _, sub := range subs { + _ = h.r.Deregister(sub.svc) + } + } + h.RUnlock() + return + } + } +} + +func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) { + if req.Method != "POST" { + err := merr.BadRequest("go.micro.broker", "Method not allowed") + http.Error(w, err.Error(), http.StatusMethodNotAllowed) + return + } + defer req.Body.Close() + + req.ParseForm() + + b, err := ioutil.ReadAll(req.Body) + if err != nil { + errr := merr.InternalServerError("go.micro.broker", "Error reading request body: %v", err) + w.WriteHeader(500) + w.Write([]byte(errr.Error())) + return + } + + var m *Message + if err = h.opts.Codec.Unmarshal(b, &m); err != nil { + errr := merr.InternalServerError("go.micro.broker", "Error parsing request body: %v", err) + w.WriteHeader(500) + w.Write([]byte(errr.Error())) + return + } + + topic := m.Header["Micro-Topic"] + //delete(m.Header, ":topic") + + if len(topic) == 0 { + errr := merr.InternalServerError("go.micro.broker", "Topic not found") + w.WriteHeader(500) + w.Write([]byte(errr.Error())) + return + } + + p := &httpEvent{m: m, t: topic} + id := req.Form.Get("id") + + //nolint:prealloc + var subs []Handler + + h.RLock() + for _, subscriber := range h.subscribers[topic] { + if id != subscriber.id { + continue + } + subs = append(subs, subscriber.fn) + } + h.RUnlock() + + // execute the handler + for _, fn := range subs { + p.err = fn(p) + } +} + +func (h *httpBroker) Address() string { + h.RLock() + defer h.RUnlock() + return h.address +} + +func (h *httpBroker) Connect() error { + h.RLock() + if h.running { + h.RUnlock() + return nil + } + h.RUnlock() + + h.Lock() + defer h.Unlock() + + var l net.Listener + var err error + + if h.opts.Secure || h.opts.TLSConfig != nil { + config := h.opts.TLSConfig + + fn := func(addr string) (net.Listener, error) { + if config == nil { + hosts := []string{addr} + + // check if its a valid host:port + if host, _, err := net.SplitHostPort(addr); err == nil { + if len(host) == 0 { + hosts = maddr.IPs() + } else { + hosts = []string{host} + } + } + + // generate a certificate + cert, err := mls.Certificate(hosts...) + if err != nil { + return nil, err + } + config = &tls.Config{Certificates: []tls.Certificate{cert}} + } + return tls.Listen("tcp", addr, config) + } + + l, err = mnet.Listen(h.address, fn) + } else { + fn := func(addr string) (net.Listener, error) { + return net.Listen("tcp", addr) + } + + l, err = mnet.Listen(h.address, fn) + } + + if err != nil { + return err + } + + addr := h.address + h.address = l.Addr().String() + + go http.Serve(l, h.mux) + go func() { + h.run(l) + h.Lock() + h.opts.Addrs = []string{addr} + h.address = addr + h.Unlock() + }() + + // get registry + reg := h.opts.Registry + if reg == nil { + reg = registry.DefaultRegistry + } + // set cache + h.r = cache.New(reg) + + // set running + h.running = true + return nil +} + +func (h *httpBroker) Disconnect() error { + h.RLock() + if !h.running { + h.RUnlock() + return nil + } + h.RUnlock() + + h.Lock() + defer h.Unlock() + + // stop cache + rc, ok := h.r.(cache.Cache) + if ok { + rc.Stop() + } + + // exit and return err + ch := make(chan error) + h.exit <- ch + err := <-ch + + // set not running + h.running = false + return err +} + +func (h *httpBroker) Init(opts ...Option) error { + h.RLock() + if h.running { + h.RUnlock() + return errors.New("cannot init while connected") + } + h.RUnlock() + + h.Lock() + defer h.Unlock() + + for _, o := range opts { + o(&h.opts) + } + + if len(h.opts.Addrs) > 0 && len(h.opts.Addrs[0]) > 0 { + h.address = h.opts.Addrs[0] + } + + if len(h.id) == 0 { + h.id = "go.micro.http.broker-" + uuid.New().String() + } + + // get registry + reg := h.opts.Registry + if reg == nil { + reg = registry.DefaultRegistry + } + + // get cache + if rc, ok := h.r.(cache.Cache); ok { + rc.Stop() + } + + // set registry + h.r = cache.New(reg) + + // reconfigure tls config + if c := h.opts.TLSConfig; c != nil { + h.c = &http.Client{ + Transport: newTransport(c), + } + } + + return nil +} + +func (h *httpBroker) Options() Options { + return h.opts +} + +func (h *httpBroker) Publish(topic string, msg *Message, opts ...PublishOption) error { + // create the message first + m := &Message{ + Header: make(map[string]string), + Body: msg.Body, + } + + for k, v := range msg.Header { + m.Header[k] = v + } + + m.Header["Micro-Topic"] = topic + + // encode the message + b, err := h.opts.Codec.Marshal(m) + if err != nil { + return err + } + + // save the message + h.saveMessage(topic, b) + + // now attempt to get the service + h.RLock() + s, err := h.r.GetService(serviceName) + if err != nil { + h.RUnlock() + return err + } + h.RUnlock() + + pub := func(node *registry.Node, t string, b []byte) error { + scheme := "http" + + // check if secure is added in metadata + if node.Metadata["secure"] == "true" { + scheme = "https" + } + + vals := url.Values{} + vals.Add("id", node.Id) + + uri := fmt.Sprintf("%s://%s%s?%s", scheme, node.Address, DefaultSubPath, vals.Encode()) + r, err := h.c.Post(uri, "application/json", bytes.NewReader(b)) + if err != nil { + return err + } + + // discard response body + io.Copy(ioutil.Discard, r.Body) + r.Body.Close() + return nil + } + + srv := func(s []*registry.Service, b []byte) { + for _, service := range s { + var nodes []*registry.Node + + for _, node := range service.Nodes { + // only use nodes tagged with broker http + if node.Metadata["broker"] != "http" { + continue + } + + // look for nodes for the topic + if node.Metadata["topic"] != topic { + continue + } + + nodes = append(nodes, node) + } + + // only process if we have nodes + if len(nodes) == 0 { + continue + } + + switch service.Version { + // broadcast version means broadcast to all nodes + case broadcastVersion: + var success bool + + // publish to all nodes + for _, node := range nodes { + // publish async + if err := pub(node, topic, b); err == nil { + success = true + } + } + + // save if it failed to publish at least once + if !success { + h.saveMessage(topic, b) + } + default: + // select node to publish to + node := nodes[rand.Int()%len(nodes)] + + // publish async to one node + if err := pub(node, topic, b); err != nil { + // if failed save it + h.saveMessage(topic, b) + } + } + } + } + + // do the rest async + go func() { + // get a third of the backlog + messages := h.getMessage(topic, 8) + delay := (len(messages) > 1) + + // publish all the messages + for _, msg := range messages { + // serialize here + srv(s, msg) + + // sending a backlog of messages + if delay { + time.Sleep(time.Millisecond * 100) + } + } + }() + + return nil +} + +func (h *httpBroker) Subscribe(topic string, handler Handler, opts ...SubscribeOption) (Subscriber, error) { + var err error + var host, port string + options := NewSubscribeOptions(opts...) + + // parse address for host, port + host, port, err = net.SplitHostPort(h.Address()) + if err != nil { + return nil, err + } + + addr, err := maddr.Extract(host) + if err != nil { + return nil, err + } + + var secure bool + + if h.opts.Secure || h.opts.TLSConfig != nil { + secure = true + } + + // register service + node := ®istry.Node{ + Id: topic + "-" + h.id, + Address: mnet.HostPort(addr, port), + Metadata: map[string]string{ + "secure": fmt.Sprintf("%t", secure), + "broker": "http", + "topic": topic, + }, + } + + // check for queue group or broadcast queue + version := options.Queue + if len(version) == 0 { + version = broadcastVersion + } + + service := ®istry.Service{ + Name: serviceName, + Version: version, + Nodes: []*registry.Node{node}, + } + + // generate subscriber + subscriber := &httpSubscriber{ + opts: options, + hb: h, + id: node.Id, + topic: topic, + fn: handler, + svc: service, + } + + // subscribe now + if err := h.subscribe(subscriber); err != nil { + return nil, err + } + + // return the subscriber + return subscriber, nil +} + +func (h *httpBroker) String() string { + return "http" +} + +// NewBroker returns a new http broker +func NewBroker(opts ...Option) Broker { + return newHttpBroker(opts...) +} diff --git a/broker/http/http.go b/broker/http/http.go new file mode 100644 index 00000000..ff28a41d --- /dev/null +++ b/broker/http/http.go @@ -0,0 +1,11 @@ +// Package http provides a http based message broker +package http + +import ( + "github.com/micro/go-micro/v2/broker" +) + +// NewBroker returns a new http broker +func NewBroker(opts ...broker.Option) broker.Broker { + return broker.NewBroker(opts...) +} diff --git a/broker/http/options.go b/broker/http/options.go new file mode 100644 index 00000000..c9825e1d --- /dev/null +++ b/broker/http/options.go @@ -0,0 +1,23 @@ +package http + +import ( + "context" + "net/http" + + "github.com/micro/go-micro/v2/broker" +) + +// Handle registers the handler for the given pattern. +func Handle(pattern string, handler http.Handler) broker.Option { + return func(o *broker.Options) { + if o.Context == nil { + o.Context = context.Background() + } + handlers, ok := o.Context.Value("http_handlers").(map[string]http.Handler) + if !ok { + handlers = make(map[string]http.Handler) + } + handlers[pattern] = handler + o.Context = context.WithValue(o.Context, "http_handlers", handlers) + } +} diff --git a/broker/http_test.go b/broker/http_test.go new file mode 100644 index 00000000..7d5309ae --- /dev/null +++ b/broker/http_test.go @@ -0,0 +1,384 @@ +package broker_test + +import ( + "sync" + "testing" + "time" + + "github.com/google/uuid" + "github.com/micro/go-micro/v2/broker" + "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/registry/memory" +) + +var ( + // mock data + testData = map[string][]*registry.Service{ + "foo": { + { + Name: "foo", + Version: "1.0.0", + Nodes: []*registry.Node{ + { + Id: "foo-1.0.0-123", + Address: "localhost:9999", + }, + { + Id: "foo-1.0.0-321", + Address: "localhost:9999", + }, + }, + }, + { + Name: "foo", + Version: "1.0.1", + Nodes: []*registry.Node{ + { + Id: "foo-1.0.1-321", + Address: "localhost:6666", + }, + }, + }, + { + Name: "foo", + Version: "1.0.3", + Nodes: []*registry.Node{ + { + Id: "foo-1.0.3-345", + Address: "localhost:8888", + }, + }, + }, + }, + } +) + +func newTestRegistry() registry.Registry { + return memory.NewRegistry(memory.Services(testData)) +} + +func sub(be *testing.B, c int) { + be.StopTimer() + m := newTestRegistry() + + b := broker.NewBroker(broker.Registry(m)) + topic := uuid.New().String() + + if err := b.Init(); err != nil { + be.Fatalf("Unexpected init error: %v", err) + } + + if err := b.Connect(); err != nil { + be.Fatalf("Unexpected connect error: %v", err) + } + + msg := &broker.Message{ + Header: map[string]string{ + "Content-Type": "application/json", + }, + Body: []byte(`{"message": "Hello World"}`), + } + + var subs []broker.Subscriber + done := make(chan bool, c) + + for i := 0; i < c; i++ { + sub, err := b.Subscribe(topic, func(p broker.Event) error { + done <- true + m := p.Message() + + if string(m.Body) != string(msg.Body) { + be.Fatalf("Unexpected msg %s, expected %s", string(m.Body), string(msg.Body)) + } + + return nil + }, broker.Queue("shared")) + if err != nil { + be.Fatalf("Unexpected subscribe error: %v", err) + } + subs = append(subs, sub) + } + + for i := 0; i < be.N; i++ { + be.StartTimer() + if err := b.Publish(topic, msg); err != nil { + be.Fatalf("Unexpected publish error: %v", err) + } + <-done + be.StopTimer() + } + + for _, sub := range subs { + sub.Unsubscribe() + } + + if err := b.Disconnect(); err != nil { + be.Fatalf("Unexpected disconnect error: %v", err) + } +} + +func pub(be *testing.B, c int) { + be.StopTimer() + m := newTestRegistry() + b := broker.NewBroker(broker.Registry(m)) + topic := uuid.New().String() + + if err := b.Init(); err != nil { + be.Fatalf("Unexpected init error: %v", err) + } + + if err := b.Connect(); err != nil { + be.Fatalf("Unexpected connect error: %v", err) + } + + msg := &broker.Message{ + Header: map[string]string{ + "Content-Type": "application/json", + }, + Body: []byte(`{"message": "Hello World"}`), + } + + done := make(chan bool, c*4) + + sub, err := b.Subscribe(topic, func(p broker.Event) error { + done <- true + m := p.Message() + if string(m.Body) != string(msg.Body) { + be.Fatalf("Unexpected msg %s, expected %s", string(m.Body), string(msg.Body)) + } + return nil + }, broker.Queue("shared")) + if err != nil { + be.Fatalf("Unexpected subscribe error: %v", err) + } + + var wg sync.WaitGroup + ch := make(chan int, c*4) + be.StartTimer() + + for i := 0; i < c; i++ { + go func() { + for range ch { + if err := b.Publish(topic, msg); err != nil { + be.Fatalf("Unexpected publish error: %v", err) + } + select { + case <-done: + case <-time.After(time.Second): + } + wg.Done() + } + }() + } + + for i := 0; i < be.N; i++ { + wg.Add(1) + ch <- i + } + + wg.Wait() + be.StopTimer() + sub.Unsubscribe() + close(ch) + close(done) + + if err := b.Disconnect(); err != nil { + be.Fatalf("Unexpected disconnect error: %v", err) + } +} + +func TestBroker(t *testing.T) { + m := newTestRegistry() + b := broker.NewBroker(broker.Registry(m)) + + if err := b.Init(); err != nil { + t.Fatalf("Unexpected init error: %v", err) + } + + if err := b.Connect(); err != nil { + t.Fatalf("Unexpected connect error: %v", err) + } + + msg := &broker.Message{ + Header: map[string]string{ + "Content-Type": "application/json", + }, + Body: []byte(`{"message": "Hello World"}`), + } + + done := make(chan bool) + + sub, err := b.Subscribe("test", func(p broker.Event) error { + m := p.Message() + + if string(m.Body) != string(msg.Body) { + t.Fatalf("Unexpected msg %s, expected %s", string(m.Body), string(msg.Body)) + } + + close(done) + return nil + }) + if err != nil { + t.Fatalf("Unexpected subscribe error: %v", err) + } + + if err := b.Publish("test", msg); err != nil { + t.Fatalf("Unexpected publish error: %v", err) + } + + <-done + sub.Unsubscribe() + + if err := b.Disconnect(); err != nil { + t.Fatalf("Unexpected disconnect error: %v", err) + } +} + +func TestConcurrentSubBroker(t *testing.T) { + m := newTestRegistry() + b := broker.NewBroker(broker.Registry(m)) + + if err := b.Init(); err != nil { + t.Fatalf("Unexpected init error: %v", err) + } + + if err := b.Connect(); err != nil { + t.Fatalf("Unexpected connect error: %v", err) + } + + msg := &broker.Message{ + Header: map[string]string{ + "Content-Type": "application/json", + }, + Body: []byte(`{"message": "Hello World"}`), + } + + var subs []broker.Subscriber + var wg sync.WaitGroup + + for i := 0; i < 10; i++ { + sub, err := b.Subscribe("test", func(p broker.Event) error { + defer wg.Done() + + m := p.Message() + + if string(m.Body) != string(msg.Body) { + t.Fatalf("Unexpected msg %s, expected %s", string(m.Body), string(msg.Body)) + } + + return nil + }) + if err != nil { + t.Fatalf("Unexpected subscribe error: %v", err) + } + + wg.Add(1) + subs = append(subs, sub) + } + + if err := b.Publish("test", msg); err != nil { + t.Fatalf("Unexpected publish error: %v", err) + } + + wg.Wait() + + for _, sub := range subs { + sub.Unsubscribe() + } + + if err := b.Disconnect(); err != nil { + t.Fatalf("Unexpected disconnect error: %v", err) + } +} + +func TestConcurrentPubBroker(t *testing.T) { + m := newTestRegistry() + b := broker.NewBroker(broker.Registry(m)) + + if err := b.Init(); err != nil { + t.Fatalf("Unexpected init error: %v", err) + } + + if err := b.Connect(); err != nil { + t.Fatalf("Unexpected connect error: %v", err) + } + + msg := &broker.Message{ + Header: map[string]string{ + "Content-Type": "application/json", + }, + Body: []byte(`{"message": "Hello World"}`), + } + + var wg sync.WaitGroup + + sub, err := b.Subscribe("test", func(p broker.Event) error { + defer wg.Done() + + m := p.Message() + + if string(m.Body) != string(msg.Body) { + t.Fatalf("Unexpected msg %s, expected %s", string(m.Body), string(msg.Body)) + } + + return nil + }) + if err != nil { + t.Fatalf("Unexpected subscribe error: %v", err) + } + + for i := 0; i < 10; i++ { + wg.Add(1) + + if err := b.Publish("test", msg); err != nil { + t.Fatalf("Unexpected publish error: %v", err) + } + } + + wg.Wait() + + sub.Unsubscribe() + + if err := b.Disconnect(); err != nil { + t.Fatalf("Unexpected disconnect error: %v", err) + } +} + +func BenchmarkSub1(b *testing.B) { + sub(b, 1) +} +func BenchmarkSub8(b *testing.B) { + sub(b, 8) +} + +func BenchmarkSub32(b *testing.B) { + sub(b, 32) +} + +func BenchmarkSub64(b *testing.B) { + sub(b, 64) +} + +func BenchmarkSub128(b *testing.B) { + sub(b, 128) +} + +func BenchmarkPub1(b *testing.B) { + pub(b, 1) +} + +func BenchmarkPub8(b *testing.B) { + pub(b, 8) +} + +func BenchmarkPub32(b *testing.B) { + pub(b, 32) +} + +func BenchmarkPub64(b *testing.B) { + pub(b, 64) +} + +func BenchmarkPub128(b *testing.B) { + pub(b, 128) +} diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 44071b71..b5cd79f8 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -36,6 +36,7 @@ import ( smucp "github.com/micro/go-micro/v2/server/mucp" // brokers + brokerHttp "github.com/micro/go-micro/v2/broker/http" "github.com/micro/go-micro/v2/broker/memory" "github.com/micro/go-micro/v2/broker/nats" brokerSrv "github.com/micro/go-micro/v2/broker/service" @@ -319,6 +320,7 @@ var ( "service": brokerSrv.NewBroker, "memory": memory.NewBroker, "nats": nats.NewBroker, + "http": brokerHttp.NewBroker, } DefaultClients = map[string]func(...client.Option) client.Client{ diff --git a/go.mod b/go.mod index 4ce7a293..9725ae12 100644 --- a/go.mod +++ b/go.mod @@ -50,8 +50,6 @@ require ( github.com/micro/mdns v0.3.0 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 - github.com/nats-io/nats-server/v2 v2.1.4 - github.com/nats-io/nats.go v1.9.1 github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/patrickmn/go-cache v2.1.0+incompatible diff --git a/go.sum b/go.sum index 63e5e123..36dee0a2 100644 --- a/go.sum +++ b/go.sum @@ -310,18 +310,6 @@ github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8d github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= -github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= -github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= -github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server/v2 v2.1.4 h1:BILRnsJ2Yb/fefiFbBWADpViGF69uh4sxe8poVDQ06g= -github.com/nats-io/nats-server/v2 v2.1.4/go.mod h1:Jw1Z28soD/QasIA2uWjXyM9El1jly3YwyFOuR8tH1rg= -github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= -github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= -github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= -github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= From 3f3d2f502750e90e7efd260b0639df7f561905cf Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 01:51:26 +0100 Subject: [PATCH 600/788] fixup broker http address --- broker/http.go | 10 ++++++---- go.mod | 6 ++++-- go.sum | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/broker/http.go b/broker/http.go index a4a90698..ef06a182 100644 --- a/broker/http.go +++ b/broker/http.go @@ -65,7 +65,8 @@ type httpEvent struct { } var ( - DefaultSubPath = "/" + DefaultPath = "/" + DefaultAddress = "127.0.0.1:0" serviceName = "micro.http.broker" broadcastVersion = "ff.http.broadcast" registerTTL = time.Minute @@ -118,7 +119,8 @@ func newHttpBroker(opts ...Option) Broker { } // set address - addr := ":0" + addr := DefaultAddress + if len(options.Addrs) > 0 && len(options.Addrs[0]) > 0 { addr = options.Addrs[0] } @@ -136,7 +138,7 @@ func newHttpBroker(opts ...Option) Broker { } // specify the message handler - h.mux.Handle(DefaultSubPath, h) + h.mux.Handle(DefaultPath, h) // get optional handlers if h.opts.Context != nil { @@ -549,7 +551,7 @@ func (h *httpBroker) Publish(topic string, msg *Message, opts ...PublishOption) vals := url.Values{} vals.Add("id", node.Id) - uri := fmt.Sprintf("%s://%s%s?%s", scheme, node.Address, DefaultSubPath, vals.Encode()) + uri := fmt.Sprintf("%s://%s%s?%s", scheme, node.Address, DefaultPath, vals.Encode()) r, err := h.c.Post(uri, "application/json", bytes.NewReader(b)) if err != nil { return err diff --git a/go.mod b/go.mod index 9725ae12..cf373f7a 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/gobwas/pool v0.2.0 // indirect github.com/gobwas/ws v1.0.3 github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect - github.com/golang/protobuf v1.3.2 + github.com/golang/protobuf v1.3.5 github.com/google/go-cmp v0.4.0 // indirect github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 @@ -50,6 +50,8 @@ require ( github.com/micro/mdns v0.3.0 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 + github.com/nats-io/nats-server/v2 v2.1.6 + github.com/nats-io/nats.go v1.9.2 github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/patrickmn/go-cache v2.1.0+incompatible @@ -61,7 +63,7 @@ require ( github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect go.etcd.io/bbolt v1.3.4 go.uber.org/zap v1.13.0 - golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d + golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect google.golang.org/grpc v1.26.0 diff --git a/go.sum b/go.sum index 36dee0a2..848d8da2 100644 --- a/go.sum +++ b/go.sum @@ -182,6 +182,8 @@ github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= @@ -310,6 +312,18 @@ github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8d github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= +github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= +github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= +github.com/nats-io/nats-server v1.4.1 h1:Ul1oSOGNV/L8kjr4v6l2f9Yet6WY+LevH1/7cRZ/qyA= +github.com/nats-io/nats-server/v2 v2.1.6 h1:qAaHZaS8pRRNQLFaiBA1rq5WynyEGp9DFgmMfoaiXGY= +github.com/nats-io/nats-server/v2 v2.1.6/go.mod h1:BL1NOtaBQ5/y97djERRVWNouMW7GT3gxnmbE/eC8u8A= +github.com/nats-io/nats.go v1.9.2 h1:oDeERm3NcZVrPpdR/JpGdWHMv3oJ8yY30YwxKq+DU2s= +github.com/nats-io/nats.go v1.9.2/go.mod h1:AjGArbfyR50+afOUotNX2Xs5SYHf+CoOa5HH1eEl2HE= +github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= +github.com/nats-io/nkeys v0.1.4 h1:aEsHIssIk6ETN5m2/MD8Y4B2X7FfXrBAUdkyRvbVYzA= +github.com/nats-io/nkeys v0.1.4/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s= +github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= +github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= @@ -453,6 +467,8 @@ golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw= golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM= +golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= From c612d86480ad8f42dcc6a65b9945b9828c397b54 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 09:33:10 +0100 Subject: [PATCH 601/788] Move sync store --- {sync/store => store/sync}/manager.go | 12 +-- {sync/store => store/sync}/options.go | 12 +-- store/sync/sync.go | 114 ++++++++++++++++++++++++++ sync/store/cache.go | 114 -------------------------- 4 files changed, 126 insertions(+), 126 deletions(-) rename {sync/store => store/sync}/manager.go (88%) rename {sync/store => store/sync}/options.go (78%) create mode 100644 store/sync/sync.go delete mode 100644 sync/store/cache.go diff --git a/sync/store/manager.go b/store/sync/manager.go similarity index 88% rename from sync/store/manager.go rename to store/sync/manager.go index 58544aa4..6f7c5d6e 100644 --- a/sync/store/manager.go +++ b/store/sync/manager.go @@ -1,4 +1,4 @@ -package store +package sync import ( "time" @@ -25,7 +25,7 @@ const ( listOp ) -func (c *cache) cacheManager() { +func (c *syncStore) syncManager() { tickerAggregator := make(chan struct{ index int }) for i, ticker := range c.pendingWriteTickers { go func(index int, c chan struct{ index int }, t *time.Ticker) { @@ -43,18 +43,18 @@ func (c *cache) cacheManager() { } } -func (c *cache) processQueue(index int) { +func (c *syncStore) processQueue(index int) { c.Lock() defer c.Unlock() q := c.pendingWrites[index] for i := 0; i < q.Len(); i++ { r, ok := q.PopFront() if !ok { - panic(errors.Errorf("retrieved an invalid value from the L%d cache queue", index+1)) + panic(errors.Errorf("retrieved an invalid value from the L%d sync queue", index+1)) } ir, ok := r.(*internalRecord) if !ok { - panic(errors.Errorf("retrieved a non-internal record from the L%d cache queue", index+1)) + panic(errors.Errorf("retrieved a non-internal record from the L%d sync queue", index+1)) } if !ir.expiresAt.IsZero() && time.Now().After(ir.expiresAt) { continue @@ -68,7 +68,7 @@ func (c *cache) processQueue(index int) { nr.Expiry = time.Until(ir.expiresAt) } // Todo = internal queue also has to hold the corresponding store.WriteOptions - if err := c.cOptions.Stores[index+1].Write(nr); err != nil { + if err := c.syncOpts.Stores[index+1].Write(nr); err != nil { // some error, so queue for retry and bail q.PushBack(ir) return diff --git a/sync/store/options.go b/store/sync/options.go similarity index 78% rename from sync/store/options.go rename to store/sync/options.go index f2a75534..30e493f2 100644 --- a/sync/store/options.go +++ b/store/sync/options.go @@ -1,4 +1,4 @@ -package store +package sync import ( "time" @@ -6,9 +6,9 @@ import ( "github.com/micro/go-micro/v2/store" ) -// Options represents Cache options +// Options represents Sync options type Options struct { - // Stores represents layers in the cache in ascending order. L0, L1, L2, etc + // Stores represents layers in the sync in ascending order. L0, L1, L2, etc Stores []store.Store // SyncInterval is the duration between syncs from L0 to L1 SyncInterval time.Duration @@ -16,10 +16,10 @@ type Options struct { SyncMultiplier int64 } -// Option sets Cache Options +// Option sets Sync Options type Option func(o *Options) -// Stores sets the layers that make up the cache +// Stores sets the layers that make up the sync func Stores(stores ...store.Store) Option { return func(o *Options) { o.Stores = make([]store.Store, len(stores)) @@ -36,7 +36,7 @@ func SyncInterval(d time.Duration) Option { } } -// SyncMultiplier sets the multiplication factor for time to wait each cache layer +// SyncMultiplier sets the multiplication factor for time to wait each sync layer func SyncMultiplier(i int64) Option { return func(o *Options) { o.SyncMultiplier = i diff --git a/store/sync/sync.go b/store/sync/sync.go new file mode 100644 index 00000000..79a7e36e --- /dev/null +++ b/store/sync/sync.go @@ -0,0 +1,114 @@ +// Package syncs will sync multiple stores +package sync + +import ( + "fmt" + "sync" + "time" + + "github.com/ef-ds/deque" + "github.com/micro/go-micro/v2/store" + "github.com/pkg/errors" +) + +// Sync implements a sync in for stores +type Sync interface { + // Implements the store interface + store.Store + // Force a full sync + Sync() error +} +type syncStore struct { + storeOpts store.Options + syncOpts Options + pendingWrites []*deque.Deque + pendingWriteTickers []*time.Ticker + sync.RWMutex +} + +// NewSync returns a new Sync +func NewSync(opts ...Option) Sync { + c := &syncStore{} + for _, o := range opts { + o(&c.syncOpts) + } + if c.syncOpts.SyncInterval == 0 { + c.syncOpts.SyncInterval = 1 * time.Minute + } + if c.syncOpts.SyncMultiplier == 0 { + c.syncOpts.SyncMultiplier = 5 + } + return c +} + +func (c *syncStore) Close() error { + return nil +} + +// Init initialises the storeOptions +func (c *syncStore) Init(opts ...store.Option) error { + for _, o := range opts { + o(&c.storeOpts) + } + if len(c.syncOpts.Stores) == 0 { + return errors.New("the sync has no stores") + } + if c.storeOpts.Context == nil { + return errors.New("please provide a context to the sync. Cancelling the context signals that the sync is being disposed and syncs the sync") + } + for _, s := range c.syncOpts.Stores { + if err := s.Init(); err != nil { + return errors.Wrapf(err, "Store %s failed to Init()", s.String()) + } + } + c.pendingWrites = make([]*deque.Deque, len(c.syncOpts.Stores)-1) + c.pendingWriteTickers = make([]*time.Ticker, len(c.syncOpts.Stores)-1) + for i := 0; i < len(c.pendingWrites); i++ { + c.pendingWrites[i] = deque.New() + c.pendingWrites[i].Init() + c.pendingWriteTickers[i] = time.NewTicker(c.syncOpts.SyncInterval * time.Duration(intpow(c.syncOpts.SyncMultiplier, int64(i)))) + } + go c.syncManager() + return nil +} + +// Options returns the sync's store options +func (c *syncStore) Options() store.Options { + return c.storeOpts +} + +// String returns a printable string describing the sync +func (c *syncStore) String() string { + backends := make([]string, len(c.syncOpts.Stores)) + for i, s := range c.syncOpts.Stores { + backends[i] = s.String() + } + return fmt.Sprintf("sync %v", backends) +} + +func (c *syncStore) List(opts ...store.ListOption) ([]string, error) { + return c.syncOpts.Stores[0].List(opts...) +} + +func (c *syncStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { + return c.syncOpts.Stores[0].Read(key, opts...) +} + +func (c *syncStore) Write(r *store.Record, opts ...store.WriteOption) error { + return c.syncOpts.Stores[0].Write(r, opts...) +} + +// Delete removes a key from the sync +func (c *syncStore) Delete(key string, opts ...store.DeleteOption) error { + return c.syncOpts.Stores[0].Delete(key, opts...) +} + +func (c *syncStore) Sync() error { + return nil +} + +type internalRecord struct { + key string + value []byte + expiresAt time.Time +} diff --git a/sync/store/cache.go b/sync/store/cache.go deleted file mode 100644 index 2385e961..00000000 --- a/sync/store/cache.go +++ /dev/null @@ -1,114 +0,0 @@ -// Package store syncs multiple go-micro stores -package store - -import ( - "fmt" - "sync" - "time" - - "github.com/ef-ds/deque" - "github.com/micro/go-micro/v2/store" - "github.com/pkg/errors" -) - -// Cache implements a cache in front of go-micro Stores -type Cache interface { - store.Store - - // Force a full sync - Sync() error -} -type cache struct { - sOptions store.Options - cOptions Options - pendingWrites []*deque.Deque - pendingWriteTickers []*time.Ticker - sync.RWMutex -} - -// NewCache returns a new Cache -func NewCache(opts ...Option) Cache { - c := &cache{} - for _, o := range opts { - o(&c.cOptions) - } - if c.cOptions.SyncInterval == 0 { - c.cOptions.SyncInterval = 1 * time.Minute - } - if c.cOptions.SyncMultiplier == 0 { - c.cOptions.SyncMultiplier = 5 - } - return c -} - -func (c *cache) Close() error { - return nil -} - -// Init initialises the storeOptions -func (c *cache) Init(opts ...store.Option) error { - for _, o := range opts { - o(&c.sOptions) - } - if len(c.cOptions.Stores) == 0 { - return errors.New("the cache has no stores") - } - if c.sOptions.Context == nil { - return errors.New("please provide a context to the cache. Cancelling the context signals that the cache is being disposed and syncs the cache") - } - for _, s := range c.cOptions.Stores { - if err := s.Init(); err != nil { - return errors.Wrapf(err, "Store %s failed to Init()", s.String()) - } - } - c.pendingWrites = make([]*deque.Deque, len(c.cOptions.Stores)-1) - c.pendingWriteTickers = make([]*time.Ticker, len(c.cOptions.Stores)-1) - for i := 0; i < len(c.pendingWrites); i++ { - c.pendingWrites[i] = deque.New() - c.pendingWrites[i].Init() - c.pendingWriteTickers[i] = time.NewTicker(c.cOptions.SyncInterval * time.Duration(intpow(c.cOptions.SyncMultiplier, int64(i)))) - } - go c.cacheManager() - return nil -} - -// Options returns the cache's store options -func (c *cache) Options() store.Options { - return c.sOptions -} - -// String returns a printable string describing the cache -func (c *cache) String() string { - backends := make([]string, len(c.cOptions.Stores)) - for i, s := range c.cOptions.Stores { - backends[i] = s.String() - } - return fmt.Sprintf("cache %v", backends) -} - -func (c *cache) List(opts ...store.ListOption) ([]string, error) { - return c.cOptions.Stores[0].List(opts...) -} - -func (c *cache) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { - return c.cOptions.Stores[0].Read(key, opts...) -} - -func (c *cache) Write(r *store.Record, opts ...store.WriteOption) error { - return c.cOptions.Stores[0].Write(r, opts...) -} - -// Delete removes a key from the cache -func (c *cache) Delete(key string, opts ...store.DeleteOption) error { - return c.cOptions.Stores[0].Delete(key, opts...) -} - -func (c *cache) Sync() error { - return nil -} - -type internalRecord struct { - key string - value []byte - expiresAt time.Time -} From 6d553cb6febeeb69bb963fe962bdb9abc9294484 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 09:34:04 +0100 Subject: [PATCH 602/788] add whitespace --- store/sync/sync.go | 1 + 1 file changed, 1 insertion(+) diff --git a/store/sync/sync.go b/store/sync/sync.go index 79a7e36e..d1f0e240 100644 --- a/store/sync/sync.go +++ b/store/sync/sync.go @@ -18,6 +18,7 @@ type Sync interface { // Force a full sync Sync() error } + type syncStore struct { storeOpts store.Options syncOpts Options From 39470c1b1113a1f2313fb3907a49903881362c86 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 10:37:54 +0100 Subject: [PATCH 603/788] Completely replace sync implementation --- sync/cron.go | 99 -------------- sync/etcd/etcd.go | 179 +++++++++++++++++++++++++ sync/leader/etcd/etcd.go | 136 ------------------- sync/leader/leader.go | 25 ---- sync/leader/options.go | 22 ---- sync/lock/etcd/etcd.go | 113 ---------------- sync/lock/http/http.go | 135 ------------------- sync/lock/http/server/server.go | 45 ------- sync/lock/lock.go | 32 ----- sync/lock/memory/memory.go | 142 -------------------- sync/lock/options.go | 33 ----- sync/map.go | 156 ---------------------- sync/memory/memory.go | 202 ++++++++++++++++++++++++++++ sync/options.go | 33 +++-- sync/sync.go | 66 ++++++---- sync/task/broker/broker.go | 227 -------------------------------- sync/task/local/local.go | 59 --------- sync/task/task.go | 85 ------------ sync/time/local/local.go | 18 --- sync/time/ntp/ntp.go | 51 ------- sync/time/time.go | 18 --- 21 files changed, 435 insertions(+), 1441 deletions(-) delete mode 100644 sync/cron.go create mode 100644 sync/etcd/etcd.go delete mode 100644 sync/leader/etcd/etcd.go delete mode 100644 sync/leader/leader.go delete mode 100644 sync/leader/options.go delete mode 100644 sync/lock/etcd/etcd.go delete mode 100644 sync/lock/http/http.go delete mode 100644 sync/lock/http/server/server.go delete mode 100644 sync/lock/lock.go delete mode 100644 sync/lock/memory/memory.go delete mode 100644 sync/lock/options.go delete mode 100644 sync/map.go create mode 100644 sync/memory/memory.go delete mode 100644 sync/task/broker/broker.go delete mode 100644 sync/task/local/local.go delete mode 100644 sync/task/task.go delete mode 100644 sync/time/local/local.go delete mode 100644 sync/time/ntp/ntp.go delete mode 100644 sync/time/time.go diff --git a/sync/cron.go b/sync/cron.go deleted file mode 100644 index fddb7e49..00000000 --- a/sync/cron.go +++ /dev/null @@ -1,99 +0,0 @@ -package sync - -import ( - "fmt" - "math" - "time" - - "github.com/micro/go-micro/v2/logger" - "github.com/micro/go-micro/v2/sync/leader/etcd" - "github.com/micro/go-micro/v2/sync/task" - "github.com/micro/go-micro/v2/sync/task/local" -) - -type syncCron struct { - opts Options -} - -func backoff(attempts int) time.Duration { - if attempts == 0 { - return time.Duration(0) - } - return time.Duration(math.Pow(10, float64(attempts))) * time.Millisecond -} - -func (c *syncCron) Schedule(s task.Schedule, t task.Command) error { - id := fmt.Sprintf("%s-%s", s.String(), t.String()) - - go func() { - // run the scheduler - tc := s.Run() - - var i int - - for { - // leader election - e, err := c.opts.Leader.Elect(id) - if err != nil { - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Errorf("[cron] leader election error: %v", err) - } - time.Sleep(backoff(i)) - i++ - continue - } - - i = 0 - r := e.Revoked() - - // execute the task - Tick: - for { - select { - // schedule tick - case _, ok := <-tc: - // ticked once - if !ok { - break Tick - } - - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Infof("[cron] executing command %s", t.Name) - } - if err := c.opts.Task.Run(t); err != nil { - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Errorf("[cron] error executing command %s: %v", t.Name, err) - } - } - // leader revoked - case <-r: - break Tick - } - } - - // resign - e.Resign() - } - }() - - return nil -} - -func NewCron(opts ...Option) Cron { - var options Options - for _, o := range opts { - o(&options) - } - - if options.Leader == nil { - options.Leader = etcd.NewLeader() - } - - if options.Task == nil { - options.Task = local.NewTask() - } - - return &syncCron{ - opts: options, - } -} diff --git a/sync/etcd/etcd.go b/sync/etcd/etcd.go new file mode 100644 index 00000000..7d493942 --- /dev/null +++ b/sync/etcd/etcd.go @@ -0,0 +1,179 @@ +// Package etcd is an etcd implementation of lock +package etcd + +import ( + "context" + "errors" + "log" + "path" + "strings" + gosync "sync" + + client "github.com/coreos/etcd/clientv3" + cc "github.com/coreos/etcd/clientv3/concurrency" + "github.com/micro/go-micro/v2/sync" +) + +type etcdSync struct { + options sync.Options + path string + client *client.Client + + mtx gosync.Mutex + locks map[string]*etcdLock +} + +type etcdLock struct { + s *cc.Session + m *cc.Mutex +} + +type etcdLeader struct { + opts sync.LeaderOptions + s *cc.Session + e *cc.Election + id string +} + +func (e *etcdSync) Leader(id string, opts ...sync.LeaderOption) (sync.Leader, error) { + var options sync.LeaderOptions + for _, o := range opts { + o(&options) + } + + // make path + path := path.Join(e.path, strings.Replace(e.options.Prefix+id, "/", "-", -1)) + + s, err := cc.NewSession(e.client) + if err != nil { + return nil, err + } + + l := cc.NewElection(s, path) + + if err := l.Campaign(context.TODO(), id); err != nil { + return nil, err + } + + return &etcdLeader{ + opts: options, + e: l, + id: id, + }, nil +} + +func (e *etcdLeader) Status() chan bool { + ch := make(chan bool, 1) + ech := e.e.Observe(context.Background()) + + go func() { + for r := range ech { + if string(r.Kvs[0].Value) != e.id { + ch <- true + close(ch) + return + } + } + }() + + return ch +} + +func (e *etcdLeader) Resign() error { + return e.e.Resign(context.Background()) +} + +func (e *etcdSync) Init(opts ...sync.Option) error { + for _, o := range opts { + o(&e.options) + } + return nil +} + +func (e *etcdSync) Options() sync.Options { + return e.options +} + +func (e *etcdSync) Lock(id string, opts ...sync.LockOption) error { + var options sync.LockOptions + for _, o := range opts { + o(&options) + } + + // make path + path := path.Join(e.path, strings.Replace(e.options.Prefix+id, "/", "-", -1)) + + var sopts []cc.SessionOption + if options.TTL > 0 { + sopts = append(sopts, cc.WithTTL(int(options.TTL.Seconds()))) + } + + s, err := cc.NewSession(e.client, sopts...) + if err != nil { + return err + } + + m := cc.NewMutex(s, path) + + if err := m.Lock(context.TODO()); err != nil { + return err + } + + e.mtx.Lock() + e.locks[id] = &etcdLock{ + s: s, + m: m, + } + e.mtx.Unlock() + return nil +} + +func (e *etcdSync) Unlock(id string) error { + e.mtx.Lock() + defer e.mtx.Unlock() + v, ok := e.locks[id] + if !ok { + return errors.New("lock not found") + } + err := v.m.Unlock(context.Background()) + delete(e.locks, id) + return err +} + +func (e *etcdSync) String() string { + return "etcd" +} + +func NewSync(opts ...sync.Option) sync.Sync { + var options sync.Options + for _, o := range opts { + o(&options) + } + + var endpoints []string + + for _, addr := range options.Nodes { + if len(addr) > 0 { + endpoints = append(endpoints, addr) + } + } + + if len(endpoints) == 0 { + endpoints = []string{"http://127.0.0.1:2379"} + } + + // TODO: parse addresses + c, err := client.New(client.Config{ + Endpoints: endpoints, + }) + if err != nil { + log.Fatal(err) + } + + return &etcdSync{ + path: "/micro/sync", + client: c, + options: options, + locks: make(map[string]*etcdLock), + } +} diff --git a/sync/leader/etcd/etcd.go b/sync/leader/etcd/etcd.go deleted file mode 100644 index 8e23370b..00000000 --- a/sync/leader/etcd/etcd.go +++ /dev/null @@ -1,136 +0,0 @@ -package etcd - -import ( - "context" - "log" - "path" - "strings" - - client "github.com/coreos/etcd/clientv3" - cc "github.com/coreos/etcd/clientv3/concurrency" - "github.com/micro/go-micro/v2/sync/leader" -) - -type etcdLeader struct { - opts leader.Options - path string - client *client.Client -} - -type etcdElected struct { - s *cc.Session - e *cc.Election - id string -} - -func (e *etcdLeader) Elect(id string, opts ...leader.ElectOption) (leader.Elected, error) { - var options leader.ElectOptions - for _, o := range opts { - o(&options) - } - - // make path - path := path.Join(e.path, strings.Replace(id, "/", "-", -1)) - - s, err := cc.NewSession(e.client) - if err != nil { - return nil, err - } - - l := cc.NewElection(s, path) - - if err := l.Campaign(context.TODO(), id); err != nil { - return nil, err - } - - return &etcdElected{ - e: l, - id: id, - }, nil -} - -func (e *etcdLeader) Follow() chan string { - ch := make(chan string) - - s, err := cc.NewSession(e.client) - if err != nil { - return ch - } - - l := cc.NewElection(s, e.path) - ech := l.Observe(context.Background()) - - go func() { - for r := range ech { - ch <- string(r.Kvs[0].Value) - } - }() - - return ch -} - -func (e *etcdLeader) String() string { - return "etcd" -} - -func (e *etcdElected) Reelect() error { - return e.e.Campaign(context.TODO(), e.id) -} - -func (e *etcdElected) Revoked() chan bool { - ch := make(chan bool, 1) - ech := e.e.Observe(context.Background()) - - go func() { - for r := range ech { - if string(r.Kvs[0].Value) != e.id { - ch <- true - close(ch) - return - } - } - }() - - return ch -} - -func (e *etcdElected) Resign() error { - return e.e.Resign(context.Background()) -} - -func (e *etcdElected) Id() string { - return e.id -} - -func NewLeader(opts ...leader.Option) leader.Leader { - var options leader.Options - for _, o := range opts { - o(&options) - } - - var endpoints []string - - for _, addr := range options.Nodes { - if len(addr) > 0 { - endpoints = append(endpoints, addr) - } - } - - if len(endpoints) == 0 { - endpoints = []string{"http://127.0.0.1:2379"} - } - - // TODO: parse addresses - c, err := client.New(client.Config{ - Endpoints: endpoints, - }) - if err != nil { - log.Fatal(err) - } - - return &etcdLeader{ - path: "/micro/leader", - client: c, - opts: options, - } -} diff --git a/sync/leader/leader.go b/sync/leader/leader.go deleted file mode 100644 index a4ac53f3..00000000 --- a/sync/leader/leader.go +++ /dev/null @@ -1,25 +0,0 @@ -// Package leader provides leader election -package leader - -// Leader provides leadership election -type Leader interface { - // elect leader - Elect(id string, opts ...ElectOption) (Elected, error) - // follow the leader - Follow() chan string -} - -type Elected interface { - // id of leader - Id() string - // seek re-election - Reelect() error - // resign leadership - Resign() error - // observe leadership revocation - Revoked() chan bool -} - -type Option func(o *Options) - -type ElectOption func(o *ElectOptions) diff --git a/sync/leader/options.go b/sync/leader/options.go deleted file mode 100644 index 05e92e91..00000000 --- a/sync/leader/options.go +++ /dev/null @@ -1,22 +0,0 @@ -package leader - -type Options struct { - Nodes []string - Group string -} - -type ElectOptions struct{} - -// Nodes sets the addresses of the underlying systems -func Nodes(a ...string) Option { - return func(o *Options) { - o.Nodes = a - } -} - -// Group sets the group name for coordinating leadership -func Group(g string) Option { - return func(o *Options) { - o.Group = g - } -} diff --git a/sync/lock/etcd/etcd.go b/sync/lock/etcd/etcd.go deleted file mode 100644 index 1d2a7e70..00000000 --- a/sync/lock/etcd/etcd.go +++ /dev/null @@ -1,113 +0,0 @@ -// Package etcd is an etcd implementation of lock -package etcd - -import ( - "context" - "errors" - "log" - "path" - "strings" - "sync" - - client "github.com/coreos/etcd/clientv3" - cc "github.com/coreos/etcd/clientv3/concurrency" - "github.com/micro/go-micro/v2/sync/lock" -) - -type etcdLock struct { - opts lock.Options - path string - client *client.Client - - sync.Mutex - locks map[string]*elock -} - -type elock struct { - s *cc.Session - m *cc.Mutex -} - -func (e *etcdLock) Acquire(id string, opts ...lock.AcquireOption) error { - var options lock.AcquireOptions - for _, o := range opts { - o(&options) - } - - // make path - path := path.Join(e.path, strings.Replace(e.opts.Prefix+id, "/", "-", -1)) - - var sopts []cc.SessionOption - if options.TTL > 0 { - sopts = append(sopts, cc.WithTTL(int(options.TTL.Seconds()))) - } - - s, err := cc.NewSession(e.client, sopts...) - if err != nil { - return err - } - - m := cc.NewMutex(s, path) - - if err := m.Lock(context.TODO()); err != nil { - return err - } - - e.Lock() - e.locks[id] = &elock{ - s: s, - m: m, - } - e.Unlock() - return nil -} - -func (e *etcdLock) Release(id string) error { - e.Lock() - defer e.Unlock() - v, ok := e.locks[id] - if !ok { - return errors.New("lock not found") - } - err := v.m.Unlock(context.Background()) - delete(e.locks, id) - return err -} - -func (e *etcdLock) String() string { - return "etcd" -} - -func NewLock(opts ...lock.Option) lock.Lock { - var options lock.Options - for _, o := range opts { - o(&options) - } - - var endpoints []string - - for _, addr := range options.Nodes { - if len(addr) > 0 { - endpoints = append(endpoints, addr) - } - } - - if len(endpoints) == 0 { - endpoints = []string{"http://127.0.0.1:2379"} - } - - // TODO: parse addresses - c, err := client.New(client.Config{ - Endpoints: endpoints, - }) - if err != nil { - log.Fatal(err) - } - - return &etcdLock{ - path: "/micro/lock", - client: c, - opts: options, - locks: make(map[string]*elock), - } -} diff --git a/sync/lock/http/http.go b/sync/lock/http/http.go deleted file mode 100644 index 3118c189..00000000 --- a/sync/lock/http/http.go +++ /dev/null @@ -1,135 +0,0 @@ -// Package http adds a http lock implementation -package http - -import ( - "errors" - "fmt" - "hash/crc32" - "io/ioutil" - "net/http" - "net/url" - "path/filepath" - "strings" - - "github.com/micro/go-micro/v2/sync/lock" -) - -var ( - DefaultPath = "/sync/lock" - DefaultAddress = "localhost:8080" -) - -type httpLock struct { - opts lock.Options -} - -func (h *httpLock) url(do, id string) (string, error) { - sum := crc32.ChecksumIEEE([]byte(id)) - node := h.opts.Nodes[sum%uint32(len(h.opts.Nodes))] - - // parse the host:port or whatever - uri, err := url.Parse(node) - if err != nil { - return "", err - } - - if len(uri.Scheme) == 0 { - uri.Scheme = "http" - } - - // set path - // build path - path := filepath.Join(DefaultPath, do, h.opts.Prefix, id) - uri.Path = path - - // return url - return uri.String(), nil -} - -func (h *httpLock) Acquire(id string, opts ...lock.AcquireOption) error { - var options lock.AcquireOptions - for _, o := range opts { - o(&options) - } - - uri, err := h.url("acquire", id) - if err != nil { - return err - } - - ttl := fmt.Sprintf("%d", int64(options.TTL.Seconds())) - wait := fmt.Sprintf("%d", int64(options.Wait.Seconds())) - - rsp, err := http.PostForm(uri, url.Values{ - "id": {id}, - "ttl": {ttl}, - "wait": {wait}, - }) - if err != nil { - return err - } - defer rsp.Body.Close() - - b, err := ioutil.ReadAll(rsp.Body) - if err != nil { - return err - } - - // success - if rsp.StatusCode == 200 { - return nil - } - - // return error - return errors.New(string(b)) -} - -func (h *httpLock) Release(id string) error { - uri, err := h.url("release", id) - if err != nil { - return err - } - - vals := url.Values{ - "id": {id}, - } - - req, err := http.NewRequest("DELETE", uri, strings.NewReader(vals.Encode())) - if err != nil { - return err - } - - rsp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer rsp.Body.Close() - - b, err := ioutil.ReadAll(rsp.Body) - if err != nil { - return err - } - - // success - if rsp.StatusCode == 200 { - return nil - } - - // return error - return errors.New(string(b)) -} - -func NewLock(opts ...lock.Option) lock.Lock { - var options lock.Options - for _, o := range opts { - o(&options) - } - - if len(options.Nodes) == 0 { - options.Nodes = []string{DefaultAddress} - } - - return &httpLock{ - opts: options, - } -} diff --git a/sync/lock/http/server/server.go b/sync/lock/http/server/server.go deleted file mode 100644 index df38fd69..00000000 --- a/sync/lock/http/server/server.go +++ /dev/null @@ -1,45 +0,0 @@ -// Package server implements the sync http server -package server - -import ( - "net/http" - - "github.com/micro/go-micro/v2/sync/lock" - lkhttp "github.com/micro/go-micro/v2/sync/lock/http" -) - -func Handler(lk lock.Lock) http.Handler { - mux := http.NewServeMux() - - mux.HandleFunc(lkhttp.DefaultPath, func(w http.ResponseWriter, r *http.Request) { - r.ParseForm() - - id := r.Form.Get("id") - if len(id) == 0 { - return - } - - switch r.Method { - case "POST": - err := lk.Acquire(id) - if err != nil { - http.Error(w, err.Error(), 500) - } - case "DELETE": - err := lk.Release(id) - if err != nil { - http.Error(w, err.Error(), 500) - } - } - }) - - return mux -} - -func Server(lk lock.Lock) *http.Server { - server := &http.Server{ - Addr: lkhttp.DefaultAddress, - Handler: Handler(lk), - } - return server -} diff --git a/sync/lock/lock.go b/sync/lock/lock.go deleted file mode 100644 index c21a9125..00000000 --- a/sync/lock/lock.go +++ /dev/null @@ -1,32 +0,0 @@ -// Package lock provides distributed locking -package lock - -import ( - "errors" - "time" -) - -var ( - ErrLockTimeout = errors.New("lock timeout") -) - -// Lock is a distributed locking interface -type Lock interface { - // Acquire a lock with given id - Acquire(id string, opts ...AcquireOption) error - // Release the lock with given id - Release(id string) error -} - -type Options struct { - Nodes []string - Prefix string -} - -type AcquireOptions struct { - TTL time.Duration - Wait time.Duration -} - -type Option func(o *Options) -type AcquireOption func(o *AcquireOptions) diff --git a/sync/lock/memory/memory.go b/sync/lock/memory/memory.go deleted file mode 100644 index 99ad1532..00000000 --- a/sync/lock/memory/memory.go +++ /dev/null @@ -1,142 +0,0 @@ -// Package memory provides a sync.Mutex implementation of the lock for local use -package memory - -import ( - "sync" - "time" - - lock "github.com/micro/go-micro/v2/sync/lock" -) - -type memoryLock struct { - sync.RWMutex - locks map[string]*mlock -} - -type mlock struct { - id string - time time.Time - ttl time.Duration - release chan bool -} - -func (m *memoryLock) Acquire(id string, opts ...lock.AcquireOption) error { - // lock our access - m.Lock() - - var options lock.AcquireOptions - for _, o := range opts { - o(&options) - } - - lk, ok := m.locks[id] - if !ok { - m.locks[id] = &mlock{ - id: id, - time: time.Now(), - ttl: options.TTL, - release: make(chan bool), - } - // unlock - m.Unlock() - return nil - } - - m.Unlock() - - // set wait time - var wait <-chan time.Time - var ttl <-chan time.Time - - // decide if we should wait - if options.Wait > time.Duration(0) { - wait = time.After(options.Wait) - } - - // check the ttl of the lock - if lk.ttl > time.Duration(0) { - // time lived for the lock - live := time.Since(lk.time) - - // set a timer for the leftover ttl - if live > lk.ttl { - // release the lock if it expired - _ = m.Release(id) - } else { - ttl = time.After(live) - } - } - -lockLoop: - for { - // wait for the lock to be released - select { - case <-lk.release: - m.Lock() - - // someone locked before us - lk, ok = m.locks[id] - if ok { - m.Unlock() - continue - } - - // got chance to lock - m.locks[id] = &mlock{ - id: id, - time: time.Now(), - ttl: options.TTL, - release: make(chan bool), - } - - m.Unlock() - - break lockLoop - case <-ttl: - // ttl exceeded - _ = m.Release(id) - // TODO: check the ttl again above - ttl = nil - // try acquire - continue - case <-wait: - return lock.ErrLockTimeout - } - } - - return nil -} - -func (m *memoryLock) Release(id string) error { - m.Lock() - defer m.Unlock() - - lk, ok := m.locks[id] - // no lock exists - if !ok { - return nil - } - - // delete the lock - delete(m.locks, id) - - select { - case <-lk.release: - return nil - default: - close(lk.release) - } - - return nil -} - -func NewLock(opts ...lock.Option) lock.Lock { - var options lock.Options - for _, o := range opts { - o(&options) - } - - return &memoryLock{ - locks: make(map[string]*mlock), - } -} diff --git a/sync/lock/options.go b/sync/lock/options.go deleted file mode 100644 index 4804ff9c..00000000 --- a/sync/lock/options.go +++ /dev/null @@ -1,33 +0,0 @@ -package lock - -import ( - "time" -) - -// Nodes sets the addresses the underlying lock implementation -func Nodes(a ...string) Option { - return func(o *Options) { - o.Nodes = a - } -} - -// Prefix sets a prefix to any lock ids used -func Prefix(p string) Option { - return func(o *Options) { - o.Prefix = p - } -} - -// TTL sets the lock ttl -func TTL(t time.Duration) AcquireOption { - return func(o *AcquireOptions) { - o.TTL = t - } -} - -// Wait sets the wait time -func Wait(t time.Duration) AcquireOption { - return func(o *AcquireOptions) { - o.Wait = t - } -} diff --git a/sync/map.go b/sync/map.go deleted file mode 100644 index 2196a4e0..00000000 --- a/sync/map.go +++ /dev/null @@ -1,156 +0,0 @@ -package sync - -import ( - "bytes" - "encoding/base64" - "encoding/json" - "fmt" - "sort" - - "github.com/micro/go-micro/v2/store" -) - -type syncMap struct { - opts Options -} - -func ekey(k interface{}) string { - b, _ := json.Marshal(k) - return base64.StdEncoding.EncodeToString(b) -} - -func (m *syncMap) Read(key, val interface{}) error { - if key == nil { - return fmt.Errorf("key is nil") - } - - kstr := ekey(key) - - // lock - if err := m.opts.Lock.Acquire(kstr); err != nil { - return err - } - defer m.opts.Lock.Release(kstr) - - // get key - kval, err := m.opts.Store.Read(kstr) - if err != nil { - return err - } - - if len(kval) == 0 { - return store.ErrNotFound - } - - // decode value - return json.Unmarshal(kval[0].Value, val) -} - -func (m *syncMap) Write(key, val interface{}) error { - if key == nil { - return fmt.Errorf("key is nil") - } - - kstr := ekey(key) - - // lock - if err := m.opts.Lock.Acquire(kstr); err != nil { - return err - } - defer m.opts.Lock.Release(kstr) - - // encode value - b, err := json.Marshal(val) - if err != nil { - return err - } - - // set key - return m.opts.Store.Write(&store.Record{ - Key: kstr, - Value: b, - }) -} - -func (m *syncMap) Delete(key interface{}) error { - if key == nil { - return fmt.Errorf("key is nil") - } - - kstr := ekey(key) - - // lock - if err := m.opts.Lock.Acquire(kstr); err != nil { - return err - } - defer m.opts.Lock.Release(kstr) - return m.opts.Store.Delete(kstr) -} - -func (m *syncMap) Iterate(fn func(key, val interface{}) error) error { - keyvals, err := m.opts.Store.Read("", store.ReadPrefix()) - if err != nil { - return err - } - - sort.Slice(keyvals, func(i, j int) bool { - return keyvals[i].Key < keyvals[j].Key - }) - - for _, keyval := range keyvals { - // lock - if err := m.opts.Lock.Acquire(keyval.Key); err != nil { - return err - } - // unlock - defer m.opts.Lock.Release(keyval.Key) - - // unmarshal value - var val interface{} - - if len(keyval.Value) > 0 && keyval.Value[0] == '{' { - if err := json.Unmarshal(keyval.Value, &val); err != nil { - return err - } - } else { - val = keyval.Value - } - - // exec func - if err := fn(keyval.Key, val); err != nil { - return err - } - - // save val - b, err := json.Marshal(val) - if err != nil { - return err - } - - // no save - if i := bytes.Compare(keyval.Value, b); i == 0 { - return nil - } - - // set key - if err := m.opts.Store.Write(&store.Record{ - Key: keyval.Key, - Value: b, - }); err != nil { - return err - } - } - - return nil -} - -func NewMap(opts ...Option) Map { - var options Options - for _, o := range opts { - o(&options) - } - - return &syncMap{ - opts: options, - } -} diff --git a/sync/memory/memory.go b/sync/memory/memory.go new file mode 100644 index 00000000..f3a92180 --- /dev/null +++ b/sync/memory/memory.go @@ -0,0 +1,202 @@ +// Package memory provides a sync.Mutex implementation of the lock for local use +package memory + +import ( + gosync "sync" + "time" + + "github.com/micro/go-micro/v2/sync" +) + +type memorySync struct { + options sync.Options + + mtx gosync.RWMutex + locks map[string]*memoryLock +} + +type memoryLock struct { + id string + time time.Time + ttl time.Duration + release chan bool +} + +type memoryLeader struct { + opts sync.LeaderOptions + id string + resign func(id string) error + status chan bool +} + +func (m *memoryLeader) Resign() error { + return m.resign(m.id) +} + +func (m *memoryLeader) Status() chan bool { + return m.status +} + +func (m *memorySync) Leader(id string, opts ...sync.LeaderOption) (sync.Leader, error) { + var once gosync.Once + var options sync.LeaderOptions + for _, o := range opts { + o(&options) + } + + // acquire a lock for the id + if err := m.Lock(id); err != nil { + return nil, err + } + + // return the leader + return &memoryLeader{ + opts: options, + id: id, + resign: func(id string) error { + once.Do(func() { + m.Unlock(id) + }) + return nil + }, + // TODO: signal when Unlock is called + status: make(chan bool, 1), + }, nil +} + +func (m *memorySync) Init(opts ...sync.Option) error { + for _, o := range opts { + o(&m.options) + } + return nil +} + +func (m *memorySync) Options() sync.Options { + return m.options +} + +func (m *memorySync) Lock(id string, opts ...sync.LockOption) error { + // lock our access + m.mtx.Lock() + + var options sync.LockOptions + for _, o := range opts { + o(&options) + } + + lk, ok := m.locks[id] + if !ok { + m.locks[id] = &memoryLock{ + id: id, + time: time.Now(), + ttl: options.TTL, + release: make(chan bool), + } + // unlock + m.mtx.Unlock() + return nil + } + + m.mtx.Unlock() + + // set wait time + var wait <-chan time.Time + var ttl <-chan time.Time + + // decide if we should wait + if options.Wait > time.Duration(0) { + wait = time.After(options.Wait) + } + + // check the ttl of the lock + if lk.ttl > time.Duration(0) { + // time lived for the lock + live := time.Since(lk.time) + + // set a timer for the leftover ttl + if live > lk.ttl { + // release the lock if it expired + _ = m.Unlock(id) + } else { + ttl = time.After(live) + } + } + +lockLoop: + for { + // wait for the lock to be released + select { + case <-lk.release: + m.mtx.Lock() + + // someone locked before us + lk, ok = m.locks[id] + if ok { + m.mtx.Unlock() + continue + } + + // got chance to lock + m.locks[id] = &memoryLock{ + id: id, + time: time.Now(), + ttl: options.TTL, + release: make(chan bool), + } + + m.mtx.Unlock() + + break lockLoop + case <-ttl: + // ttl exceeded + _ = m.Unlock(id) + // TODO: check the ttl again above + ttl = nil + // try acquire + continue + case <-wait: + return sync.ErrLockTimeout + } + } + + return nil +} + +func (m *memorySync) Unlock(id string) error { + m.mtx.Lock() + defer m.mtx.Unlock() + + lk, ok := m.locks[id] + // no lock exists + if !ok { + return nil + } + + // delete the lock + delete(m.locks, id) + + select { + case <-lk.release: + return nil + default: + close(lk.release) + } + + return nil +} + +func (m *memorySync) String() string { + return "memory" +} + +func NewSync(opts ...sync.Option) sync.Sync { + var options sync.Options + for _, o := range opts { + o(&options) + } + + return &memorySync{ + options: options, + locks: make(map[string]*memoryLock), + } +} diff --git a/sync/options.go b/sync/options.go index a179479d..6c546356 100644 --- a/sync/options.go +++ b/sync/options.go @@ -1,36 +1,33 @@ package sync import ( - "github.com/micro/go-micro/v2/store" - "github.com/micro/go-micro/v2/sync/leader" - "github.com/micro/go-micro/v2/sync/lock" - "github.com/micro/go-micro/v2/sync/time" + "time" ) -// WithLeader sets the leader election implementation opton -func WithLeader(l leader.Leader) Option { +// Nodes sets the addresses to use +func Nodes(a ...string) Option { return func(o *Options) { - o.Leader = l + o.Nodes = a } } -// WithLock sets the locking implementation option -func WithLock(l lock.Lock) Option { +// Prefix sets a prefix to any lock ids used +func Prefix(p string) Option { return func(o *Options) { - o.Lock = l + o.Prefix = p } } -// WithStore sets the store implementation option -func WithStore(s store.Store) Option { - return func(o *Options) { - o.Store = s +// LockTTL sets the lock ttl +func LockTTL(t time.Duration) LockOption { + return func(o *LockOptions) { + o.TTL = t } } -// WithTime sets the time implementation option -func WithTime(t time.Time) Option { - return func(o *Options) { - o.Time = t +// LockWait sets the wait time +func LockWait(t time.Duration) LockOption { + return func(o *LockOptions) { + o.Wait = t } } diff --git a/sync/sync.go b/sync/sync.go index 69d0c410..94d62043 100644 --- a/sync/sync.go +++ b/sync/sync.go @@ -2,40 +2,52 @@ package sync import ( - "github.com/micro/go-micro/v2/store" - "github.com/micro/go-micro/v2/sync/leader" - "github.com/micro/go-micro/v2/sync/lock" - "github.com/micro/go-micro/v2/sync/task" - "github.com/micro/go-micro/v2/sync/time" + "errors" + "time" ) -// Map provides synchronized access to key-value storage. -// It uses the store interface and lock interface to -// provide a consistent storage mechanism. -type Map interface { - // Read value with given key - Read(key, val interface{}) error - // Write value with given key - Write(key, val interface{}) error - // Delete value with given key - Delete(key interface{}) error - // Iterate over all key/vals. Value changes are saved - Iterate(func(key, val interface{}) error) error +var ( + ErrLockTimeout = errors.New("lock timeout") +) + +// Sync is an interface for synchronization +type Sync interface { + // Initialise options + Init(...Option) error + // Return the options + Options() Options + // Elect a leader + Leader(id string, opts ...LeaderOption) (Leader, error) + // Lock acquires a lock + Lock(id string, opts ...LockOption) error + // Unlock releases a lock + Unlock(id string) error + // Sync implementation + String() string } -// Cron is a distributed scheduler using leader election -// and distributed task runners. It uses the leader and -// task interfaces. -type Cron interface { - Schedule(task.Schedule, task.Command) error +// Leader provides leadership election +type Leader interface { + // resign leadership + Resign() error + // status returns when leadership is lost + Status() chan bool } type Options struct { - Leader leader.Leader - Lock lock.Lock - Store store.Store - Task task.Task - Time time.Time + Nodes []string + Prefix string } type Option func(o *Options) + +type LeaderOptions struct {} + +type LeaderOption func(o *LeaderOptions) + +type LockOptions struct { + TTL time.Duration + Wait time.Duration +} + +type LockOption func(o *LockOptions) diff --git a/sync/task/broker/broker.go b/sync/task/broker/broker.go deleted file mode 100644 index feedb0ec..00000000 --- a/sync/task/broker/broker.go +++ /dev/null @@ -1,227 +0,0 @@ -// Package broker provides a distributed task manager built on the micro broker -package broker - -import ( - "context" - "errors" - "fmt" - "math/rand" - "strings" - "sync" - "time" - - "github.com/google/uuid" - "github.com/micro/go-micro/v2/broker" - "github.com/micro/go-micro/v2/sync/task" -) - -type brokerKey struct{} - -// Task is a broker task -type Task struct { - // a micro broker - Broker broker.Broker - // Options - Options task.Options - - mtx sync.RWMutex - status string -} - -func returnError(err error, ch chan error) { - select { - case ch <- err: - default: - } -} - -func (t *Task) Run(c task.Command) error { - // connect - t.Broker.Connect() - // unique id for this runner - id := uuid.New().String() - // topic of the command - topic := fmt.Sprintf("task.%s", c.Name) - - // global error - errCh := make(chan error, t.Options.Pool) - - // subscribe for distributed work - workFn := func(p broker.Event) error { - msg := p.Message() - - // get command name - command := msg.Header["Command"] - - // check the command is what we expect - if command != c.Name { - returnError(errors.New("received unknown command: "+command), errCh) - return nil - } - - // new task created - switch msg.Header["Status"] { - case "start": - // artificially delay start of processing - time.Sleep(time.Millisecond * time.Duration(10+rand.Intn(100))) - - // execute the function - err := c.Func() - - status := "done" - errors := "" - - if err != nil { - status = "error" - errors = err.Error() - } - - // create response - msg := &broker.Message{ - Header: map[string]string{ - "Command": c.Name, - "Error": errors, - "Id": id, - "Status": status, - "Timestamp": fmt.Sprintf("%d", time.Now().Unix()), - }, - // Body is nil, may be used in future - } - - // publish end of task - if err := t.Broker.Publish(topic, msg); err != nil { - returnError(err, errCh) - } - } - - return nil - } - - // subscribe for the pool size - for i := 0; i < t.Options.Pool; i++ { - err := func() error { - // subscribe to work - subWork, err := t.Broker.Subscribe(topic, workFn, broker.Queue(fmt.Sprintf("work.%d", i))) - if err != nil { - return err - } - - // unsubscribe on completion - defer subWork.Unsubscribe() - - return nil - }() - - if err != nil { - return err - } - } - - // subscribe to all status messages - subStatus, err := t.Broker.Subscribe(topic, func(p broker.Event) error { - msg := p.Message() - - // get command name - command := msg.Header["Command"] - - // check the command is what we expect - if command != c.Name { - return nil - } - - // check task status - switch msg.Header["Status"] { - // task is complete - case "done": - errCh <- nil - // someone failed - case "error": - returnError(errors.New(msg.Header["Error"]), errCh) - } - - return nil - }) - if err != nil { - return err - } - defer subStatus.Unsubscribe() - - // a new task - msg := &broker.Message{ - Header: map[string]string{ - "Command": c.Name, - "Id": id, - "Status": "start", - "Timestamp": fmt.Sprintf("%d", time.Now().Unix()), - }, - } - - // artificially delay the start of the task - time.Sleep(time.Millisecond * time.Duration(10+rand.Intn(100))) - - // publish the task - if err := t.Broker.Publish(topic, msg); err != nil { - return err - } - - var gerrors []string - - // wait for all responses - for i := 0; i < t.Options.Pool; i++ { - // check errors - err := <-errCh - - // append to errors - if err != nil { - gerrors = append(gerrors, err.Error()) - } - } - - // return the errors - if len(gerrors) > 0 { - return errors.New("errors: " + strings.Join(gerrors, "\n")) - } - - return nil -} - -func (t *Task) Status() string { - t.mtx.RLock() - defer t.mtx.RUnlock() - return t.status -} - -// Broker sets the micro broker -func WithBroker(b broker.Broker) task.Option { - return func(o *task.Options) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, brokerKey{}, b) - } -} - -// NewTask returns a new broker task -func NewTask(opts ...task.Option) task.Task { - options := task.Options{ - Context: context.Background(), - } - - for _, o := range opts { - o(&options) - } - - if options.Pool == 0 { - options.Pool = 1 - } - - b, ok := options.Context.Value(brokerKey{}).(broker.Broker) - if !ok { - b = broker.DefaultBroker - } - - return &Task{ - Broker: b, - Options: options, - } -} diff --git a/sync/task/local/local.go b/sync/task/local/local.go deleted file mode 100644 index 5ce2631d..00000000 --- a/sync/task/local/local.go +++ /dev/null @@ -1,59 +0,0 @@ -// Package local provides a local task runner -package local - -import ( - "fmt" - "sync" - - "github.com/micro/go-micro/v2/sync/task" -) - -type localTask struct { - opts task.Options - mtx sync.RWMutex - status string -} - -func (l *localTask) Run(t task.Command) error { - ch := make(chan error, l.opts.Pool) - - for i := 0; i < l.opts.Pool; i++ { - go func() { - ch <- t.Execute() - }() - } - - var err error - - for i := 0; i < l.opts.Pool; i++ { - er := <-ch - if err != nil { - err = er - l.mtx.Lock() - l.status = fmt.Sprintf("command [%s] status: %s", t.Name, err.Error()) - l.mtx.Unlock() - } - } - - close(ch) - return err -} - -func (l *localTask) Status() string { - l.mtx.RLock() - defer l.mtx.RUnlock() - return l.status -} - -func NewTask(opts ...task.Option) task.Task { - var options task.Options - for _, o := range opts { - o(&options) - } - if options.Pool == 0 { - options.Pool = 1 - } - return &localTask{ - opts: options, - } -} diff --git a/sync/task/task.go b/sync/task/task.go deleted file mode 100644 index c9b9b5d6..00000000 --- a/sync/task/task.go +++ /dev/null @@ -1,85 +0,0 @@ -// Package task provides an interface for distributed jobs -package task - -import ( - "context" - "fmt" - "time" -) - -// Task represents a distributed task -type Task interface { - // Run runs a command immediately until completion - Run(Command) error - // Status provides status of last execution - Status() string -} - -// Command to be executed -type Command struct { - Name string - Func func() error -} - -// Schedule represents a time or interval at which a task should run -type Schedule struct { - // When to start the schedule. Zero time means immediately - Time time.Time - // Non zero interval dictates an ongoing schedule - Interval time.Duration -} - -type Options struct { - // Pool size for workers - Pool int - // Alternative options - Context context.Context -} - -type Option func(o *Options) - -func (c Command) Execute() error { - return c.Func() -} - -func (c Command) String() string { - return c.Name -} - -func (s Schedule) Run() <-chan time.Time { - d := s.Time.Sub(time.Now()) - - ch := make(chan time.Time, 1) - - go func() { - // wait for start time - <-time.After(d) - - // zero interval - if s.Interval == time.Duration(0) { - ch <- time.Now() - close(ch) - return - } - - // start ticker - ticker := time.NewTicker(s.Interval) - defer ticker.Stop() - for t := range ticker.C { - ch <- t - } - }() - - return ch -} - -func (s Schedule) String() string { - return fmt.Sprintf("%d-%d", s.Time.Unix(), s.Interval) -} - -// WithPool sets the pool size for concurrent work -func WithPool(i int) Option { - return func(o *Options) { - o.Pool = i - } -} diff --git a/sync/time/local/local.go b/sync/time/local/local.go deleted file mode 100644 index 6be36de7..00000000 --- a/sync/time/local/local.go +++ /dev/null @@ -1,18 +0,0 @@ -// Package local provides a local clock -package local - -import ( - gotime "time" - - "github.com/micro/go-micro/v2/sync/time" -) - -type Time struct{} - -func (t *Time) Now() (gotime.Time, error) { - return gotime.Now(), nil -} - -func NewTime(opts ...time.Option) time.Time { - return new(Time) -} diff --git a/sync/time/ntp/ntp.go b/sync/time/ntp/ntp.go deleted file mode 100644 index 91cf5862..00000000 --- a/sync/time/ntp/ntp.go +++ /dev/null @@ -1,51 +0,0 @@ -// Package ntp provides ntp synchronized time -package ntp - -import ( - "context" - gotime "time" - - "github.com/beevik/ntp" - "github.com/micro/go-micro/v2/sync/time" -) - -type ntpTime struct { - server string -} - -type ntpServerKey struct{} - -func (n *ntpTime) Now() (gotime.Time, error) { - return ntp.Time(n.server) -} - -// NewTime returns ntp time -func NewTime(opts ...time.Option) time.Time { - options := time.Options{ - Context: context.Background(), - } - - for _, o := range opts { - o(&options) - } - - server := "time.google.com" - - if k, ok := options.Context.Value(ntpServerKey{}).(string); ok { - server = k - } - - return &ntpTime{ - server: server, - } -} - -// WithServer sets the ntp server -func WithServer(s string) time.Option { - return func(o *time.Options) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, ntpServerKey{}, s) - } -} diff --git a/sync/time/time.go b/sync/time/time.go deleted file mode 100644 index 7c11a751..00000000 --- a/sync/time/time.go +++ /dev/null @@ -1,18 +0,0 @@ -// Package time provides clock synchronization -package time - -import ( - "context" - "time" -) - -// Time returns synchronized time -type Time interface { - Now() (time.Time, error) -} - -type Options struct { - Context context.Context -} - -type Option func(o *Options) From b887d91f94078eeb65698f3368db80e1b7b5a2f2 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 10:38:13 +0100 Subject: [PATCH 604/788] remove readme --- sync/README.md | 116 ------------------------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 sync/README.md diff --git a/sync/README.md b/sync/README.md deleted file mode 100644 index d69c2060..00000000 --- a/sync/README.md +++ /dev/null @@ -1,116 +0,0 @@ -# Sync - -Sync is a synchronization library for distributed systems. - -## Overview - -Distributed systems by their very nature are decoupled and independent. In most cases they must honour 2 out of 3 letters of the CAP theorem -e.g Availability and Partitional tolerance but sacrificing consistency. In the case of microservices we often offload this concern to -an external database or eventing system. Go Sync provides a framework for synchronization which can be used in the application by the developer. - -## Getting Started - -- [Leader](#leader) - leadership election for group coordination -- [Lock](#lock) - distributed locking for exclusive resource access -- [Task](#task) - distributed job execution -- [Time](#time) - provides synchronized time - -## Lock - -The Lock interface provides distributed locking. Multiple instances attempting to lock the same id will block until available. - -```go -import "github.com/micro/go-micro/sync/lock/consul" - -lock := consul.NewLock() - -// acquire lock -err := lock.Acquire("id") -// handle err - -// release lock -err = lock.Release("id") -// handle err -``` - -## Leader - -Leader provides leadership election. Useful where one node needs to coordinate some action. - -```go -import ( - "github.com/micro/go-micro/sync/leader" - "github.com/micro/go-micro/sync/leader/consul" -) - -l := consul.NewLeader( - leader.Group("name"), -) - -// elect leader -e, err := l.Elect("id") -// handle err - - -// operate while leader -revoked := e.Revoked() - -for { - select { - case <-revoked: - // re-elect - e.Elect("id") - default: - // leader operation - } -} - -// resign leadership -e.Resign() -``` - -## Task - -Task provides distributed job execution. It's a simple way to distribute work across a coordinated pool of workers. - -```go -import ( - "github.com/micro/go-micro/sync/task" - "github.com/micro/go-micro/sync/task/local" -) - -t := local.NewTask( - task.WithPool(10), -) - -err := t.Run(task.Command{ - Name: "atask", - Func: func() error { - // exec some work - return nil - }, -}) - -if err != nil { - // do something -} -``` - -## Time - -Time provides synchronized time. Local machines may have clock skew and time cannot be guaranteed to be the same everywhere. -Synchronized Time allows you to decide how time is defined for your applications. - -```go -import ( - "github.com/micro/go-micro/sync/time/ntp" -) - - -t := ntp.NewTime() -time, err := t.Now() -``` - -## TODO - -- Event package - strongly consistent event stream e.g kafka From c697eed1be8be7060c84008f3c145af7111dacd9 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 10:48:32 +0100 Subject: [PATCH 605/788] Update comments --- sync/sync.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sync/sync.go b/sync/sync.go index 94d62043..ebaec6da 100644 --- a/sync/sync.go +++ b/sync/sync.go @@ -1,4 +1,4 @@ -// Package sync is a distributed synchronization framework +// Package sync is an interface for distributed synchronization package sync import ( @@ -10,7 +10,7 @@ var ( ErrLockTimeout = errors.New("lock timeout") ) -// Sync is an interface for synchronization +// Sync is an interface for distributed synchronization type Sync interface { // Initialise options Init(...Option) error From 0f2006ac508f3ab69349349453496a5be9325200 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 11:02:06 +0100 Subject: [PATCH 606/788] fix compilation issues --- api/server/acme/certmagic/storage.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/server/acme/certmagic/storage.go b/api/server/acme/certmagic/storage.go index dc805e98..4e26b888 100644 --- a/api/server/acme/certmagic/storage.go +++ b/api/server/acme/certmagic/storage.go @@ -11,7 +11,7 @@ import ( "github.com/mholt/certmagic" "github.com/micro/go-micro/v2/store" - "github.com/micro/go-micro/v2/sync/lock" + "github.com/micro/go-micro/v2/sync" ) // File represents a "File" that will be stored in store.Store - the contents and last modified time @@ -26,16 +26,16 @@ type File struct { // As certmagic storage expects a filesystem (with stat() abilities) we have to implement // the bare minimum of metadata. type storage struct { - lock lock.Lock + lock sync.Sync store store.Store } func (s *storage) Lock(key string) error { - return s.lock.Acquire(key, lock.TTL(10*time.Minute)) + return s.lock.Lock(key, sync.LockTTL(10*time.Minute)) } func (s *storage) Unlock(key string) error { - return s.lock.Release(key) + return s.lock.Unlock(key) } func (s *storage) Store(key string, value []byte) error { @@ -139,7 +139,7 @@ func (s *storage) Stat(key string) (certmagic.KeyInfo, error) { } // NewStorage returns a certmagic.Storage backed by a go-micro/lock and go-micro/store -func NewStorage(lock lock.Lock, store store.Store) certmagic.Storage { +func NewStorage(lock sync.Sync, store store.Store) certmagic.Storage { return &storage{ lock: lock, store: store, From ac8b6f944ecabc7ec1b8c3a66cd60376698ab960 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 11:15:01 +0100 Subject: [PATCH 607/788] Prefix logs dir micro/logs for runtime --- runtime/default.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/default.go b/runtime/default.go index a0ea161b..e8b567c5 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -178,7 +178,7 @@ func (r *runtime) run(events <-chan Event) { func logFile(serviceName string) string { name := strings.Replace(serviceName, "/", "-", -1) - return filepath.Join(os.TempDir(), fmt.Sprintf("%v.log", name)) + return filepath.Join(os.TempDir(), "micro", "logs", fmt.Sprintf("%v.log", name)) } // Create creates a new service which is then started by runtime From c8782375675b7430a879da9fed16fcaa576628bb Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 11:22:02 +0100 Subject: [PATCH 608/788] fix log file creation --- runtime/default.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/default.go b/runtime/default.go index e8b567c5..2ef813ff 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -40,6 +40,10 @@ func NewRuntime(opts ...Option) Runtime { o(&options) } + // make the logs directory + path := filepath.Join(os.TempDir(), "micro", "logs") + _ = os.MkdirAll(path, 0755) + return &runtime{ options: options, closed: make(chan bool), @@ -177,8 +181,10 @@ func (r *runtime) run(events <-chan Event) { } func logFile(serviceName string) string { + // make the directory name := strings.Replace(serviceName, "/", "-", -1) - return filepath.Join(os.TempDir(), "micro", "logs", fmt.Sprintf("%v.log", name)) + path := filepath.Join(os.TempDir(), "micro", "logs") + return filepath.Join(path, fmt.Sprintf("%v.log", name)) } // Create creates a new service which is then started by runtime From bb1ccf09e8b33581fe2d76091caa1923ebd53df3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 11:23:41 +0100 Subject: [PATCH 609/788] prefix store dir --- store/file/file.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/store/file/file.go b/store/file/file.go index cddcaf80..5f0fc95e 100644 --- a/store/file/file.go +++ b/store/file/file.go @@ -21,7 +21,7 @@ var ( // DefaultTable when none is specified DefaultTable = "micro" // DefaultDir is the default directory for bbolt files - DefaultDir = os.TempDir() + DefaultDir = filepath.Join(os.TempDir(), "micro", "store") // bucket used for data storage dataBucket = "data" From 3f81f685dfb584005705890ff0740b932509c033 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 12:00:34 +0100 Subject: [PATCH 610/788] Move sync --- {store => util}/sync/manager.go | 0 {store => util}/sync/options.go | 0 {store => util}/sync/sync.go | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {store => util}/sync/manager.go (100%) rename {store => util}/sync/options.go (100%) rename {store => util}/sync/sync.go (100%) diff --git a/store/sync/manager.go b/util/sync/manager.go similarity index 100% rename from store/sync/manager.go rename to util/sync/manager.go diff --git a/store/sync/options.go b/util/sync/options.go similarity index 100% rename from store/sync/options.go rename to util/sync/options.go diff --git a/store/sync/sync.go b/util/sync/sync.go similarity index 100% rename from store/sync/sync.go rename to util/sync/sync.go From 51d4f737b8129b76c953dbef757a3479e4549a48 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 12:10:19 +0100 Subject: [PATCH 611/788] fixup store cache# --- store/cache/cache.go | 39 ++++++++++++++++++++++++++++----------- store/cache/cache_test.go | 7 +++---- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/store/cache/cache.go b/store/cache/cache.go index 96790b7a..996d96e1 100644 --- a/store/cache/cache.go +++ b/store/cache/cache.go @@ -5,21 +5,34 @@ import ( "fmt" "github.com/micro/go-micro/v2/store" + "github.com/micro/go-micro/v2/store/memory" "github.com/pkg/errors" ) type cache struct { - stores []store.Store - options store.Options + stores []store.Store +} + +// Cache is a cpu register style cache for the store. +// It syncs between N stores in a faulting manner. +type Cache interface { + // Implements the store interface + store.Store } // NewCache returns a new store using the underlying stores, which must be already Init()ialised -func NewCache(stores ...store.Store) store.Store { - c := &cache{} - c.stores = make([]store.Store, len(stores)) - for i, s := range stores { - c.stores[i] = s +func NewCache(stores ...store.Store) Cache { + if len(stores) == 0 { + stores = []store.Store{ + memory.NewStore(), + } } + + // TODO: build in an in memory cache + c := &cache{ + stores: stores, + } + return c } @@ -27,15 +40,19 @@ func (c *cache) Close() error { return nil } -func (c *cache) Init(...store.Option) error { - if len(c.stores) < 2 { - return errors.New("cache requires at least 2 stores") +func (c *cache) Init(opts ...store.Option) error { + // pass to the stores + for _, store := range c.stores { + if err := store.Init(opts...); err != nil { + return err + } } return nil } func (c *cache) Options() store.Options { - return c.options + // return from first store + return c.stores[0].Options() } func (c *cache) String() string { diff --git a/store/cache/cache_test.go b/store/cache/cache_test.go index e58b2b0b..ddfa5494 100644 --- a/store/cache/cache_test.go +++ b/store/cache/cache_test.go @@ -15,13 +15,12 @@ func TestCache(t *testing.T) { assert := assert.New(t) - nonCache := NewCache(l0) - assert.NotNil(nonCache.Init(), "Expected a cache initialised with just 1 store to fail") + nonCache := NewCache(nil) + assert.Equal(len(nonCache.(*cache).stores), 1, "Expected a cache initialised with just 1 store to fail") // Basic functionality cachedStore := NewCache(l0, l1, l2) - assert.Nil(cachedStore.Init(), "Init should not error") - assert.Equal(cachedStore.Options(), store.Options{}, "Options on store/cache are nonsensical") + assert.Equal(cachedStore.Options(), l0.Options(), "Options on store/cache are nonsensical") expectedString := "cache [memory memory memory]" assert.Equal(cachedStore.String(), expectedString, "Cache couldn't describe itself as expected") From ea2bb0275c7f2a6afb1fec8bd2269adb6c818f04 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 13:02:53 +0100 Subject: [PATCH 612/788] Strip external use of mdns --- go.mod | 2 - go.sum | 10 - registry/mdns_registry.go | 2 +- registry/mdns_watcher.go | 2 +- util/mdns/.gitignore | 23 ++ util/mdns/client.go | 501 ++++++++++++++++++++++++++++++++++++++ util/mdns/dns_sd.go | 84 +++++++ util/mdns/dns_sd_test.go | 68 ++++++ util/mdns/server.go | 476 ++++++++++++++++++++++++++++++++++++ util/mdns/server_test.go | 61 +++++ util/mdns/zone.go | 309 +++++++++++++++++++++++ util/mdns/zone_test.go | 275 +++++++++++++++++++++ 12 files changed, 1799 insertions(+), 14 deletions(-) create mode 100644 util/mdns/.gitignore create mode 100644 util/mdns/client.go create mode 100644 util/mdns/dns_sd.go create mode 100644 util/mdns/dns_sd_test.go create mode 100644 util/mdns/server.go create mode 100644 util/mdns/server_test.go create mode 100644 util/mdns/zone.go create mode 100644 util/mdns/zone_test.go diff --git a/go.mod b/go.mod index cf373f7a..8a445a11 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.13 require ( github.com/BurntSushi/toml v0.3.1 - github.com/beevik/ntp v0.2.0 github.com/bitly/go-simplejson v0.5.0 github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect github.com/bwmarrin/discordgo v0.20.2 @@ -47,7 +46,6 @@ require ( github.com/lucas-clemente/quic-go v0.14.1 github.com/mholt/certmagic v0.9.3 github.com/micro/cli/v2 v2.1.2 - github.com/micro/mdns v0.3.0 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 github.com/nats-io/nats-server/v2 v2.1.6 diff --git a/go.sum b/go.sum index 848d8da2..db9453b6 100644 --- a/go.sum +++ b/go.sum @@ -53,8 +53,6 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aws/aws-sdk-go v1.23.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= -github.com/beevik/ntp v0.2.0 h1:sGsd+kAXzT0bfVfzJfce04g+dSRfrs+tbQW8lweuYgw= -github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -290,9 +288,6 @@ github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= -github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= -github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= -github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= @@ -314,7 +309,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server v1.4.1 h1:Ul1oSOGNV/L8kjr4v6l2f9Yet6WY+LevH1/7cRZ/qyA= github.com/nats-io/nats-server/v2 v2.1.6 h1:qAaHZaS8pRRNQLFaiBA1rq5WynyEGp9DFgmMfoaiXGY= github.com/nats-io/nats-server/v2 v2.1.6/go.mod h1:BL1NOtaBQ5/y97djERRVWNouMW7GT3gxnmbE/eC8u8A= github.com/nats-io/nats.go v1.9.2 h1:oDeERm3NcZVrPpdR/JpGdWHMv3oJ8yY30YwxKq+DU2s= @@ -454,7 +448,6 @@ go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -465,8 +458,6 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw= -golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -530,7 +521,6 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/registry/mdns_registry.go b/registry/mdns_registry.go index 7e614840..dfc8e6f0 100644 --- a/registry/mdns_registry.go +++ b/registry/mdns_registry.go @@ -17,7 +17,7 @@ import ( "github.com/google/uuid" "github.com/micro/go-micro/v2/logger" - "github.com/micro/mdns" + "github.com/micro/go-micro/v2/util/mdns" ) var ( diff --git a/registry/mdns_watcher.go b/registry/mdns_watcher.go index 402811b9..e0ef4a48 100644 --- a/registry/mdns_watcher.go +++ b/registry/mdns_watcher.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/micro/mdns" + "github.com/micro/go-micro/v2/util/mdns" ) type mdnsWatcher struct { diff --git a/util/mdns/.gitignore b/util/mdns/.gitignore new file mode 100644 index 00000000..83656241 --- /dev/null +++ b/util/mdns/.gitignore @@ -0,0 +1,23 @@ +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +*.test diff --git a/util/mdns/client.go b/util/mdns/client.go new file mode 100644 index 00000000..176ebac4 --- /dev/null +++ b/util/mdns/client.go @@ -0,0 +1,501 @@ +package mdns + +import ( + "context" + "fmt" + "log" + "net" + "strings" + "sync" + "time" + + "github.com/miekg/dns" + "golang.org/x/net/ipv4" + "golang.org/x/net/ipv6" +) + +// ServiceEntry is returned after we query for a service +type ServiceEntry struct { + Name string + Host string + AddrV4 net.IP + AddrV6 net.IP + Port int + Info string + InfoFields []string + TTL int + Type uint16 + + Addr net.IP // @Deprecated + + hasTXT bool + sent bool +} + +// complete is used to check if we have all the info we need +func (s *ServiceEntry) complete() bool { + return (s.AddrV4 != nil || s.AddrV6 != nil || s.Addr != nil) && s.Port != 0 && s.hasTXT +} + +// QueryParam is used to customize how a Lookup is performed +type QueryParam struct { + Service string // Service to lookup + Domain string // Lookup domain, default "local" + Type uint16 // Lookup type, defaults to dns.TypePTR + Context context.Context // Context + Timeout time.Duration // Lookup timeout, default 1 second. Ignored if Context is provided + Interface *net.Interface // Multicast interface to use + Entries chan<- *ServiceEntry // Entries Channel + WantUnicastResponse bool // Unicast response desired, as per 5.4 in RFC +} + +// DefaultParams is used to return a default set of QueryParam's +func DefaultParams(service string) *QueryParam { + return &QueryParam{ + Service: service, + Domain: "local", + Timeout: time.Second, + Entries: make(chan *ServiceEntry), + WantUnicastResponse: false, // TODO(reddaly): Change this default. + } +} + +// Query looks up a given service, in a domain, waiting at most +// for a timeout before finishing the query. The results are streamed +// to a channel. Sends will not block, so clients should make sure to +// either read or buffer. +func Query(params *QueryParam) error { + // Create a new client + client, err := newClient() + if err != nil { + return err + } + defer client.Close() + + // Set the multicast interface + if params.Interface != nil { + if err := client.setInterface(params.Interface, false); err != nil { + return err + } + } + + // Ensure defaults are set + if params.Domain == "" { + params.Domain = "local" + } + + if params.Context == nil { + if params.Timeout == 0 { + params.Timeout = time.Second + } + params.Context, _ = context.WithTimeout(context.Background(), params.Timeout) + if err != nil { + return err + } + } + + // Run the query + return client.query(params) +} + +// Listen listens indefinitely for multicast updates +func Listen(entries chan<- *ServiceEntry, exit chan struct{}) error { + // Create a new client + client, err := newClient() + if err != nil { + return err + } + defer client.Close() + + client.setInterface(nil, true) + + // Start listening for response packets + msgCh := make(chan *dns.Msg, 32) + + go client.recv(client.ipv4UnicastConn, msgCh) + go client.recv(client.ipv6UnicastConn, msgCh) + go client.recv(client.ipv4MulticastConn, msgCh) + go client.recv(client.ipv6MulticastConn, msgCh) + + ip := make(map[string]*ServiceEntry) + + for { + select { + case <-exit: + return nil + case <-client.closedCh: + return nil + case m := <-msgCh: + e := messageToEntry(m, ip) + if e == nil { + continue + } + + // Check if this entry is complete + if e.complete() { + if e.sent { + continue + } + e.sent = true + entries <- e + ip = make(map[string]*ServiceEntry) + } else { + // Fire off a node specific query + m := new(dns.Msg) + m.SetQuestion(e.Name, dns.TypePTR) + m.RecursionDesired = false + if err := client.sendQuery(m); err != nil { + log.Printf("[ERR] mdns: Failed to query instance %s: %v", e.Name, err) + } + } + } + } + + return nil +} + +// Lookup is the same as Query, however it uses all the default parameters +func Lookup(service string, entries chan<- *ServiceEntry) error { + params := DefaultParams(service) + params.Entries = entries + return Query(params) +} + +// Client provides a query interface that can be used to +// search for service providers using mDNS +type client struct { + ipv4UnicastConn *net.UDPConn + ipv6UnicastConn *net.UDPConn + + ipv4MulticastConn *net.UDPConn + ipv6MulticastConn *net.UDPConn + + closed bool + closedCh chan struct{} // TODO(reddaly): This doesn't appear to be used. + closeLock sync.Mutex +} + +// NewClient creates a new mdns Client that can be used to query +// for records +func newClient() (*client, error) { + // TODO(reddaly): At least attempt to bind to the port required in the spec. + // Create a IPv4 listener + uconn4, err4 := net.ListenUDP("udp4", &net.UDPAddr{IP: net.IPv4zero, Port: 0}) + uconn6, err6 := net.ListenUDP("udp6", &net.UDPAddr{IP: net.IPv6zero, Port: 0}) + if err4 != nil && err6 != nil { + log.Printf("[ERR] mdns: Failed to bind to udp port: %v %v", err4, err6) + } + + if uconn4 == nil && uconn6 == nil { + return nil, fmt.Errorf("failed to bind to any unicast udp port") + } + + if uconn4 == nil { + uconn4 = &net.UDPConn{} + } + + if uconn6 == nil { + uconn6 = &net.UDPConn{} + } + + mconn4, err4 := net.ListenUDP("udp4", mdnsWildcardAddrIPv4) + mconn6, err6 := net.ListenUDP("udp6", mdnsWildcardAddrIPv6) + if err4 != nil && err6 != nil { + log.Printf("[ERR] mdns: Failed to bind to udp port: %v %v", err4, err6) + } + + if mconn4 == nil && mconn6 == nil { + return nil, fmt.Errorf("failed to bind to any multicast udp port") + } + + if mconn4 == nil { + mconn4 = &net.UDPConn{} + } + + if mconn6 == nil { + mconn6 = &net.UDPConn{} + } + + p1 := ipv4.NewPacketConn(mconn4) + p2 := ipv6.NewPacketConn(mconn6) + p1.SetMulticastLoopback(true) + p2.SetMulticastLoopback(true) + + ifaces, err := net.Interfaces() + if err != nil { + return nil, err + } + + var errCount1, errCount2 int + + for _, iface := range ifaces { + if err := p1.JoinGroup(&iface, &net.UDPAddr{IP: mdnsGroupIPv4}); err != nil { + errCount1++ + } + if err := p2.JoinGroup(&iface, &net.UDPAddr{IP: mdnsGroupIPv6}); err != nil { + errCount2++ + } + } + + if len(ifaces) == errCount1 && len(ifaces) == errCount2 { + return nil, fmt.Errorf("Failed to join multicast group on all interfaces!") + } + + c := &client{ + ipv4MulticastConn: mconn4, + ipv6MulticastConn: mconn6, + ipv4UnicastConn: uconn4, + ipv6UnicastConn: uconn6, + closedCh: make(chan struct{}), + } + return c, nil +} + +// Close is used to cleanup the client +func (c *client) Close() error { + c.closeLock.Lock() + defer c.closeLock.Unlock() + + if c.closed { + return nil + } + c.closed = true + + close(c.closedCh) + + if c.ipv4UnicastConn != nil { + c.ipv4UnicastConn.Close() + } + if c.ipv6UnicastConn != nil { + c.ipv6UnicastConn.Close() + } + if c.ipv4MulticastConn != nil { + c.ipv4MulticastConn.Close() + } + if c.ipv6MulticastConn != nil { + c.ipv6MulticastConn.Close() + } + + return nil +} + +// setInterface is used to set the query interface, uses sytem +// default if not provided +func (c *client) setInterface(iface *net.Interface, loopback bool) error { + p := ipv4.NewPacketConn(c.ipv4UnicastConn) + if err := p.JoinGroup(iface, &net.UDPAddr{IP: mdnsGroupIPv4}); err != nil { + return err + } + p2 := ipv6.NewPacketConn(c.ipv6UnicastConn) + if err := p2.JoinGroup(iface, &net.UDPAddr{IP: mdnsGroupIPv6}); err != nil { + return err + } + p = ipv4.NewPacketConn(c.ipv4MulticastConn) + if err := p.JoinGroup(iface, &net.UDPAddr{IP: mdnsGroupIPv4}); err != nil { + return err + } + p2 = ipv6.NewPacketConn(c.ipv6MulticastConn) + if err := p2.JoinGroup(iface, &net.UDPAddr{IP: mdnsGroupIPv6}); err != nil { + return err + } + + if loopback { + p.SetMulticastLoopback(true) + p2.SetMulticastLoopback(true) + } + + return nil +} + +// query is used to perform a lookup and stream results +func (c *client) query(params *QueryParam) error { + // Create the service name + serviceAddr := fmt.Sprintf("%s.%s.", trimDot(params.Service), trimDot(params.Domain)) + + // Start listening for response packets + msgCh := make(chan *dns.Msg, 32) + go c.recv(c.ipv4UnicastConn, msgCh) + go c.recv(c.ipv6UnicastConn, msgCh) + go c.recv(c.ipv4MulticastConn, msgCh) + go c.recv(c.ipv6MulticastConn, msgCh) + + // Send the query + m := new(dns.Msg) + if params.Type == dns.TypeNone { + m.SetQuestion(serviceAddr, dns.TypePTR) + } else { + m.SetQuestion(serviceAddr, params.Type) + } + // RFC 6762, section 18.12. Repurposing of Top Bit of qclass in Question + // Section + // + // In the Question Section of a Multicast DNS query, the top bit of the qclass + // field is used to indicate that unicast responses are preferred for this + // particular question. (See Section 5.4.) + if params.WantUnicastResponse { + m.Question[0].Qclass |= 1 << 15 + } + m.RecursionDesired = false + if err := c.sendQuery(m); err != nil { + return err + } + + // Map the in-progress responses + inprogress := make(map[string]*ServiceEntry) + + for { + select { + case resp := <-msgCh: + inp := messageToEntry(resp, inprogress) + if inp == nil { + continue + } + + // Check if this entry is complete + if inp.complete() { + if inp.sent { + continue + } + inp.sent = true + select { + case params.Entries <- inp: + case <-params.Context.Done(): + return nil + } + } else { + // Fire off a node specific query + m := new(dns.Msg) + m.SetQuestion(inp.Name, inp.Type) + m.RecursionDesired = false + if err := c.sendQuery(m); err != nil { + log.Printf("[ERR] mdns: Failed to query instance %s: %v", inp.Name, err) + } + } + case <-params.Context.Done(): + return nil + } + } +} + +// sendQuery is used to multicast a query out +func (c *client) sendQuery(q *dns.Msg) error { + buf, err := q.Pack() + if err != nil { + return err + } + if c.ipv4UnicastConn != nil { + c.ipv4UnicastConn.WriteToUDP(buf, ipv4Addr) + } + if c.ipv6UnicastConn != nil { + c.ipv6UnicastConn.WriteToUDP(buf, ipv6Addr) + } + return nil +} + +// recv is used to receive until we get a shutdown +func (c *client) recv(l *net.UDPConn, msgCh chan *dns.Msg) { + if l == nil { + return + } + buf := make([]byte, 65536) + for { + c.closeLock.Lock() + if c.closed { + c.closeLock.Unlock() + return + } + c.closeLock.Unlock() + n, err := l.Read(buf) + if err != nil { + continue + } + msg := new(dns.Msg) + if err := msg.Unpack(buf[:n]); err != nil { + continue + } + select { + case msgCh <- msg: + case <-c.closedCh: + return + } + } +} + +// ensureName is used to ensure the named node is in progress +func ensureName(inprogress map[string]*ServiceEntry, name string, typ uint16) *ServiceEntry { + if inp, ok := inprogress[name]; ok { + return inp + } + inp := &ServiceEntry{ + Name: name, + Type: typ, + } + inprogress[name] = inp + return inp +} + +// alias is used to setup an alias between two entries +func alias(inprogress map[string]*ServiceEntry, src, dst string, typ uint16) { + srcEntry := ensureName(inprogress, src, typ) + inprogress[dst] = srcEntry +} + +func messageToEntry(m *dns.Msg, inprogress map[string]*ServiceEntry) *ServiceEntry { + var inp *ServiceEntry + + for _, answer := range append(m.Answer, m.Extra...) { + // TODO(reddaly): Check that response corresponds to serviceAddr? + switch rr := answer.(type) { + case *dns.PTR: + // Create new entry for this + inp = ensureName(inprogress, rr.Ptr, rr.Hdr.Rrtype) + if inp.complete() { + continue + } + case *dns.SRV: + // Check for a target mismatch + if rr.Target != rr.Hdr.Name { + alias(inprogress, rr.Hdr.Name, rr.Target, rr.Hdr.Rrtype) + } + + // Get the port + inp = ensureName(inprogress, rr.Hdr.Name, rr.Hdr.Rrtype) + if inp.complete() { + continue + } + inp.Host = rr.Target + inp.Port = int(rr.Port) + case *dns.TXT: + // Pull out the txt + inp = ensureName(inprogress, rr.Hdr.Name, rr.Hdr.Rrtype) + if inp.complete() { + continue + } + inp.Info = strings.Join(rr.Txt, "|") + inp.InfoFields = rr.Txt + inp.hasTXT = true + case *dns.A: + // Pull out the IP + inp = ensureName(inprogress, rr.Hdr.Name, rr.Hdr.Rrtype) + if inp.complete() { + continue + } + inp.Addr = rr.A // @Deprecated + inp.AddrV4 = rr.A + case *dns.AAAA: + // Pull out the IP + inp = ensureName(inprogress, rr.Hdr.Name, rr.Hdr.Rrtype) + if inp.complete() { + continue + } + inp.Addr = rr.AAAA // @Deprecated + inp.AddrV6 = rr.AAAA + } + + if inp != nil { + inp.TTL = int(answer.Header().Ttl) + } + } + + return inp +} diff --git a/util/mdns/dns_sd.go b/util/mdns/dns_sd.go new file mode 100644 index 00000000..18444c34 --- /dev/null +++ b/util/mdns/dns_sd.go @@ -0,0 +1,84 @@ +package mdns + +import "github.com/miekg/dns" + +// DNSSDService is a service that complies with the DNS-SD (RFC 6762) and MDNS +// (RFC 6762) specs for local, multicast-DNS-based discovery. +// +// DNSSDService implements the Zone interface and wraps an MDNSService instance. +// To deploy an mDNS service that is compliant with DNS-SD, it's recommended to +// register only the wrapped instance with the server. +// +// Example usage: +// service := &mdns.DNSSDService{ +// MDNSService: &mdns.MDNSService{ +// Instance: "My Foobar Service", +// Service: "_foobar._tcp", +// Port: 8000, +// } +// } +// server, err := mdns.NewServer(&mdns.Config{Zone: service}) +// if err != nil { +// log.Fatalf("Error creating server: %v", err) +// } +// defer server.Shutdown() +type DNSSDService struct { + MDNSService *MDNSService +} + +// Records returns DNS records in response to a DNS question. +// +// This function returns the DNS response of the underlying MDNSService +// instance. It also returns a PTR record for a request for " +// _services._dns-sd._udp.", as described in section 9 of RFC 6763 +// ("Service Type Enumeration"), to allow browsing of the underlying MDNSService +// instance. +func (s *DNSSDService) Records(q dns.Question) []dns.RR { + var recs []dns.RR + if q.Name == "_services._dns-sd._udp."+s.MDNSService.Domain+"." { + recs = s.dnssdMetaQueryRecords(q) + } + return append(recs, s.MDNSService.Records(q)...) +} + +// dnssdMetaQueryRecords returns the DNS records in response to a "meta-query" +// issued to browse for DNS-SD services, as per section 9. of RFC6763. +// +// A meta-query has a name of the form "_services._dns-sd._udp." where +// Domain is a fully-qualified domain, such as "local." +func (s *DNSSDService) dnssdMetaQueryRecords(q dns.Question) []dns.RR { + // Intended behavior, as described in the RFC: + // ...it may be useful for network administrators to find the list of + // advertised service types on the network, even if those Service Names + // are just opaque identifiers and not particularly informative in + // isolation. + // + // For this purpose, a special meta-query is defined. A DNS query for PTR + // records with the name "_services._dns-sd._udp." yields a set of + // PTR records, where the rdata of each PTR record is the two-abel + // name, plus the same domain, e.g., "_http._tcp.". + // Including the domain in the PTR rdata allows for slightly better name + // compression in Unicast DNS responses, but only the first two labels are + // relevant for the purposes of service type enumeration. These two-label + // service types can then be used to construct subsequent Service Instance + // Enumeration PTR queries, in this or others, to discover + // instances of that service type. + return []dns.RR{ + &dns.PTR{ + Hdr: dns.RR_Header{ + Name: q.Name, + Rrtype: dns.TypePTR, + Class: dns.ClassINET, + Ttl: defaultTTL, + }, + Ptr: s.MDNSService.serviceAddr, + }, + } +} + +// Announcement returns DNS records that should be broadcast during the initial +// availability of the service, as described in section 8.3 of RFC 6762. +// TODO(reddaly): Add this when Announcement is added to the mdns.Zone interface. +//func (s *DNSSDService) Announcement() []dns.RR { +// return s.MDNSService.Announcement() +//} diff --git a/util/mdns/dns_sd_test.go b/util/mdns/dns_sd_test.go new file mode 100644 index 00000000..d973fd7e --- /dev/null +++ b/util/mdns/dns_sd_test.go @@ -0,0 +1,68 @@ +package mdns + +import ( + "reflect" + "testing" +) +import "github.com/miekg/dns" + +type mockMDNSService struct{} + +func (s *mockMDNSService) Records(q dns.Question) []dns.RR { + return []dns.RR{ + &dns.PTR{ + Hdr: dns.RR_Header{ + Name: "fakerecord", + Rrtype: dns.TypePTR, + Class: dns.ClassINET, + Ttl: 42, + }, + Ptr: "fake.local.", + }, + } +} + +func (s *mockMDNSService) Announcement() []dns.RR { + return []dns.RR{ + &dns.PTR{ + Hdr: dns.RR_Header{ + Name: "fakeannounce", + Rrtype: dns.TypePTR, + Class: dns.ClassINET, + Ttl: 42, + }, + Ptr: "fake.local.", + }, + } +} + +func TestDNSSDServiceRecords(t *testing.T) { + s := &DNSSDService{ + MDNSService: &MDNSService{ + serviceAddr: "_foobar._tcp.local.", + Domain: "local", + }, + } + q := dns.Question{ + Name: "_services._dns-sd._udp.local.", + Qtype: dns.TypePTR, + Qclass: dns.ClassINET, + } + recs := s.Records(q) + if got, want := len(recs), 1; got != want { + t.Fatalf("s.Records(%v) returned %v records, want %v", q, got, want) + } + + want := dns.RR(&dns.PTR{ + Hdr: dns.RR_Header{ + Name: "_services._dns-sd._udp.local.", + Rrtype: dns.TypePTR, + Class: dns.ClassINET, + Ttl: defaultTTL, + }, + Ptr: "_foobar._tcp.local.", + }) + if got := recs[0]; !reflect.DeepEqual(got, want) { + t.Errorf("s.Records()[0] = %v, want %v", got, want) + } +} diff --git a/util/mdns/server.go b/util/mdns/server.go new file mode 100644 index 00000000..909b39c5 --- /dev/null +++ b/util/mdns/server.go @@ -0,0 +1,476 @@ +package mdns + +import ( + "fmt" + "log" + "math/rand" + "net" + "sync" + "sync/atomic" + "time" + + "github.com/miekg/dns" + "golang.org/x/net/ipv4" + "golang.org/x/net/ipv6" +) + +var ( + mdnsGroupIPv4 = net.ParseIP("224.0.0.251") + mdnsGroupIPv6 = net.ParseIP("ff02::fb") + + // mDNS wildcard addresses + mdnsWildcardAddrIPv4 = &net.UDPAddr{ + IP: net.ParseIP("224.0.0.0"), + Port: 5353, + } + mdnsWildcardAddrIPv6 = &net.UDPAddr{ + IP: net.ParseIP("ff02::"), + Port: 5353, + } + + // mDNS endpoint addresses + ipv4Addr = &net.UDPAddr{ + IP: mdnsGroupIPv4, + Port: 5353, + } + ipv6Addr = &net.UDPAddr{ + IP: mdnsGroupIPv6, + Port: 5353, + } +) + +// Config is used to configure the mDNS server +type Config struct { + // Zone must be provided to support responding to queries + Zone Zone + + // Iface if provided binds the multicast listener to the given + // interface. If not provided, the system default multicase interface + // is used. + Iface *net.Interface + + // Port If it is not 0, replace the port 5353 with this port number. + Port int +} + +// mDNS server is used to listen for mDNS queries and respond if we +// have a matching local record +type Server struct { + config *Config + + ipv4List *net.UDPConn + ipv6List *net.UDPConn + + shutdown bool + shutdownCh chan struct{} + shutdownLock sync.Mutex + wg sync.WaitGroup +} + +// NewServer is used to create a new mDNS server from a config +func NewServer(config *Config) (*Server, error) { + setCustomPort(config.Port) + + // Create the listeners + // Create wildcard connections (because :5353 can be already taken by other apps) + ipv4List, _ := net.ListenUDP("udp4", mdnsWildcardAddrIPv4) + ipv6List, _ := net.ListenUDP("udp6", mdnsWildcardAddrIPv6) + if ipv4List == nil && ipv6List == nil { + return nil, fmt.Errorf("[ERR] mdns: Failed to bind to any udp port!") + } + + if ipv4List == nil { + ipv4List = &net.UDPConn{} + } + if ipv6List == nil { + ipv6List = &net.UDPConn{} + } + + // Join multicast groups to receive announcements + p1 := ipv4.NewPacketConn(ipv4List) + p2 := ipv6.NewPacketConn(ipv6List) + p1.SetMulticastLoopback(true) + p2.SetMulticastLoopback(true) + + if config.Iface != nil { + if err := p1.JoinGroup(config.Iface, &net.UDPAddr{IP: mdnsGroupIPv4}); err != nil { + return nil, err + } + if err := p2.JoinGroup(config.Iface, &net.UDPAddr{IP: mdnsGroupIPv6}); err != nil { + return nil, err + } + } else { + ifaces, err := net.Interfaces() + if err != nil { + return nil, err + } + errCount1, errCount2 := 0, 0 + for _, iface := range ifaces { + if err := p1.JoinGroup(&iface, &net.UDPAddr{IP: mdnsGroupIPv4}); err != nil { + errCount1++ + } + if err := p2.JoinGroup(&iface, &net.UDPAddr{IP: mdnsGroupIPv6}); err != nil { + errCount2++ + } + } + if len(ifaces) == errCount1 && len(ifaces) == errCount2 { + return nil, fmt.Errorf("Failed to join multicast group on all interfaces!") + } + } + + s := &Server{ + config: config, + ipv4List: ipv4List, + ipv6List: ipv6List, + shutdownCh: make(chan struct{}), + } + + go s.recv(s.ipv4List) + go s.recv(s.ipv6List) + + s.wg.Add(1) + go s.probe() + + return s, nil +} + +// Shutdown is used to shutdown the listener +func (s *Server) Shutdown() error { + s.shutdownLock.Lock() + defer s.shutdownLock.Unlock() + + if s.shutdown { + return nil + } + + s.shutdown = true + close(s.shutdownCh) + s.unregister() + + if s.ipv4List != nil { + s.ipv4List.Close() + } + if s.ipv6List != nil { + s.ipv6List.Close() + } + + s.wg.Wait() + return nil +} + +// recv is a long running routine to receive packets from an interface +func (s *Server) recv(c *net.UDPConn) { + if c == nil { + return + } + buf := make([]byte, 65536) + for { + s.shutdownLock.Lock() + if s.shutdown { + s.shutdownLock.Unlock() + return + } + s.shutdownLock.Unlock() + n, from, err := c.ReadFrom(buf) + if err != nil { + continue + } + if err := s.parsePacket(buf[:n], from); err != nil { + log.Printf("[ERR] mdns: Failed to handle query: %v", err) + } + } +} + +// parsePacket is used to parse an incoming packet +func (s *Server) parsePacket(packet []byte, from net.Addr) error { + var msg dns.Msg + if err := msg.Unpack(packet); err != nil { + log.Printf("[ERR] mdns: Failed to unpack packet: %v", err) + return err + } + // TODO: This is a bit of a hack + // We decided to ignore some mDNS answers for the time being + // See: https://tools.ietf.org/html/rfc6762#section-7.2 + msg.Truncated = false + return s.handleQuery(&msg, from) +} + +// handleQuery is used to handle an incoming query +func (s *Server) handleQuery(query *dns.Msg, from net.Addr) error { + if query.Opcode != dns.OpcodeQuery { + // "In both multicast query and multicast response messages, the OPCODE MUST + // be zero on transmission (only standard queries are currently supported + // over multicast). Multicast DNS messages received with an OPCODE other + // than zero MUST be silently ignored." Note: OpcodeQuery == 0 + return fmt.Errorf("mdns: received query with non-zero Opcode %v: %v", query.Opcode, *query) + } + if query.Rcode != 0 { + // "In both multicast query and multicast response messages, the Response + // Code MUST be zero on transmission. Multicast DNS messages received with + // non-zero Response Codes MUST be silently ignored." + return fmt.Errorf("mdns: received query with non-zero Rcode %v: %v", query.Rcode, *query) + } + + // TODO(reddaly): Handle "TC (Truncated) Bit": + // In query messages, if the TC bit is set, it means that additional + // Known-Answer records may be following shortly. A responder SHOULD + // record this fact, and wait for those additional Known-Answer records, + // before deciding whether to respond. If the TC bit is clear, it means + // that the querying host has no additional Known Answers. + if query.Truncated { + return fmt.Errorf("[ERR] mdns: support for DNS requests with high truncated bit not implemented: %v", *query) + } + + var unicastAnswer, multicastAnswer []dns.RR + + // Handle each question + for _, q := range query.Question { + mrecs, urecs := s.handleQuestion(q) + multicastAnswer = append(multicastAnswer, mrecs...) + unicastAnswer = append(unicastAnswer, urecs...) + } + + // See section 18 of RFC 6762 for rules about DNS headers. + resp := func(unicast bool) *dns.Msg { + // 18.1: ID (Query Identifier) + // 0 for multicast response, query.Id for unicast response + id := uint16(0) + if unicast { + id = query.Id + } + + var answer []dns.RR + if unicast { + answer = unicastAnswer + } else { + answer = multicastAnswer + } + if len(answer) == 0 { + return nil + } + + return &dns.Msg{ + MsgHdr: dns.MsgHdr{ + Id: id, + + // 18.2: QR (Query/Response) Bit - must be set to 1 in response. + Response: true, + + // 18.3: OPCODE - must be zero in response (OpcodeQuery == 0) + Opcode: dns.OpcodeQuery, + + // 18.4: AA (Authoritative Answer) Bit - must be set to 1 + Authoritative: true, + + // The following fields must all be set to 0: + // 18.5: TC (TRUNCATED) Bit + // 18.6: RD (Recursion Desired) Bit + // 18.7: RA (Recursion Available) Bit + // 18.8: Z (Zero) Bit + // 18.9: AD (Authentic Data) Bit + // 18.10: CD (Checking Disabled) Bit + // 18.11: RCODE (Response Code) + }, + // 18.12 pertains to questions (handled by handleQuestion) + // 18.13 pertains to resource records (handled by handleQuestion) + + // 18.14: Name Compression - responses should be compressed (though see + // caveats in the RFC), so set the Compress bit (part of the dns library + // API, not part of the DNS packet) to true. + Compress: true, + + Answer: answer, + } + } + + if mresp := resp(false); mresp != nil { + if err := s.sendResponse(mresp, from); err != nil { + return fmt.Errorf("mdns: error sending multicast response: %v", err) + } + } + if uresp := resp(true); uresp != nil { + if err := s.sendResponse(uresp, from); err != nil { + return fmt.Errorf("mdns: error sending unicast response: %v", err) + } + } + return nil +} + +// handleQuestion is used to handle an incoming question +// +// The response to a question may be transmitted over multicast, unicast, or +// both. The return values are DNS records for each transmission type. +func (s *Server) handleQuestion(q dns.Question) (multicastRecs, unicastRecs []dns.RR) { + records := s.config.Zone.Records(q) + + if len(records) == 0 { + return nil, nil + } + + // Handle unicast and multicast responses. + // TODO(reddaly): The decision about sending over unicast vs. multicast is not + // yet fully compliant with RFC 6762. For example, the unicast bit should be + // ignored if the records in question are close to TTL expiration. For now, + // we just use the unicast bit to make the decision, as per the spec: + // RFC 6762, section 18.12. Repurposing of Top Bit of qclass in Question + // Section + // + // In the Question Section of a Multicast DNS query, the top bit of the + // qclass field is used to indicate that unicast responses are preferred + // for this particular question. (See Section 5.4.) + if q.Qclass&(1<<15) != 0 { + return nil, records + } + return records, nil +} + +func (s *Server) probe() { + defer s.wg.Done() + + sd, ok := s.config.Zone.(*MDNSService) + if !ok { + return + } + + name := fmt.Sprintf("%s.%s.%s.", sd.Instance, trimDot(sd.Service), trimDot(sd.Domain)) + + q := new(dns.Msg) + q.SetQuestion(name, dns.TypePTR) + q.RecursionDesired = false + + srv := &dns.SRV{ + Hdr: dns.RR_Header{ + Name: name, + Rrtype: dns.TypeSRV, + Class: dns.ClassINET, + Ttl: defaultTTL, + }, + Priority: 0, + Weight: 0, + Port: uint16(sd.Port), + Target: sd.HostName, + } + txt := &dns.TXT{ + Hdr: dns.RR_Header{ + Name: name, + Rrtype: dns.TypeTXT, + Class: dns.ClassINET, + Ttl: defaultTTL, + }, + Txt: sd.TXT, + } + q.Ns = []dns.RR{srv, txt} + + randomizer := rand.New(rand.NewSource(time.Now().UnixNano())) + + for i := 0; i < 3; i++ { + if err := s.SendMulticast(q); err != nil { + log.Println("[ERR] mdns: failed to send probe:", err.Error()) + } + time.Sleep(time.Duration(randomizer.Intn(250)) * time.Millisecond) + } + + resp := new(dns.Msg) + resp.MsgHdr.Response = true + + // set for query + q.SetQuestion(name, dns.TypeANY) + + resp.Answer = append(resp.Answer, s.config.Zone.Records(q.Question[0])...) + + // reset + q.SetQuestion(name, dns.TypePTR) + + // From RFC6762 + // The Multicast DNS responder MUST send at least two unsolicited + // responses, one second apart. To provide increased robustness against + // packet loss, a responder MAY send up to eight unsolicited responses, + // provided that the interval between unsolicited responses increases by + // at least a factor of two with every response sent. + timeout := 1 * time.Second + timer := time.NewTimer(timeout) + for i := 0; i < 3; i++ { + if err := s.SendMulticast(resp); err != nil { + log.Println("[ERR] mdns: failed to send announcement:", err.Error()) + } + select { + case <-timer.C: + timeout *= 2 + timer.Reset(timeout) + case <-s.shutdownCh: + timer.Stop() + return + } + } +} + +// multicastResponse us used to send a multicast response packet +func (s *Server) SendMulticast(msg *dns.Msg) error { + buf, err := msg.Pack() + if err != nil { + return err + } + if s.ipv4List != nil { + s.ipv4List.WriteToUDP(buf, ipv4Addr) + } + if s.ipv6List != nil { + s.ipv6List.WriteToUDP(buf, ipv6Addr) + } + return nil +} + +// sendResponse is used to send a response packet +func (s *Server) sendResponse(resp *dns.Msg, from net.Addr) error { + // TODO(reddaly): Respect the unicast argument, and allow sending responses + // over multicast. + buf, err := resp.Pack() + if err != nil { + return err + } + + // Determine the socket to send from + addr := from.(*net.UDPAddr) + if addr.IP.To4() != nil { + _, err = s.ipv4List.WriteToUDP(buf, addr) + return err + } else { + _, err = s.ipv6List.WriteToUDP(buf, addr) + return err + } +} + +func (s *Server) unregister() error { + sd, ok := s.config.Zone.(*MDNSService) + if !ok { + return nil + } + + atomic.StoreUint32(&sd.TTL, 0) + name := fmt.Sprintf("%s.%s.%s.", sd.Instance, trimDot(sd.Service), trimDot(sd.Domain)) + + q := new(dns.Msg) + q.SetQuestion(name, dns.TypeANY) + + resp := new(dns.Msg) + resp.MsgHdr.Response = true + resp.Answer = append(resp.Answer, s.config.Zone.Records(q.Question[0])...) + + return s.SendMulticast(resp) +} + +func setCustomPort(port int) { + if port != 0 { + if mdnsWildcardAddrIPv4.Port != port { + mdnsWildcardAddrIPv4.Port = port + } + if mdnsWildcardAddrIPv6.Port != port { + mdnsWildcardAddrIPv6.Port = port + } + if ipv4Addr.Port != port { + ipv4Addr.Port = port + } + if ipv6Addr.Port != port { + ipv6Addr.Port = port + } + } +} diff --git a/util/mdns/server_test.go b/util/mdns/server_test.go new file mode 100644 index 00000000..6fb00fa2 --- /dev/null +++ b/util/mdns/server_test.go @@ -0,0 +1,61 @@ +package mdns + +import ( + "testing" + "time" +) + +func TestServer_StartStop(t *testing.T) { + s := makeService(t) + serv, err := NewServer(&Config{Zone: s}) + if err != nil { + t.Fatalf("err: %v", err) + } + defer serv.Shutdown() +} + +func TestServer_Lookup(t *testing.T) { + serv, err := NewServer(&Config{Zone: makeServiceWithServiceName(t, "_foobar._tcp")}) + if err != nil { + t.Fatalf("err: %v", err) + } + defer serv.Shutdown() + + entries := make(chan *ServiceEntry, 1) + found := false + doneCh := make(chan struct{}) + go func() { + select { + case e := <-entries: + if e.Name != "hostname._foobar._tcp.local." { + t.Fatalf("bad: %v", e) + } + if e.Port != 80 { + t.Fatalf("bad: %v", e) + } + if e.Info != "Local web server" { + t.Fatalf("bad: %v", e) + } + found = true + + case <-time.After(80 * time.Millisecond): + t.Fatalf("timeout") + } + close(doneCh) + }() + + params := &QueryParam{ + Service: "_foobar._tcp", + Domain: "local", + Timeout: 50 * time.Millisecond, + Entries: entries, + } + err = Query(params) + if err != nil { + t.Fatalf("err: %v", err) + } + <-doneCh + if !found { + t.Fatalf("record not found") + } +} diff --git a/util/mdns/zone.go b/util/mdns/zone.go new file mode 100644 index 00000000..abbab4bd --- /dev/null +++ b/util/mdns/zone.go @@ -0,0 +1,309 @@ +package mdns + +import ( + "fmt" + "net" + "os" + "strings" + "sync/atomic" + + "github.com/miekg/dns" +) + +const ( + // defaultTTL is the default TTL value in returned DNS records in seconds. + defaultTTL = 120 +) + +// Zone is the interface used to integrate with the server and +// to serve records dynamically +type Zone interface { + // Records returns DNS records in response to a DNS question. + Records(q dns.Question) []dns.RR +} + +// MDNSService is used to export a named service by implementing a Zone +type MDNSService struct { + Instance string // Instance name (e.g. "hostService name") + Service string // Service name (e.g. "_http._tcp.") + Domain string // If blank, assumes "local" + HostName string // Host machine DNS name (e.g. "mymachine.net.") + Port int // Service Port + IPs []net.IP // IP addresses for the service's host + TXT []string // Service TXT records + TTL uint32 + serviceAddr string // Fully qualified service address + instanceAddr string // Fully qualified instance address + enumAddr string // _services._dns-sd._udp. +} + +// validateFQDN returns an error if the passed string is not a fully qualified +// hdomain name (more specifically, a hostname). +func validateFQDN(s string) error { + if len(s) == 0 { + return fmt.Errorf("FQDN must not be blank") + } + if s[len(s)-1] != '.' { + return fmt.Errorf("FQDN must end in period: %s", s) + } + // TODO(reddaly): Perform full validation. + + return nil +} + +// NewMDNSService returns a new instance of MDNSService. +// +// If domain, hostName, or ips is set to the zero value, then a default value +// will be inferred from the operating system. +// +// TODO(reddaly): This interface may need to change to account for "unique +// record" conflict rules of the mDNS protocol. Upon startup, the server should +// check to ensure that the instance name does not conflict with other instance +// names, and, if required, select a new name. There may also be conflicting +// hostName A/AAAA records. +func NewMDNSService(instance, service, domain, hostName string, port int, ips []net.IP, txt []string) (*MDNSService, error) { + // Sanity check inputs + if instance == "" { + return nil, fmt.Errorf("missing service instance name") + } + if service == "" { + return nil, fmt.Errorf("missing service name") + } + if port == 0 { + return nil, fmt.Errorf("missing service port") + } + + // Set default domain + if domain == "" { + domain = "local." + } + if err := validateFQDN(domain); err != nil { + return nil, fmt.Errorf("domain %q is not a fully-qualified domain name: %v", domain, err) + } + + // Get host information if no host is specified. + if hostName == "" { + var err error + hostName, err = os.Hostname() + if err != nil { + return nil, fmt.Errorf("could not determine host: %v", err) + } + hostName = fmt.Sprintf("%s.", hostName) + } + if err := validateFQDN(hostName); err != nil { + return nil, fmt.Errorf("hostName %q is not a fully-qualified domain name: %v", hostName, err) + } + + if len(ips) == 0 { + var err error + ips, err = net.LookupIP(trimDot(hostName)) + if err != nil { + // Try appending the host domain suffix and lookup again + // (required for Linux-based hosts) + tmpHostName := fmt.Sprintf("%s%s", hostName, domain) + + ips, err = net.LookupIP(trimDot(tmpHostName)) + + if err != nil { + return nil, fmt.Errorf("could not determine host IP addresses for %s", hostName) + } + } + } + for _, ip := range ips { + if ip.To4() == nil && ip.To16() == nil { + return nil, fmt.Errorf("invalid IP address in IPs list: %v", ip) + } + } + + return &MDNSService{ + Instance: instance, + Service: service, + Domain: domain, + HostName: hostName, + Port: port, + IPs: ips, + TXT: txt, + TTL: defaultTTL, + serviceAddr: fmt.Sprintf("%s.%s.", trimDot(service), trimDot(domain)), + instanceAddr: fmt.Sprintf("%s.%s.%s.", instance, trimDot(service), trimDot(domain)), + enumAddr: fmt.Sprintf("_services._dns-sd._udp.%s.", trimDot(domain)), + }, nil +} + +// trimDot is used to trim the dots from the start or end of a string +func trimDot(s string) string { + return strings.Trim(s, ".") +} + +// Records returns DNS records in response to a DNS question. +func (m *MDNSService) Records(q dns.Question) []dns.RR { + switch q.Name { + case m.enumAddr: + return m.serviceEnum(q) + case m.serviceAddr: + return m.serviceRecords(q) + case m.instanceAddr: + return m.instanceRecords(q) + case m.HostName: + if q.Qtype == dns.TypeA || q.Qtype == dns.TypeAAAA { + return m.instanceRecords(q) + } + fallthrough + default: + return nil + } +} + +func (m *MDNSService) serviceEnum(q dns.Question) []dns.RR { + switch q.Qtype { + case dns.TypeANY: + fallthrough + case dns.TypePTR: + rr := &dns.PTR{ + Hdr: dns.RR_Header{ + Name: q.Name, + Rrtype: dns.TypePTR, + Class: dns.ClassINET, + Ttl: atomic.LoadUint32(&m.TTL), + }, + Ptr: m.serviceAddr, + } + return []dns.RR{rr} + default: + return nil + } +} + +// serviceRecords is called when the query matches the service name +func (m *MDNSService) serviceRecords(q dns.Question) []dns.RR { + switch q.Qtype { + case dns.TypeANY: + fallthrough + case dns.TypePTR: + // Build a PTR response for the service + rr := &dns.PTR{ + Hdr: dns.RR_Header{ + Name: q.Name, + Rrtype: dns.TypePTR, + Class: dns.ClassINET, + Ttl: atomic.LoadUint32(&m.TTL), + }, + Ptr: m.instanceAddr, + } + servRec := []dns.RR{rr} + + // Get the instance records + instRecs := m.instanceRecords(dns.Question{ + Name: m.instanceAddr, + Qtype: dns.TypeANY, + }) + + // Return the service record with the instance records + return append(servRec, instRecs...) + default: + return nil + } +} + +// serviceRecords is called when the query matches the instance name +func (m *MDNSService) instanceRecords(q dns.Question) []dns.RR { + switch q.Qtype { + case dns.TypeANY: + // Get the SRV, which includes A and AAAA + recs := m.instanceRecords(dns.Question{ + Name: m.instanceAddr, + Qtype: dns.TypeSRV, + }) + + // Add the TXT record + recs = append(recs, m.instanceRecords(dns.Question{ + Name: m.instanceAddr, + Qtype: dns.TypeTXT, + })...) + return recs + + case dns.TypeA: + var rr []dns.RR + for _, ip := range m.IPs { + if ip4 := ip.To4(); ip4 != nil { + rr = append(rr, &dns.A{ + Hdr: dns.RR_Header{ + Name: m.HostName, + Rrtype: dns.TypeA, + Class: dns.ClassINET, + Ttl: atomic.LoadUint32(&m.TTL), + }, + A: ip4, + }) + } + } + return rr + + case dns.TypeAAAA: + var rr []dns.RR + for _, ip := range m.IPs { + if ip.To4() != nil { + // TODO(reddaly): IPv4 addresses could be encoded in IPv6 format and + // putinto AAAA records, but the current logic puts ipv4-encodable + // addresses into the A records exclusively. Perhaps this should be + // configurable? + continue + } + + if ip16 := ip.To16(); ip16 != nil { + rr = append(rr, &dns.AAAA{ + Hdr: dns.RR_Header{ + Name: m.HostName, + Rrtype: dns.TypeAAAA, + Class: dns.ClassINET, + Ttl: atomic.LoadUint32(&m.TTL), + }, + AAAA: ip16, + }) + } + } + return rr + + case dns.TypeSRV: + // Create the SRV Record + srv := &dns.SRV{ + Hdr: dns.RR_Header{ + Name: q.Name, + Rrtype: dns.TypeSRV, + Class: dns.ClassINET, + Ttl: atomic.LoadUint32(&m.TTL), + }, + Priority: 10, + Weight: 1, + Port: uint16(m.Port), + Target: m.HostName, + } + recs := []dns.RR{srv} + + // Add the A record + recs = append(recs, m.instanceRecords(dns.Question{ + Name: m.instanceAddr, + Qtype: dns.TypeA, + })...) + + // Add the AAAA record + recs = append(recs, m.instanceRecords(dns.Question{ + Name: m.instanceAddr, + Qtype: dns.TypeAAAA, + })...) + return recs + + case dns.TypeTXT: + txt := &dns.TXT{ + Hdr: dns.RR_Header{ + Name: q.Name, + Rrtype: dns.TypeTXT, + Class: dns.ClassINET, + Ttl: atomic.LoadUint32(&m.TTL), + }, + Txt: m.TXT, + } + return []dns.RR{txt} + } + return nil +} diff --git a/util/mdns/zone_test.go b/util/mdns/zone_test.go new file mode 100644 index 00000000..082d72dd --- /dev/null +++ b/util/mdns/zone_test.go @@ -0,0 +1,275 @@ +package mdns + +import ( + "bytes" + "net" + "reflect" + "testing" + + "github.com/miekg/dns" +) + +func makeService(t *testing.T) *MDNSService { + return makeServiceWithServiceName(t, "_http._tcp") +} + +func makeServiceWithServiceName(t *testing.T, service string) *MDNSService { + m, err := NewMDNSService( + "hostname", + service, + "local.", + "testhost.", + 80, // port + []net.IP{net.IP([]byte{192, 168, 0, 42}), net.ParseIP("2620:0:1000:1900:b0c2:d0b2:c411:18bc")}, + []string{"Local web server"}) // TXT + + if err != nil { + t.Fatalf("err: %v", err) + } + + return m +} + +func TestNewMDNSService_BadParams(t *testing.T) { + for _, test := range []struct { + testName string + hostName string + domain string + }{ + { + "NewMDNSService should fail when passed hostName that is not a legal fully-qualified domain name", + "hostname", // not legal FQDN - should be "hostname." or "hostname.local.", etc. + "local.", // legal + }, + { + "NewMDNSService should fail when passed domain that is not a legal fully-qualified domain name", + "hostname.", // legal + "local", // should be "local." + }, + } { + _, err := NewMDNSService( + "instance name", + "_http._tcp", + test.domain, + test.hostName, + 80, // port + []net.IP{net.IP([]byte{192, 168, 0, 42})}, + []string{"Local web server"}) // TXT + if err == nil { + t.Fatalf("%s: error expected, but got none", test.testName) + } + } +} + +func TestMDNSService_BadAddr(t *testing.T) { + s := makeService(t) + q := dns.Question{ + Name: "random", + Qtype: dns.TypeANY, + } + recs := s.Records(q) + if len(recs) != 0 { + t.Fatalf("bad: %v", recs) + } +} + +func TestMDNSService_ServiceAddr(t *testing.T) { + s := makeService(t) + q := dns.Question{ + Name: "_http._tcp.local.", + Qtype: dns.TypeANY, + } + recs := s.Records(q) + if got, want := len(recs), 5; got != want { + t.Fatalf("got %d records, want %d: %v", got, want, recs) + } + + if ptr, ok := recs[0].(*dns.PTR); !ok { + t.Errorf("recs[0] should be PTR record, got: %v, all records: %v", recs[0], recs) + } else if got, want := ptr.Ptr, "hostname._http._tcp.local."; got != want { + t.Fatalf("bad PTR record %v: got %v, want %v", ptr, got, want) + } + + if _, ok := recs[1].(*dns.SRV); !ok { + t.Errorf("recs[1] should be SRV record, got: %v, all reccords: %v", recs[1], recs) + } + if _, ok := recs[2].(*dns.A); !ok { + t.Errorf("recs[2] should be A record, got: %v, all records: %v", recs[2], recs) + } + if _, ok := recs[3].(*dns.AAAA); !ok { + t.Errorf("recs[3] should be AAAA record, got: %v, all records: %v", recs[3], recs) + } + if _, ok := recs[4].(*dns.TXT); !ok { + t.Errorf("recs[4] should be TXT record, got: %v, all records: %v", recs[4], recs) + } + + q.Qtype = dns.TypePTR + if recs2 := s.Records(q); !reflect.DeepEqual(recs, recs2) { + t.Fatalf("PTR question should return same result as ANY question: ANY => %v, PTR => %v", recs, recs2) + } +} + +func TestMDNSService_InstanceAddr_ANY(t *testing.T) { + s := makeService(t) + q := dns.Question{ + Name: "hostname._http._tcp.local.", + Qtype: dns.TypeANY, + } + recs := s.Records(q) + if len(recs) != 4 { + t.Fatalf("bad: %v", recs) + } + if _, ok := recs[0].(*dns.SRV); !ok { + t.Fatalf("bad: %v", recs[0]) + } + if _, ok := recs[1].(*dns.A); !ok { + t.Fatalf("bad: %v", recs[1]) + } + if _, ok := recs[2].(*dns.AAAA); !ok { + t.Fatalf("bad: %v", recs[2]) + } + if _, ok := recs[3].(*dns.TXT); !ok { + t.Fatalf("bad: %v", recs[3]) + } +} + +func TestMDNSService_InstanceAddr_SRV(t *testing.T) { + s := makeService(t) + q := dns.Question{ + Name: "hostname._http._tcp.local.", + Qtype: dns.TypeSRV, + } + recs := s.Records(q) + if len(recs) != 3 { + t.Fatalf("bad: %v", recs) + } + srv, ok := recs[0].(*dns.SRV) + if !ok { + t.Fatalf("bad: %v", recs[0]) + } + if _, ok := recs[1].(*dns.A); !ok { + t.Fatalf("bad: %v", recs[1]) + } + if _, ok := recs[2].(*dns.AAAA); !ok { + t.Fatalf("bad: %v", recs[2]) + } + + if srv.Port != uint16(s.Port) { + t.Fatalf("bad: %v", recs[0]) + } +} + +func TestMDNSService_InstanceAddr_A(t *testing.T) { + s := makeService(t) + q := dns.Question{ + Name: "hostname._http._tcp.local.", + Qtype: dns.TypeA, + } + recs := s.Records(q) + if len(recs) != 1 { + t.Fatalf("bad: %v", recs) + } + a, ok := recs[0].(*dns.A) + if !ok { + t.Fatalf("bad: %v", recs[0]) + } + if !bytes.Equal(a.A, []byte{192, 168, 0, 42}) { + t.Fatalf("bad: %v", recs[0]) + } +} + +func TestMDNSService_InstanceAddr_AAAA(t *testing.T) { + s := makeService(t) + q := dns.Question{ + Name: "hostname._http._tcp.local.", + Qtype: dns.TypeAAAA, + } + recs := s.Records(q) + if len(recs) != 1 { + t.Fatalf("bad: %v", recs) + } + a4, ok := recs[0].(*dns.AAAA) + if !ok { + t.Fatalf("bad: %v", recs[0]) + } + ip6 := net.ParseIP("2620:0:1000:1900:b0c2:d0b2:c411:18bc") + if got := len(ip6); got != net.IPv6len { + t.Fatalf("test IP failed to parse (len = %d, want %d)", got, net.IPv6len) + } + if !bytes.Equal(a4.AAAA, ip6) { + t.Fatalf("bad: %v", recs[0]) + } +} + +func TestMDNSService_InstanceAddr_TXT(t *testing.T) { + s := makeService(t) + q := dns.Question{ + Name: "hostname._http._tcp.local.", + Qtype: dns.TypeTXT, + } + recs := s.Records(q) + if len(recs) != 1 { + t.Fatalf("bad: %v", recs) + } + txt, ok := recs[0].(*dns.TXT) + if !ok { + t.Fatalf("bad: %v", recs[0]) + } + if got, want := txt.Txt, s.TXT; !reflect.DeepEqual(got, want) { + t.Fatalf("TXT record mismatch for %v: got %v, want %v", recs[0], got, want) + } +} + +func TestMDNSService_HostNameQuery(t *testing.T) { + s := makeService(t) + for _, test := range []struct { + q dns.Question + want []dns.RR + }{ + { + dns.Question{Name: "testhost.", Qtype: dns.TypeA}, + []dns.RR{&dns.A{ + Hdr: dns.RR_Header{ + Name: "testhost.", + Rrtype: dns.TypeA, + Class: dns.ClassINET, + Ttl: 120, + }, + A: net.IP([]byte{192, 168, 0, 42}), + }}, + }, + { + dns.Question{Name: "testhost.", Qtype: dns.TypeAAAA}, + []dns.RR{&dns.AAAA{ + Hdr: dns.RR_Header{ + Name: "testhost.", + Rrtype: dns.TypeAAAA, + Class: dns.ClassINET, + Ttl: 120, + }, + AAAA: net.ParseIP("2620:0:1000:1900:b0c2:d0b2:c411:18bc"), + }}, + }, + } { + if got := s.Records(test.q); !reflect.DeepEqual(got, test.want) { + t.Errorf("hostname query failed: s.Records(%v) = %v, want %v", test.q, got, test.want) + } + } +} + +func TestMDNSService_serviceEnum_PTR(t *testing.T) { + s := makeService(t) + q := dns.Question{ + Name: "_services._dns-sd._udp.local.", + Qtype: dns.TypePTR, + } + recs := s.Records(q) + if len(recs) != 1 { + t.Fatalf("bad: %v", recs) + } + if ptr, ok := recs[0].(*dns.PTR); !ok { + t.Errorf("recs[0] should be PTR record, got: %v, all records: %v", recs[0], recs) + } else if got, want := ptr.Ptr, "_http._tcp.local."; got != want { + t.Fatalf("bad PTR record %v: got %v, want %v", ptr, got, want) + } +} From ec80ceb8c2ba3d447c1c638090614bc19626fc99 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 11 Apr 2020 18:23:37 +0100 Subject: [PATCH 613/788] Update readme --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index d6294ace..d6b39afc 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,7 @@ communication. A request made to a service will be automatically resolved, load transport is [gRPC](https://grpc.io/). - **Async Messaging** - PubSub is built in as a first class citizen for asynchronous communication and event driven architectures. -Event notifications are a core pattern in micro service development. The default messaging system is an embedded [NATS](https://nats.io/) -server. +Event notifications are a core pattern in micro service development. The default messaging system is a HTTP event message broker. - **Pluggable Interfaces** - Go Micro makes use of Go interfaces for each distributed system abstraction. Because of this these interfaces are pluggable and allows Go Micro to be runtime agnostic. You can plugin any underlying technology. Find plugins in From 0a2363b49ba351fb0093ab3c7205bb216b5d1c73 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 11 Apr 2020 22:21:55 +0300 Subject: [PATCH 614/788] api minor improvements (#1526) * api/handler/rpc: unblock all http methods and set Host meta * api/router/static: add debug log Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 6 +++--- api/router/static/static.go | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index f4d23bc9..980333b5 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -100,8 +100,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - // only allow post when we have the router - if r.Method != "GET" && (h.opts.Router != nil && r.Method != "POST") { + if h.opts.Router == nil && r.Method != "GET" { writeError(w, r, errors.MethodNotAllowed("go.micro.api", "method not allowed")) return } @@ -123,7 +122,8 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if !ok { md = make(metadata.Metadata) } - + // fill contex with http headers + md["Host"] = r.Host // merge context with overwrite cx = metadata.MergeContext(cx, md, true) diff --git a/api/router/static/static.go b/api/router/static/static.go index f868e52d..0c659c31 100644 --- a/api/router/static/static.go +++ b/api/router/static/static.go @@ -264,7 +264,9 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { for _, pathreg := range ep.pathregs { matches, err := pathreg.Match(path, "") if err != nil { - // TODO: log error + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api path not match %s != %v", path, pathreg) + } continue } pMatch = true @@ -290,7 +292,7 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { } // no match - return nil, fmt.Errorf("endpoint not found for %v", req) + return nil, fmt.Errorf("endpoint not found for %v", req.URL) } func (r *staticRouter) Route(req *http.Request) (*api.Service, error) { From 3ce2ab88f553bf490a8af54da670315c014cd130 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 11 Apr 2020 22:37:29 +0300 Subject: [PATCH 615/788] broker/nats: remove embed nats server reference (#1527) Signed-off-by: Vasiliy Tolstov --- broker/nats/nats.go | 222 ++++------------------------------------- broker/nats/options.go | 6 -- go.mod | 2 +- 3 files changed, 19 insertions(+), 211 deletions(-) diff --git a/broker/nats/nats.go b/broker/nats/nats.go index 01b59d18..b8bf6daf 100644 --- a/broker/nats/nats.go +++ b/broker/nats/nats.go @@ -4,19 +4,13 @@ package nats import ( "context" "errors" - "net" - "net/url" - "strconv" "strings" "sync" - "time" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/codec/json" "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" - "github.com/micro/go-micro/v2/util/addr" - "github.com/nats-io/nats-server/v2/server" nats "github.com/nats-io/nats.go" ) @@ -35,13 +29,6 @@ type natsBroker struct { // should we drain the connection drain bool closeCh chan (error) - - // embedded server - server *server.Server - // configure to use local server - local bool - // server exit channel - exit chan bool } type subscriber struct { @@ -108,186 +95,18 @@ func (n *natsBroker) setAddrs(addrs []string) []string { } cAddrs = append(cAddrs, addr) } - // if there's no address and we weren't told to - // embed a local server then use the default url - if len(cAddrs) == 0 && !n.local { + if len(cAddrs) == 0 { cAddrs = []string{nats.DefaultURL} } return cAddrs } -// serve stats a local nats server if needed -func (n *natsBroker) serve(exit chan bool) error { - var host string - var port int - var local bool - - // with no address we just default it - // this is a local client address - if len(n.addrs) == 0 { - // find an advertiseable ip - if h, err := addr.Extract(""); err != nil { - host = "127.0.0.1" - } else { - host = h - } - - port = -1 - local = true - } else { - address := n.addrs[0] - if strings.HasPrefix(address, "nats://") { - address = strings.TrimPrefix(address, "nats://") - } - - // check if its a local address and only then embed - if addr.IsLocal(address) { - h, p, err := net.SplitHostPort(address) - if err == nil { - host = h - port, _ = strconv.Atoi(p) - local = true - } - } - } - - // we only setup a server for local things - if !local { - return nil - } - - // 1. create new server - // 2. register the server - // 3. connect to other servers - var cOpts server.ClusterOpts - var routes []*url.URL - - // get existing nats servers to connect to - services, err := n.opts.Registry.GetService("go.micro.nats.broker") - if err == nil { - for _, service := range services { - for _, node := range service.Nodes { - u, err := url.Parse("nats://" + node.Address) - if err != nil { - if logger.V(logger.ErrorLevel, logger.DefaultLogger) { - logger.Error(err) - } - continue - } - // append to the cluster routes - routes = append(routes, u) - } - } - } - - // try get existing server - s := n.server - - // get a host address - caddr, err := addr.Extract("") - if err != nil { - caddr = "0.0.0.0" - } - - // set cluster opts - cOpts = server.ClusterOpts{ - Host: caddr, - Port: -1, - } - - if s == nil { - var err error - s, err = server.NewServer(&server.Options{ - // Specify the host - Host: host, - // Use a random port - Port: port, - // Set the cluster ops - Cluster: cOpts, - // Set the routes - Routes: routes, - NoLog: true, - NoSigs: true, - MaxControlLine: 2048, - TLSConfig: n.opts.TLSConfig, - }) - if err != nil { - return err - } - - // save the server - n.server = s - } - - // start the server - go s.Start() - - var ready bool - - // wait till its ready for connections - for i := 0; i < 3; i++ { - if s.ReadyForConnections(time.Second) { - ready = true - break - } - } - - if !ready { - return errors.New("server not ready") - } - - // set the client address - n.addrs = []string{s.ClientURL()} - - go func() { - // register the cluster address - for { - select { - case <-exit: - // deregister on exit - n.opts.Registry.Deregister(®istry.Service{ - Name: "go.micro.nats.broker", - Version: "v2", - Nodes: []*registry.Node{ - {Id: s.ID(), Address: s.ClusterAddr().String()}, - }, - }) - s.Shutdown() - return - default: - // register the broker - n.opts.Registry.Register(®istry.Service{ - Name: "go.micro.nats.broker", - Version: "v2", - Nodes: []*registry.Node{ - {Id: s.ID(), Address: s.ClusterAddr().String()}, - }, - }, registry.RegisterTTL(time.Minute)) - time.Sleep(time.Minute) - } - } - }() - - return nil -} - func (n *natsBroker) Connect() error { n.Lock() defer n.Unlock() - if !n.connected { - // create exit chan - n.exit = make(chan bool) - - // start embedded server if asked to - if n.local { - if err := n.serve(n.exit); err != nil { - return err - } - } - - // set to connected - n.connected = true + if n.connected { + return nil } status := nats.CLOSED @@ -297,6 +116,7 @@ func (n *natsBroker) Connect() error { switch status { case nats.CONNECTED, nats.RECONNECTING, nats.CONNECTING: + n.connected = true return nil default: // DISCONNECTED or CLOSED or DRAINING opts := n.nopts @@ -314,13 +134,14 @@ func (n *natsBroker) Connect() error { return err } n.conn = c + n.connected = true return nil } } func (n *natsBroker) Disconnect() error { - n.RLock() - defer n.RUnlock() + n.Lock() + defer n.Unlock() // drain the connection if specified if n.drain { @@ -331,16 +152,6 @@ func (n *natsBroker) Disconnect() error { // close the client connection n.conn.Close() - // shutdown the local server - // and deregister - if n.server != nil { - select { - case <-n.exit: - default: - close(n.exit) - } - } - // set not connected n.connected = false @@ -357,19 +168,27 @@ func (n *natsBroker) Options() broker.Options { } func (n *natsBroker) Publish(topic string, msg *broker.Message, opts ...broker.PublishOption) error { + n.RLock() + defer n.RUnlock() + + if n.conn == nil { + return errors.New("not connected") + } + b, err := n.opts.Codec.Marshal(msg) if err != nil { return err } - n.RLock() - defer n.RUnlock() return n.conn.Publish(topic, b) } func (n *natsBroker) Subscribe(topic string, handler broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) { + n.RLock() if n.conn == nil { + n.RUnlock() return nil, errors.New("not connected") } + n.RUnlock() opt := broker.SubscribeOptions{ AutoAck: true, @@ -441,15 +260,10 @@ func (n *natsBroker) setOption(opts ...broker.Option) { n.nopts = nopts } - local, ok := n.opts.Context.Value(localServerKey{}).(bool) - if ok { - n.local = local - } - // broker.Options have higher priority than nats.Options // only if Addrs, Secure or TLSConfig were not set through a broker.Option // we read them from nats.Option - if len(n.opts.Addrs) == 0 && !n.local { + if len(n.opts.Addrs) == 0 { n.opts.Addrs = n.nopts.Servers } diff --git a/broker/nats/options.go b/broker/nats/options.go index ba127e73..78708c0b 100644 --- a/broker/nats/options.go +++ b/broker/nats/options.go @@ -7,18 +7,12 @@ import ( type optionsKey struct{} type drainConnectionKey struct{} -type localServerKey struct{} // Options accepts nats.Options func Options(opts nats.Options) broker.Option { return setBrokerOption(optionsKey{}, opts) } -// LocalServer embeds a local server rather than connecting to one -func LocalServer() broker.Option { - return setBrokerOption(localServerKey{}, true) -} - // DrainConnection will drain subscription on close func DrainConnection() broker.Option { return setBrokerOption(drainConnectionKey{}, struct{}{}) diff --git a/go.mod b/go.mod index 8a445a11..ffed3e84 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/micro/cli/v2 v2.1.2 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 - github.com/nats-io/nats-server/v2 v2.1.6 + github.com/nats-io/nats-server/v2 v2.1.6 // indirect github.com/nats-io/nats.go v1.9.2 github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c From 4e539361fa704bad168305e92b7d5c0a17ab70c9 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 12 Apr 2020 10:58:12 +0100 Subject: [PATCH 616/788] strip file --- registry/registry.go | 27 +++++++++++++++++++++++++++ registry/service.go | 28 ---------------------------- 2 files changed, 27 insertions(+), 28 deletions(-) delete mode 100644 registry/service.go diff --git a/registry/registry.go b/registry/registry.go index 6ec72292..291a1988 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -28,6 +28,33 @@ type Registry interface { String() string } +type Service struct { + Name string `json:"name"` + Version string `json:"version"` + Metadata map[string]string `json:"metadata"` + Endpoints []*Endpoint `json:"endpoints"` + Nodes []*Node `json:"nodes"` +} + +type Node struct { + Id string `json:"id"` + Address string `json:"address"` + Metadata map[string]string `json:"metadata"` +} + +type Endpoint struct { + Name string `json:"name"` + Request *Value `json:"request"` + Response *Value `json:"response"` + Metadata map[string]string `json:"metadata"` +} + +type Value struct { + Name string `json:"name"` + Type string `json:"type"` + Values []*Value `json:"values"` +} + type Option func(*Options) type RegisterOption func(*RegisterOptions) diff --git a/registry/service.go b/registry/service.go deleted file mode 100644 index 5259a6b6..00000000 --- a/registry/service.go +++ /dev/null @@ -1,28 +0,0 @@ -package registry - -type Service struct { - Name string `json:"name"` - Version string `json:"version"` - Metadata map[string]string `json:"metadata"` - Endpoints []*Endpoint `json:"endpoints"` - Nodes []*Node `json:"nodes"` -} - -type Node struct { - Id string `json:"id"` - Address string `json:"address"` - Metadata map[string]string `json:"metadata"` -} - -type Endpoint struct { - Name string `json:"name"` - Request *Value `json:"request"` - Response *Value `json:"response"` - Metadata map[string]string `json:"metadata"` -} - -type Value struct { - Name string `json:"name"` - Type string `json:"type"` - Values []*Value `json:"values"` -} From cf67d460b761109e22d9e5755b1d6d77d5ad305e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 12 Apr 2020 11:01:09 +0100 Subject: [PATCH 617/788] strip down mdns watcher --- registry/mdns_registry.go | 79 ++++++++++++++++++ registry/mdns_test.go | 142 ++++++++++++++++++++++++++++++++ registry/mdns_watcher.go | 87 -------------------- registry/mdns_watcher_test.go | 149 ---------------------------------- 4 files changed, 221 insertions(+), 236 deletions(-) delete mode 100644 registry/mdns_watcher.go delete mode 100644 registry/mdns_watcher_test.go diff --git a/registry/mdns_registry.go b/registry/mdns_registry.go index dfc8e6f0..18758878 100644 --- a/registry/mdns_registry.go +++ b/registry/mdns_registry.go @@ -54,6 +54,17 @@ type mdnsRegistry struct { listener chan *mdns.ServiceEntry } +type mdnsWatcher struct { + id string + wo WatchOptions + ch chan *mdns.ServiceEntry + exit chan struct{} + // the mdns domain + domain string + // the registry + registry *mdnsRegistry +} + func encode(txt *mdnsTxt) ([]string, error) { b, err := json.Marshal(txt) if err != nil { @@ -534,6 +545,74 @@ func (m *mdnsRegistry) String() string { return "mdns" } +func (m *mdnsWatcher) Next() (*Result, error) { + for { + select { + case e := <-m.ch: + txt, err := decode(e.InfoFields) + if err != nil { + continue + } + + if len(txt.Service) == 0 || len(txt.Version) == 0 { + continue + } + + // Filter watch options + // wo.Service: Only keep services we care about + if len(m.wo.Service) > 0 && txt.Service != m.wo.Service { + continue + } + + var action string + + if e.TTL == 0 { + action = "delete" + } else { + action = "create" + } + + service := &Service{ + Name: txt.Service, + Version: txt.Version, + Endpoints: txt.Endpoints, + } + + // skip anything without the domain we care about + suffix := fmt.Sprintf(".%s.%s.", service.Name, m.domain) + if !strings.HasSuffix(e.Name, suffix) { + continue + } + + service.Nodes = append(service.Nodes, &Node{ + Id: strings.TrimSuffix(e.Name, suffix), + Address: fmt.Sprintf("%s:%d", e.AddrV4.String(), e.Port), + Metadata: txt.Metadata, + }) + + return &Result{ + Action: action, + Service: service, + }, nil + case <-m.exit: + return nil, ErrWatcherStopped + } + } +} + +func (m *mdnsWatcher) Stop() { + select { + case <-m.exit: + return + default: + close(m.exit) + // remove self from the registry + m.registry.mtx.Lock() + delete(m.registry.watchers, m.id) + m.registry.mtx.Unlock() + } +} + // NewRegistry returns a new default registry which is mdns func NewRegistry(opts ...Option) Registry { return newRegistry(opts...) diff --git a/registry/mdns_test.go b/registry/mdns_test.go index c9979d5c..5f5cc617 100644 --- a/registry/mdns_test.go +++ b/registry/mdns_test.go @@ -197,3 +197,145 @@ func TestEncoding(t *testing.T) { } } + +func TestWatcher(t *testing.T) { + if travis := os.Getenv("TRAVIS"); travis == "true" { + t.Skip() + } + + testData := []*Service{ + { + Name: "test1", + Version: "1.0.1", + Nodes: []*Node{ + { + Id: "test1-1", + Address: "10.0.0.1:10001", + Metadata: map[string]string{ + "foo": "bar", + }, + }, + }, + }, + { + Name: "test2", + Version: "1.0.2", + Nodes: []*Node{ + { + Id: "test2-1", + Address: "10.0.0.2:10002", + Metadata: map[string]string{ + "foo2": "bar2", + }, + }, + }, + }, + { + Name: "test3", + Version: "1.0.3", + Nodes: []*Node{ + { + Id: "test3-1", + Address: "10.0.0.3:10003", + Metadata: map[string]string{ + "foo3": "bar3", + }, + }, + }, + }, + } + + testFn := func(service, s *Service) { + if s == nil { + t.Fatalf("Expected one result for %s got nil", service.Name) + + } + + if s.Name != service.Name { + t.Fatalf("Expected name %s got %s", service.Name, s.Name) + } + + if s.Version != service.Version { + t.Fatalf("Expected version %s got %s", service.Version, s.Version) + } + + if len(s.Nodes) != 1 { + t.Fatalf("Expected 1 node, got %d", len(s.Nodes)) + } + + node := s.Nodes[0] + + if node.Id != service.Nodes[0].Id { + t.Fatalf("Expected node id %s got %s", service.Nodes[0].Id, node.Id) + } + + if node.Address != service.Nodes[0].Address { + t.Fatalf("Expected node address %s got %s", service.Nodes[0].Address, node.Address) + } + } + + travis := os.Getenv("TRAVIS") + + var opts []Option + + if travis == "true" { + opts = append(opts, Timeout(time.Millisecond*100)) + } + + // new registry + r := NewRegistry(opts...) + + w, err := r.Watch() + if err != nil { + t.Fatal(err) + } + defer w.Stop() + + for _, service := range testData { + // register service + if err := r.Register(service); err != nil { + t.Fatal(err) + } + + for { + res, err := w.Next() + if err != nil { + t.Fatal(err) + } + + if res.Service.Name != service.Name { + continue + } + + if res.Action != "create" { + t.Fatalf("Expected create event got %s for %s", res.Action, res.Service.Name) + } + + testFn(service, res.Service) + break + } + + // deregister + if err := r.Deregister(service); err != nil { + t.Fatal(err) + } + + for { + res, err := w.Next() + if err != nil { + t.Fatal(err) + } + + if res.Service.Name != service.Name { + continue + } + + if res.Action != "delete" { + continue + } + + testFn(service, res.Service) + break + } + } +} diff --git a/registry/mdns_watcher.go b/registry/mdns_watcher.go deleted file mode 100644 index e0ef4a48..00000000 --- a/registry/mdns_watcher.go +++ /dev/null @@ -1,87 +0,0 @@ -package registry - -import ( - "fmt" - "strings" - - "github.com/micro/go-micro/v2/util/mdns" -) - -type mdnsWatcher struct { - id string - wo WatchOptions - ch chan *mdns.ServiceEntry - exit chan struct{} - // the mdns domain - domain string - // the registry - registry *mdnsRegistry -} - -func (m *mdnsWatcher) Next() (*Result, error) { - for { - select { - case e := <-m.ch: - txt, err := decode(e.InfoFields) - if err != nil { - continue - } - - if len(txt.Service) == 0 || len(txt.Version) == 0 { - continue - } - - // Filter watch options - // wo.Service: Only keep services we care about - if len(m.wo.Service) > 0 && txt.Service != m.wo.Service { - continue - } - - var action string - - if e.TTL == 0 { - action = "delete" - } else { - action = "create" - } - - service := &Service{ - Name: txt.Service, - Version: txt.Version, - Endpoints: txt.Endpoints, - } - - // skip anything without the domain we care about - suffix := fmt.Sprintf(".%s.%s.", service.Name, m.domain) - if !strings.HasSuffix(e.Name, suffix) { - continue - } - - service.Nodes = append(service.Nodes, &Node{ - Id: strings.TrimSuffix(e.Name, suffix), - Address: fmt.Sprintf("%s:%d", e.AddrV4.String(), e.Port), - Metadata: txt.Metadata, - }) - - return &Result{ - Action: action, - Service: service, - }, nil - case <-m.exit: - return nil, ErrWatcherStopped - } - } -} - -func (m *mdnsWatcher) Stop() { - select { - case <-m.exit: - return - default: - close(m.exit) - // remove self from the registry - m.registry.mtx.Lock() - delete(m.registry.watchers, m.id) - m.registry.mtx.Unlock() - } -} diff --git a/registry/mdns_watcher_test.go b/registry/mdns_watcher_test.go deleted file mode 100644 index bd837c58..00000000 --- a/registry/mdns_watcher_test.go +++ /dev/null @@ -1,149 +0,0 @@ -package registry - -import ( - "os" - "testing" - "time" -) - -func TestWatcher(t *testing.T) { - if travis := os.Getenv("TRAVIS"); travis == "true" { - t.Skip() - } - - testData := []*Service{ - { - Name: "test1", - Version: "1.0.1", - Nodes: []*Node{ - { - Id: "test1-1", - Address: "10.0.0.1:10001", - Metadata: map[string]string{ - "foo": "bar", - }, - }, - }, - }, - { - Name: "test2", - Version: "1.0.2", - Nodes: []*Node{ - { - Id: "test2-1", - Address: "10.0.0.2:10002", - Metadata: map[string]string{ - "foo2": "bar2", - }, - }, - }, - }, - { - Name: "test3", - Version: "1.0.3", - Nodes: []*Node{ - { - Id: "test3-1", - Address: "10.0.0.3:10003", - Metadata: map[string]string{ - "foo3": "bar3", - }, - }, - }, - }, - } - - testFn := func(service, s *Service) { - if s == nil { - t.Fatalf("Expected one result for %s got nil", service.Name) - - } - - if s.Name != service.Name { - t.Fatalf("Expected name %s got %s", service.Name, s.Name) - } - - if s.Version != service.Version { - t.Fatalf("Expected version %s got %s", service.Version, s.Version) - } - - if len(s.Nodes) != 1 { - t.Fatalf("Expected 1 node, got %d", len(s.Nodes)) - } - - node := s.Nodes[0] - - if node.Id != service.Nodes[0].Id { - t.Fatalf("Expected node id %s got %s", service.Nodes[0].Id, node.Id) - } - - if node.Address != service.Nodes[0].Address { - t.Fatalf("Expected node address %s got %s", service.Nodes[0].Address, node.Address) - } - } - - travis := os.Getenv("TRAVIS") - - var opts []Option - - if travis == "true" { - opts = append(opts, Timeout(time.Millisecond*100)) - } - - // new registry - r := NewRegistry(opts...) - - w, err := r.Watch() - if err != nil { - t.Fatal(err) - } - defer w.Stop() - - for _, service := range testData { - // register service - if err := r.Register(service); err != nil { - t.Fatal(err) - } - - for { - res, err := w.Next() - if err != nil { - t.Fatal(err) - } - - if res.Service.Name != service.Name { - continue - } - - if res.Action != "create" { - t.Fatalf("Expected create event got %s for %s", res.Action, res.Service.Name) - } - - testFn(service, res.Service) - break - } - - // deregister - if err := r.Deregister(service); err != nil { - t.Fatal(err) - } - - for { - res, err := w.Next() - if err != nil { - t.Fatal(err) - } - - if res.Service.Name != service.Name { - continue - } - - if res.Action != "delete" { - continue - } - - testFn(service, res.Service) - break - } - } -} From 962588b64970f11c98b79d3cd6345821a97a0ec5 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 12 Apr 2020 11:16:08 +0100 Subject: [PATCH 618/788] Strip MetadataKey global var --- api/handler/rpc/rpc.go | 4 ++-- api/router/static/static.go | 4 ++-- metadata/metadata.go | 12 ++++++------ sync/sync.go | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 980333b5..7c06b663 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -118,7 +118,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // create context cx := ctx.FromRequest(r) // get context from http handler wrappers - md, ok := r.Context().Value(metadata.MetadataKey{}).(metadata.Metadata) + md, ok := metadata.FromContext(r.Context()) if !ok { md = make(metadata.Metadata) } @@ -293,7 +293,7 @@ func requestPayload(r *http.Request) ([]byte, error) { // otherwise as per usual ctx := r.Context() // dont user meadata.FromContext as it mangles names - md, ok := ctx.Value(metadata.MetadataKey{}).(metadata.Metadata) + md, ok := metadata.FromContext(ctx) if !ok { md = make(map[string]string) } diff --git a/api/router/static/static.go b/api/router/static/static.go index 0c659c31..2b0218f1 100644 --- a/api/router/static/static.go +++ b/api/router/static/static.go @@ -271,7 +271,7 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { } pMatch = true ctx := req.Context() - md, ok := ctx.Value(metadata.MetadataKey{}).(metadata.Metadata) + md, ok := metadata.FromContext(ctx) if !ok { md = make(metadata.Metadata) } @@ -279,7 +279,7 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { md[fmt.Sprintf("x-api-field-%s", k)] = v } md["x-api-body"] = ep.apiep.Body - *req = *req.Clone(context.WithValue(ctx, metadata.MetadataKey{}, md)) + *req = *req.Clone(metadata.NewContext(ctx, md)) break pathLoop } if !pMatch { diff --git a/metadata/metadata.go b/metadata/metadata.go index bd539314..c99766a8 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -6,7 +6,7 @@ import ( "strings" ) -type MetadataKey struct{} +type metadataKey struct{} // Metadata is our way of representing request headers internally. // They're used at the RPC level and translate back and forth @@ -57,7 +57,7 @@ func Set(ctx context.Context, k, v string) context.Context { } else { md[k] = v } - return context.WithValue(ctx, MetadataKey{}, md) + return context.WithValue(ctx, metadataKey{}, md) } // Get returns a single value from metadata in the context @@ -80,7 +80,7 @@ func Get(ctx context.Context, key string) (string, bool) { // FromContext returns metadata from the given context func FromContext(ctx context.Context) (Metadata, bool) { - md, ok := ctx.Value(MetadataKey{}).(Metadata) + md, ok := ctx.Value(metadataKey{}).(Metadata) if !ok { return nil, ok } @@ -96,7 +96,7 @@ func FromContext(ctx context.Context) (Metadata, bool) { // NewContext creates a new context with the given metadata func NewContext(ctx context.Context, md Metadata) context.Context { - return context.WithValue(ctx, MetadataKey{}, md) + return context.WithValue(ctx, metadataKey{}, md) } // MergeContext merges metadata to existing metadata, overwriting if specified @@ -104,7 +104,7 @@ func MergeContext(ctx context.Context, patchMd Metadata, overwrite bool) context if ctx == nil { ctx = context.Background() } - md, _ := ctx.Value(MetadataKey{}).(Metadata) + md, _ := ctx.Value(metadataKey{}).(Metadata) cmd := make(Metadata, len(md)) for k, v := range md { cmd[k] = v @@ -118,5 +118,5 @@ func MergeContext(ctx context.Context, patchMd Metadata, overwrite bool) context delete(cmd, k) } } - return context.WithValue(ctx, MetadataKey{}, cmd) + return context.WithValue(ctx, metadataKey{}, cmd) } diff --git a/sync/sync.go b/sync/sync.go index ebaec6da..0c5203b7 100644 --- a/sync/sync.go +++ b/sync/sync.go @@ -28,10 +28,10 @@ type Sync interface { // Leader provides leadership election type Leader interface { - // resign leadership - Resign() error - // status returns when leadership is lost - Status() chan bool + // resign leadership + Resign() error + // status returns when leadership is lost + Status() chan bool } type Options struct { @@ -41,7 +41,7 @@ type Options struct { type Option func(o *Options) -type LeaderOptions struct {} +type LeaderOptions struct{} type LeaderOption func(o *LeaderOptions) From 08ca61c12193f807feced9b0128640fa95b519c2 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 12 Apr 2020 11:17:23 +0100 Subject: [PATCH 619/788] add metadata set --- metadata/metadata.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/metadata/metadata.go b/metadata/metadata.go index c99766a8..6fcb8199 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -25,6 +25,10 @@ func (md Metadata) Get(key string) (string, bool) { return val, ok } +func (md Metadata) Set(key, val string) { + md[key] = val +} + func (md Metadata) Delete(key string) { // delete key as-is delete(md, key) From d03a02f2e41f4d9826fa568e5ee96dd7958a4cc6 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 12 Apr 2020 11:25:12 +0100 Subject: [PATCH 620/788] fix import --- api/router/static/static.go | 1 - 1 file changed, 1 deletion(-) diff --git a/api/router/static/static.go b/api/router/static/static.go index 2b0218f1..fd630cc2 100644 --- a/api/router/static/static.go +++ b/api/router/static/static.go @@ -1,7 +1,6 @@ package static import ( - "context" "errors" "fmt" "net/http" From b08c636b44e22c56882fed8f705b26ce5ae6f0f8 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 12 Apr 2020 14:29:38 +0100 Subject: [PATCH 621/788] fixup handler tests --- api/grpc_test.go | 60 ++++++++++++-------------------------- api/handler/api/api.go | 2 +- api/handler/event/event.go | 2 +- api/handler/options.go | 15 +++++----- api/handler/rpc/rpc.go | 2 +- 5 files changed, 28 insertions(+), 53 deletions(-) diff --git a/api/grpc_test.go b/api/grpc_test.go index f40734c3..e31f3759 100644 --- a/api/grpc_test.go +++ b/api/grpc_test.go @@ -9,20 +9,16 @@ import ( "testing" "time" - "github.com/micro/go-micro/v2" "github.com/micro/go-micro/v2/api" - ahandler "github.com/micro/go-micro/v2/api/handler" - apirpc "github.com/micro/go-micro/v2/api/handler/rpc" + "github.com/micro/go-micro/v2/api/handler" + "github.com/micro/go-micro/v2/api/handler/rpc" "github.com/micro/go-micro/v2/api/router" rstatic "github.com/micro/go-micro/v2/api/router/static" - bmemory "github.com/micro/go-micro/v2/broker/memory" "github.com/micro/go-micro/v2/client" gcli "github.com/micro/go-micro/v2/client/grpc" rmemory "github.com/micro/go-micro/v2/registry/memory" "github.com/micro/go-micro/v2/server" gsrv "github.com/micro/go-micro/v2/server/grpc" - tgrpc "github.com/micro/go-micro/v2/transport/grpc" - pb "github.com/micro/go-micro/v2/server/grpc/proto" ) @@ -39,49 +35,33 @@ func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response func TestApiAndGRPC(t *testing.T) { r := rmemory.NewRegistry() - b := bmemory.NewBroker() - tr := tgrpc.NewTransport() + + // create a new client s := gsrv.NewServer( - server.Broker(b), server.Name("foo"), server.Registry(r), - server.Transport(tr), ) + + // create a new server c := gcli.NewClient( client.Registry(r), - client.Broker(b), - client.Transport(tr), ) - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - svc := micro.NewService( - micro.Server(s), - micro.Client(c), - micro.Broker(b), - micro.Registry(r), - micro.Transport(tr), - micro.Context(ctx)) h := &testServer{} pb.RegisterTestHandler(s, h) - go func() { - if err := svc.Run(); err != nil { - t.Fatalf("failed to start: %v", err) - } - }() - time.Sleep(1 * time.Second) - // check registration - services, err := r.GetService("foo") - if err != nil || len(services) == 0 { - t.Fatalf("failed to get service: %v # %d", err, len(services)) + if err := s.Start(); err != nil { + t.Fatalf("failed to start: %v", err) } + defer s.Stop() + // create a new router router := rstatic.NewRouter( - router.WithHandler(apirpc.Handler), - router.WithRegistry(svc.Server().Options().Registry), + router.WithHandler(rpc.Handler), + router.WithRegistry(r), ) - err = router.Register(&api.Endpoint{ + + err := router.Register(&api.Endpoint{ Name: "foo.Test.Call", Method: []string{"GET"}, Path: []string{"/api/v0/test/call/{name}"}, @@ -91,9 +71,9 @@ func TestApiAndGRPC(t *testing.T) { t.Fatal(err) } - hrpc := apirpc.NewHandler( - ahandler.WithService(svc), - ahandler.WithRouter(router), + hrpc := rpc.NewHandler( + handler.WithClient(c), + handler.WithRouter(router), ) hsrv := &http.Server{ @@ -115,6 +95,7 @@ func TestApiAndGRPC(t *testing.T) { t.Fatalf("Failed to created http.Request: %v", err) } defer rsp.Body.Close() + buf, err := ioutil.ReadAll(rsp.Body) if err != nil { t.Fatal(err) @@ -124,9 +105,4 @@ func TestApiAndGRPC(t *testing.T) { if string(buf) != jsonMsg { t.Fatalf("invalid message received, parsing error %s != %s", buf, jsonMsg) } - select { - case <-ctx.Done(): - return - } - } diff --git a/api/handler/api/api.go b/api/handler/api/api.go index 85c7be75..53d707ed 100644 --- a/api/handler/api/api.go +++ b/api/handler/api/api.go @@ -65,7 +65,7 @@ func (a *apiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // create request and response - c := a.opts.Service.Client() + c := a.opts.Client req := c.NewRequest(service.Name, service.Endpoint.Name, request) rsp := &api.Response{} diff --git a/api/handler/event/event.go b/api/handler/event/event.go index 27393165..98dbfe90 100644 --- a/api/handler/event/event.go +++ b/api/handler/event/event.go @@ -118,7 +118,7 @@ func (e *event) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // get client - c := e.opts.Service.Client() + c := e.opts.Client // create publication p := c.NewMessage(topic, ev) diff --git a/api/handler/options.go b/api/handler/options.go index 43401167..76f7eff5 100644 --- a/api/handler/options.go +++ b/api/handler/options.go @@ -1,8 +1,9 @@ package handler import ( - "github.com/micro/go-micro/v2" "github.com/micro/go-micro/v2/api/router" + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/grpc" ) var ( @@ -13,7 +14,7 @@ type Options struct { MaxRecvSize int64 Namespace string Router router.Router - Service micro.Service + Client client.Client } type Option func(o *Options) @@ -25,9 +26,8 @@ func NewOptions(opts ...Option) Options { o(&options) } - // create service if its blank - if options.Service == nil { - WithService(micro.NewService())(&options) + if options.Client == nil { + WithClient(grpc.NewClient())(&options) } // set namespace if blank @@ -56,10 +56,9 @@ func WithRouter(r router.Router) Option { } } -// WithService specifies a micro.Service -func WithService(s micro.Service) Option { +func WithClient(c client.Client) Option { return func(o *Options) { - o.Service = s + o.Client = c } } diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 7c06b663..d396274f 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -113,7 +113,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // micro client - c := h.opts.Service.Client() + c := h.opts.Client // create context cx := ctx.FromRequest(r) From a056bdce7c292ba0cb0d5fe826a3342e2aee43e0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 12 Apr 2020 14:40:37 +0100 Subject: [PATCH 622/788] fix metadata parsing --- api/handler/rpc/rpc.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index d396274f..58493c49 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -304,6 +304,7 @@ func requestPayload(r *http.Request) ([]byte, error) { // get fields from url path for k, v := range md { + k = strings.ToLower(k) // filter own keys if strings.HasPrefix(k, "x-api-field-") { matches[strings.TrimPrefix(k, "x-api-field-")] = v From 1bb6967a38ccaac050fd9be2eee6543be5783b0d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 12 Apr 2020 23:41:21 +0100 Subject: [PATCH 623/788] reorder --- runtime/runtime.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/runtime.go b/runtime/runtime.go index f13db91b..0db14113 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -17,8 +17,6 @@ var ( // Runtime is a service runtime manager type Runtime interface { - // String describes runtime - String() string // Init initializes runtime Init(...Option) error // Create registers a service @@ -31,12 +29,14 @@ type Runtime interface { Delete(*Service) error // List the managed services List() ([]*Service, error) + // Logs returns the logs for a service + Logs(*Service, ...LogsOption) (LogStream, error) // Start starts the runtime Start() error // Stop shuts down the runtime Stop() error - // Logs - Logs(*Service, ...LogsOption) (LogStream, error) + // String describes runtime + String() string } // Stream returns a log stream From 5ef1698632d62926314f0cd2661befa1ac89837f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 12 Apr 2020 23:43:55 +0100 Subject: [PATCH 624/788] remove readme --- runtime/README.md | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 runtime/README.md diff --git a/runtime/README.md b/runtime/README.md deleted file mode 100644 index 600bdceb..00000000 --- a/runtime/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# Runtime - -A runtime for self governing services. - -## Overview - -In recent years we've started to develop complex architectures for the pipeline between writing code and running it. This -philosophy of build, run, manage or however many variations, has created a number of layers of abstraction that make it -all the more difficult to run code. - -Runtime manages the lifecycle of a service from source to running process. If the source is the *source of truth* then -everything in between running is wasted breath. Applications should be self governing and self sustaining. -To enable that we need libraries which make it possible. - -Runtime will fetch source code, build a binary and execute it. Any Go program that uses this library should be able -to run dependencies or itself with ease, with the ability to update itself as the source is updated. - -## Features - -- **Source** - Fetches source whether it be git, go, docker, etc -- **Package** - Compiles the source into a binary which can be executed -- **Process** - Executes a binary and creates a running process - -## Usage - -TODO - - From f840a5003ef482bcf9a0d25fd0ae3d9c0a722386 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 12 Apr 2020 23:46:06 +0100 Subject: [PATCH 625/788] Remove runtime List --- runtime/runtime.go | 2 - runtime/service/proto/runtime.pb.go | 124 +++++++++++----------- runtime/service/proto/runtime.pb.micro.go | 19 +--- runtime/service/proto/runtime.proto | 1 - runtime/service/service.go | 22 ---- 5 files changed, 63 insertions(+), 105 deletions(-) diff --git a/runtime/runtime.go b/runtime/runtime.go index 0db14113..2df1530c 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -27,8 +27,6 @@ type Runtime interface { Update(*Service) error // Remove a service Delete(*Service) error - // List the managed services - List() ([]*Service, error) // Logs returns the logs for a service Logs(*Service, ...LogsOption) (LogStream, error) // Start starts the runtime diff --git a/runtime/service/proto/runtime.pb.go b/runtime/service/proto/runtime.pb.go index 2ac1af66..09a56e9f 100644 --- a/runtime/service/proto/runtime.pb.go +++ b/runtime/service/proto/runtime.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: micro/go-micro/runtime/service/proto/runtime.proto +// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto package go_micro_runtime @@ -38,7 +38,7 @@ func (m *Service) Reset() { *m = Service{} } func (m *Service) String() string { return proto.CompactTextString(m) } func (*Service) ProtoMessage() {} func (*Service) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{0} + return fileDescriptor_976fccef828ab1f0, []int{0} } func (m *Service) XXX_Unmarshal(b []byte) error { @@ -101,7 +101,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{1} + return fileDescriptor_976fccef828ab1f0, []int{1} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -172,7 +172,7 @@ func (m *CreateOptions) Reset() { *m = CreateOptions{} } func (m *CreateOptions) String() string { return proto.CompactTextString(m) } func (*CreateOptions) ProtoMessage() {} func (*CreateOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{2} + return fileDescriptor_976fccef828ab1f0, []int{2} } func (m *CreateOptions) XXX_Unmarshal(b []byte) error { @@ -247,7 +247,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{3} + return fileDescriptor_976fccef828ab1f0, []int{3} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -292,7 +292,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{4} + return fileDescriptor_976fccef828ab1f0, []int{4} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -329,7 +329,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{5} + return fileDescriptor_976fccef828ab1f0, []int{5} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -382,7 +382,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{6} + return fileDescriptor_976fccef828ab1f0, []int{6} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -421,7 +421,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{7} + return fileDescriptor_976fccef828ab1f0, []int{7} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -460,7 +460,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{8} + return fileDescriptor_976fccef828ab1f0, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -498,7 +498,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{9} + return fileDescriptor_976fccef828ab1f0, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -530,7 +530,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{10} + return fileDescriptor_976fccef828ab1f0, []int{10} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -568,7 +568,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{11} + return fileDescriptor_976fccef828ab1f0, []int{11} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -599,7 +599,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{12} + return fileDescriptor_976fccef828ab1f0, []int{12} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -631,7 +631,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{13} + return fileDescriptor_976fccef828ab1f0, []int{13} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -679,7 +679,7 @@ func (m *LogsRequest) Reset() { *m = LogsRequest{} } func (m *LogsRequest) String() string { return proto.CompactTextString(m) } func (*LogsRequest) ProtoMessage() {} func (*LogsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{14} + return fileDescriptor_976fccef828ab1f0, []int{14} } func (m *LogsRequest) XXX_Unmarshal(b []byte) error { @@ -744,7 +744,7 @@ func (m *LogRecord) Reset() { *m = LogRecord{} } func (m *LogRecord) String() string { return proto.CompactTextString(m) } func (*LogRecord) ProtoMessage() {} func (*LogRecord) Descriptor() ([]byte, []int) { - return fileDescriptor_4bc91a8efec81434, []int{15} + return fileDescriptor_976fccef828ab1f0, []int{15} } func (m *LogRecord) XXX_Unmarshal(b []byte) error { @@ -808,51 +808,51 @@ func init() { } func init() { - proto.RegisterFile("micro/go-micro/runtime/service/proto/runtime.proto", fileDescriptor_4bc91a8efec81434) + proto.RegisterFile("github.com/micro/go-micro/runtime/service/proto/runtime.proto", fileDescriptor_976fccef828ab1f0) } -var fileDescriptor_4bc91a8efec81434 = []byte{ - // 663 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcb, 0x6e, 0xd3, 0x40, - 0x14, 0xad, 0xe3, 0x3c, 0xda, 0x6b, 0x82, 0xaa, 0x51, 0x85, 0x4c, 0x79, 0x45, 0xde, 0x50, 0x16, - 0xb8, 0x28, 0x15, 0xe2, 0xb5, 0x6c, 0x53, 0x36, 0x8d, 0x90, 0x8c, 0xfa, 0x01, 0x83, 0x73, 0x65, - 0x59, 0xad, 0x3d, 0xc6, 0x33, 0x8e, 0x94, 0x15, 0xdf, 0xc0, 0x57, 0xb1, 0x85, 0x3f, 0x42, 0xf3, - 0xf0, 0x2b, 0xb1, 0xbb, 0xc9, 0x6e, 0xee, 0xe4, 0xce, 0xf1, 0x39, 0x67, 0xce, 0x9d, 0xc0, 0x3c, - 0x89, 0xc3, 0x9c, 0x9d, 0x47, 0xec, 0xad, 0x5e, 0xe4, 0x45, 0x2a, 0xe2, 0x04, 0xcf, 0x39, 0xe6, - 0xeb, 0x38, 0xc4, 0xf3, 0x2c, 0x67, 0xa2, 0xda, 0xf5, 0x55, 0x45, 0x8e, 0x23, 0xe6, 0xab, 0x6e, - 0xdf, 0xec, 0x7b, 0xff, 0x2c, 0x98, 0x7c, 0xd7, 0x27, 0x08, 0x81, 0x61, 0x4a, 0x13, 0x74, 0xad, - 0x99, 0x75, 0x76, 0x14, 0xa8, 0x35, 0x71, 0x61, 0xb2, 0xc6, 0x9c, 0xc7, 0x2c, 0x75, 0x07, 0x6a, - 0xbb, 0x2c, 0xc9, 0x13, 0x18, 0x73, 0x56, 0xe4, 0x21, 0xba, 0xb6, 0xfa, 0xc1, 0x54, 0xe4, 0x12, - 0x0e, 0x13, 0x14, 0x74, 0x45, 0x05, 0x75, 0x87, 0x33, 0xfb, 0xcc, 0x99, 0xbf, 0xf6, 0xb7, 0x3f, - 0xeb, 0x9b, 0x4f, 0xfa, 0x4b, 0xd3, 0xb9, 0x48, 0x45, 0xbe, 0x09, 0xaa, 0x83, 0xa7, 0x5f, 0x60, - 0xda, 0xfa, 0x89, 0x1c, 0x83, 0x7d, 0x87, 0x1b, 0x43, 0x4d, 0x2e, 0xc9, 0x09, 0x8c, 0xd6, 0xf4, - 0xbe, 0x40, 0xc3, 0x4b, 0x17, 0x9f, 0x07, 0x1f, 0x2d, 0x2f, 0x81, 0xd1, 0x62, 0x8d, 0xa9, 0x90, - 0x82, 0xc4, 0x26, 0xab, 0x04, 0xc9, 0x35, 0x79, 0x0e, 0x47, 0x92, 0x01, 0x17, 0x34, 0xc9, 0xd4, - 0x51, 0x3b, 0xa8, 0x37, 0xa4, 0x5c, 0xe3, 0x9f, 0x51, 0x55, 0x96, 0x4d, 0x23, 0x86, 0x2d, 0x23, - 0xbc, 0xdf, 0x16, 0x4c, 0x2f, 0x73, 0xa4, 0x02, 0xbf, 0x65, 0x22, 0x66, 0x29, 0x97, 0xbd, 0x21, - 0x4b, 0x12, 0x9a, 0xae, 0x5c, 0x6b, 0x66, 0xcb, 0x5e, 0x53, 0x4a, 0x46, 0x34, 0x8f, 0xb8, 0x3b, - 0x50, 0xdb, 0x6a, 0x2d, 0xa5, 0x61, 0xba, 0x76, 0x6d, 0xb5, 0x25, 0x97, 0xd2, 0x5a, 0x56, 0x88, - 0xac, 0x10, 0xe6, 0x53, 0xa6, 0xaa, 0xf4, 0x8c, 0x1a, 0x7a, 0x4e, 0x60, 0x14, 0x27, 0x34, 0x42, - 0x77, 0xac, 0x6d, 0x50, 0x85, 0xf7, 0xab, 0xa4, 0x14, 0xe0, 0xcf, 0x02, 0xb9, 0x20, 0x17, 0xb5, - 0x30, 0xe9, 0x86, 0x33, 0x7f, 0xda, 0x7b, 0x29, 0xb5, 0xe6, 0x4f, 0x30, 0x61, 0x5a, 0x92, 0x72, - 0xca, 0x99, 0xbf, 0xda, 0x3d, 0xd4, 0x52, 0x1e, 0x94, 0xfd, 0xde, 0x31, 0x3c, 0x2e, 0x09, 0x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xb5, 0x61, 0x12, 0x68, 0x12, 0x64, 0x09, 0x63, 0x3d, 0x40, 0xa4, - 0x77, 0xe8, 0x8c, 0xbd, 0xa7, 0xb3, 0xfe, 0x06, 0x73, 0xcb, 0x07, 0xe4, 0x2b, 0x0c, 0x65, 0xbc, - 0x49, 0xcf, 0x38, 0x94, 0x50, 0x2f, 0xfb, 0x7e, 0xae, 0x80, 0x96, 0x30, 0xd6, 0xd1, 0xec, 0xe2, - 0xd5, 0x8a, 0x7e, 0x17, 0xaf, 0xad, 0x54, 0x2b, 0x38, 0x9d, 0xc8, 0x2e, 0xb8, 0x56, 0xe2, 0xbb, - 0xe0, 0xb6, 0xc2, 0xac, 0x64, 0xca, 0xfc, 0x76, 0xc9, 0x6c, 0xc4, 0xbc, 0x4b, 0x66, 0x33, 0xf6, - 0xde, 0x01, 0xb9, 0x86, 0xa1, 0x4c, 0x70, 0x27, 0x50, 0x9d, 0xec, 0xd3, 0x67, 0x0f, 0xa4, 0xc7, - 0x3b, 0x78, 0x67, 0xfd, 0x18, 0xab, 0x3f, 0xde, 0x8b, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x17, - 0xe1, 0xab, 0x77, 0xae, 0x07, 0x00, 0x00, +var fileDescriptor_976fccef828ab1f0 = []byte{ + // 662 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xbb, 0x6e, 0xdb, 0x4a, + 0x10, 0x35, 0x45, 0x3d, 0xec, 0xd1, 0xd5, 0x85, 0xb1, 0x30, 0x02, 0xc6, 0x79, 0x09, 0x6c, 0xe2, + 0x14, 0xa1, 0x02, 0x19, 0x41, 0x5e, 0x48, 0x65, 0xcb, 0x69, 0x6c, 0x04, 0x60, 0xe0, 0x0f, 0x58, + 0x53, 0x03, 0x86, 0xb0, 0x97, 0xcb, 0x70, 0x97, 0x02, 0x5c, 0xa5, 0x4c, 0x9d, 0xaf, 0x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xd5, 0x1a, 0xce, 0x4c, 0x64, 0x1b, 0x5c, 0x63, 0xe2, 0xdb, 0xe0, 0x36, 0x86, 0x79, + 0x8f, 0x5c, 0x40, 0x5f, 0x0d, 0x5e, 0x9b, 0xcc, 0xda, 0x40, 0x1e, 0x3f, 0x79, 0xa0, 0xe9, 0xfe, + 0xde, 0x1b, 0xe7, 0x66, 0xa8, 0xff, 0x2f, 0x4f, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x40, 0x42, + 0xb3, 0x4e, 0x70, 0x07, 0x00, 0x00, } diff --git a/runtime/service/proto/runtime.pb.micro.go b/runtime/service/proto/runtime.pb.micro.go index eff7c76e..da23a4e7 100644 --- a/runtime/service/proto/runtime.pb.micro.go +++ b/runtime/service/proto/runtime.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: micro/go-micro/runtime/service/proto/runtime.proto +// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto package go_micro_runtime @@ -38,7 +38,6 @@ type RuntimeService interface { Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) - List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) Logs(ctx context.Context, in *LogsRequest, opts ...client.CallOption) (Runtime_LogsService, error) } @@ -94,16 +93,6 @@ func (c *runtimeService) Update(ctx context.Context, in *UpdateRequest, opts ... return out, nil } -func (c *runtimeService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error) { - req := c.c.NewRequest(c.name, "Runtime.List", in) - out := new(ListResponse) - err := c.c.Call(ctx, req, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *runtimeService) Logs(ctx context.Context, in *LogsRequest, opts ...client.CallOption) (Runtime_LogsService, error) { req := c.c.NewRequest(c.name, "Runtime.Logs", &LogsRequest{}) stream, err := c.c.Stream(ctx, req, opts...) @@ -160,7 +149,6 @@ type RuntimeHandler interface { Read(context.Context, *ReadRequest, *ReadResponse) error Delete(context.Context, *DeleteRequest, *DeleteResponse) error Update(context.Context, *UpdateRequest, *UpdateResponse) error - List(context.Context, *ListRequest, *ListResponse) error Logs(context.Context, *LogsRequest, Runtime_LogsStream) error } @@ -170,7 +158,6 @@ func RegisterRuntimeHandler(s server.Server, hdlr RuntimeHandler, opts ...server Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error - List(ctx context.Context, in *ListRequest, out *ListResponse) error Logs(ctx context.Context, stream server.Stream) error } type Runtime struct { @@ -200,10 +187,6 @@ func (h *runtimeHandler) Update(ctx context.Context, in *UpdateRequest, out *Upd return h.RuntimeHandler.Update(ctx, in, out) } -func (h *runtimeHandler) List(ctx context.Context, in *ListRequest, out *ListResponse) error { - return h.RuntimeHandler.List(ctx, in, out) -} - func (h *runtimeHandler) Logs(ctx context.Context, stream server.Stream) error { m := new(LogsRequest) if err := stream.Recv(m); err != nil { diff --git a/runtime/service/proto/runtime.proto b/runtime/service/proto/runtime.proto index e8d563e0..65c2c497 100644 --- a/runtime/service/proto/runtime.proto +++ b/runtime/service/proto/runtime.proto @@ -7,7 +7,6 @@ service Runtime { rpc Read(ReadRequest) returns (ReadResponse) {}; rpc Delete(DeleteRequest) returns (DeleteResponse) {}; rpc Update(UpdateRequest) returns (UpdateResponse) {}; - rpc List(ListRequest) returns (ListResponse) {}; rpc Logs(LogsRequest) returns (stream LogRecord) {}; } diff --git a/runtime/service/service.go b/runtime/service/service.go index 8cadfcdf..d065038c 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -194,28 +194,6 @@ func (s *svc) Delete(svc *runtime.Service) error { return nil } -// List lists all services managed by the runtime -func (s *svc) List() ([]*runtime.Service, error) { - // list all services managed by the runtime - resp, err := s.runtime.List(context.Background(), &pb.ListRequest{}) - if err != nil { - return nil, err - } - - services := make([]*runtime.Service, 0, len(resp.Services)) - for _, service := range resp.Services { - svc := &runtime.Service{ - Name: service.Name, - Version: service.Version, - Source: service.Source, - Metadata: service.Metadata, - } - services = append(services, svc) - } - - return services, nil -} - // Start starts the runtime func (s *svc) Start() error { // NOTE: nothing to be done here From 4bdc18d64aacf95b58cfb53113bcf8b17b32aa86 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 13 Apr 2020 22:15:21 +0100 Subject: [PATCH 626/788] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d6b39afc..a39364a1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Go Micro [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/micro/go-micro?tab=doc) [![Travis CI](https://api.travis-ci.org/micro/go-micro.svg?branch=master)](https://travis-ci.org/micro/go-micro) [![Go Report Card](https://goreportcard.com/badge/micro/go-micro)](https://goreportcard.com/report/github.com/micro/go-micro) -Go Micro is a framework for microservice development. +Go Micro is a framework for distributed systems development. ## Overview From e515005083ef83dc1978359c78fd16f10c3a5f9b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 13 Apr 2020 23:05:39 +0100 Subject: [PATCH 627/788] Remove only allowing certain methods --- api/handler/rpc/rpc.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 58493c49..d9ff31ad 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -100,11 +100,6 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - if h.opts.Router == nil && r.Method != "GET" { - writeError(w, r, errors.MethodNotAllowed("go.micro.api", "method not allowed")) - return - } - ct := r.Header.Get("Content-Type") // Strip charset from Content-Type (like `application/json; charset=UTF-8`) From d61d30ef66fe85bc7c47d56639146aa10ccb6ea3 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 14 Apr 2020 09:14:07 +0100 Subject: [PATCH 628/788] Inject Namespace into Context --- auth/auth.go | 8 ++++++++ auth/default.go | 2 +- auth/options.go | 13 +++++++++++++ auth/service/service.go | 4 +--- util/wrapper/wrapper.go | 7 ++++++- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index e34051fa..64b29d81 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -133,3 +133,11 @@ func ContextWithAccount(ctx context.Context, account *Account) (context.Context, // generate a new context with the MetadataKey set return metadata.Set(ctx, MetadataKey, string(bytes)), nil } + +// NamespaceFromContext gets the namespace from the context +func NamespaceFromContext(ctx context.Context) string { + if ns, ok := metadata.Get(ctx, NamespaceKey); ok { + return ns + } + return DefaultNamespace +} diff --git a/auth/default.go b/auth/default.go index 358cf099..0c295df6 100644 --- a/auth/default.go +++ b/auth/default.go @@ -9,7 +9,7 @@ var ( ) func NewAuth(opts ...Option) Auth { - return &noop{} + return &noop{opts: NewOptions(opts...)} } type noop struct { diff --git a/auth/options.go b/auth/options.go index d3c0f4ea..3cd1bc69 100644 --- a/auth/options.go +++ b/auth/options.go @@ -7,6 +7,19 @@ import ( "github.com/micro/go-micro/v2/store" ) +func NewOptions(opts ...Option) Options { + var options Options + for _, o := range opts { + o(&options) + } + + if len(options.Namespace) == 0 { + options.Namespace = DefaultNamespace + } + + return options +} + type Options struct { // Namespace the service belongs to Namespace string diff --git a/auth/service/service.go b/auth/service/service.go index cb1740c7..5a59f988 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -18,9 +18,7 @@ import ( // NewAuth returns a new instance of the Auth service func NewAuth(opts ...auth.Option) auth.Auth { - svc := new(svc) - svc.Init(opts...) - return svc + return &svc{options: auth.NewOptions(opts...)} } // svc is the service implementation of the Auth interface diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 13ae5531..414a4c6b 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -159,7 +159,7 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { // Inspect the token and get the account account, err := a.Inspect(token) if err != nil { - account = &auth.Account{} + account = &auth.Account{Namespace: a.Options().Namespace} } // construct the resource @@ -183,6 +183,11 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { return err } + // Set the namespace in the context + if _, ok := metadata.Get(ctx, auth.NamespaceKey); !ok { + ctx = metadata.Set(ctx, auth.NamespaceKey, a.Options().Namespace) + } + // The user is authorised, allow the call return h(ctx, req, rsp) } From e17825474fcd8c5c22134c30ba1a0372074b8c47 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 14 Apr 2020 12:32:59 +0100 Subject: [PATCH 629/788] Add context options to the runtime --- auth/auth.go | 10 -------- auth/service/service.go | 20 ++++++++++------ registry/cache/cache.go | 2 +- registry/etcd/etcd.go | 6 ++--- registry/mdns_registry.go | 6 ++--- registry/memory/memory.go | 6 ++--- registry/options.go | 42 +++++++++++++++++++++++++++++++++ registry/registry.go | 12 +++++++--- registry/service/service.go | 46 ++++++++++++++++++++++++++++++------- util/wrapper/wrapper.go | 5 ---- 10 files changed, 112 insertions(+), 43 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 64b29d81..d18b0e38 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -90,8 +90,6 @@ type Token struct { const ( // DefaultNamespace used for auth DefaultNamespace = "go.micro" - // NamespaceKey is the key used when storing the namespace in metadata - NamespaceKey = "Micro-Namespace" // MetadataKey is the key used when storing the account in metadata MetadataKey = "auth-account" // TokenCookieName is the name of the cookie which stores the auth token @@ -133,11 +131,3 @@ func ContextWithAccount(ctx context.Context, account *Account) (context.Context, // generate a new context with the MetadataKey set return metadata.Set(ctx, MetadataKey, string(bytes)), nil } - -// NamespaceFromContext gets the namespace from the context -func NamespaceFromContext(ctx context.Context) string { - if ns, ok := metadata.Get(ctx, NamespaceKey); ok { - return ns - } - return DefaultNamespace -} diff --git a/auth/service/service.go b/auth/service/service.go index 5a59f988..73e3f80a 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -53,8 +53,9 @@ func (s *svc) Init(opts ...auth.Option) { } // load rules periodically from the auth service - ruleTimer := time.NewTicker(time.Second * 30) go func() { + ruleTimer := time.NewTicker(time.Second * 30) + // load rules immediately on startup s.loadRules() @@ -72,10 +73,11 @@ func (s *svc) Init(opts ...auth.Option) { // we have client credentials and must load a new token // periodically if len(s.options.ID) > 0 || len(s.options.Secret) > 0 { - tokenTimer := time.NewTicker(time.Minute) + // get a token immediately + s.refreshToken() go func() { - s.refreshToken() + tokenTimer := time.NewTicker(time.Minute) for { <-tokenTimer.C @@ -178,11 +180,15 @@ func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { } } - // set a default account id to log + // set a default account id / namespace to log logID := acc.ID if len(logID) == 0 { logID = "[no account]" } + logNamespace := acc.Namespace + if len(logNamespace) == 0 { + logNamespace = "[no namespace]" + } for _, q := range queries { for _, rule := range s.listRules(q...) { @@ -190,17 +196,17 @@ func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { case pb.Access_UNKNOWN: continue // rule did not specify access, check the next rule case pb.Access_GRANTED: - log.Infof("%v:%v granted access to %v:%v:%v:%v by rule %v", acc.Namespace, logID, res.Namespace, res.Type, res.Name, res.Endpoint, rule.Id) + log.Tracef("%v:%v granted access to %v:%v:%v:%v by rule %v", logNamespace, logID, res.Namespace, res.Type, res.Name, res.Endpoint, rule.Id) return nil // rule grants the account access to the resource case pb.Access_DENIED: - log.Infof("%v:%v denied access to %v:%v:%v:%v by rule %v", acc.Namespace, logID, res.Namespace, res.Type, res.Name, res.Endpoint, rule.Id) + log.Tracef("%v:%v denied access to %v:%v:%v:%v by rule %v", logNamespace, logID, res.Namespace, res.Type, res.Name, res.Endpoint, rule.Id) return auth.ErrForbidden // rule denies access to the resource } } } // no rules were found for the resource, default to denying access - log.Infof("%v:%v denied access to %v:%v:%v:%v by lack of rule (%v rules found for namespace)", acc.Namespace, logID, res.Namespace, res.Type, res.Name, res.Endpoint, len(s.listRules(res.Namespace))) + log.Tracef("%v:%v denied access to %v:%v:%v:%v by lack of rule (%v rules found for namespace)", logNamespace, logID, res.Namespace, res.Type, res.Name, res.Endpoint, len(s.listRules(res.Namespace))) return auth.ErrForbidden } diff --git a/registry/cache/cache.go b/registry/cache/cache.go index 7714f980..2799f2d4 100644 --- a/registry/cache/cache.go +++ b/registry/cache/cache.go @@ -419,7 +419,7 @@ func (c *cache) watch(w registry.Watcher) error { } } -func (c *cache) GetService(service string) ([]*registry.Service, error) { +func (c *cache) GetService(service string, opts ...registry.GetOption) ([]*registry.Service, error) { // get the service services, err := c.get(service) if err != nil { diff --git a/registry/etcd/etcd.go b/registry/etcd/etcd.go index 8b7a65e1..8cbda8cf 100644 --- a/registry/etcd/etcd.go +++ b/registry/etcd/etcd.go @@ -276,7 +276,7 @@ func (e *etcdRegistry) registerNode(s *registry.Service, node *registry.Node, op return nil } -func (e *etcdRegistry) Deregister(s *registry.Service) error { +func (e *etcdRegistry) Deregister(s *registry.Service, opts ...registry.DeregisterOption) error { if len(s.Nodes) == 0 { return errors.New("Require at least one node") } @@ -322,7 +322,7 @@ func (e *etcdRegistry) Register(s *registry.Service, opts ...registry.RegisterOp return gerr } -func (e *etcdRegistry) GetService(name string) ([]*registry.Service, error) { +func (e *etcdRegistry) GetService(name string, opts ...registry.GetOption) ([]*registry.Service, error) { ctx, cancel := context.WithTimeout(context.Background(), e.options.Timeout) defer cancel() @@ -362,7 +362,7 @@ func (e *etcdRegistry) GetService(name string) ([]*registry.Service, error) { return services, nil } -func (e *etcdRegistry) ListServices() ([]*registry.Service, error) { +func (e *etcdRegistry) ListServices(opts ...registry.ListOption) ([]*registry.Service, error) { versions := make(map[string]*registry.Service) ctx, cancel := context.WithTimeout(context.Background(), e.options.Timeout) diff --git a/registry/mdns_registry.go b/registry/mdns_registry.go index 18758878..fde00f37 100644 --- a/registry/mdns_registry.go +++ b/registry/mdns_registry.go @@ -269,7 +269,7 @@ func (m *mdnsRegistry) Register(service *Service, opts ...RegisterOption) error return gerr } -func (m *mdnsRegistry) Deregister(service *Service) error { +func (m *mdnsRegistry) Deregister(service *Service, opts ...DeregisterOption) error { m.Lock() defer m.Unlock() @@ -304,7 +304,7 @@ func (m *mdnsRegistry) Deregister(service *Service) error { return nil } -func (m *mdnsRegistry) GetService(service string) ([]*Service, error) { +func (m *mdnsRegistry) GetService(service string, opts ...GetOption) ([]*Service, error) { serviceMap := make(map[string]*Service) entries := make(chan *mdns.ServiceEntry, 10) done := make(chan bool) @@ -396,7 +396,7 @@ func (m *mdnsRegistry) GetService(service string) ([]*Service, error) { return services, nil } -func (m *mdnsRegistry) ListServices() ([]*Service, error) { +func (m *mdnsRegistry) ListServices(opts ...ListOption) ([]*Service, error) { serviceMap := make(map[string]bool) entries := make(chan *mdns.ServiceEntry, 10) done := make(chan bool) diff --git a/registry/memory/memory.go b/registry/memory/memory.go index cde49b96..44f22439 100644 --- a/registry/memory/memory.go +++ b/registry/memory/memory.go @@ -207,7 +207,7 @@ func (m *Registry) Register(s *registry.Service, opts ...registry.RegisterOption return nil } -func (m *Registry) Deregister(s *registry.Service) error { +func (m *Registry) Deregister(s *registry.Service, opts ...registry.DeregisterOption) error { m.Lock() defer m.Unlock() @@ -240,7 +240,7 @@ func (m *Registry) Deregister(s *registry.Service) error { return nil } -func (m *Registry) GetService(name string) ([]*registry.Service, error) { +func (m *Registry) GetService(name string, opts ...registry.GetOption) ([]*registry.Service, error) { m.RLock() defer m.RUnlock() @@ -259,7 +259,7 @@ func (m *Registry) GetService(name string) ([]*registry.Service, error) { return services, nil } -func (m *Registry) ListServices() ([]*registry.Service, error) { +func (m *Registry) ListServices(opts ...registry.ListOption) ([]*registry.Service, error) { m.RLock() defer m.RUnlock() diff --git a/registry/options.go b/registry/options.go index d3a54856..03fd5eb4 100644 --- a/registry/options.go +++ b/registry/options.go @@ -32,6 +32,18 @@ type WatchOptions struct { Context context.Context } +type DeregisterOptions struct { + Context context.Context +} + +type GetOptions struct { + Context context.Context +} + +type ListOptions struct { + Context context.Context +} + // Addrs is the registry addresses to use func Addrs(addrs ...string) Option { return func(o *Options) { @@ -65,9 +77,39 @@ func RegisterTTL(t time.Duration) RegisterOption { } } +func RegisterContext(ctx context.Context) RegisterOption { + return func(o *RegisterOptions) { + o.Context = ctx + } +} + // Watch a service func WatchService(name string) WatchOption { return func(o *WatchOptions) { o.Service = name } } + +func WatchContext(ctx context.Context) WatchOption { + return func(o *WatchOptions) { + o.Context = ctx + } +} + +func DeregisterContext(ctx context.Context) DeregisterOption { + return func(o *DeregisterOptions) { + o.Context = ctx + } +} + +func GetContext(ctx context.Context) GetOption { + return func(o *GetOptions) { + o.Context = ctx + } +} + +func ListContext(ctx context.Context) ListOption { + return func(o *ListOptions) { + o.Context = ctx + } +} diff --git a/registry/registry.go b/registry/registry.go index 291a1988..dce9b431 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -21,9 +21,9 @@ type Registry interface { Init(...Option) error Options() Options Register(*Service, ...RegisterOption) error - Deregister(*Service) error - GetService(string) ([]*Service, error) - ListServices() ([]*Service, error) + Deregister(*Service, ...DeregisterOption) error + GetService(string, ...GetOption) ([]*Service, error) + ListServices(...ListOption) ([]*Service, error) Watch(...WatchOption) (Watcher, error) String() string } @@ -61,6 +61,12 @@ type RegisterOption func(*RegisterOptions) type WatchOption func(*WatchOptions) +type DeregisterOption func(*DeregisterOptions) + +type GetOption func(*GetOptions) + +type ListOption func(*ListOptions) + // Register a service node. Additionally supply options such as TTL. func Register(s *Service, opts ...RegisterOption) error { return DefaultRegistry.Register(s, opts...) diff --git a/registry/service/service.go b/registry/service/service.go index e266347f..acf42d3a 100644 --- a/registry/service/service.go +++ b/registry/service/service.go @@ -58,13 +58,16 @@ func (s *serviceRegistry) Register(srv *registry.Service, opts ...registry.Regis for _, o := range opts { o(&options) } + if options.Context == nil { + options.Context = context.TODO() + } // encode srv into protobuf and pack Register TTL into it pbSrv := ToProto(srv) pbSrv.Options.Ttl = int64(options.TTL.Seconds()) // register the service - _, err := s.client.Register(context.TODO(), pbSrv, s.callOpts()...) + _, err := s.client.Register(options.Context, pbSrv, s.callOpts()...) if err != nil { return err } @@ -72,17 +75,33 @@ func (s *serviceRegistry) Register(srv *registry.Service, opts ...registry.Regis return nil } -func (s *serviceRegistry) Deregister(srv *registry.Service) error { +func (s *serviceRegistry) Deregister(srv *registry.Service, opts ...registry.DeregisterOption) error { + var options registry.DeregisterOptions + for _, o := range opts { + o(&options) + } + if options.Context == nil { + options.Context = context.TODO() + } + // deregister the service - _, err := s.client.Deregister(context.TODO(), ToProto(srv), s.callOpts()...) + _, err := s.client.Deregister(options.Context, ToProto(srv), s.callOpts()...) if err != nil { return err } return nil } -func (s *serviceRegistry) GetService(name string) ([]*registry.Service, error) { - rsp, err := s.client.GetService(context.TODO(), &pb.GetRequest{ +func (s *serviceRegistry) GetService(name string, opts ...registry.GetOption) ([]*registry.Service, error) { + var options registry.GetOptions + for _, o := range opts { + o(&options) + } + if options.Context == nil { + options.Context = context.TODO() + } + + rsp, err := s.client.GetService(options.Context, &pb.GetRequest{ Service: name, }, s.callOpts()...) @@ -97,8 +116,16 @@ func (s *serviceRegistry) GetService(name string) ([]*registry.Service, error) { return services, nil } -func (s *serviceRegistry) ListServices() ([]*registry.Service, error) { - rsp, err := s.client.ListServices(context.TODO(), &pb.ListRequest{}, s.callOpts()...) +func (s *serviceRegistry) ListServices(opts ...registry.ListOption) ([]*registry.Service, error) { + var options registry.ListOptions + for _, o := range opts { + o(&options) + } + if options.Context == nil { + options.Context = context.TODO() + } + + rsp, err := s.client.ListServices(options.Context, &pb.ListRequest{}, s.callOpts()...) if err != nil { return nil, err } @@ -116,8 +143,11 @@ func (s *serviceRegistry) Watch(opts ...registry.WatchOption) (registry.Watcher, for _, o := range opts { o(&options) } + if options.Context == nil { + options.Context = context.TODO() + } - stream, err := s.client.Watch(context.TODO(), &pb.WatchRequest{ + stream, err := s.client.Watch(options.Context, &pb.WatchRequest{ Service: options.Service, }, s.callOpts()...) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 414a4c6b..e5ce4bb1 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -183,11 +183,6 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { return err } - // Set the namespace in the context - if _, ok := metadata.Get(ctx, auth.NamespaceKey); !ok { - ctx = metadata.Set(ctx, auth.NamespaceKey, a.Options().Namespace) - } - // The user is authorised, allow the call return h(ctx, req, rsp) } From 268651df18fd9eb0249288329f61bd37cb7e9e12 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 14 Apr 2020 16:25:09 +0300 Subject: [PATCH 630/788] regenerate all proto based files (#1531) Signed-off-by: Vasiliy Tolstov --- .github/generate.sh | 2 +- agent/proto/bot.pb.micro.go | 8 + api/service/proto/api.pb.micro.go | 8 + auth/service/proto/auth.pb.go | 539 +++++++++++++++--- auth/service/proto/auth.pb.micro.go | 22 +- broker/service/proto/broker.pb.micro.go | 8 + client/service/proto/client.pb.micro.go | 8 + .../source/service/proto/service.pb.micro.go | 8 + debug/service/proto/debug.pb.micro.go | 8 + network/service/proto/network.pb.micro.go | 8 + registry/service/proto/registry.pb.micro.go | 8 + router/service/proto/router.pb.micro.go | 14 + runtime/service/proto/runtime.pb.go | 379 ++++++++++-- runtime/service/proto/runtime.pb.micro.go | 10 +- server/grpc/proto/test.pb.go | 31 +- server/grpc/proto/test.pb.micro.go | 22 + server/grpc/proto/test.proto | 10 +- server/proto/server.pb.micro.go | 8 + service/grpc/proto/test.pb.micro.go | 8 + store/service/proto/store.pb.go | 405 +++++++++++-- store/service/proto/store.pb.micro.go | 10 +- transport/grpc/proto/transport.pb.micro.go | 8 + 22 files changed, 1313 insertions(+), 219 deletions(-) diff --git a/.github/generate.sh b/.github/generate.sh index 059277a9..672ce4ff 100755 --- a/.github/generate.sh +++ b/.github/generate.sh @@ -5,5 +5,5 @@ PROTOS=$(find . -type f -name '*.proto') for PROTO in $PROTOS; do echo $PROTO - protoc -I./ -I$(dirname $PROTO) --go_out=plugins=grpc,paths=source_relative:. --micro_out=paths=source_relative:. $PROTO + protoc -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I./ -I$(dirname $PROTO) --go_out=plugins=grpc,paths=source_relative:. --micro_out=paths=source_relative:. $PROTO done diff --git a/agent/proto/bot.pb.micro.go b/agent/proto/bot.pb.micro.go index 60338cda..7c105aa6 100644 --- a/agent/proto/bot.pb.micro.go +++ b/agent/proto/bot.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Command service + +func NewCommandEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Command service type CommandService interface { diff --git a/api/service/proto/api.pb.micro.go b/api/service/proto/api.pb.micro.go index 301b7c55..c2bcfbc6 100644 --- a/api/service/proto/api.pb.micro.go +++ b/api/service/proto/api.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Api service + +func NewApiEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Api service type ApiService interface { diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index aac61c2a..0cd12014 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/auth/service/proto/auth.proto +// source: auth/service/proto/auth.proto package go_micro_auth import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -45,7 +49,7 @@ func (x Access) String() string { } func (Access) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{0} + return fileDescriptor_21300bfacc51fc2a, []int{0} } type ListAccountsRequest struct { @@ -58,7 +62,7 @@ func (m *ListAccountsRequest) Reset() { *m = ListAccountsRequest{} } func (m *ListAccountsRequest) String() string { return proto.CompactTextString(m) } func (*ListAccountsRequest) ProtoMessage() {} func (*ListAccountsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{0} + return fileDescriptor_21300bfacc51fc2a, []int{0} } func (m *ListAccountsRequest) XXX_Unmarshal(b []byte) error { @@ -90,7 +94,7 @@ func (m *ListAccountsResponse) Reset() { *m = ListAccountsResponse{} } func (m *ListAccountsResponse) String() string { return proto.CompactTextString(m) } func (*ListAccountsResponse) ProtoMessage() {} func (*ListAccountsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{1} + return fileDescriptor_21300bfacc51fc2a, []int{1} } func (m *ListAccountsResponse) XXX_Unmarshal(b []byte) error { @@ -132,7 +136,7 @@ func (m *Token) Reset() { *m = Token{} } func (m *Token) String() string { return proto.CompactTextString(m) } func (*Token) ProtoMessage() {} func (*Token) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{2} + return fileDescriptor_21300bfacc51fc2a, []int{2} } func (m *Token) XXX_Unmarshal(b []byte) error { @@ -198,7 +202,7 @@ func (m *Account) Reset() { *m = Account{} } func (m *Account) String() string { return proto.CompactTextString(m) } func (*Account) ProtoMessage() {} func (*Account) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{3} + return fileDescriptor_21300bfacc51fc2a, []int{3} } func (m *Account) XXX_Unmarshal(b []byte) error { @@ -282,7 +286,7 @@ func (m *Resource) Reset() { *m = Resource{} } func (m *Resource) String() string { return proto.CompactTextString(m) } func (*Resource) ProtoMessage() {} func (*Resource) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{4} + return fileDescriptor_21300bfacc51fc2a, []int{4} } func (m *Resource) XXX_Unmarshal(b []byte) error { @@ -348,7 +352,7 @@ func (m *GenerateRequest) Reset() { *m = GenerateRequest{} } func (m *GenerateRequest) String() string { return proto.CompactTextString(m) } func (*GenerateRequest) ProtoMessage() {} func (*GenerateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{5} + return fileDescriptor_21300bfacc51fc2a, []int{5} } func (m *GenerateRequest) XXX_Unmarshal(b []byte) error { @@ -429,7 +433,7 @@ func (m *GenerateResponse) Reset() { *m = GenerateResponse{} } func (m *GenerateResponse) String() string { return proto.CompactTextString(m) } func (*GenerateResponse) ProtoMessage() {} func (*GenerateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{6} + return fileDescriptor_21300bfacc51fc2a, []int{6} } func (m *GenerateResponse) XXX_Unmarshal(b []byte) error { @@ -469,7 +473,7 @@ func (m *GrantRequest) Reset() { *m = GrantRequest{} } func (m *GrantRequest) String() string { return proto.CompactTextString(m) } func (*GrantRequest) ProtoMessage() {} func (*GrantRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{7} + return fileDescriptor_21300bfacc51fc2a, []int{7} } func (m *GrantRequest) XXX_Unmarshal(b []byte) error { @@ -514,7 +518,7 @@ func (m *GrantResponse) Reset() { *m = GrantResponse{} } func (m *GrantResponse) String() string { return proto.CompactTextString(m) } func (*GrantResponse) ProtoMessage() {} func (*GrantResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{8} + return fileDescriptor_21300bfacc51fc2a, []int{8} } func (m *GrantResponse) XXX_Unmarshal(b []byte) error { @@ -547,7 +551,7 @@ func (m *RevokeRequest) Reset() { *m = RevokeRequest{} } func (m *RevokeRequest) String() string { return proto.CompactTextString(m) } func (*RevokeRequest) ProtoMessage() {} func (*RevokeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{9} + return fileDescriptor_21300bfacc51fc2a, []int{9} } func (m *RevokeRequest) XXX_Unmarshal(b []byte) error { @@ -592,7 +596,7 @@ func (m *RevokeResponse) Reset() { *m = RevokeResponse{} } func (m *RevokeResponse) String() string { return proto.CompactTextString(m) } func (*RevokeResponse) ProtoMessage() {} func (*RevokeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{10} + return fileDescriptor_21300bfacc51fc2a, []int{10} } func (m *RevokeResponse) XXX_Unmarshal(b []byte) error { @@ -624,7 +628,7 @@ func (m *InspectRequest) Reset() { *m = InspectRequest{} } func (m *InspectRequest) String() string { return proto.CompactTextString(m) } func (*InspectRequest) ProtoMessage() {} func (*InspectRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{11} + return fileDescriptor_21300bfacc51fc2a, []int{11} } func (m *InspectRequest) XXX_Unmarshal(b []byte) error { @@ -663,7 +667,7 @@ func (m *InspectResponse) Reset() { *m = InspectResponse{} } func (m *InspectResponse) String() string { return proto.CompactTextString(m) } func (*InspectResponse) ProtoMessage() {} func (*InspectResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{12} + return fileDescriptor_21300bfacc51fc2a, []int{12} } func (m *InspectResponse) XXX_Unmarshal(b []byte) error { @@ -705,7 +709,7 @@ func (m *TokenRequest) Reset() { *m = TokenRequest{} } func (m *TokenRequest) String() string { return proto.CompactTextString(m) } func (*TokenRequest) ProtoMessage() {} func (*TokenRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{13} + return fileDescriptor_21300bfacc51fc2a, []int{13} } func (m *TokenRequest) XXX_Unmarshal(b []byte) error { @@ -765,7 +769,7 @@ func (m *TokenResponse) Reset() { *m = TokenResponse{} } func (m *TokenResponse) String() string { return proto.CompactTextString(m) } func (*TokenResponse) ProtoMessage() {} func (*TokenResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{14} + return fileDescriptor_21300bfacc51fc2a, []int{14} } func (m *TokenResponse) XXX_Unmarshal(b []byte) error { @@ -807,7 +811,7 @@ func (m *Rule) Reset() { *m = Rule{} } func (m *Rule) String() string { return proto.CompactTextString(m) } func (*Rule) ProtoMessage() {} func (*Rule) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{15} + return fileDescriptor_21300bfacc51fc2a, []int{15} } func (m *Rule) XXX_Unmarshal(b []byte) error { @@ -869,7 +873,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{16} + return fileDescriptor_21300bfacc51fc2a, []int{16} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -921,7 +925,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{17} + return fileDescriptor_21300bfacc51fc2a, []int{17} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -955,7 +959,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{18} + return fileDescriptor_21300bfacc51fc2a, []int{18} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -1007,7 +1011,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{19} + return fileDescriptor_21300bfacc51fc2a, []int{19} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -1038,7 +1042,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{20} + return fileDescriptor_21300bfacc51fc2a, []int{20} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -1070,7 +1074,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_11312eec02fd5712, []int{21} + return fileDescriptor_21300bfacc51fc2a, []int{21} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -1126,67 +1130,432 @@ func init() { proto.RegisterType((*ListResponse)(nil), "go.micro.auth.ListResponse") } -func init() { - proto.RegisterFile("github.com/micro/go-micro/auth/service/proto/auth.proto", fileDescriptor_11312eec02fd5712) +func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } + +var fileDescriptor_21300bfacc51fc2a = []byte{ + // 885 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4f, 0x6f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0x23, 0x7b, 0xf2, 0x8f, 0x05, 0xad, 0x93, 0x82, 0x9f, 0x92, 0x17, 0xd0, 0x35, 0x1b, 0x89, 0xdc, + 0x7f, 0xf3, 0xe2, 0xf5, 0xdf, 0xdd, 0x6a, 0xd7, 0x78, 0x76, 0xc8, 0x73, 0xe8, 0xe8, 0xcb, 0x49, + 0x0e, 0x6a, 0xde, 0xd5, 0xcb, 0xed, 0xdf, 0xdf, 0x66, 0x2e, 0x63, 0x4d, 0xcd, 0xdb, 0xe2, 0x6e, + 0xe3, 0x65, 0xd0, 0x71, 0xee, 0x35, 0x1b, 0x4d, 0x94, 0xc9, 0xf7, 0xd0, 0x35, 0x4f, 0x1d, 0xf2, + 0x0d, 0xb4, 0x04, 0xc1, 0x24, 0xa8, 0x7d, 0xd3, 0xf0, 0x4c, 0xf2, 0x1f, 0xbe, 0xd1, 0xa7, 0x0c, + 0xff, 0xb7, 0x05, 0x6d, 0xd1, 0x08, 0x46, 0xe6, 0xe0, 0xaa, 0xd1, 0x23, 0xf5, 0x92, 0x2a, 0x57, + 0xc3, 0x3f, 0xd8, 0x62, 0x2d, 0x71, 0xcf, 0xc1, 0x55, 0x73, 0xb2, 0x11, 0xa8, 0x32, 0xc7, 0x1b, + 0x81, 0x6a, 0xc3, 0xb5, 0x43, 0x4e, 0x34, 0x5c, 0xbf, 0x01, 0x8a, 0x09, 0x72, 0xb7, 0xd1, 0x66, + 0x42, 0xfc, 0xe0, 0xca, 0x97, 0xe5, 0xe3, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x8c, 0xe4, 0x2e, + 0x5a, 0x7a, 0x0a, 0x00, 0x00, } -var fileDescriptor_11312eec02fd5712 = []byte{ - // 901 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4b, 0x6f, 0xdb, 0x46, - 0x10, 0x36, 0x49, 0x89, 0x92, 0x47, 0x0f, 0x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, 0xc6, 0xe1, - 0x6e, 0xd0, 0x93, 0x3a, 0xe9, 0xf2, 0x00, 0x06, 0x14, 0x7f, 0xa2, 0xc8, 0x4e, 0x95, 0x8f, 0x29, - 0x7c, 0xfa, 0x4a, 0x29, 0x9d, 0x1c, 0xe8, 0x44, 0x14, 0x43, 0x8e, 0x0b, 0xc7, 0x3a, 0x30, 0x0e, - 0xad, 0x40, 0x8b, 0xe4, 0x16, 0xd8, 0xf8, 0x4b, 0x16, 0xd3, 0x95, 0xd3, 0x12, 0x06, 0x25, 0x79, - 0x7f, 0x9a, 0xd0, 0x51, 0x95, 0x91, 0x21, 0x98, 0xf1, 0x42, 0xe5, 0x36, 0xe3, 0x05, 0x21, 0xd0, - 0xe2, 0xab, 0x0c, 0x55, 0x26, 0x71, 0x26, 0xfb, 0xd0, 0xa6, 0xe9, 0x12, 0x99, 0x63, 0x1d, 0x58, - 0x87, 0xbb, 0x81, 0x14, 0xc8, 0x97, 0xd0, 0x3d, 0x47, 0x1e, 0x2e, 0x42, 0x1e, 0x3a, 0x2d, 0x81, - 0xfe, 0x83, 0x66, 0xf4, 0xfe, 0x0b, 0xe5, 0x36, 0x4d, 0x38, 0x5d, 0x05, 0xe5, 0x57, 0xe4, 0x0e, - 0xec, 0x26, 0xe1, 0x39, 0xb2, 0x2c, 0x8c, 0xd0, 0x69, 0x8b, 0x84, 0x97, 0x0a, 0xe2, 0x42, 0x37, - 0xa3, 0xe9, 0x45, 0xbc, 0x40, 0xea, 0xd8, 0xc2, 0x58, 0xca, 0x05, 0x32, 0x86, 0x11, 0x45, 0xee, - 0x74, 0x84, 0x45, 0x49, 0xee, 0x13, 0x18, 0x54, 0x92, 0x91, 0x11, 0x58, 0x67, 0xb8, 0x52, 0xf8, - 0x8a, 0x63, 0x01, 0xe6, 0x22, 0x5c, 0xe6, 0x1a, 0xa1, 0x14, 0xbe, 0x30, 0x3f, 0x33, 0xbc, 0x25, - 0x74, 0x03, 0x64, 0x69, 0x4e, 0x23, 0x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xd0, 0x3a, 0xce, 0xf9, 0x29, 0x79, 0x01, 0x5d, 0xbd, 0x91, 0xc8, 0xbd, - 0xb7, 0x2f, 0x5e, 0xf7, 0xfd, 0xad, 0x76, 0x85, 0x67, 0x87, 0x3c, 0x87, 0x8e, 0xba, 0x9c, 0xe4, - 0x6e, 0xcd, 0xbb, 0x7a, 0xb9, 0xdd, 0x7b, 0xdb, 0xcc, 0x65, 0xac, 0x89, 0x7e, 0x5b, 0xdc, 0x6e, - 0xbc, 0x0c, 0x2a, 0xce, 0x9d, 0x66, 0xa3, 0x8e, 0x32, 0xfe, 0x11, 0xba, 0xfa, 0xa9, 0x43, 0xbe, - 0x83, 0x56, 0x41, 0x30, 0xf1, 0x6a, 0xdf, 0x34, 0x3c, 0x93, 0xdc, 0x07, 0x6f, 0xf5, 0x29, 0xc3, - 0xff, 0x6d, 0x40, 0xbb, 0x68, 0x04, 0x23, 0x33, 0xb0, 0xe5, 0xe8, 0x91, 0x7a, 0x49, 0x95, 0xab, - 0xe1, 0xde, 0xdd, 0x62, 0x2d, 0x71, 0xcf, 0xc0, 0x96, 0x73, 0xb2, 0x11, 0xa8, 0x32, 0xc7, 0x1b, - 0x81, 0x6a, 0xc3, 0xb5, 0x43, 0x8e, 0x15, 0x5c, 0xb7, 0x01, 0x8a, 0x0e, 0x72, 0xbb, 0xd1, 0xa6, - 0x43, 0xbc, 0xb1, 0xc5, 0xcb, 0xf2, 0xf1, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xfa, 0x51, 0x05, - 0x6e, 0x94, 0x0a, 0x00, 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// AuthClient is the client API for Auth service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type AuthClient interface { + Generate(ctx context.Context, in *GenerateRequest, opts ...grpc.CallOption) (*GenerateResponse, error) + Inspect(ctx context.Context, in *InspectRequest, opts ...grpc.CallOption) (*InspectResponse, error) + Token(ctx context.Context, in *TokenRequest, opts ...grpc.CallOption) (*TokenResponse, error) +} + +type authClient struct { + cc *grpc.ClientConn +} + +func NewAuthClient(cc *grpc.ClientConn) AuthClient { + return &authClient{cc} +} + +func (c *authClient) Generate(ctx context.Context, in *GenerateRequest, opts ...grpc.CallOption) (*GenerateResponse, error) { + out := new(GenerateResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Auth/Generate", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authClient) Inspect(ctx context.Context, in *InspectRequest, opts ...grpc.CallOption) (*InspectResponse, error) { + out := new(InspectResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Auth/Inspect", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *authClient) Token(ctx context.Context, in *TokenRequest, opts ...grpc.CallOption) (*TokenResponse, error) { + out := new(TokenResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Auth/Token", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// AuthServer is the server API for Auth service. +type AuthServer interface { + Generate(context.Context, *GenerateRequest) (*GenerateResponse, error) + Inspect(context.Context, *InspectRequest) (*InspectResponse, error) + Token(context.Context, *TokenRequest) (*TokenResponse, error) +} + +// UnimplementedAuthServer can be embedded to have forward compatible implementations. +type UnimplementedAuthServer struct { +} + +func (*UnimplementedAuthServer) Generate(ctx context.Context, req *GenerateRequest) (*GenerateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Generate not implemented") +} +func (*UnimplementedAuthServer) Inspect(ctx context.Context, req *InspectRequest) (*InspectResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Inspect not implemented") +} +func (*UnimplementedAuthServer) Token(ctx context.Context, req *TokenRequest) (*TokenResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Token not implemented") +} + +func RegisterAuthServer(s *grpc.Server, srv AuthServer) { + s.RegisterService(&_Auth_serviceDesc, srv) +} + +func _Auth_Generate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GenerateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthServer).Generate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Auth/Generate", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthServer).Generate(ctx, req.(*GenerateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Auth_Inspect_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(InspectRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthServer).Inspect(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Auth/Inspect", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthServer).Inspect(ctx, req.(*InspectRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Auth_Token_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TokenRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AuthServer).Token(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Auth/Token", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AuthServer).Token(ctx, req.(*TokenRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Auth_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.auth.Auth", + HandlerType: (*AuthServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Generate", + Handler: _Auth_Generate_Handler, + }, + { + MethodName: "Inspect", + Handler: _Auth_Inspect_Handler, + }, + { + MethodName: "Token", + Handler: _Auth_Token_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "auth/service/proto/auth.proto", +} + +// AccountsClient is the client API for Accounts service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type AccountsClient interface { + List(ctx context.Context, in *ListAccountsRequest, opts ...grpc.CallOption) (*ListAccountsResponse, error) +} + +type accountsClient struct { + cc *grpc.ClientConn +} + +func NewAccountsClient(cc *grpc.ClientConn) AccountsClient { + return &accountsClient{cc} +} + +func (c *accountsClient) List(ctx context.Context, in *ListAccountsRequest, opts ...grpc.CallOption) (*ListAccountsResponse, error) { + out := new(ListAccountsResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Accounts/List", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// AccountsServer is the server API for Accounts service. +type AccountsServer interface { + List(context.Context, *ListAccountsRequest) (*ListAccountsResponse, error) +} + +// UnimplementedAccountsServer can be embedded to have forward compatible implementations. +type UnimplementedAccountsServer struct { +} + +func (*UnimplementedAccountsServer) List(ctx context.Context, req *ListAccountsRequest) (*ListAccountsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method List not implemented") +} + +func RegisterAccountsServer(s *grpc.Server, srv AccountsServer) { + s.RegisterService(&_Accounts_serviceDesc, srv) +} + +func _Accounts_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListAccountsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AccountsServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Accounts/List", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AccountsServer).List(ctx, req.(*ListAccountsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Accounts_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.auth.Accounts", + HandlerType: (*AccountsServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "List", + Handler: _Accounts_List_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "auth/service/proto/auth.proto", +} + +// RulesClient is the client API for Rules service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type RulesClient interface { + Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) + List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) +} + +type rulesClient struct { + cc *grpc.ClientConn +} + +func NewRulesClient(cc *grpc.ClientConn) RulesClient { + return &rulesClient{cc} +} + +func (c *rulesClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { + out := new(CreateResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Rules/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *rulesClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { + out := new(DeleteResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Rules/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *rulesClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) { + out := new(ListResponse) + err := c.cc.Invoke(ctx, "/go.micro.auth.Rules/List", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// RulesServer is the server API for Rules service. +type RulesServer interface { + Create(context.Context, *CreateRequest) (*CreateResponse, error) + Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) + List(context.Context, *ListRequest) (*ListResponse, error) +} + +// UnimplementedRulesServer can be embedded to have forward compatible implementations. +type UnimplementedRulesServer struct { +} + +func (*UnimplementedRulesServer) Create(ctx context.Context, req *CreateRequest) (*CreateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") +} +func (*UnimplementedRulesServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} +func (*UnimplementedRulesServer) List(ctx context.Context, req *ListRequest) (*ListResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method List not implemented") +} + +func RegisterRulesServer(s *grpc.Server, srv RulesServer) { + s.RegisterService(&_Rules_serviceDesc, srv) +} + +func _Rules_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RulesServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Rules/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RulesServer).Create(ctx, req.(*CreateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Rules_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RulesServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Rules/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RulesServer).Delete(ctx, req.(*DeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Rules_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RulesServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.auth.Rules/List", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RulesServer).List(ctx, req.(*ListRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Rules_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.auth.Rules", + HandlerType: (*RulesServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _Rules_Create_Handler, + }, + { + MethodName: "Delete", + Handler: _Rules_Delete_Handler, + }, + { + MethodName: "List", + Handler: _Rules_List_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "auth/service/proto/auth.proto", } diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index 334f2369..0fcdaf74 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/auth/service/proto/auth.proto +// source: auth/service/proto/auth.proto package go_micro_auth @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Auth service + +func NewAuthEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Auth service type AuthService interface { @@ -118,6 +126,12 @@ func (h *authHandler) Token(ctx context.Context, in *TokenRequest, out *TokenRes return h.AuthHandler.Token(ctx, in, out) } +// Api Endpoints for Accounts service + +func NewAccountsEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Accounts service type AccountsService interface { @@ -171,6 +185,12 @@ func (h *accountsHandler) List(ctx context.Context, in *ListAccountsRequest, out return h.AccountsHandler.List(ctx, in, out) } +// Api Endpoints for Rules service + +func NewRulesEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Rules service type RulesService interface { diff --git a/broker/service/proto/broker.pb.micro.go b/broker/service/proto/broker.pb.micro.go index 384f66f6..01e6f938 100644 --- a/broker/service/proto/broker.pb.micro.go +++ b/broker/service/proto/broker.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Broker service + +func NewBrokerEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Broker service type BrokerService interface { diff --git a/client/service/proto/client.pb.micro.go b/client/service/proto/client.pb.micro.go index 671e5021..0f3094bb 100644 --- a/client/service/proto/client.pb.micro.go +++ b/client/service/proto/client.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Client service + +func NewClientEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Client service type ClientService interface { diff --git a/config/source/service/proto/service.pb.micro.go b/config/source/service/proto/service.pb.micro.go index 58e606ee..d37fc283 100644 --- a/config/source/service/proto/service.pb.micro.go +++ b/config/source/service/proto/service.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Config service + +func NewConfigEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Config service type ConfigService interface { diff --git a/debug/service/proto/debug.pb.micro.go b/debug/service/proto/debug.pb.micro.go index 9747f3c2..3d71b722 100644 --- a/debug/service/proto/debug.pb.micro.go +++ b/debug/service/proto/debug.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Debug service + +func NewDebugEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Debug service type DebugService interface { diff --git a/network/service/proto/network.pb.micro.go b/network/service/proto/network.pb.micro.go index 8b5ab957..2446ff23 100644 --- a/network/service/proto/network.pb.micro.go +++ b/network/service/proto/network.pb.micro.go @@ -12,6 +12,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,10 +29,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Network service + +func NewNetworkEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Network service type NetworkService interface { diff --git a/registry/service/proto/registry.pb.micro.go b/registry/service/proto/registry.pb.micro.go index 96af6f7e..482b2146 100644 --- a/registry/service/proto/registry.pb.micro.go +++ b/registry/service/proto/registry.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Registry service + +func NewRegistryEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Registry service type RegistryService interface { diff --git a/router/service/proto/router.pb.micro.go b/router/service/proto/router.pb.micro.go index d554458a..b39fff3a 100644 --- a/router/service/proto/router.pb.micro.go +++ b/router/service/proto/router.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Router service + +func NewRouterEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Router service type RouterService interface { @@ -285,6 +293,12 @@ func (h *routerHandler) Process(ctx context.Context, in *Advert, out *ProcessRes return h.RouterHandler.Process(ctx, in, out) } +// Api Endpoints for Table service + +func NewTableEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Table service type TableService interface { diff --git a/runtime/service/proto/runtime.pb.go b/runtime/service/proto/runtime.pb.go index 09a56e9f..1c401b4a 100644 --- a/runtime/service/proto/runtime.pb.go +++ b/runtime/service/proto/runtime.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto +// source: runtime/service/proto/runtime.proto package go_micro_runtime import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -38,7 +42,7 @@ func (m *Service) Reset() { *m = Service{} } func (m *Service) String() string { return proto.CompactTextString(m) } func (*Service) ProtoMessage() {} func (*Service) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{0} + return fileDescriptor_2434d8152598889b, []int{0} } func (m *Service) XXX_Unmarshal(b []byte) error { @@ -101,7 +105,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{1} + return fileDescriptor_2434d8152598889b, []int{1} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -172,7 +176,7 @@ func (m *CreateOptions) Reset() { *m = CreateOptions{} } func (m *CreateOptions) String() string { return proto.CompactTextString(m) } func (*CreateOptions) ProtoMessage() {} func (*CreateOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{2} + return fileDescriptor_2434d8152598889b, []int{2} } func (m *CreateOptions) XXX_Unmarshal(b []byte) error { @@ -247,7 +251,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{3} + return fileDescriptor_2434d8152598889b, []int{3} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -292,7 +296,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{4} + return fileDescriptor_2434d8152598889b, []int{4} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -329,7 +333,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{5} + return fileDescriptor_2434d8152598889b, []int{5} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -382,7 +386,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{6} + return fileDescriptor_2434d8152598889b, []int{6} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -421,7 +425,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{7} + return fileDescriptor_2434d8152598889b, []int{7} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -460,7 +464,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{8} + return fileDescriptor_2434d8152598889b, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -498,7 +502,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{9} + return fileDescriptor_2434d8152598889b, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -530,7 +534,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{10} + return fileDescriptor_2434d8152598889b, []int{10} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -568,7 +572,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{11} + return fileDescriptor_2434d8152598889b, []int{11} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -599,7 +603,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{12} + return fileDescriptor_2434d8152598889b, []int{12} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -631,7 +635,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{13} + return fileDescriptor_2434d8152598889b, []int{13} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -679,7 +683,7 @@ func (m *LogsRequest) Reset() { *m = LogsRequest{} } func (m *LogsRequest) String() string { return proto.CompactTextString(m) } func (*LogsRequest) ProtoMessage() {} func (*LogsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{14} + return fileDescriptor_2434d8152598889b, []int{14} } func (m *LogsRequest) XXX_Unmarshal(b []byte) error { @@ -744,7 +748,7 @@ func (m *LogRecord) Reset() { *m = LogRecord{} } func (m *LogRecord) String() string { return proto.CompactTextString(m) } func (*LogRecord) ProtoMessage() {} func (*LogRecord) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{15} + return fileDescriptor_2434d8152598889b, []int{15} } func (m *LogRecord) XXX_Unmarshal(b []byte) error { @@ -808,51 +812,302 @@ func init() { } func init() { - proto.RegisterFile("github.com/micro/go-micro/runtime/service/proto/runtime.proto", fileDescriptor_976fccef828ab1f0) + proto.RegisterFile("runtime/service/proto/runtime.proto", fileDescriptor_2434d8152598889b) } -var fileDescriptor_976fccef828ab1f0 = []byte{ - // 662 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xbb, 0x6e, 0xdb, 0x4a, - 0x10, 0x35, 0x45, 0x3d, 0xec, 0xd1, 0xd5, 0x85, 0xb1, 0x30, 0x02, 0xc6, 0x79, 0x09, 0x6c, 0xe2, - 0x14, 0xa1, 0x02, 0x19, 0x41, 0x5e, 0x48, 0x65, 0xcb, 0x69, 0x6c, 0x04, 0x60, 0xe0, 0x0f, 0x58, - 0x53, 0x03, 0x86, 0xb0, 0x97, 0xcb, 0x70, 0x97, 0x02, 0x5c, 0xa5, 0x4c, 0x9d, 0xaf, 0x4a, 0x9d, - 0x3f, 0x0a, 0xf6, 0x41, 0x8a, 0x94, 0x48, 0x37, 0xea, 0x76, 0x46, 0xb3, 0x87, 0xe7, 0x9c, 0x99, - 0x59, 0xc1, 0xe7, 0x38, 0x91, 0xdf, 0x8b, 0x9b, 0x20, 0xe2, 0x6c, 0xc6, 0x92, 0x28, 0xe7, 0xb3, - 0x98, 0xbf, 0x36, 0x87, 0xbc, 0x48, 0x65, 0xc2, 0x70, 0x26, 0x30, 0x5f, 0x25, 0x11, 0xce, 0xb2, - 0x9c, 0xcb, 0x2a, 0x1b, 0xe8, 0x88, 0x1c, 0xc6, 0x3c, 0xd0, 0xd5, 0x81, 0xcd, 0xfb, 0x7f, 0x1d, - 0x18, 0x7d, 0x33, 0x37, 0x08, 0x81, 0x7e, 0x4a, 0x19, 0x7a, 0xce, 0xd4, 0x39, 0x39, 0x08, 0xf5, - 0x99, 0x78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b5, - 0x70, 0x43, 0x13, 0xf8, 0x7f, 0x1c, 0x38, 0xb8, 0xe4, 0x71, 0x88, 0x11, 0xcf, 0x97, 0xcd, 0xfd, - 0x76, 0x36, 0xf7, 0x7b, 0x51, 0x7b, 0x9c, 0x7a, 0x5a, 0xcf, 0xab, 0x6d, 0x3d, 0x15, 0x58, 0xd7, - 0xf3, 0xa4, 0x04, 0x31, 0x14, 0x42, 0xad, 0x9d, 0x7d, 0x26, 0x6c, 0xb8, 0xd3, 0xc3, 0x35, 0xff, - 0xe5, 0xc2, 0x28, 0x34, 0x24, 0xc8, 0x15, 0x0c, 0xcd, 0x02, 0x91, 0xce, 0xa5, 0xb3, 0xf6, 0x1e, - 0x4f, 0xbb, 0x0b, 0x6c, 0x97, 0xf7, 0xc8, 0x17, 0xe8, 0xab, 0xf1, 0x26, 0x1d, 0xeb, 0x50, 0x42, - 0x3d, 0xef, 0xfa, 0xb9, 0x02, 0xba, 0x82, 0xa1, 0x19, 0xcd, 0x36, 0x5e, 0x8d, 0xd1, 0x6f, 0xe3, - 0xb5, 0x31, 0xd5, 0x1a, 0xce, 0x4c, 0x64, 0x1b, 0x5c, 0x63, 0xe2, 0xdb, 0xe0, 0x36, 0x86, 0x79, - 0x8f, 0x5c, 0x40, 0x5f, 0x0d, 0x5e, 0x9b, 0xcc, 0xda, 0x40, 0x1e, 0x3f, 0x79, 0xa0, 0xe9, 0xfe, - 0xde, 0x1b, 0xe7, 0x66, 0xa8, 0xff, 0x2f, 0x4f, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x40, 0x42, - 0xb3, 0x4e, 0x70, 0x07, 0x00, 0x00, +var fileDescriptor_2434d8152598889b = []byte{ + // 645 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xc9, 0x6e, 0xdb, 0x30, + 0x10, 0x8d, 0x2c, 0x2f, 0xc9, 0xa8, 0x2e, 0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x1d, 0xe3, 0x50, 0x40, 0xbd, + 0xec, 0xfa, 0x5c, 0x02, 0x2d, 0x61, 0xa8, 0x5b, 0xb3, 0x8d, 0x57, 0xa3, 0xf5, 0xdb, 0x78, 0xed, + 0x74, 0xb5, 0x82, 0xd3, 0x1d, 0xd9, 0x06, 0xd7, 0xe8, 0xf8, 0x36, 0xb8, 0x9d, 0x66, 0x3e, 0x22, + 0x37, 0xd0, 0x97, 0x8d, 0xd7, 0x26, 0xb3, 0xd6, 0x90, 0xe7, 0xcf, 0x1e, 0x28, 0xba, 0x77, 0xf4, + 0xce, 0xfa, 0x31, 0x54, 0xff, 0xcb, 0xab, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x20, 0x0e, 0x37, + 0xf1, 0x56, 0x07, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// RuntimeClient is the client API for Runtime service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type RuntimeClient interface { + Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) + Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) + Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) + Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Runtime_LogsClient, error) +} + +type runtimeClient struct { + cc *grpc.ClientConn +} + +func NewRuntimeClient(cc *grpc.ClientConn) RuntimeClient { + return &runtimeClient{cc} +} + +func (c *runtimeClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { + out := new(CreateResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *runtimeClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { + out := new(ReadResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Read", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *runtimeClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { + out := new(DeleteResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *runtimeClient) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) { + out := new(UpdateResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Update", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *runtimeClient) Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Runtime_LogsClient, error) { + stream, err := c.cc.NewStream(ctx, &_Runtime_serviceDesc.Streams[0], "/go.micro.runtime.Runtime/Logs", opts...) + if err != nil { + return nil, err + } + x := &runtimeLogsClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Runtime_LogsClient interface { + Recv() (*LogRecord, error) + grpc.ClientStream +} + +type runtimeLogsClient struct { + grpc.ClientStream +} + +func (x *runtimeLogsClient) Recv() (*LogRecord, error) { + m := new(LogRecord) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// RuntimeServer is the server API for Runtime service. +type RuntimeServer interface { + Create(context.Context, *CreateRequest) (*CreateResponse, error) + Read(context.Context, *ReadRequest) (*ReadResponse, error) + Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) + Update(context.Context, *UpdateRequest) (*UpdateResponse, error) + Logs(*LogsRequest, Runtime_LogsServer) error +} + +// UnimplementedRuntimeServer can be embedded to have forward compatible implementations. +type UnimplementedRuntimeServer struct { +} + +func (*UnimplementedRuntimeServer) Create(ctx context.Context, req *CreateRequest) (*CreateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") +} +func (*UnimplementedRuntimeServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") +} +func (*UnimplementedRuntimeServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} +func (*UnimplementedRuntimeServer) Update(ctx context.Context, req *UpdateRequest) (*UpdateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Update not implemented") +} +func (*UnimplementedRuntimeServer) Logs(req *LogsRequest, srv Runtime_LogsServer) error { + return status.Errorf(codes.Unimplemented, "method Logs not implemented") +} + +func RegisterRuntimeServer(s *grpc.Server, srv RuntimeServer) { + s.RegisterService(&_Runtime_serviceDesc, srv) +} + +func _Runtime_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).Create(ctx, req.(*CreateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Runtime_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReadRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).Read(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/Read", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).Read(ctx, req.(*ReadRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Runtime_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).Delete(ctx, req.(*DeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Runtime_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).Update(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/Update", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).Update(ctx, req.(*UpdateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Runtime_Logs_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(LogsRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(RuntimeServer).Logs(m, &runtimeLogsServer{stream}) +} + +type Runtime_LogsServer interface { + Send(*LogRecord) error + grpc.ServerStream +} + +type runtimeLogsServer struct { + grpc.ServerStream +} + +func (x *runtimeLogsServer) Send(m *LogRecord) error { + return x.ServerStream.SendMsg(m) +} + +var _Runtime_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.runtime.Runtime", + HandlerType: (*RuntimeServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _Runtime_Create_Handler, + }, + { + MethodName: "Read", + Handler: _Runtime_Read_Handler, + }, + { + MethodName: "Delete", + Handler: _Runtime_Delete_Handler, + }, + { + MethodName: "Update", + Handler: _Runtime_Update_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "Logs", + Handler: _Runtime_Logs_Handler, + ServerStreams: true, + }, + }, + Metadata: "runtime/service/proto/runtime.proto", } diff --git a/runtime/service/proto/runtime.pb.micro.go b/runtime/service/proto/runtime.pb.micro.go index da23a4e7..73b7c3ca 100644 --- a/runtime/service/proto/runtime.pb.micro.go +++ b/runtime/service/proto/runtime.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto +// source: runtime/service/proto/runtime.proto package go_micro_runtime @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Runtime service + +func NewRuntimeEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Runtime service type RuntimeService interface { diff --git a/server/grpc/proto/test.pb.go b/server/grpc/proto/test.pb.go index 9028bc7e..27232e75 100644 --- a/server/grpc/proto/test.pb.go +++ b/server/grpc/proto/test.pb.go @@ -7,6 +7,7 @@ import ( context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -25,7 +26,8 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package type Request struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -56,6 +58,13 @@ func (m *Request) XXX_DiscardUnknown() { var xxx_messageInfo_Request proto.InternalMessageInfo +func (m *Request) GetUuid() string { + if m != nil { + return m.Uuid + } + return "" +} + func (m *Request) GetName() string { if m != nil { return m.Name @@ -110,16 +119,20 @@ func init() { func init() { proto.RegisterFile("server/grpc/proto/test.proto", fileDescriptor_bb9c685b7640cf1e) } var fileDescriptor_bb9c685b7640cf1e = []byte{ - // 132 bytes of a gzipped FileDescriptorProto + // 198 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x29, 0x4e, 0x2d, 0x2a, 0x4b, 0x2d, 0xd2, 0x4f, 0x2f, 0x2a, 0x48, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x2f, 0x49, - 0x2d, 0x2e, 0xd1, 0x03, 0x33, 0x95, 0x64, 0xb9, 0xd8, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, - 0x84, 0x84, 0xb8, 0x58, 0xf2, 0x12, 0x73, 0x53, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xc0, - 0x6c, 0x25, 0x19, 0x2e, 0x8e, 0xa0, 0xd4, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x21, 0x01, 0x2e, - 0xe6, 0xdc, 0xe2, 0x74, 0xa8, 0x34, 0x88, 0x69, 0xa4, 0xca, 0xc5, 0x12, 0x02, 0xd2, 0x29, 0xcb, - 0xc5, 0xe2, 0x9c, 0x98, 0x93, 0x23, 0xc4, 0xa1, 0x07, 0x35, 0x4b, 0x8a, 0x53, 0x0f, 0xa6, 0x4d, - 0x89, 0x21, 0x89, 0x0d, 0x6c, 0x95, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xe6, 0xc8, 0xea, 0xc1, - 0x8a, 0x00, 0x00, 0x00, + 0x2d, 0x2e, 0xd1, 0x03, 0x33, 0xa5, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b, + 0x32, 0xf5, 0x13, 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0x21, 0xb2, 0x4a, + 0x86, 0x5c, 0xec, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0x42, 0x5c, 0x2c, 0xa5, 0xa5, + 0x99, 0x29, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x60, 0x36, 0x48, 0x2c, 0x2f, 0x31, 0x37, + 0x55, 0x82, 0x09, 0x22, 0x06, 0x62, 0x2b, 0xc9, 0x70, 0x71, 0x04, 0xa5, 0x16, 0x17, 0xe4, 0xe7, + 0x15, 0xa7, 0x0a, 0x09, 0x70, 0x31, 0xe7, 0x16, 0xa7, 0x43, 0xb5, 0x80, 0x98, 0x46, 0x1e, 0x5c, + 0x2c, 0x21, 0x20, 0xd3, 0x1c, 0xb8, 0x58, 0x9c, 0x13, 0x73, 0x72, 0x84, 0x38, 0xf4, 0xa0, 0xe6, + 0x4b, 0x71, 0xea, 0xc1, 0xb4, 0x29, 0x29, 0x37, 0x5d, 0x7e, 0x32, 0x99, 0x49, 0x56, 0x49, 0x02, + 0xec, 0xaa, 0x32, 0x03, 0xb0, 0x7b, 0xf5, 0x93, 0x13, 0x73, 0x72, 0xf4, 0xab, 0x41, 0xf6, 0xd6, + 0x5a, 0x31, 0x6a, 0x25, 0xb1, 0x81, 0x5d, 0x68, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xd0, 0xc1, + 0x00, 0x50, 0xdf, 0x00, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/server/grpc/proto/test.pb.micro.go b/server/grpc/proto/test.pb.micro.go index a06bd3ee..46c76443 100644 --- a/server/grpc/proto/test.pb.micro.go +++ b/server/grpc/proto/test.pb.micro.go @@ -6,11 +6,13 @@ package test import ( fmt "fmt" proto "github.com/golang/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" math "math" ) import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +29,24 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Test service + +func NewTestEndpoints() []*api.Endpoint { + return []*api.Endpoint{ + &api.Endpoint{ + Name: "Test.Call", + Path: []string{"/api/v0/test/call/{uuid}"}, + Method: []string{"POST"}, + Handler: "rpc", + }, + } +} + // Client API for Test service type TestService interface { @@ -73,6 +89,12 @@ func RegisterTestHandler(s server.Server, hdlr TestHandler, opts ...server.Handl test } h := &testHandler{hdlr} + opts = append(opts, api.WithEndpoint(&api.Endpoint{ + Name: "Test.Call", + Path: []string{"/api/v0/test/call/{uuid}"}, + Method: []string{"POST"}, + Handler: "rpc", + })) return s.Handle(s.NewHandler(&Test{h}, opts...)) } diff --git a/server/grpc/proto/test.proto b/server/grpc/proto/test.proto index 0dbbea9b..cbef20e1 100644 --- a/server/grpc/proto/test.proto +++ b/server/grpc/proto/test.proto @@ -1,11 +1,17 @@ syntax = "proto3"; +import "google/api/annotations.proto"; + service Test { - rpc Call(Request) returns (Response) {} + rpc Call(Request) returns (Response) { + option (google.api.http) = { post: "/api/v0/test/call/{uuid}"; body:"*"; }; + }; + } message Request { - string name = 1; + string uuid = 1; + string name = 2; } message Response { diff --git a/server/proto/server.pb.micro.go b/server/proto/server.pb.micro.go index 892ce569..5d84eda9 100644 --- a/server/proto/server.pb.micro.go +++ b/server/proto/server.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Server service + +func NewServerEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Server service type ServerService interface { diff --git a/service/grpc/proto/test.pb.micro.go b/service/grpc/proto/test.pb.micro.go index f4d93011..0c748d47 100644 --- a/service/grpc/proto/test.pb.micro.go +++ b/service/grpc/proto/test.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Test service + +func NewTestEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Test service type TestService interface { diff --git a/store/service/proto/store.pb.go b/store/service/proto/store.pb.go index bcab9640..e6ea5285 100644 --- a/store/service/proto/store.pb.go +++ b/store/service/proto/store.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: store.proto +// source: store/service/proto/store.proto package go_micro_store import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -36,7 +40,7 @@ func (m *Record) Reset() { *m = Record{} } func (m *Record) String() string { return proto.CompactTextString(m) } func (*Record) ProtoMessage() {} func (*Record) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{0} + return fileDescriptor_1ba364858f5c3cdb, []int{0} } func (m *Record) XXX_Unmarshal(b []byte) error { @@ -92,7 +96,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{1} + return fileDescriptor_1ba364858f5c3cdb, []int{1} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -153,7 +157,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{2} + return fileDescriptor_1ba364858f5c3cdb, []int{2} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -199,7 +203,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{3} + return fileDescriptor_1ba364858f5c3cdb, []int{3} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -241,7 +245,7 @@ func (m *WriteOptions) Reset() { *m = WriteOptions{} } func (m *WriteOptions) String() string { return proto.CompactTextString(m) } func (*WriteOptions) ProtoMessage() {} func (*WriteOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{4} + return fileDescriptor_1ba364858f5c3cdb, []int{4} } func (m *WriteOptions) XXX_Unmarshal(b []byte) error { @@ -288,7 +292,7 @@ func (m *WriteRequest) Reset() { *m = WriteRequest{} } func (m *WriteRequest) String() string { return proto.CompactTextString(m) } func (*WriteRequest) ProtoMessage() {} func (*WriteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{5} + return fileDescriptor_1ba364858f5c3cdb, []int{5} } func (m *WriteRequest) XXX_Unmarshal(b []byte) error { @@ -333,7 +337,7 @@ func (m *WriteResponse) Reset() { *m = WriteResponse{} } func (m *WriteResponse) String() string { return proto.CompactTextString(m) } func (*WriteResponse) ProtoMessage() {} func (*WriteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{6} + return fileDescriptor_1ba364858f5c3cdb, []int{6} } func (m *WriteResponse) XXX_Unmarshal(b []byte) error { @@ -364,7 +368,7 @@ func (m *DeleteOptions) Reset() { *m = DeleteOptions{} } func (m *DeleteOptions) String() string { return proto.CompactTextString(m) } func (*DeleteOptions) ProtoMessage() {} func (*DeleteOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{7} + return fileDescriptor_1ba364858f5c3cdb, []int{7} } func (m *DeleteOptions) XXX_Unmarshal(b []byte) error { @@ -397,7 +401,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{8} + return fileDescriptor_1ba364858f5c3cdb, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -442,7 +446,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{9} + return fileDescriptor_1ba364858f5c3cdb, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -477,7 +481,7 @@ func (m *ListOptions) Reset() { *m = ListOptions{} } func (m *ListOptions) String() string { return proto.CompactTextString(m) } func (*ListOptions) ProtoMessage() {} func (*ListOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{10} + return fileDescriptor_1ba364858f5c3cdb, []int{10} } func (m *ListOptions) XXX_Unmarshal(b []byte) error { @@ -537,7 +541,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{11} + return fileDescriptor_1ba364858f5c3cdb, []int{11} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -576,7 +580,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{12} + return fileDescriptor_1ba364858f5c3cdb, []int{12} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -614,7 +618,7 @@ func (m *DatabasesRequest) Reset() { *m = DatabasesRequest{} } func (m *DatabasesRequest) String() string { return proto.CompactTextString(m) } func (*DatabasesRequest) ProtoMessage() {} func (*DatabasesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{13} + return fileDescriptor_1ba364858f5c3cdb, []int{13} } func (m *DatabasesRequest) XXX_Unmarshal(b []byte) error { @@ -646,7 +650,7 @@ func (m *DatabasesResponse) Reset() { *m = DatabasesResponse{} } func (m *DatabasesResponse) String() string { return proto.CompactTextString(m) } func (*DatabasesResponse) ProtoMessage() {} func (*DatabasesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{14} + return fileDescriptor_1ba364858f5c3cdb, []int{14} } func (m *DatabasesResponse) XXX_Unmarshal(b []byte) error { @@ -685,7 +689,7 @@ func (m *TablesRequest) Reset() { *m = TablesRequest{} } func (m *TablesRequest) String() string { return proto.CompactTextString(m) } func (*TablesRequest) ProtoMessage() {} func (*TablesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{15} + return fileDescriptor_1ba364858f5c3cdb, []int{15} } func (m *TablesRequest) XXX_Unmarshal(b []byte) error { @@ -724,7 +728,7 @@ func (m *TablesResponse) Reset() { *m = TablesResponse{} } func (m *TablesResponse) String() string { return proto.CompactTextString(m) } func (*TablesResponse) ProtoMessage() {} func (*TablesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_98bbca36ef968dfc, []int{16} + return fileDescriptor_1ba364858f5c3cdb, []int{16} } func (m *TablesResponse) XXX_Unmarshal(b []byte) error { @@ -772,45 +776,332 @@ func init() { proto.RegisterType((*TablesResponse)(nil), "go.micro.store.TablesResponse") } -func init() { - proto.RegisterFile("store.proto", fileDescriptor_98bbca36ef968dfc) +func init() { proto.RegisterFile("store/service/proto/store.proto", fileDescriptor_1ba364858f5c3cdb) } + +var fileDescriptor_1ba364858f5c3cdb = []byte{ + // 563 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x5d, 0x8f, 0xd2, 0x40, + 0x14, 0xa5, 0xb4, 0x74, 0xe9, 0x85, 0x45, 0x9c, 0x18, 0x42, 0x90, 0x55, 0x9c, 0xa7, 0x26, 0x26, + 0x65, 0xc5, 0xf8, 0xf1, 0x68, 0x22, 0x1a, 0x35, 0x26, 0x26, 0xa3, 0xd1, 0xc4, 0xb7, 0x02, 0x83, + 0x69, 0x60, 0x77, 0x6a, 0x67, 0x20, 0xcb, 0x0f, 0xf4, 0x7f, 0x99, 0xf9, 0x2a, 0xa5, 0xb4, 0x3e, + 0xf8, 0x36, 0xf7, 0xcc, 0x9d, 0x73, 0xee, 0xb9, 0xf7, 0xb6, 0xf0, 0x98, 0x0b, 0x96, 0xd1, 0x29, + 0xa7, 0xd9, 0x3e, 0x59, 0xd2, 0x69, 0x9a, 0x31, 0xc1, 0xa6, 0x0a, 0x8b, 0xd4, 0x19, 0xf5, 0x7e, + 0xb1, 0xe8, 0x26, 0x59, 0x66, 0x2c, 0x52, 0x28, 0xfe, 0x00, 0x3e, 0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, 0x0d, 0xf4, 0x1e, 0x5a, 0x6a, 0xb3, 0x50, 0xf5, 0x26, 0x5a, + 0x9a, 0xab, 0x9a, 0xdb, 0x9c, 0xe7, 0x23, 0xf8, 0x7a, 0x47, 0x50, 0xcd, 0x56, 0x59, 0xa6, 0x47, + 0x75, 0xd7, 0x39, 0xd5, 0x3b, 0xf0, 0xe4, 0xa4, 0x50, 0xe5, 0x5c, 0x6b, 0x7d, 0x15, 0x87, 0x8b, + 0x1b, 0xd7, 0x0e, 0x22, 0x10, 0xe4, 0x23, 0x43, 0x93, 0x33, 0xd5, 0xd2, 0x84, 0x47, 0x4f, 0xfe, + 0x91, 0x51, 0x74, 0xa9, 0xc7, 0x74, 0xee, 0xf2, 0x64, 0xd6, 0xe7, 0x2e, 0x4f, 0xa7, 0x8b, 0x1b, + 0x0b, 0x5f, 0xfd, 0xec, 0x9f, 0xff, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xa8, 0x04, 0x5f, 0x7c, 0x0f, + 0x06, 0x00, 0x00, } -var fileDescriptor_98bbca36ef968dfc = []byte{ - // 552 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x5d, 0x8b, 0xd3, 0x40, - 0x14, 0x6d, 0x9a, 0x34, 0xdb, 0xdc, 0x76, 0x6b, 0x1d, 0xa4, 0x94, 0xda, 0x95, 0x38, 0x4f, 0x01, - 0x21, 0xac, 0x15, 0x3f, 0x1e, 0x05, 0xab, 0xa8, 0x08, 0xc2, 0x28, 0x0a, 0xbe, 0xa5, 0xdb, 0xa9, - 0x84, 0x66, 0x77, 0x62, 0x66, 0xba, 0x6c, 0x7f, 0xa0, 0xff, 0x4b, 0xe6, 0x2b, 0x4d, 0xd3, 0xc4, - 0x87, 0x7d, 0x9b, 0x7b, 0xe7, 0xce, 0x39, 0xf7, 0xdc, 0x7b, 0x12, 0x18, 0x70, 0xc1, 0x0a, 0x1a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x4f, 0x7e, - 0x08, 0xa8, 0xf1, 0xb3, 0x31, 0xa4, 0xb3, 0x79, 0xf3, 0xa5, 0xd9, 0x63, 0x07, 0x7d, 0x80, 0x9e, - 0x72, 0x16, 0x6a, 0x76, 0xa2, 0x85, 0xb9, 0x68, 0xb9, 0x2d, 0x71, 0x3e, 0x81, 0xaf, 0x3d, 0x82, - 0x5a, 0x5c, 0x65, 0x91, 0x9e, 0xb4, 0x5d, 0x97, 0x50, 0xef, 0xc1, 0x93, 0x9b, 0x42, 0x8d, 0x7b, - 0x6d, 0xd5, 0x55, 0x5d, 0x2e, 0xee, 0x5c, 0x3a, 0x88, 0x40, 0x50, 0xae, 0x0c, 0x85, 0x27, 0xac, - 0xb5, 0x0d, 0xcf, 0x9e, 0xfe, 0xa7, 0xa2, 0xaa, 0x52, 0xaf, 0xe9, 0x54, 0xe5, 0xd1, 0xae, 0x4f, - 0x55, 0x1e, 0x6f, 0x17, 0x77, 0x56, 0xbe, 0xfa, 0xd9, 0xbf, 0xf8, 0x17, 0x00, 0x00, 0xff, 0xff, - 0x18, 0xa5, 0x9b, 0x82, 0xfb, 0x05, 0x00, 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// StoreClient is the client API for Store service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type StoreClient interface { + Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) + Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) + List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (Store_ListClient, error) + Databases(ctx context.Context, in *DatabasesRequest, opts ...grpc.CallOption) (*DatabasesResponse, error) + Tables(ctx context.Context, in *TablesRequest, opts ...grpc.CallOption) (*TablesResponse, error) +} + +type storeClient struct { + cc *grpc.ClientConn +} + +func NewStoreClient(cc *grpc.ClientConn) StoreClient { + return &storeClient{cc} +} + +func (c *storeClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { + out := new(ReadResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Read", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *storeClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) { + out := new(WriteResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Write", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *storeClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { + out := new(DeleteResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *storeClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (Store_ListClient, error) { + stream, err := c.cc.NewStream(ctx, &_Store_serviceDesc.Streams[0], "/go.micro.store.Store/List", opts...) + if err != nil { + return nil, err + } + x := &storeListClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Store_ListClient interface { + Recv() (*ListResponse, error) + grpc.ClientStream +} + +type storeListClient struct { + grpc.ClientStream +} + +func (x *storeListClient) Recv() (*ListResponse, error) { + m := new(ListResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *storeClient) Databases(ctx context.Context, in *DatabasesRequest, opts ...grpc.CallOption) (*DatabasesResponse, error) { + out := new(DatabasesResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Databases", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *storeClient) Tables(ctx context.Context, in *TablesRequest, opts ...grpc.CallOption) (*TablesResponse, error) { + out := new(TablesResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Tables", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// StoreServer is the server API for Store service. +type StoreServer interface { + Read(context.Context, *ReadRequest) (*ReadResponse, error) + Write(context.Context, *WriteRequest) (*WriteResponse, error) + Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) + List(*ListRequest, Store_ListServer) error + Databases(context.Context, *DatabasesRequest) (*DatabasesResponse, error) + Tables(context.Context, *TablesRequest) (*TablesResponse, error) +} + +// UnimplementedStoreServer can be embedded to have forward compatible implementations. +type UnimplementedStoreServer struct { +} + +func (*UnimplementedStoreServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") +} +func (*UnimplementedStoreServer) Write(ctx context.Context, req *WriteRequest) (*WriteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Write not implemented") +} +func (*UnimplementedStoreServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} +func (*UnimplementedStoreServer) List(req *ListRequest, srv Store_ListServer) error { + return status.Errorf(codes.Unimplemented, "method List not implemented") +} +func (*UnimplementedStoreServer) Databases(ctx context.Context, req *DatabasesRequest) (*DatabasesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Databases not implemented") +} +func (*UnimplementedStoreServer) Tables(ctx context.Context, req *TablesRequest) (*TablesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Tables not implemented") +} + +func RegisterStoreServer(s *grpc.Server, srv StoreServer) { + s.RegisterService(&_Store_serviceDesc, srv) +} + +func _Store_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReadRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Read(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Read", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Read(ctx, req.(*ReadRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Store_Write_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WriteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Write(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Write", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Write(ctx, req.(*WriteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Store_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Delete(ctx, req.(*DeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Store_List_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(ListRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(StoreServer).List(m, &storeListServer{stream}) +} + +type Store_ListServer interface { + Send(*ListResponse) error + grpc.ServerStream +} + +type storeListServer struct { + grpc.ServerStream +} + +func (x *storeListServer) Send(m *ListResponse) error { + return x.ServerStream.SendMsg(m) +} + +func _Store_Databases_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DatabasesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Databases(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Databases", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Databases(ctx, req.(*DatabasesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Store_Tables_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TablesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Tables(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Tables", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Tables(ctx, req.(*TablesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Store_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.store.Store", + HandlerType: (*StoreServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Read", + Handler: _Store_Read_Handler, + }, + { + MethodName: "Write", + Handler: _Store_Write_Handler, + }, + { + MethodName: "Delete", + Handler: _Store_Delete_Handler, + }, + { + MethodName: "Databases", + Handler: _Store_Databases_Handler, + }, + { + MethodName: "Tables", + Handler: _Store_Tables_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "List", + Handler: _Store_List_Handler, + ServerStreams: true, + }, + }, + Metadata: "store/service/proto/store.proto", } diff --git a/store/service/proto/store.pb.micro.go b/store/service/proto/store.pb.micro.go index 2c5ca29f..0e622f09 100644 --- a/store/service/proto/store.pb.micro.go +++ b/store/service/proto/store.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: store.proto +// source: store/service/proto/store.proto package go_micro_store @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Store service + +func NewStoreEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Store service type StoreService interface { diff --git a/transport/grpc/proto/transport.pb.micro.go b/transport/grpc/proto/transport.pb.micro.go index d3866eb3..96532171 100644 --- a/transport/grpc/proto/transport.pb.micro.go +++ b/transport/grpc/proto/transport.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Transport service + +func NewTransportEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Transport service type TransportService interface { From 9d0381306de888c1ee51f42e53d4a548190a14ad Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 14 Apr 2020 15:54:25 +0100 Subject: [PATCH 631/788] add a proto message without serialisation --- codec/proto/message.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 codec/proto/message.go diff --git a/codec/proto/message.go b/codec/proto/message.go new file mode 100644 index 00000000..3cb3c513 --- /dev/null +++ b/codec/proto/message.go @@ -0,0 +1,28 @@ +package proto + +type Message struct { + Data []byte +} + +func (m *Message) ProtoMessage() {} + +func (m *Message) Reset() { + *m = Message{} +} + +func (m *Message) String() string { + return string(m.Data) +} + +func (m *Message) Marshal() ([]byte, error) { + return m.Data, nil +} + +func (m *Message) Unmarshal(data []byte) error { + m.Data = data + return nil +} + +func NewMessage(data []byte) *Message { + return &Message{data} +} From 1134ea5ff343a18620c27f265c4143b0215f9927 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 14 Apr 2020 16:59:24 +0100 Subject: [PATCH 632/788] make proto.Message compatible with raw json --- codec/proto/message.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/codec/proto/message.go b/codec/proto/message.go index 3cb3c513..28866c52 100644 --- a/codec/proto/message.go +++ b/codec/proto/message.go @@ -4,6 +4,15 @@ type Message struct { Data []byte } +func (m Message) MarshalJSON() ([]byte, error) { + return m.Data, nil +} + +func (m *Message) UnmarshalJSON(data []byte) error { + m.Data = data + return nil +} + func (m *Message) ProtoMessage() {} func (m *Message) Reset() { From c787fd048310e55d3ef0d0301de3daedb545119d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 14 Apr 2020 17:13:38 +0100 Subject: [PATCH 633/788] fix missing pointer --- codec/proto/message.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codec/proto/message.go b/codec/proto/message.go index 28866c52..fd5cc6fa 100644 --- a/codec/proto/message.go +++ b/codec/proto/message.go @@ -4,7 +4,7 @@ type Message struct { Data []byte } -func (m Message) MarshalJSON() ([]byte, error) { +func (m *Message) MarshalJSON() ([]byte, error) { return m.Data, nil } From 9a5b8ff50d317efda00a0d1650c3099b69dea567 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 14 Apr 2020 22:14:55 +0100 Subject: [PATCH 634/788] use api --- network/resolver/http/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/resolver/http/http.go b/network/resolver/http/http.go index ad3d1654..3c316f62 100644 --- a/network/resolver/http/http.go +++ b/network/resolver/http/http.go @@ -30,7 +30,7 @@ type Response struct { // Resolve assumes ID is a domain which can be converted to a http://name/network request func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) { proto := "https" - host := "micro.mu" + host := "api.micro.mu" path := "/network" if len(r.Proto) > 0 { From b700d425a40108ebda1d8da4274674e6b06ce102 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 15 Apr 2020 01:37:15 +0300 Subject: [PATCH 635/788] api/handler/rpc: improvements and fixes (#1535) * api/handler/rpc: fix empty body case * api/handler/rpc: copy all request headers to metadata Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index d9ff31ad..16e34d0e 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -5,6 +5,7 @@ import ( "encoding/json" "io" "net/http" + "net/textproto" "strconv" "strings" @@ -119,6 +120,13 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // fill contex with http headers md["Host"] = r.Host + md["Method"] = r.Method + // get canonical headers + for k, _ := range r.Header { + // may be need to get all values for key like r.Header.Values() provide in go 1.14 + md[textproto.CanonicalMIMEHeaderKey(k)] = r.Header.Get(k) + } + // merge context with overwrite cx = metadata.MergeContext(cx, md, true) @@ -384,8 +392,6 @@ func requestPayload(r *http.Request) ([]byte, error) { } if b := buf.Bytes(); len(b) > 0 { bodybuf = b - } else { - return []byte{}, nil } if bodydst == "" || bodydst == "*" { if out, err = jsonpatch.MergeMergePatches(out, bodybuf); err == nil { From 4d177a782ec575569dc1979ad8f968620f00ed3e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 15 Apr 2020 13:22:32 +0300 Subject: [PATCH 636/788] vendor proto files from google (#1536) Signed-off-by: Vasiliy Tolstov --- .github/generate.sh | 10 ++++++++-- server/grpc/proto/test.pb.micro.go | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/generate.sh b/.github/generate.sh index 672ce4ff..97a81de2 100755 --- a/.github/generate.sh +++ b/.github/generate.sh @@ -1,9 +1,15 @@ #!/bin/bash -e find . -type f -name '*.pb.*.go' -o -name '*.pb.go' -a ! -name 'message.pb.go' -delete -PROTOS=$(find . -type f -name '*.proto') +PROTOS=$(find . -type f -name '*.proto' | grep -v proto/google/api) + +mkdir -p proto/google/api +curl -s -o proto/google/api/annotations.proto -L https://raw.githubusercontent.com/googleapis/googleapis/master/google/api/annotations.proto +curl -s -o proto/google/api/http.proto -L https://raw.githubusercontent.com/googleapis/googleapis/master/google/api/http.proto for PROTO in $PROTOS; do echo $PROTO - protoc -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I./ -I$(dirname $PROTO) --go_out=plugins=grpc,paths=source_relative:. --micro_out=paths=source_relative:. $PROTO + protoc -I./proto -I. -I$(dirname $PROTO) --go_out=plugins=grpc,paths=source_relative:. --micro_out=paths=source_relative:. $PROTO done + +rm -r proto diff --git a/server/grpc/proto/test.pb.micro.go b/server/grpc/proto/test.pb.micro.go index 46c76443..0139530b 100644 --- a/server/grpc/proto/test.pb.micro.go +++ b/server/grpc/proto/test.pb.micro.go @@ -42,6 +42,7 @@ func NewTestEndpoints() []*api.Endpoint { Name: "Test.Call", Path: []string{"/api/v0/test/call/{uuid}"}, Method: []string{"POST"}, + Body: "*", Handler: "rpc", }, } @@ -93,6 +94,7 @@ func RegisterTestHandler(s server.Server, hdlr TestHandler, opts ...server.Handl Name: "Test.Call", Path: []string{"/api/v0/test/call/{uuid}"}, Method: []string{"POST"}, + Body: "*", Handler: "rpc", })) return s.Handle(s.NewHandler(&Test{h}, opts...)) From ea29920afb9a4cbebcf16deefee75893344537ec Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 15 Apr 2020 11:31:19 +0100 Subject: [PATCH 637/788] Add Priority to auth rules --- agent/proto/bot.pb.micro.go | 8 -- api/service/proto/api.pb.micro.go | 8 -- auth/service/proto/auth.pb.go | 123 ++++++++++-------- auth/service/proto/auth.pb.micro.go | 20 --- auth/service/proto/auth.proto | 1 + auth/service/service.go | 6 + auth/service/sevice_test.go | 26 ++++ broker/service/proto/broker.pb.micro.go | 8 -- client/service/proto/client.pb.micro.go | 8 -- .../source/service/proto/service.pb.micro.go | 8 -- debug/service/proto/debug.pb.micro.go | 8 -- go.sum | 1 + network/service/proto/network.pb.micro.go | 8 -- registry/service/proto/registry.pb.micro.go | 8 -- router/service/proto/router.pb.micro.go | 14 -- runtime/service/proto/runtime.pb.micro.go | 8 -- server/grpc/proto/test.pb.micro.go | 23 ---- server/proto/server.pb.micro.go | 8 -- service/grpc/proto/test.pb.micro.go | 8 -- store/service/proto/store.pb.micro.go | 8 -- transport/grpc/proto/transport.pb.micro.go | 8 -- 21 files changed, 100 insertions(+), 218 deletions(-) create mode 100644 auth/service/sevice_test.go diff --git a/agent/proto/bot.pb.micro.go b/agent/proto/bot.pb.micro.go index 7c105aa6..60338cda 100644 --- a/agent/proto/bot.pb.micro.go +++ b/agent/proto/bot.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Command service - -func NewCommandEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Command service type CommandService interface { diff --git a/api/service/proto/api.pb.micro.go b/api/service/proto/api.pb.micro.go index c2bcfbc6..301b7c55 100644 --- a/api/service/proto/api.pb.micro.go +++ b/api/service/proto/api.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Api service - -func NewApiEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Api service type ApiService interface { diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index 0cd12014..58f5c535 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -802,6 +802,7 @@ type Rule struct { Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` Resource *Resource `protobuf:"bytes,3,opt,name=resource,proto3" json:"resource,omitempty"` Access Access `protobuf:"varint,4,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` + Priority int32 `protobuf:"varint,5,opt,name=priority,proto3" json:"priority,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -860,6 +861,13 @@ func (m *Rule) GetAccess() Access { return Access_UNKNOWN } +func (m *Rule) GetPriority() int32 { + if m != nil { + return m.Priority + } + return 0 +} + type CreateRequest struct { Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` @@ -1133,63 +1141,64 @@ func init() { func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } var fileDescriptor_21300bfacc51fc2a = []byte{ - // 885 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4f, 0x6f, 0xdc, 0x54, - 0x10, 0x8f, 0xed, 0x5d, 0xef, 0x66, 0xf6, 0x4f, 0x56, 0xaf, 0x69, 0xb1, 0xdc, 0xa6, 0xa4, 0x2e, - 0x42, 0xa1, 0x82, 0x0d, 0xda, 0x5e, 0x80, 0x5e, 0x88, 0xba, 0xab, 0xa5, 0x85, 0x2e, 0xc2, 0x2a, - 0x2a, 0x17, 0x54, 0x19, 0xef, 0x40, 0xac, 0x6c, 0x6c, 0xf3, 0xde, 0x73, 0x44, 0x2e, 0x48, 0x9c, - 0xb8, 0x71, 0xe2, 0x23, 0xf0, 0xb1, 0xb8, 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, 0xc9, 0xf7, 0xd0, 0x35, 0x4f, 0x1d, 0xf2, - 0x0d, 0xb4, 0x04, 0xc1, 0x24, 0xa8, 0x7d, 0xd3, 0xf0, 0x4c, 0xf2, 0x1f, 0xbe, 0xd1, 0xa7, 0x0c, - 0xff, 0xb7, 0x05, 0x6d, 0xd1, 0x08, 0x46, 0xe6, 0xe0, 0xaa, 0xd1, 0x23, 0xf5, 0x92, 0x2a, 0x57, - 0xc3, 0x3f, 0xd8, 0x62, 0x2d, 0x71, 0xcf, 0xc1, 0x55, 0x73, 0xb2, 0x11, 0xa8, 0x32, 0xc7, 0x1b, - 0x81, 0x6a, 0xc3, 0xb5, 0x43, 0x4e, 0x34, 0x5c, 0xbf, 0x01, 0x8a, 0x09, 0x72, 0xb7, 0xd1, 0x66, - 0x42, 0xfc, 0xe0, 0xca, 0x97, 0xe5, 0xe3, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x8c, 0xe4, 0x2e, - 0x5a, 0x7a, 0x0a, 0x00, 0x00, + // 897 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4f, 0x8f, 0xdb, 0x54, + 0x10, 0x5f, 0xdb, 0x89, 0x93, 0x9d, 0x24, 0xbb, 0xd1, 0xeb, 0xb6, 0x58, 0x6e, 0xb7, 0x6c, 0x5d, + 0x84, 0x96, 0x0a, 0xb2, 0x28, 0xbd, 0x00, 0xbd, 0xb0, 0x6a, 0xa2, 0xd0, 0x42, 0x83, 0xb0, 0x8a, + 0xca, 0x05, 0x55, 0xc6, 0x19, 0x58, 0x6b, 0xb3, 0xb6, 0x79, 0xef, 0x79, 0x45, 0x2e, 0x48, 0x9c, + 0xf8, 0x02, 0x7c, 0x04, 0x4e, 0x7c, 0x26, 0xee, 0x7c, 0x0d, 0xf4, 0xfe, 0x79, 0x63, 0xc7, 0xa9, + 0x56, 0xb0, 0x87, 0xde, 0xde, 0xbc, 0x19, 0xcf, 0xcc, 0xef, 0x37, 0x7f, 0xfc, 0xe0, 0x30, 0x2a, + 0xf8, 0xd9, 0x09, 0x43, 0x7a, 0x99, 0xc4, 0x78, 0x92, 0xd3, 0x8c, 0x67, 0x27, 0xe2, 0x6a, 0x24, + 0x8f, 0x64, 0xf0, 0x53, 0x36, 0xba, 0x48, 0x62, 0x9a, 0x8d, 0xc4, 0x65, 0x70, 0x1b, 0x6e, 0x7d, + 0x95, 0x30, 0x7e, 0x1a, 0xc7, 0x59, 0x91, 0x72, 0x16, 0xe2, 0xcf, 0x05, 0x32, 0x1e, 0x3c, 0x87, + 0x83, 0xea, 0x35, 0xcb, 0xb3, 0x94, 0x21, 0x19, 0x43, 0x37, 0xd2, 0x77, 0x9e, 0x75, 0xe4, 0x1c, + 0xf7, 0xc6, 0x77, 0x46, 0x15, 0x87, 0x23, 0xfd, 0x49, 0x58, 0xda, 0x05, 0xbf, 0x59, 0xd0, 0x7e, + 0x99, 0x9d, 0x63, 0x4a, 0x1e, 0x40, 0x3f, 0x8a, 0x63, 0x64, 0xec, 0x35, 0x17, 0xb2, 0x67, 0x1d, + 0x59, 0xc7, 0xbb, 0x61, 0x4f, 0xdd, 0x29, 0x93, 0x87, 0x30, 0xa0, 0xf8, 0x23, 0x45, 0x76, 0xa6, + 0x6d, 0x6c, 0x69, 0xd3, 0xd7, 0x97, 0xca, 0xc8, 0x83, 0x4e, 0x4c, 0x31, 0xe2, 0xb8, 0xf0, 0x9c, + 0x23, 0xeb, 0xd8, 0x09, 0x8d, 0x48, 0xee, 0x80, 0x8b, 0xbf, 0xe4, 0x09, 0x5d, 0x79, 0x2d, 0xa9, + 0xd0, 0x52, 0xf0, 0x87, 0x0d, 0x1d, 0x9d, 0x19, 0xd9, 0x03, 0x3b, 0x59, 0xe8, 0xd8, 0x76, 0xb2, + 0x20, 0x04, 0x5a, 0x7c, 0x95, 0xa3, 0x8e, 0x24, 0xcf, 0xe4, 0x00, 0xda, 0x34, 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98, 0x04, 0xb5, 0x6f, 0x1a, 0x9e, 0x50, 0xfe, 0xc3, 0x37, 0xda, 0x94, 0xee, 0xff, 0xb6, 0xa0, + 0x2d, 0x0a, 0xc1, 0xc8, 0x0c, 0x5c, 0xd5, 0x7a, 0xa4, 0x9e, 0x52, 0x65, 0x34, 0xfc, 0xc3, 0x2d, + 0xda, 0x12, 0xf7, 0x0c, 0x5c, 0xd5, 0x27, 0x1b, 0x8e, 0x2a, 0x7d, 0xbc, 0xe1, 0xa8, 0xd6, 0x5c, + 0x3b, 0xe4, 0x54, 0xc3, 0xf5, 0x1b, 0xa0, 0x18, 0x27, 0x77, 0x1b, 0x75, 0xc6, 0xc5, 0x0f, 0xae, + 0x7c, 0x75, 0x3e, 0xfe, 0x37, 0x00, 0x00, 0xff, 0xff, 0xe8, 0xcd, 0x03, 0x66, 0x96, 0x0a, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index 0fcdaf74..52008a15 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Auth service - -func NewAuthEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Auth service type AuthService interface { @@ -126,12 +118,6 @@ func (h *authHandler) Token(ctx context.Context, in *TokenRequest, out *TokenRes return h.AuthHandler.Token(ctx, in, out) } -// Api Endpoints for Accounts service - -func NewAccountsEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Accounts service type AccountsService interface { @@ -185,12 +171,6 @@ func (h *accountsHandler) List(ctx context.Context, in *ListAccountsRequest, out return h.AccountsHandler.List(ctx, in, out) } -// Api Endpoints for Rules service - -func NewRulesEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Rules service type RulesService interface { diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index 77a44af8..aa225f1d 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -107,6 +107,7 @@ message Rule { string role = 2; Resource resource = 3; Access access = 4; + int32 priority = 5; } message CreateRequest { diff --git a/auth/service/service.go b/auth/service/service.go index 73e3f80a..67c4d4ca 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -3,6 +3,7 @@ package service import ( "context" "fmt" + "sort" "strings" "sync" "time" @@ -290,6 +291,11 @@ func (s *svc) listRules(filters ...string) []*pb.Rule { rules = append(rules, r) } + // sort rules by priority + sort.Slice(rules, func(i, j int) bool { + return rules[i].Priority < rules[j].Priority + }) + return rules } diff --git a/auth/service/sevice_test.go b/auth/service/sevice_test.go new file mode 100644 index 00000000..1c206ee3 --- /dev/null +++ b/auth/service/sevice_test.go @@ -0,0 +1,26 @@ +package service + +import ( + "testing" + + pb "github.com/micro/go-micro/v2/auth/service/proto" +) + +func TestListRulesSorting(t *testing.T) { + s := &svc{ + rules: []*pb.Rule{ + &pb.Rule{Priority: 1}, + &pb.Rule{Priority: 3}, + &pb.Rule{Priority: 2}, + }, + } + + var priorities []int32 + for _, r := range s.listRules() { + priorities = append(priorities, r.Priority) + } + + if priorities[0] != 1 || priorities[1] != 2 || priorities[2] != 3 { + t.Errorf("Incorrect Rule Sequence") + } +} diff --git a/broker/service/proto/broker.pb.micro.go b/broker/service/proto/broker.pb.micro.go index 01e6f938..384f66f6 100644 --- a/broker/service/proto/broker.pb.micro.go +++ b/broker/service/proto/broker.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Broker service - -func NewBrokerEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Broker service type BrokerService interface { diff --git a/client/service/proto/client.pb.micro.go b/client/service/proto/client.pb.micro.go index 0f3094bb..671e5021 100644 --- a/client/service/proto/client.pb.micro.go +++ b/client/service/proto/client.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Client service - -func NewClientEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Client service type ClientService interface { diff --git a/config/source/service/proto/service.pb.micro.go b/config/source/service/proto/service.pb.micro.go index d37fc283..58e606ee 100644 --- a/config/source/service/proto/service.pb.micro.go +++ b/config/source/service/proto/service.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Config service - -func NewConfigEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Config service type ConfigService interface { diff --git a/debug/service/proto/debug.pb.micro.go b/debug/service/proto/debug.pb.micro.go index 3d71b722..9747f3c2 100644 --- a/debug/service/proto/debug.pb.micro.go +++ b/debug/service/proto/debug.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Debug service - -func NewDebugEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Debug service type DebugService interface { diff --git a/go.sum b/go.sum index db9453b6..f36442e8 100644 --- a/go.sum +++ b/go.sum @@ -288,6 +288,7 @@ github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= +github.com/micro/go-micro v1.18.0 h1:gP70EZVHpJuUIT0YWth192JmlIci+qMOEByHm83XE9E= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= diff --git a/network/service/proto/network.pb.micro.go b/network/service/proto/network.pb.micro.go index 2446ff23..8b5ab957 100644 --- a/network/service/proto/network.pb.micro.go +++ b/network/service/proto/network.pb.micro.go @@ -12,7 +12,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -29,17 +28,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Network service - -func NewNetworkEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Network service type NetworkService interface { diff --git a/registry/service/proto/registry.pb.micro.go b/registry/service/proto/registry.pb.micro.go index 482b2146..96af6f7e 100644 --- a/registry/service/proto/registry.pb.micro.go +++ b/registry/service/proto/registry.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Registry service - -func NewRegistryEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Registry service type RegistryService interface { diff --git a/router/service/proto/router.pb.micro.go b/router/service/proto/router.pb.micro.go index b39fff3a..d554458a 100644 --- a/router/service/proto/router.pb.micro.go +++ b/router/service/proto/router.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Router service - -func NewRouterEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Router service type RouterService interface { @@ -293,12 +285,6 @@ func (h *routerHandler) Process(ctx context.Context, in *Advert, out *ProcessRes return h.RouterHandler.Process(ctx, in, out) } -// Api Endpoints for Table service - -func NewTableEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Table service type TableService interface { diff --git a/runtime/service/proto/runtime.pb.micro.go b/runtime/service/proto/runtime.pb.micro.go index 73b7c3ca..8c968415 100644 --- a/runtime/service/proto/runtime.pb.micro.go +++ b/runtime/service/proto/runtime.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Runtime service - -func NewRuntimeEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Runtime service type RuntimeService interface { diff --git a/server/grpc/proto/test.pb.micro.go b/server/grpc/proto/test.pb.micro.go index 0139530b..c1bdad72 100644 --- a/server/grpc/proto/test.pb.micro.go +++ b/server/grpc/proto/test.pb.micro.go @@ -12,7 +12,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -29,25 +28,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Test service - -func NewTestEndpoints() []*api.Endpoint { - return []*api.Endpoint{ - &api.Endpoint{ - Name: "Test.Call", - Path: []string{"/api/v0/test/call/{uuid}"}, - Method: []string{"POST"}, - Body: "*", - Handler: "rpc", - }, - } -} - // Client API for Test service type TestService interface { @@ -90,13 +74,6 @@ func RegisterTestHandler(s server.Server, hdlr TestHandler, opts ...server.Handl test } h := &testHandler{hdlr} - opts = append(opts, api.WithEndpoint(&api.Endpoint{ - Name: "Test.Call", - Path: []string{"/api/v0/test/call/{uuid}"}, - Method: []string{"POST"}, - Body: "*", - Handler: "rpc", - })) return s.Handle(s.NewHandler(&Test{h}, opts...)) } diff --git a/server/proto/server.pb.micro.go b/server/proto/server.pb.micro.go index 5d84eda9..892ce569 100644 --- a/server/proto/server.pb.micro.go +++ b/server/proto/server.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Server service - -func NewServerEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Server service type ServerService interface { diff --git a/service/grpc/proto/test.pb.micro.go b/service/grpc/proto/test.pb.micro.go index 0c748d47..f4d93011 100644 --- a/service/grpc/proto/test.pb.micro.go +++ b/service/grpc/proto/test.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Test service - -func NewTestEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Test service type TestService interface { diff --git a/store/service/proto/store.pb.micro.go b/store/service/proto/store.pb.micro.go index 0e622f09..819b1974 100644 --- a/store/service/proto/store.pb.micro.go +++ b/store/service/proto/store.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Store service - -func NewStoreEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Store service type StoreService interface { diff --git a/transport/grpc/proto/transport.pb.micro.go b/transport/grpc/proto/transport.pb.micro.go index 96532171..d3866eb3 100644 --- a/transport/grpc/proto/transport.pb.micro.go +++ b/transport/grpc/proto/transport.pb.micro.go @@ -11,7 +11,6 @@ import ( import ( context "context" - api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,17 +27,10 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. -var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option -// Api Endpoints for Transport service - -func NewTransportEndpoints() []*api.Endpoint { - return []*api.Endpoint{} -} - // Client API for Transport service type TransportService interface { From 234c192faf74f2b6941028b7b4880116dbadc7d3 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 15 Apr 2020 11:39:12 +0100 Subject: [PATCH 638/788] Update protoc-gen-micro --- agent/proto/bot.pb.micro.go | 8 +++++++ api/service/proto/api.pb.micro.go | 8 +++++++ auth/service/proto/auth.pb.micro.go | 20 ++++++++++++++++ broker/service/proto/broker.pb.micro.go | 8 +++++++ client/service/proto/client.pb.micro.go | 8 +++++++ .../source/service/proto/service.pb.micro.go | 8 +++++++ debug/service/proto/debug.pb.micro.go | 8 +++++++ network/service/proto/network.pb.micro.go | 8 +++++++ registry/service/proto/registry.pb.micro.go | 8 +++++++ router/service/proto/router.pb.micro.go | 14 +++++++++++ runtime/service/proto/runtime.pb.micro.go | 8 +++++++ server/grpc/proto/test.pb.micro.go | 23 +++++++++++++++++++ server/proto/server.pb.micro.go | 8 +++++++ service/grpc/proto/test.pb.micro.go | 8 +++++++ store/service/proto/store.pb.micro.go | 8 +++++++ transport/grpc/proto/transport.pb.micro.go | 8 +++++++ 16 files changed, 161 insertions(+) diff --git a/agent/proto/bot.pb.micro.go b/agent/proto/bot.pb.micro.go index 60338cda..7c105aa6 100644 --- a/agent/proto/bot.pb.micro.go +++ b/agent/proto/bot.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Command service + +func NewCommandEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Command service type CommandService interface { diff --git a/api/service/proto/api.pb.micro.go b/api/service/proto/api.pb.micro.go index 301b7c55..c2bcfbc6 100644 --- a/api/service/proto/api.pb.micro.go +++ b/api/service/proto/api.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Api service + +func NewApiEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Api service type ApiService interface { diff --git a/auth/service/proto/auth.pb.micro.go b/auth/service/proto/auth.pb.micro.go index 52008a15..0fcdaf74 100644 --- a/auth/service/proto/auth.pb.micro.go +++ b/auth/service/proto/auth.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Auth service + +func NewAuthEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Auth service type AuthService interface { @@ -118,6 +126,12 @@ func (h *authHandler) Token(ctx context.Context, in *TokenRequest, out *TokenRes return h.AuthHandler.Token(ctx, in, out) } +// Api Endpoints for Accounts service + +func NewAccountsEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Accounts service type AccountsService interface { @@ -171,6 +185,12 @@ func (h *accountsHandler) List(ctx context.Context, in *ListAccountsRequest, out return h.AccountsHandler.List(ctx, in, out) } +// Api Endpoints for Rules service + +func NewRulesEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Rules service type RulesService interface { diff --git a/broker/service/proto/broker.pb.micro.go b/broker/service/proto/broker.pb.micro.go index 384f66f6..01e6f938 100644 --- a/broker/service/proto/broker.pb.micro.go +++ b/broker/service/proto/broker.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Broker service + +func NewBrokerEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Broker service type BrokerService interface { diff --git a/client/service/proto/client.pb.micro.go b/client/service/proto/client.pb.micro.go index 671e5021..0f3094bb 100644 --- a/client/service/proto/client.pb.micro.go +++ b/client/service/proto/client.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Client service + +func NewClientEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Client service type ClientService interface { diff --git a/config/source/service/proto/service.pb.micro.go b/config/source/service/proto/service.pb.micro.go index 58e606ee..d37fc283 100644 --- a/config/source/service/proto/service.pb.micro.go +++ b/config/source/service/proto/service.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Config service + +func NewConfigEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Config service type ConfigService interface { diff --git a/debug/service/proto/debug.pb.micro.go b/debug/service/proto/debug.pb.micro.go index 9747f3c2..3d71b722 100644 --- a/debug/service/proto/debug.pb.micro.go +++ b/debug/service/proto/debug.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Debug service + +func NewDebugEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Debug service type DebugService interface { diff --git a/network/service/proto/network.pb.micro.go b/network/service/proto/network.pb.micro.go index 8b5ab957..2446ff23 100644 --- a/network/service/proto/network.pb.micro.go +++ b/network/service/proto/network.pb.micro.go @@ -12,6 +12,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,10 +29,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Network service + +func NewNetworkEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Network service type NetworkService interface { diff --git a/registry/service/proto/registry.pb.micro.go b/registry/service/proto/registry.pb.micro.go index 96af6f7e..482b2146 100644 --- a/registry/service/proto/registry.pb.micro.go +++ b/registry/service/proto/registry.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Registry service + +func NewRegistryEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Registry service type RegistryService interface { diff --git a/router/service/proto/router.pb.micro.go b/router/service/proto/router.pb.micro.go index d554458a..b39fff3a 100644 --- a/router/service/proto/router.pb.micro.go +++ b/router/service/proto/router.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Router service + +func NewRouterEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Router service type RouterService interface { @@ -285,6 +293,12 @@ func (h *routerHandler) Process(ctx context.Context, in *Advert, out *ProcessRes return h.RouterHandler.Process(ctx, in, out) } +// Api Endpoints for Table service + +func NewTableEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Table service type TableService interface { diff --git a/runtime/service/proto/runtime.pb.micro.go b/runtime/service/proto/runtime.pb.micro.go index 8c968415..73b7c3ca 100644 --- a/runtime/service/proto/runtime.pb.micro.go +++ b/runtime/service/proto/runtime.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Runtime service + +func NewRuntimeEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Runtime service type RuntimeService interface { diff --git a/server/grpc/proto/test.pb.micro.go b/server/grpc/proto/test.pb.micro.go index c1bdad72..0139530b 100644 --- a/server/grpc/proto/test.pb.micro.go +++ b/server/grpc/proto/test.pb.micro.go @@ -12,6 +12,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -28,10 +29,25 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Test service + +func NewTestEndpoints() []*api.Endpoint { + return []*api.Endpoint{ + &api.Endpoint{ + Name: "Test.Call", + Path: []string{"/api/v0/test/call/{uuid}"}, + Method: []string{"POST"}, + Body: "*", + Handler: "rpc", + }, + } +} + // Client API for Test service type TestService interface { @@ -74,6 +90,13 @@ func RegisterTestHandler(s server.Server, hdlr TestHandler, opts ...server.Handl test } h := &testHandler{hdlr} + opts = append(opts, api.WithEndpoint(&api.Endpoint{ + Name: "Test.Call", + Path: []string{"/api/v0/test/call/{uuid}"}, + Method: []string{"POST"}, + Body: "*", + Handler: "rpc", + })) return s.Handle(s.NewHandler(&Test{h}, opts...)) } diff --git a/server/proto/server.pb.micro.go b/server/proto/server.pb.micro.go index 892ce569..5d84eda9 100644 --- a/server/proto/server.pb.micro.go +++ b/server/proto/server.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Server service + +func NewServerEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Server service type ServerService interface { diff --git a/service/grpc/proto/test.pb.micro.go b/service/grpc/proto/test.pb.micro.go index f4d93011..0c748d47 100644 --- a/service/grpc/proto/test.pb.micro.go +++ b/service/grpc/proto/test.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Test service + +func NewTestEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Test service type TestService interface { diff --git a/store/service/proto/store.pb.micro.go b/store/service/proto/store.pb.micro.go index 819b1974..0e622f09 100644 --- a/store/service/proto/store.pb.micro.go +++ b/store/service/proto/store.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Store service + +func NewStoreEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Store service type StoreService interface { diff --git a/transport/grpc/proto/transport.pb.micro.go b/transport/grpc/proto/transport.pb.micro.go index d3866eb3..96532171 100644 --- a/transport/grpc/proto/transport.pb.micro.go +++ b/transport/grpc/proto/transport.pb.micro.go @@ -11,6 +11,7 @@ import ( import ( context "context" + api "github.com/micro/go-micro/v2/api" client "github.com/micro/go-micro/v2/client" server "github.com/micro/go-micro/v2/server" ) @@ -27,10 +28,17 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package // Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint var _ context.Context var _ client.Option var _ server.Option +// Api Endpoints for Transport service + +func NewTransportEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + // Client API for Transport service type TransportService interface { From 2de03e5fd7fd9fd853582fd2198eec559f100d8f Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 15 Apr 2020 11:39:53 +0100 Subject: [PATCH 639/788] Tidy go mod --- go.mod | 1 + go.sum | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ffed3e84..78c51dff 100644 --- a/go.mod +++ b/go.mod @@ -64,6 +64,7 @@ require ( golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect + google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1 google.golang.org/grpc v1.26.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 diff --git a/go.sum b/go.sum index f36442e8..db9453b6 100644 --- a/go.sum +++ b/go.sum @@ -288,7 +288,6 @@ github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= -github.com/micro/go-micro v1.18.0 h1:gP70EZVHpJuUIT0YWth192JmlIci+qMOEByHm83XE9E= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= From c9a6b07c5245d049f656c4301f03767e0458804e Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 15 Apr 2020 11:49:24 +0100 Subject: [PATCH 640/788] Add priority to auth.CreateRequest and auth.DeleteRequest --- auth/service/proto/auth.pb.go | 132 +++++++++++++++++++--------------- auth/service/proto/auth.proto | 20 +++--- 2 files changed, 86 insertions(+), 66 deletions(-) diff --git a/auth/service/proto/auth.pb.go b/auth/service/proto/auth.pb.go index 58f5c535..cba1c78f 100644 --- a/auth/service/proto/auth.pb.go +++ b/auth/service/proto/auth.pb.go @@ -872,6 +872,7 @@ type CreateRequest struct { Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` Access Access `protobuf:"varint,3,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` + Priority int32 `protobuf:"varint,4,opt,name=priority,proto3" json:"priority,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -923,6 +924,13 @@ func (m *CreateRequest) GetAccess() Access { return Access_UNKNOWN } +func (m *CreateRequest) GetPriority() int32 { + if m != nil { + return m.Priority + } + return 0 +} + type CreateResponse struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -958,6 +966,7 @@ type DeleteRequest struct { Role string `protobuf:"bytes,1,opt,name=role,proto3" json:"role,omitempty"` Resource *Resource `protobuf:"bytes,2,opt,name=resource,proto3" json:"resource,omitempty"` Access Access `protobuf:"varint,3,opt,name=access,proto3,enum=go.micro.auth.Access" json:"access,omitempty"` + Priority int32 `protobuf:"varint,4,opt,name=priority,proto3" json:"priority,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -1009,6 +1018,13 @@ func (m *DeleteRequest) GetAccess() Access { return Access_UNKNOWN } +func (m *DeleteRequest) GetPriority() int32 { + if m != nil { + return m.Priority + } + return 0 +} + type DeleteResponse struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -1141,64 +1157,64 @@ func init() { func init() { proto.RegisterFile("auth/service/proto/auth.proto", fileDescriptor_21300bfacc51fc2a) } var fileDescriptor_21300bfacc51fc2a = []byte{ - // 897 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x4f, 0x8f, 0xdb, 0x54, - 0x10, 0x5f, 0xdb, 0x89, 0x93, 0x9d, 0x24, 0xbb, 0xd1, 0xeb, 0xb6, 0x58, 0x6e, 0xb7, 0x6c, 0x5d, - 0x84, 0x96, 0x0a, 0xb2, 0x28, 0xbd, 0x00, 0xbd, 0xb0, 0x6a, 0xa2, 0xd0, 0x42, 0x83, 0xb0, 0x8a, - 0xca, 0x05, 0x55, 0xc6, 0x19, 0x58, 0x6b, 0xb3, 0xb6, 0x79, 0xef, 0x79, 0x45, 0x2e, 0x48, 0x9c, - 0xf8, 0x02, 0x7c, 0x04, 0x4e, 0x7c, 0x26, 0xee, 0x7c, 0x0d, 0xf4, 0xfe, 0x79, 0x63, 0xc7, 0xa9, - 0x56, 0xb0, 0x87, 0xde, 0xde, 0xbc, 0x19, 0xcf, 0xcc, 0xef, 0x37, 0x7f, 0xfc, 0xe0, 0x30, 0x2a, - 0xf8, 0xd9, 0x09, 0x43, 0x7a, 0x99, 0xc4, 0x78, 0x92, 0xd3, 0x8c, 0x67, 0x27, 0xe2, 0x6a, 0x24, - 0x8f, 0x64, 0xf0, 0x53, 0x36, 0xba, 0x48, 0x62, 0x9a, 0x8d, 0xc4, 0x65, 0x70, 0x1b, 0x6e, 0x7d, - 0x95, 0x30, 0x7e, 0x1a, 0xc7, 0x59, 0x91, 0x72, 0x16, 0xe2, 0xcf, 0x05, 0x32, 0x1e, 0x3c, 0x87, - 0x83, 0xea, 0x35, 0xcb, 0xb3, 0x94, 0x21, 0x19, 0x43, 0x37, 0xd2, 0x77, 0x9e, 0x75, 0xe4, 0x1c, - 0xf7, 0xc6, 0x77, 0x46, 0x15, 0x87, 0x23, 0xfd, 0x49, 0x58, 0xda, 0x05, 0xbf, 0x59, 0xd0, 0x7e, - 0x99, 0x9d, 0x63, 0x4a, 0x1e, 0x40, 0x3f, 0x8a, 0x63, 0x64, 0xec, 0x35, 0x17, 0xb2, 0x67, 0x1d, - 0x59, 0xc7, 0xbb, 0x61, 0x4f, 0xdd, 0x29, 0x93, 0x87, 0x30, 0xa0, 0xf8, 0x23, 0x45, 0x76, 0xa6, - 0x6d, 0x6c, 0x69, 0xd3, 0xd7, 0x97, 0xca, 0xc8, 0x83, 0x4e, 0x4c, 0x31, 0xe2, 0xb8, 0xf0, 0x9c, - 0x23, 0xeb, 0xd8, 0x09, 0x8d, 0x48, 0xee, 0x80, 0x8b, 0xbf, 0xe4, 0x09, 0x5d, 0x79, 0x2d, 0xa9, - 0xd0, 0x52, 0xf0, 0x87, 0x0d, 0x1d, 0x9d, 0x19, 0xd9, 0x03, 0x3b, 0x59, 0xe8, 0xd8, 0x76, 0xb2, - 0x20, 0x04, 0x5a, 0x7c, 0x95, 0xa3, 0x8e, 0x24, 0xcf, 0xe4, 0x00, 0xda, 0x34, 0x5b, 0x22, 0xf3, - 0x9c, 0x23, 0xe7, 0x78, 0x37, 0x54, 0x02, 0xf9, 0x1c, 0xba, 0x17, 0xc8, 0xa3, 0x45, 0xc4, 0x23, - 0xaf, 0x25, 0xd1, 0xbf, 0xd7, 0x8c, 0x7e, 0xf4, 0x42, 0x9b, 0x4d, 0x53, 0x4e, 0x57, 0x61, 0xf9, - 0x15, 0xb9, 0x07, 0xbb, 0x69, 0x74, 0x81, 0x2c, 0x8f, 0x62, 0xf4, 0xda, 0x32, 0xe0, 0xd5, 0x05, - 0xf1, 0xa1, 0x9b, 0xd3, 0xec, 0x32, 0x59, 0x20, 0xf5, 0x5c, 0xa9, 0x2c, 0x65, 0x81, 0x8c, 0x61, - 0x4c, 0x91, 0x7b, 0x1d, 0xa9, 0xd1, 0x92, 0xff, 0x04, 0x06, 0x95, 0x60, 0x64, 0x08, 0xce, 0x39, - 0xae, 0x34, 0x3e, 0x71, 0x14, 0x60, 0x2e, 0xa3, 0x65, 0x61, 0x10, 0x2a, 0xe1, 0x33, 0xfb, 0x13, - 0x2b, 0x58, 0x42, 0x37, 0x44, 0x96, 0x15, 0x34, 0x46, 0x41, 0x83, 0xc8, 0x44, 0x7f, 0x28, 0xcf, - 0x8d, 0xd4, 0xf8, 0xd0, 0xc5, 0x74, 0x91, 0x67, 0x49, 0xca, 0x25, 0xfb, 0xbb, 0x61, 0x29, 0x57, - 0xe1, 0xb5, 0x6a, 0xf0, 0x82, 0x3f, 0x6d, 0xd8, 0x9f, 0x61, 0x8a, 0x34, 0xe2, 0xa8, 0x1b, 0x6d, - 0xa3, 0x18, 0x25, 0xf1, 0xf6, 0x3a, 0x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 0xfb, 0xf7, 0xb7, 0xa9, 0x4b, 0x5f, 0x13, 0xf3, 0xee, 0xb8, 0xdb, 0x38, 0x28, 0xda, - 0xcf, 0xbd, 0x66, 0xa5, 0xf1, 0x32, 0xfe, 0x1e, 0xba, 0xe6, 0x19, 0x44, 0xbe, 0x81, 0x96, 0x20, - 0x98, 0x04, 0xb5, 0x6f, 0x1a, 0x9e, 0x50, 0xfe, 0xc3, 0x37, 0xda, 0x94, 0xee, 0xff, 0xb6, 0xa0, - 0x2d, 0x0a, 0xc1, 0xc8, 0x0c, 0x5c, 0xd5, 0x7a, 0xa4, 0x9e, 0x52, 0x65, 0x34, 0xfc, 0xc3, 0x2d, - 0xda, 0x12, 0xf7, 0x0c, 0x5c, 0xd5, 0x27, 0x1b, 0x8e, 0x2a, 0x7d, 0xbc, 0xe1, 0xa8, 0xd6, 0x5c, - 0x3b, 0xe4, 0x54, 0xc3, 0xf5, 0x1b, 0xa0, 0x18, 0x27, 0x77, 0x1b, 0x75, 0xc6, 0xc5, 0x0f, 0xae, - 0x7c, 0x75, 0x3e, 0xfe, 0x37, 0x00, 0x00, 0xff, 0xff, 0xe8, 0xcd, 0x03, 0x66, 0x96, 0x0a, 0x00, - 0x00, + // 900 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xdd, 0x8e, 0xdb, 0x44, + 0x14, 0x5e, 0xff, 0xc4, 0xc9, 0x9e, 0xfc, 0x6c, 0x34, 0xdd, 0x16, 0x2b, 0xed, 0x96, 0xad, 0x8b, + 0xd0, 0x52, 0x41, 0x16, 0xa5, 0x37, 0x40, 0x6f, 0x58, 0x35, 0x51, 0x68, 0xa1, 0x41, 0x58, 0x45, + 0xe5, 0x06, 0x55, 0xc6, 0x39, 0xb0, 0xd6, 0x66, 0x6d, 0x33, 0x33, 0x5e, 0x91, 0x1b, 0x24, 0xde, + 0x81, 0x37, 0x80, 0x2b,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0x5f, 0x13, 0xbe, + 0x96, 0xf7, 0xf5, 0x0a, 0x50, 0x47, 0xb8, 0x21, 0x72, 0x6b, 0x53, 0xe4, 0x52, 0x07, 0xaf, 0xaa, + 0x43, 0x59, 0xac, 0x76, 0xb5, 0x58, 0xff, 0xad, 0x28, 0x53, 0x18, 0x5e, 0xb3, 0xd1, 0xf7, 0xee, + 0x43, 0x68, 0xeb, 0xfb, 0x24, 0x73, 0xec, 0xbe, 0x76, 0x26, 0x2c, 0x78, 0x01, 0xbd, 0x39, 0x8d, + 0x52, 0x6e, 0x84, 0x26, 0xe0, 0x0a, 0x2d, 0x4d, 0x79, 0xc5, 0x9a, 0x3c, 0x84, 0x0e, 0xd5, 0xe5, + 0x97, 0x30, 0xba, 0x93, 0xb7, 0x6a, 0x69, 0x4d, 0x77, 0x84, 0x65, 0x60, 0x70, 0x00, 0x7d, 0x9d, + 0x58, 0x61, 0x0b, 0xbe, 0x81, 0x7e, 0x88, 0x57, 0xd9, 0x05, 0xbe, 0xf1, 0xa3, 0x86, 0x30, 0x30, + 0x99, 0xf5, 0x59, 0xef, 0xc2, 0xe0, 0x49, 0xca, 0x72, 0x8c, 0x4b, 0x5e, 0x87, 0xd0, 0xda, 0x1c, + 0x26, 0xca, 0x08, 0x1e, 0xc3, 0x41, 0x19, 0xf7, 0xaf, 0x25, 0xfc, 0x19, 0x7a, 0x72, 0xde, 0xec, + 0xea, 0xd5, 0xeb, 0x6e, 0xb1, 0x2b, 0xdd, 0xb2, 0x35, 0xc3, 0x9c, 0x86, 0x19, 0x76, 0x0f, 0x7a, + 0xd2, 0xf9, 0xb2, 0x32, 0xaf, 0xba, 0x72, 0x6f, 0xa6, 0x86, 0xd6, 0x23, 0xe8, 0xeb, 0xf3, 0x35, + 0x85, 0x07, 0x9b, 0x5c, 0xbb, 0x93, 0xc3, 0x1a, 0x01, 0x15, 0xac, 0x15, 0xf8, 0xc3, 0x02, 0x37, + 0x2c, 0x56, 0xd8, 0x34, 0xee, 0x64,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0xa6, 0xe6, 0xbd, 0x72, 0xbb, 0xf1, + 0x82, 0xe9, 0x3c, 0x77, 0x9a, 0x9d, 0x26, 0xcb, 0xe4, 0x5b, 0xe8, 0x98, 0xe7, 0x13, 0xf9, 0x0a, + 0x5c, 0x21, 0x30, 0x09, 0x6a, 0xdf, 0x34, 0x3c, 0xbd, 0x46, 0xf7, 0x5f, 0x19, 0x53, 0xa6, 0xff, + 0xd3, 0x82, 0x96, 0x28, 0x04, 0x23, 0x73, 0xf0, 0x54, 0x5b, 0x92, 0x3a, 0xa4, 0xca, 0x95, 0x1a, + 0x1d, 0xed, 0xf0, 0x96, 0xbc, 0xe7, 0xe0, 0xa9, 0x3e, 0xd9, 0x4a, 0x54, 0xe9, 0xf1, 0xad, 0x44, + 0xb5, 0xe6, 0xda, 0x23, 0x67, 0x9a, 0xee, 0xa8, 0x81, 0x8a, 0x49, 0x72, 0xbb, 0xd1, 0x67, 0x52, + 0x7c, 0xe7, 0xc9, 0xd7, 0xea, 0xc3, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xdf, 0x67, 0x3c, 0x6e, + 0xce, 0x0a, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index aa225f1d..5343569c 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -4,12 +4,14 @@ package go.micro.auth; service Auth { rpc Generate(GenerateRequest) returns (GenerateResponse) {}; - rpc Inspect(InspectRequest) returns (InspectResponse) {}; - rpc Token(TokenRequest) returns (TokenResponse) {}; + rpc Inspect(InspectRequest) + returns (InspectResponse) {}; + rpc Token(TokenRequest) + returns (TokenResponse) {}; } service Accounts { - rpc List(ListAccountsRequest) returns (ListAccountsResponse) {}; + rpc List(ListAccountsRequest) returns (ListAccountsResponse) {}; } service Rules { @@ -22,7 +24,7 @@ message ListAccountsRequest { } message ListAccountsResponse { - repeated Account accounts = 1; + repeated Account accounts = 1; } message Token { @@ -112,16 +114,18 @@ message Rule { message CreateRequest { string role = 1; - Resource resource = 2; - Access access = 3; + Resource resource = 2; + Access access = 3; + int32 priority = 4; } message CreateResponse {} message DeleteRequest { string role = 1; - Resource resource = 2; - Access access = 3; + Resource resource = 2; + Access access = 3; + int32 priority = 4; } message DeleteResponse {} From fe31a71557b36360f79a2582dac6765d2cf00aeb Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 15 Apr 2020 11:50:52 +0100 Subject: [PATCH 641/788] Fix formatting --- auth/service/proto/auth.proto | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/auth/service/proto/auth.proto b/auth/service/proto/auth.proto index 5343569c..7590957a 100644 --- a/auth/service/proto/auth.proto +++ b/auth/service/proto/auth.proto @@ -4,10 +4,8 @@ package go.micro.auth; service Auth { rpc Generate(GenerateRequest) returns (GenerateResponse) {}; - rpc Inspect(InspectRequest) - returns (InspectResponse) {}; - rpc Token(TokenRequest) - returns (TokenResponse) {}; + rpc Inspect(InspectRequest) returns (InspectResponse) {}; + rpc Token(TokenRequest) returns (TokenResponse) {}; } service Accounts { From 62cedf64daaf59287f1723fdbe9d4f76d0db7796 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 15 Apr 2020 17:50:51 +0300 Subject: [PATCH 642/788] api/router/registry: extract path based parameters from url to req (#1530) * api/router/registry: extract path based parameters from url to req * api/handler/rpc: fix empty body request parsing * bundle grpc-gateway util funcs Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 1 - api/router/registry/registry.go | 160 ++++++--- api/router/registry/registry_test.go | 136 -------- api/{grpc_test.go => router/router_test.go} | 119 +++++-- api/router/static/static.go | 15 +- api/router/util/LICENSE.txt | 27 ++ api/router/util/compile.go | 115 +++++++ api/router/util/compile_test.go | 122 +++++++ api/router/util/parse.go | 363 ++++++++++++++++++++ api/router/util/parse_test.go | 321 +++++++++++++++++ api/router/util/pattern.go | 24 ++ api/router/util/runtime.go | 283 +++++++++++++++ api/router/util/types.go | 62 ++++ api/router/util/types_test.go | 93 +++++ go.mod | 2 +- 15 files changed, 1619 insertions(+), 224 deletions(-) delete mode 100644 api/router/registry/registry_test.go rename api/{grpc_test.go => router/router_test.go} (60%) create mode 100644 api/router/util/LICENSE.txt create mode 100644 api/router/util/compile.go create mode 100644 api/router/util/compile_test.go create mode 100644 api/router/util/parse.go create mode 100644 api/router/util/parse_test.go create mode 100644 api/router/util/pattern.go create mode 100644 api/router/util/runtime.go create mode 100644 api/router/util/types.go create mode 100644 api/router/util/types_test.go diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 16e34d0e..64f0cf48 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -208,7 +208,6 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { &request, client.WithContentType(ct), ) - // make the call if err := c.Call(cx, req, &response, client.WithSelectOption(so)); err != nil { writeError(w, r, err) diff --git a/api/router/registry/registry.go b/api/router/registry/registry.go index b3f04958..d5cd2569 100644 --- a/api/router/registry/registry.go +++ b/api/router/registry/registry.go @@ -6,16 +6,25 @@ import ( "fmt" "net/http" "regexp" + "strings" "sync" "time" "github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/api/router" + "github.com/micro/go-micro/v2/api/router/util" "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/registry/cache" ) +// endpoint struct, that holds compiled pcre +type endpoint struct { + hostregs []*regexp.Regexp + pathregs []util.Pattern +} + // router is the default router type registryRouter struct { exit chan bool @@ -26,6 +35,8 @@ type registryRouter struct { sync.RWMutex eps map[string]*api.Service + // compiled regexp for host and path + ceps map[string]*endpoint } func (r *registryRouter) isClosed() bool { @@ -67,6 +78,7 @@ func (r *registryRouter) refresh() { } // refresh list in 10 minutes... cruft + // use registry watching select { case <-time.After(time.Minute * 10): case <-r.exit: @@ -109,11 +121,11 @@ func (r *registryRouter) store(services []*registry.Service) { names[service.Name] = true // map per endpoint - for _, endpoint := range service.Endpoints { + for _, sep := range service.Endpoints { // create a key service:endpoint_name - key := fmt.Sprintf("%s:%s", service.Name, endpoint.Name) + key := fmt.Sprintf("%s.%s", service.Name, sep.Name) // decode endpoint - end := api.Decode(endpoint.Metadata) + end := api.Decode(sep.Metadata) // if we got nothing skip if err := api.Validate(end); err != nil { @@ -154,8 +166,44 @@ func (r *registryRouter) store(services []*registry.Service) { } // now set the eps we have - for name, endpoint := range eps { - r.eps[name] = endpoint + for name, ep := range eps { + r.eps[name] = ep + cep := &endpoint{} + + for _, h := range ep.Endpoint.Host { + if h == "" || h == "*" { + continue + } + hostreg, err := regexp.CompilePOSIX(h) + if err != nil { + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("endpoint have invalid host regexp: %v", err) + } + continue + } + cep.hostregs = append(cep.hostregs, hostreg) + } + + for _, p := range ep.Endpoint.Path { + rule, err := util.Parse(p) + if err != nil { + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("endpoint have invalid path pattern: %v", err) + } + continue + } + tpl := rule.Compile() + pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "") + if err != nil { + if logger.V(logger.TraceLevel, logger.DefaultLogger) { + logger.Tracef("endpoint have invalid path pattern: %v", err) + } + continue + } + cep.pathregs = append(cep.pathregs, pathreg) + } + + r.ceps[name] = cep } } @@ -239,60 +287,89 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) { r.RLock() defer r.RUnlock() + var idx int + if len(req.URL.Path) > 0 && req.URL.Path != "/" { + idx = 1 + } + path := strings.Split(req.URL.Path[idx:], "/") + // use the first match // TODO: weighted matching - for _, e := range r.eps { + for n, e := range r.eps { + cep, ok := r.ceps[n] + if !ok { + continue + } ep := e.Endpoint - - // match - var pathMatch, hostMatch, methodMatch bool - - // 1. try method GET, POST, PUT, etc - // 2. try host example.com, foobar.com, etc - // 3. try path /foo/bar, /bar/baz, etc - - // 1. try match method + var mMatch, hMatch, pMatch bool + // 1. try method + methodLoop: for _, m := range ep.Method { - if req.Method == m { - methodMatch = true - break + if m == req.Method { + mMatch = true + break methodLoop } } - - // no match on method pass - if len(ep.Method) > 0 && !methodMatch { + if !mMatch { continue } - - // 2. try match host - for _, h := range ep.Host { - if req.Host == h { - hostMatch = true - break - } + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api method match %s", req.Method) } - // no match on host pass - if len(ep.Host) > 0 && !hostMatch { + // 2. try host + if len(ep.Host) == 0 { + hMatch = true + } else { + hostLoop: + for idx, h := range ep.Host { + if h == "" || h == "*" { + hMatch = true + break hostLoop + } else { + if cep.hostregs[idx].MatchString(req.URL.Host) { + hMatch = true + break hostLoop + } + } + } + } + if !hMatch { continue } - - // 3. try match paths - for _, p := range ep.Path { - re, err := regexp.CompilePOSIX(p) - if err == nil && re.MatchString(req.URL.Path) { - pathMatch = true - break - } + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api host match %s", req.URL.Host) } - // no match pass - if len(ep.Path) > 0 && !pathMatch { + // 3. try path + // 3. try path + pathLoop: + for _, pathreg := range cep.pathregs { + matches, err := pathreg.Match(path, "") + if err != nil { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api path not match %s != %v", path, pathreg) + } + continue + } + pMatch = true + ctx := req.Context() + md, ok := metadata.FromContext(ctx) + if !ok { + md = make(metadata.Metadata) + } + for k, v := range matches { + md[fmt.Sprintf("x-api-field-%s", k)] = v + } + md["x-api-body"] = ep.Body + *req = *req.Clone(metadata.NewContext(ctx, md)) + break pathLoop + } + if !pMatch { continue } // TODO: Percentage traffic - // we got here, so its a match return e, nil } @@ -377,6 +454,7 @@ func newRouter(opts ...router.Option) *registryRouter { opts: options, rc: cache.New(options.Registry), eps: make(map[string]*api.Service), + ceps: make(map[string]*endpoint), } go r.watch() go r.refresh() diff --git a/api/router/registry/registry_test.go b/api/router/registry/registry_test.go deleted file mode 100644 index 5824d237..00000000 --- a/api/router/registry/registry_test.go +++ /dev/null @@ -1,136 +0,0 @@ -package registry - -import ( - "fmt" - "net/http" - "net/url" - "testing" - - "github.com/micro/go-micro/v2/api" -) - -func TestRouter(t *testing.T) { - r := newRouter() - - compare := func(expect, got []string) bool { - // no data to compare, return true - if len(expect) == 0 && len(got) == 0 { - return true - } - // no data expected but got some return false - if len(expect) == 0 && len(got) > 0 { - return false - } - - // compare expected with what we got - for _, e := range expect { - var seen bool - for _, g := range got { - if e == g { - seen = true - break - } - } - if !seen { - return false - } - } - - // we're done, return true - return true - } - - testData := []struct { - e *api.Endpoint - r *http.Request - m bool - }{ - { - e: &api.Endpoint{ - Name: "Foo.Bar", - Host: []string{"example.com"}, - Method: []string{"GET"}, - Path: []string{"/foo"}, - }, - r: &http.Request{ - Host: "example.com", - Method: "GET", - URL: &url.URL{ - Path: "/foo", - }, - }, - m: true, - }, - { - e: &api.Endpoint{ - Name: "Bar.Baz", - Host: []string{"example.com", "foo.com"}, - Method: []string{"GET", "POST"}, - Path: []string{"/foo/bar"}, - }, - r: &http.Request{ - Host: "foo.com", - Method: "POST", - URL: &url.URL{ - Path: "/foo/bar", - }, - }, - m: true, - }, - { - e: &api.Endpoint{ - Name: "Test.Cruft", - Host: []string{"example.com", "foo.com"}, - Method: []string{"GET", "POST"}, - Path: []string{"/xyz"}, - }, - r: &http.Request{ - Host: "fail.com", - Method: "DELETE", - URL: &url.URL{ - Path: "/test/fail", - }, - }, - m: false, - }, - } - - for _, d := range testData { - key := fmt.Sprintf("%s:%s", "test.service", d.e.Name) - r.eps[key] = &api.Service{ - Endpoint: d.e, - } - } - - for _, d := range testData { - e, err := r.Endpoint(d.r) - if d.m && err != nil { - t.Fatalf("expected match, got %v", err) - } - if !d.m && err == nil { - t.Fatal("expected error got match") - } - // skip testing the non match - if !d.m { - continue - } - - ep := e.Endpoint - - // test the match - if d.e.Name != ep.Name { - t.Fatalf("expected %v got %v", d.e.Name, ep.Name) - } - if ok := compare(d.e.Method, ep.Method); !ok { - t.Fatalf("expected %v got %v", d.e.Method, ep.Method) - } - if ok := compare(d.e.Path, ep.Path); !ok { - t.Fatalf("expected %v got %v", d.e.Path, ep.Path) - } - if ok := compare(d.e.Host, ep.Host); !ok { - t.Fatalf("expected %v got %v", d.e.Host, ep.Host) - } - - } - -} diff --git a/api/grpc_test.go b/api/router/router_test.go similarity index 60% rename from api/grpc_test.go rename to api/router/router_test.go index e31f3759..ec1efc7e 100644 --- a/api/grpc_test.go +++ b/api/router/router_test.go @@ -1,4 +1,4 @@ -package api_test +package router_test import ( "context" @@ -13,6 +13,7 @@ import ( "github.com/micro/go-micro/v2/api/handler" "github.com/micro/go-micro/v2/api/handler/rpc" "github.com/micro/go-micro/v2/api/router" + rregistry "github.com/micro/go-micro/v2/api/router/registry" rstatic "github.com/micro/go-micro/v2/api/router/static" "github.com/micro/go-micro/v2/client" gcli "github.com/micro/go-micro/v2/client/grpc" @@ -29,11 +30,11 @@ type testServer struct { // TestHello implements helloworld.GreeterServer func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error { - rsp.Msg = "Hello " + req.Name + rsp.Msg = "Hello " + req.Uuid return nil } -func TestApiAndGRPC(t *testing.T) { +func initial(t *testing.T) (server.Server, client.Client) { r := rmemory.NewRegistry() // create a new client @@ -53,44 +54,17 @@ func TestApiAndGRPC(t *testing.T) { if err := s.Start(); err != nil { t.Fatalf("failed to start: %v", err) } - defer s.Stop() - // create a new router - router := rstatic.NewRouter( - router.WithHandler(rpc.Handler), - router.WithRegistry(r), - ) + return s, c +} - err := router.Register(&api.Endpoint{ - Name: "foo.Test.Call", - Method: []string{"GET"}, - Path: []string{"/api/v0/test/call/{name}"}, - Handler: "rpc", - }) +func check(addr string, t *testing.T) { + req, err := http.NewRequest("POST", fmt.Sprintf("http://%s/api/v0/test/call/TEST", addr), nil) if err != nil { - t.Fatal(err) + t.Fatalf("Failed to created http.Request: %v", err) } - - hrpc := rpc.NewHandler( - handler.WithClient(c), - handler.WithRouter(router), - ) - - hsrv := &http.Server{ - Handler: hrpc, - Addr: "127.0.0.1:6543", - WriteTimeout: 15 * time.Second, - ReadTimeout: 15 * time.Second, - IdleTimeout: 20 * time.Second, - MaxHeaderBytes: 1024 * 1024 * 1, // 1Mb - } - - go func() { - log.Println(hsrv.ListenAndServe()) - }() - - time.Sleep(1 * time.Second) - rsp, err := http.Get(fmt.Sprintf("http://%s/api/v0/test/call/TEST", hsrv.Addr)) + req.Header.Set("Content-Type", "application/json") + rsp, err := (&http.Client{}).Do(req) if err != nil { t.Fatalf("Failed to created http.Request: %v", err) } @@ -106,3 +80,74 @@ func TestApiAndGRPC(t *testing.T) { t.Fatalf("invalid message received, parsing error %s != %s", buf, jsonMsg) } } + +func TestRouterRegistry(t *testing.T) { + s, c := initial(t) + defer s.Stop() + + router := rregistry.NewRouter( + router.WithHandler(rpc.Handler), + router.WithRegistry(s.Options().Registry), + ) + hrpc := rpc.NewHandler( + handler.WithClient(c), + handler.WithRouter(router), + ) + hsrv := &http.Server{ + Handler: hrpc, + Addr: "127.0.0.1:6543", + WriteTimeout: 15 * time.Second, + ReadTimeout: 15 * time.Second, + IdleTimeout: 20 * time.Second, + MaxHeaderBytes: 1024 * 1024 * 1, // 1Mb + } + + go func() { + log.Println(hsrv.ListenAndServe()) + }() + + defer hsrv.Close() + time.Sleep(1 * time.Second) + check(hsrv.Addr, t) +} + +func TestRouterStatic(t *testing.T) { + s, c := initial(t) + defer s.Stop() + + router := rstatic.NewRouter( + router.WithHandler(rpc.Handler), + router.WithRegistry(s.Options().Registry), + ) + + err := router.Register(&api.Endpoint{ + Name: "foo.Test.Call", + Method: []string{"POST"}, + Path: []string{"/api/v0/test/call/{uuid}"}, + Handler: "rpc", + }) + if err != nil { + t.Fatal(err) + } + + hrpc := rpc.NewHandler( + handler.WithClient(c), + handler.WithRouter(router), + ) + hsrv := &http.Server{ + Handler: hrpc, + Addr: "127.0.0.1:6543", + WriteTimeout: 15 * time.Second, + ReadTimeout: 15 * time.Second, + IdleTimeout: 20 * time.Second, + MaxHeaderBytes: 1024 * 1024 * 1, // 1Mb + } + + go func() { + log.Println(hsrv.ListenAndServe()) + }() + defer hsrv.Close() + + time.Sleep(1 * time.Second) + check(hsrv.Addr, t) +} diff --git a/api/router/static/static.go b/api/router/static/static.go index fd630cc2..927969cb 100644 --- a/api/router/static/static.go +++ b/api/router/static/static.go @@ -8,20 +8,19 @@ import ( "strings" "sync" - "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule" - "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/api/router" + "github.com/micro/go-micro/v2/api/router/util" "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" - util "github.com/micro/go-micro/v2/util/registry" + rutil "github.com/micro/go-micro/v2/util/registry" ) type endpoint struct { apiep *api.Endpoint hostregs []*regexp.Regexp - pathregs []runtime.Pattern + pathregs []util.Pattern } // router is the default router @@ -93,7 +92,7 @@ func (r *staticRouter) Register(ep *api.Endpoint) error { return err } - var pathregs []runtime.Pattern + var pathregs []util.Pattern var hostregs []*regexp.Regexp for _, h := range ep.Host { @@ -108,12 +107,12 @@ func (r *staticRouter) Register(ep *api.Endpoint) error { } for _, p := range ep.Path { - rule, err := httprule.Parse(p) + rule, err := util.Parse(p) if err != nil { return err } tpl := rule.Compile() - pathreg, err := runtime.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "") + pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "") if err != nil { return err } @@ -164,7 +163,7 @@ func (r *staticRouter) Endpoint(req *http.Request) (*api.Service, error) { // hack for stream endpoint if ep.apiep.Stream { - svcs := util.Copy(services) + svcs := rutil.Copy(services) for _, svc := range svcs { if len(svc.Endpoints) == 0 { e := ®istry.Endpoint{} diff --git a/api/router/util/LICENSE.txt b/api/router/util/LICENSE.txt new file mode 100644 index 00000000..36451625 --- /dev/null +++ b/api/router/util/LICENSE.txt @@ -0,0 +1,27 @@ +Copyright (c) 2015, Gengo, Inc. +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 Gengo, Inc. 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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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/api/router/util/compile.go b/api/router/util/compile.go new file mode 100644 index 00000000..ca52c061 --- /dev/null +++ b/api/router/util/compile.go @@ -0,0 +1,115 @@ +package util + +// download from https://raw.githubusercontent.com/grpc-ecosystem/grpc-gateway/master/protoc-gen-grpc-gateway/httprule/compile.go + +const ( + opcodeVersion = 1 +) + +// Template is a compiled representation of path templates. +type Template struct { + // Version is the version number of the format. + Version int + // OpCodes is a sequence of operations. + OpCodes []int + // Pool is a constant pool + Pool []string + // Verb is a VERB part in the template. + Verb string + // Fields is a list of field paths bound in this template. + Fields []string + // Original template (example: /v1/a_bit_of_everything) + Template string +} + +// Compiler compiles utilities representation of path templates into marshallable operations. +// They can be unmarshalled by runtime.NewPattern. +type Compiler interface { + Compile() Template +} + +type op struct { + // code is the opcode of the operation + code OpCode + + // str is a string operand of the code. + // operand is ignored if str is not empty. + str string + + // operand is a numeric operand of the code. + operand int +} + +func (w wildcard) compile() []op { + return []op{ + {code: OpPush}, + } +} + +func (w deepWildcard) compile() []op { + return []op{ + {code: OpPushM}, + } +} + +func (l literal) compile() []op { + return []op{ + { + code: OpLitPush, + str: string(l), + }, + } +} + +func (v variable) compile() []op { + var ops []op + for _, s := range v.segments { + ops = append(ops, s.compile()...) + } + ops = append(ops, op{ + code: OpConcatN, + operand: len(v.segments), + }, op{ + code: OpCapture, + str: v.path, + }) + + return ops +} + +func (t template) Compile() Template { + var rawOps []op + for _, s := range t.segments { + rawOps = append(rawOps, s.compile()...) + } + + var ( + ops []int + pool []string + fields []string + ) + consts := make(map[string]int) + for _, op := range rawOps { + ops = append(ops, int(op.code)) + if op.str == "" { + ops = append(ops, op.operand) + } else { + if _, ok := consts[op.str]; !ok { + consts[op.str] = len(pool) + pool = append(pool, op.str) + } + ops = append(ops, consts[op.str]) + } + if op.code == OpCapture { + fields = append(fields, op.str) + } + } + return Template{ + Version: opcodeVersion, + OpCodes: ops, + Pool: pool, + Verb: t.verb, + Fields: fields, + Template: t.template, + } +} diff --git a/api/router/util/compile_test.go b/api/router/util/compile_test.go new file mode 100644 index 00000000..3ed6f43c --- /dev/null +++ b/api/router/util/compile_test.go @@ -0,0 +1,122 @@ +package util + +// download from https://raw.githubusercontent.com/grpc-ecosystem/grpc-gateway/master/protoc-gen-grpc-gateway/httprule/compile_test.go + +import ( + "reflect" + "testing" +) + +const ( + operandFiller = 0 +) + +func TestCompile(t *testing.T) { + for _, spec := range []struct { + segs []segment + verb string + + ops []int + pool []string + fields []string + }{ + {}, + { + segs: []segment{ + wildcard{}, + }, + ops: []int{int(OpPush), operandFiller}, + }, + { + segs: []segment{ + deepWildcard{}, + }, + ops: []int{int(OpPushM), operandFiller}, + }, + { + segs: []segment{ + literal("v1"), + }, + ops: []int{int(OpLitPush), 0}, + pool: []string{"v1"}, + }, + { + segs: []segment{ + literal("v1"), + }, + verb: "LOCK", + ops: []int{int(OpLitPush), 0}, + pool: []string{"v1"}, + }, + { + segs: []segment{ + variable{ + path: "name.nested", + segments: []segment{ + wildcard{}, + }, + }, + }, + ops: []int{ + int(OpPush), operandFiller, + int(OpConcatN), 1, + int(OpCapture), 0, + }, + pool: []string{"name.nested"}, + fields: []string{"name.nested"}, + }, + { + segs: []segment{ + literal("obj"), + variable{ + path: "name.nested", + segments: []segment{ + literal("a"), + wildcard{}, + literal("b"), + }, + }, + variable{ + path: "obj", + segments: []segment{ + deepWildcard{}, + }, + }, + }, + ops: []int{ + int(OpLitPush), 0, + int(OpLitPush), 1, + int(OpPush), operandFiller, + int(OpLitPush), 2, + int(OpConcatN), 3, + int(OpCapture), 3, + int(OpPushM), operandFiller, + int(OpConcatN), 1, + int(OpCapture), 0, + }, + pool: []string{"obj", "a", "b", "name.nested"}, + fields: []string{"name.nested", "obj"}, + }, + } { + tmpl := template{ + segments: spec.segs, + verb: spec.verb, + } + compiled := tmpl.Compile() + if got, want := compiled.Version, opcodeVersion; got != want { + t.Errorf("tmpl.Compile().Version = %d; want %d; segs=%#v, verb=%q", got, want, spec.segs, spec.verb) + } + if got, want := compiled.OpCodes, spec.ops; !reflect.DeepEqual(got, want) { + t.Errorf("tmpl.Compile().OpCodes = %v; want %v; segs=%#v, verb=%q", got, want, spec.segs, spec.verb) + } + if got, want := compiled.Pool, spec.pool; !reflect.DeepEqual(got, want) { + t.Errorf("tmpl.Compile().Pool = %q; want %q; segs=%#v, verb=%q", got, want, spec.segs, spec.verb) + } + if got, want := compiled.Verb, spec.verb; got != want { + t.Errorf("tmpl.Compile().Verb = %q; want %q; segs=%#v, verb=%q", got, want, spec.segs, spec.verb) + } + if got, want := compiled.Fields, spec.fields; !reflect.DeepEqual(got, want) { + t.Errorf("tmpl.Compile().Fields = %q; want %q; segs=%#v, verb=%q", got, want, spec.segs, spec.verb) + } + } +} diff --git a/api/router/util/parse.go b/api/router/util/parse.go new file mode 100644 index 00000000..83db2d47 --- /dev/null +++ b/api/router/util/parse.go @@ -0,0 +1,363 @@ +package util + +// download from https://raw.githubusercontent.com/grpc-ecosystem/grpc-gateway/master/protoc-gen-grpc-gateway/httprule/parse.go + +import ( + "fmt" + "strings" + + "github.com/micro/go-micro/v2/logger" +) + +// InvalidTemplateError indicates that the path template is not valid. +type InvalidTemplateError struct { + tmpl string + msg string +} + +func (e InvalidTemplateError) Error() string { + return fmt.Sprintf("%s: %s", e.msg, e.tmpl) +} + +// Parse parses the string representation of path template +func Parse(tmpl string) (Compiler, error) { + if !strings.HasPrefix(tmpl, "/") { + return template{}, InvalidTemplateError{tmpl: tmpl, msg: "no leading /"} + } + tokens, verb := tokenize(tmpl[1:]) + + p := parser{tokens: tokens} + segs, err := p.topLevelSegments() + if err != nil { + return template{}, InvalidTemplateError{tmpl: tmpl, msg: err.Error()} + } + + return template{ + segments: segs, + verb: verb, + template: tmpl, + }, nil +} + +func tokenize(path string) (tokens []string, verb string) { + if path == "" { + return []string{eof}, "" + } + + const ( + init = iota + field + nested + ) + var ( + st = init + ) + for path != "" { + var idx int + switch st { + case init: + idx = strings.IndexAny(path, "/{") + case field: + idx = strings.IndexAny(path, ".=}") + case nested: + idx = strings.IndexAny(path, "/}") + } + if idx < 0 { + tokens = append(tokens, path) + break + } + switch r := path[idx]; r { + case '/', '.': + case '{': + st = field + case '=': + st = nested + case '}': + st = init + } + if idx == 0 { + tokens = append(tokens, path[idx:idx+1]) + } else { + tokens = append(tokens, path[:idx], path[idx:idx+1]) + } + path = path[idx+1:] + } + + l := len(tokens) + t := tokens[l-1] + if idx := strings.LastIndex(t, ":"); idx == 0 { + tokens, verb = tokens[:l-1], t[1:] + } else if idx > 0 { + tokens[l-1], verb = t[:idx], t[idx+1:] + } + tokens = append(tokens, eof) + return tokens, verb +} + +// parser is a parser of the template syntax defined in github.com/googleapis/googleapis/google/api/http.proto. +type parser struct { + tokens []string + accepted []string +} + +// topLevelSegments is the target of this parser. +func (p *parser) topLevelSegments() ([]segment, error) { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Parsing %q", p.tokens) + } + segs, err := p.segments() + if err != nil { + return nil, err + } + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("accept segments: %q; %q", p.accepted, p.tokens) + } + if _, err := p.accept(typeEOF); err != nil { + return nil, fmt.Errorf("unexpected token %q after segments %q", p.tokens[0], strings.Join(p.accepted, "")) + } + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("accept eof: %q; %q", p.accepted, p.tokens) + } + return segs, nil +} + +func (p *parser) segments() ([]segment, error) { + s, err := p.segment() + if err != nil { + return nil, err + } + + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("accept segment: %q; %q", p.accepted, p.tokens) + } + segs := []segment{s} + for { + if _, err := p.accept("/"); err != nil { + return segs, nil + } + s, err := p.segment() + if err != nil { + return segs, err + } + segs = append(segs, s) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("accept segment: %q; %q", p.accepted, p.tokens) + } + } +} + +func (p *parser) segment() (segment, error) { + if _, err := p.accept("*"); err == nil { + return wildcard{}, nil + } + if _, err := p.accept("**"); err == nil { + return deepWildcard{}, nil + } + if l, err := p.literal(); err == nil { + return l, nil + } + + v, err := p.variable() + if err != nil { + return nil, fmt.Errorf("segment neither wildcards, literal or variable: %v", err) + } + return v, err +} + +func (p *parser) literal() (segment, error) { + lit, err := p.accept(typeLiteral) + if err != nil { + return nil, err + } + return literal(lit), nil +} + +func (p *parser) variable() (segment, error) { + if _, err := p.accept("{"); err != nil { + return nil, err + } + + path, err := p.fieldPath() + if err != nil { + return nil, err + } + + var segs []segment + if _, err := p.accept("="); err == nil { + segs, err = p.segments() + if err != nil { + return nil, fmt.Errorf("invalid segment in variable %q: %v", path, err) + } + } else { + segs = []segment{wildcard{}} + } + + if _, err := p.accept("}"); err != nil { + return nil, fmt.Errorf("unterminated variable segment: %s", path) + } + return variable{ + path: path, + segments: segs, + }, nil +} + +func (p *parser) fieldPath() (string, error) { + c, err := p.accept(typeIdent) + if err != nil { + return "", err + } + components := []string{c} + for { + if _, err = p.accept("."); err != nil { + return strings.Join(components, "."), nil + } + c, err := p.accept(typeIdent) + if err != nil { + return "", fmt.Errorf("invalid field path component: %v", err) + } + components = append(components, c) + } +} + +// A termType is a type of terminal symbols. +type termType string + +// These constants define some of valid values of termType. +// They improve readability of parse functions. +// +// You can also use "/", "*", "**", "." or "=" as valid values. +const ( + typeIdent = termType("ident") + typeLiteral = termType("literal") + typeEOF = termType("$") +) + +const ( + // eof is the terminal symbol which always appears at the end of token sequence. + eof = "\u0000" +) + +// accept tries to accept a token in "p". +// This function consumes a token and returns it if it matches to the specified "term". +// If it doesn't match, the function does not consume any tokens and return an error. +func (p *parser) accept(term termType) (string, error) { + t := p.tokens[0] + switch term { + case "/", "*", "**", ".", "=", "{", "}": + if t != string(term) && t != "/" { + return "", fmt.Errorf("expected %q but got %q", term, t) + } + case typeEOF: + if t != eof { + return "", fmt.Errorf("expected EOF but got %q", t) + } + case typeIdent: + if err := expectIdent(t); err != nil { + return "", err + } + case typeLiteral: + if err := expectPChars(t); err != nil { + return "", err + } + default: + return "", fmt.Errorf("unknown termType %q", term) + } + p.tokens = p.tokens[1:] + p.accepted = append(p.accepted, t) + return t, nil +} + +// expectPChars determines if "t" consists of only pchars defined in RFC3986. +// +// https://www.ietf.org/rfc/rfc3986.txt, P.49 +// pchar = unreserved / pct-encoded / sub-delims / ":" / "@" +// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" +// sub-delims = "!" / "$" / "&" / "'" / "(" / ")" +// / "*" / "+" / "," / ";" / "=" +// pct-encoded = "%" HEXDIG HEXDIG +func expectPChars(t string) error { + const ( + init = iota + pct1 + pct2 + ) + st := init + for _, r := range t { + if st != init { + if !isHexDigit(r) { + return fmt.Errorf("invalid hexdigit: %c(%U)", r, r) + } + switch st { + case pct1: + st = pct2 + case pct2: + st = init + } + continue + } + + // unreserved + switch { + case 'A' <= r && r <= 'Z': + continue + case 'a' <= r && r <= 'z': + continue + case '0' <= r && r <= '9': + continue + } + switch r { + case '-', '.', '_', '~': + // unreserved + case '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=': + // sub-delims + case ':', '@': + // rest of pchar + case '%': + // pct-encoded + st = pct1 + default: + return fmt.Errorf("invalid character in path segment: %q(%U)", r, r) + } + } + if st != init { + return fmt.Errorf("invalid percent-encoding in %q", t) + } + return nil +} + +// expectIdent determines if "ident" is a valid identifier in .proto schema ([[:alpha:]_][[:alphanum:]_]*). +func expectIdent(ident string) error { + if ident == "" { + return fmt.Errorf("empty identifier") + } + for pos, r := range ident { + switch { + case '0' <= r && r <= '9': + if pos == 0 { + return fmt.Errorf("identifier starting with digit: %s", ident) + } + continue + case 'A' <= r && r <= 'Z': + continue + case 'a' <= r && r <= 'z': + continue + case r == '_': + continue + default: + return fmt.Errorf("invalid character %q(%U) in identifier: %s", r, r, ident) + } + } + return nil +} + +func isHexDigit(r rune) bool { + switch { + case '0' <= r && r <= '9': + return true + case 'A' <= r && r <= 'F': + return true + case 'a' <= r && r <= 'f': + return true + } + return false +} diff --git a/api/router/util/parse_test.go b/api/router/util/parse_test.go new file mode 100644 index 00000000..b15b6184 --- /dev/null +++ b/api/router/util/parse_test.go @@ -0,0 +1,321 @@ +package util + +// download from https://raw.githubusercontent.com/grpc-ecosystem/grpc-gateway/master/protoc-gen-grpc-gateway/httprule/parse_test.go + +import ( + "flag" + "fmt" + "reflect" + "testing" + + "github.com/micro/go-micro/v2/logger" +) + +func TestTokenize(t *testing.T) { + for _, spec := range []struct { + src string + tokens []string + }{ + { + src: "", + tokens: []string{eof}, + }, + { + src: "v1", + tokens: []string{"v1", eof}, + }, + { + src: "v1/b", + tokens: []string{"v1", "/", "b", eof}, + }, + { + src: "v1/endpoint/*", + tokens: []string{"v1", "/", "endpoint", "/", "*", eof}, + }, + { + src: "v1/endpoint/**", + tokens: []string{"v1", "/", "endpoint", "/", "**", eof}, + }, + { + src: "v1/b/{bucket_name=*}", + tokens: []string{ + "v1", "/", + "b", "/", + "{", "bucket_name", "=", "*", "}", + eof, + }, + }, + { + src: "v1/b/{bucket_name=buckets/*}", + tokens: []string{ + "v1", "/", + "b", "/", + "{", "bucket_name", "=", "buckets", "/", "*", "}", + eof, + }, + }, + { + src: "v1/b/{bucket_name=buckets/*}/o", + tokens: []string{ + "v1", "/", + "b", "/", + "{", "bucket_name", "=", "buckets", "/", "*", "}", "/", + "o", + eof, + }, + }, + { + src: "v1/b/{bucket_name=buckets/*}/o/{name}", + tokens: []string{ + "v1", "/", + "b", "/", + "{", "bucket_name", "=", "buckets", "/", "*", "}", "/", + "o", "/", "{", "name", "}", + eof, + }, + }, + { + src: "v1/a=b&c=d;e=f:g/endpoint.rdf", + tokens: []string{ + "v1", "/", + "a=b&c=d;e=f:g", "/", + "endpoint.rdf", + eof, + }, + }, + } { + tokens, verb := tokenize(spec.src) + if got, want := tokens, spec.tokens; !reflect.DeepEqual(got, want) { + t.Errorf("tokenize(%q) = %q, _; want %q, _", spec.src, got, want) + } + if got, want := verb, ""; got != want { + t.Errorf("tokenize(%q) = _, %q; want _, %q", spec.src, got, want) + } + + src := fmt.Sprintf("%s:%s", spec.src, "LOCK") + tokens, verb = tokenize(src) + if got, want := tokens, spec.tokens; !reflect.DeepEqual(got, want) { + t.Errorf("tokenize(%q) = %q, _; want %q, _", src, got, want) + } + if got, want := verb, "LOCK"; got != want { + t.Errorf("tokenize(%q) = _, %q; want _, %q", src, got, want) + } + } +} + +func TestParseSegments(t *testing.T) { + flag.Set("v", "3") + for _, spec := range []struct { + tokens []string + want []segment + }{ + { + tokens: []string{"v1", eof}, + want: []segment{ + literal("v1"), + }, + }, + { + tokens: []string{"/", eof}, + want: []segment{ + wildcard{}, + }, + }, + { + tokens: []string{"-._~!$&'()*+,;=:@", eof}, + want: []segment{ + literal("-._~!$&'()*+,;=:@"), + }, + }, + { + tokens: []string{"%e7%ac%ac%e4%b8%80%e7%89%88", eof}, + want: []segment{ + literal("%e7%ac%ac%e4%b8%80%e7%89%88"), + }, + }, + { + tokens: []string{"v1", "/", "*", eof}, + want: []segment{ + literal("v1"), + wildcard{}, + }, + }, + { + tokens: []string{"v1", "/", "**", eof}, + want: []segment{ + literal("v1"), + deepWildcard{}, + }, + }, + { + tokens: []string{"{", "name", "}", eof}, + want: []segment{ + variable{ + path: "name", + segments: []segment{ + wildcard{}, + }, + }, + }, + }, + { + tokens: []string{"{", "name", "=", "*", "}", eof}, + want: []segment{ + variable{ + path: "name", + segments: []segment{ + wildcard{}, + }, + }, + }, + }, + { + tokens: []string{"{", "field", ".", "nested", ".", "nested2", "=", "*", "}", eof}, + want: []segment{ + variable{ + path: "field.nested.nested2", + segments: []segment{ + wildcard{}, + }, + }, + }, + }, + { + tokens: []string{"{", "name", "=", "a", "/", "b", "/", "*", "}", eof}, + want: []segment{ + variable{ + path: "name", + segments: []segment{ + literal("a"), + literal("b"), + wildcard{}, + }, + }, + }, + }, + { + tokens: []string{ + "v1", "/", + "{", + "name", ".", "nested", ".", "nested2", + "=", + "a", "/", "b", "/", "*", + "}", "/", + "o", "/", + "{", + "another_name", + "=", + "a", "/", "b", "/", "*", "/", "c", + "}", "/", + "**", + eof}, + want: []segment{ + literal("v1"), + variable{ + path: "name.nested.nested2", + segments: []segment{ + literal("a"), + literal("b"), + wildcard{}, + }, + }, + literal("o"), + variable{ + path: "another_name", + segments: []segment{ + literal("a"), + literal("b"), + wildcard{}, + literal("c"), + }, + }, + deepWildcard{}, + }, + }, + } { + p := parser{tokens: spec.tokens} + segs, err := p.topLevelSegments() + if err != nil { + t.Errorf("parser{%q}.segments() failed with %v; want success", spec.tokens, err) + continue + } + if got, want := segs, spec.want; !reflect.DeepEqual(got, want) { + t.Errorf("parser{%q}.segments() = %#v; want %#v", spec.tokens, got, want) + } + if got := p.tokens; len(got) > 0 { + t.Errorf("p.tokens = %q; want []; spec.tokens=%q", got, spec.tokens) + } + } +} + +func TestParseSegmentsWithErrors(t *testing.T) { + flag.Set("v", "3") + for _, spec := range []struct { + tokens []string + }{ + { + // double slash + tokens: []string{"//", eof}, + }, + { + // invalid literal + tokens: []string{"a?b", eof}, + }, + { + // invalid percent-encoding + tokens: []string{"%", eof}, + }, + { + // invalid percent-encoding + tokens: []string{"%2", eof}, + }, + { + // invalid percent-encoding + tokens: []string{"a%2z", eof}, + }, + { + // empty segments + tokens: []string{eof}, + }, + { + // unterminated variable + tokens: []string{"{", "name", eof}, + }, + { + // unterminated variable + tokens: []string{"{", "name", "=", eof}, + }, + { + // unterminated variable + tokens: []string{"{", "name", "=", "*", eof}, + }, + { + // empty component in field path + tokens: []string{"{", "name", ".", "}", eof}, + }, + { + // empty component in field path + tokens: []string{"{", "name", ".", ".", "nested", "}", eof}, + }, + { + // invalid character in identifier + tokens: []string{"{", "field-name", "}", eof}, + }, + { + // no slash between segments + tokens: []string{"v1", "endpoint", eof}, + }, + { + // no slash between segments + tokens: []string{"v1", "{", "name", "}", eof}, + }, + } { + p := parser{tokens: spec.tokens} + segs, err := p.topLevelSegments() + if err == nil { + t.Errorf("parser{%q}.segments() succeeded; want InvalidTemplateError; accepted %#v", spec.tokens, segs) + continue + } + logger.Info(err) + } +} diff --git a/api/router/util/pattern.go b/api/router/util/pattern.go new file mode 100644 index 00000000..5cc9af13 --- /dev/null +++ b/api/router/util/pattern.go @@ -0,0 +1,24 @@ +package util + +// download from https://raw.githubusercontent.com/grpc-ecosystem/grpc-gateway/master/utilities/pattern.go + +// An OpCode is a opcode of compiled path patterns. +type OpCode int + +// These constants are the valid values of OpCode. +const ( + // OpNop does nothing + OpNop = OpCode(iota) + // OpPush pushes a component to stack + OpPush + // OpLitPush pushes a component to stack if it matches to the literal + OpLitPush + // OpPushM concatenates the remaining components and pushes it to stack + OpPushM + // OpConcatN pops N items from stack, concatenates them and pushes it back to stack + OpConcatN + // OpCapture pops an item and binds it to the variable + OpCapture + // OpEnd is the least positive invalid opcode. + OpEnd +) diff --git a/api/router/util/runtime.go b/api/router/util/runtime.go new file mode 100644 index 00000000..7b615552 --- /dev/null +++ b/api/router/util/runtime.go @@ -0,0 +1,283 @@ +package util + +// download from https://raw.githubusercontent.com/grpc-ecosystem/grpc-gateway/master/runtime/pattern.go + +import ( + "errors" + "fmt" + "strings" + + "github.com/micro/go-micro/v2/logger" +) + +var ( + // ErrNotMatch indicates that the given HTTP request path does not match to the pattern. + ErrNotMatch = errors.New("not match to the path pattern") + // ErrInvalidPattern indicates that the given definition of Pattern is not valid. + ErrInvalidPattern = errors.New("invalid pattern") +) + +type rop struct { + code OpCode + operand int +} + +// Pattern is a template pattern of http request paths defined in github.com/googleapis/googleapis/google/api/http.proto. +type Pattern struct { + // ops is a list of operations + ops []rop + // pool is a constant pool indexed by the operands or vars. + pool []string + // vars is a list of variables names to be bound by this pattern + vars []string + // stacksize is the max depth of the stack + stacksize int + // tailLen is the length of the fixed-size segments after a deep wildcard + tailLen int + // verb is the VERB part of the path pattern. It is empty if the pattern does not have VERB part. + verb string + // assumeColonVerb indicates whether a path suffix after a final + // colon may only be interpreted as a verb. + assumeColonVerb bool +} + +type patternOptions struct { + assumeColonVerb bool +} + +// PatternOpt is an option for creating Patterns. +type PatternOpt func(*patternOptions) + +// NewPattern returns a new Pattern from the given definition values. +// "ops" is a sequence of op codes. "pool" is a constant pool. +// "verb" is the verb part of the pattern. It is empty if the pattern does not have the part. +// "version" must be 1 for now. +// It returns an error if the given definition is invalid. +func NewPattern(version int, ops []int, pool []string, verb string, opts ...PatternOpt) (Pattern, error) { + options := patternOptions{ + assumeColonVerb: true, + } + for _, o := range opts { + o(&options) + } + + if version != 1 { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("unsupported version: %d", version) + } + return Pattern{}, ErrInvalidPattern + } + + l := len(ops) + if l%2 != 0 { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("odd number of ops codes: %d", l) + } + return Pattern{}, ErrInvalidPattern + } + + var ( + typedOps []rop + stack, maxstack int + tailLen int + pushMSeen bool + vars []string + ) + for i := 0; i < l; i += 2 { + op := rop{code: OpCode(ops[i]), operand: ops[i+1]} + switch op.code { + case OpNop: + continue + case OpPush: + if pushMSeen { + tailLen++ + } + stack++ + case OpPushM: + if pushMSeen { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debug("pushM appears twice") + } + return Pattern{}, ErrInvalidPattern + } + pushMSeen = true + stack++ + case OpLitPush: + if op.operand < 0 || len(pool) <= op.operand { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("negative literal index: %d", op.operand) + } + return Pattern{}, ErrInvalidPattern + } + if pushMSeen { + tailLen++ + } + stack++ + case OpConcatN: + if op.operand <= 0 { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("negative concat size: %d", op.operand) + } + return Pattern{}, ErrInvalidPattern + } + stack -= op.operand + if stack < 0 { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debug("stack underflow") + } + return Pattern{}, ErrInvalidPattern + } + stack++ + case OpCapture: + if op.operand < 0 || len(pool) <= op.operand { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("variable name index out of bound: %d", op.operand) + } + return Pattern{}, ErrInvalidPattern + } + v := pool[op.operand] + op.operand = len(vars) + vars = append(vars, v) + stack-- + if stack < 0 { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debug("stack underflow") + } + return Pattern{}, ErrInvalidPattern + } + default: + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("invalid opcode: %d", op.code) + } + return Pattern{}, ErrInvalidPattern + } + + if maxstack < stack { + maxstack = stack + } + typedOps = append(typedOps, op) + } + return Pattern{ + ops: typedOps, + pool: pool, + vars: vars, + stacksize: maxstack, + tailLen: tailLen, + verb: verb, + assumeColonVerb: options.assumeColonVerb, + }, nil +} + +// MustPattern is a helper function which makes it easier to call NewPattern in variable initialization. +func MustPattern(p Pattern, err error) Pattern { + if err != nil { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Fatalf("Pattern initialization failed: %v", err) + } + } + return p +} + +// Match examines components if it matches to the Pattern. +// If it matches, the function returns a mapping from field paths to their captured values. +// If otherwise, the function returns an error. +func (p Pattern) Match(components []string, verb string) (map[string]string, error) { + if p.verb != verb { + if p.assumeColonVerb || p.verb != "" { + return nil, ErrNotMatch + } + if len(components) == 0 { + components = []string{":" + verb} + } else { + components = append([]string{}, components...) + components[len(components)-1] += ":" + verb + } + verb = "" + } + + var pos int + stack := make([]string, 0, p.stacksize) + captured := make([]string, len(p.vars)) + l := len(components) + for _, op := range p.ops { + switch op.code { + case OpNop: + continue + case OpPush, OpLitPush: + if pos >= l { + return nil, ErrNotMatch + } + c := components[pos] + if op.code == OpLitPush { + if lit := p.pool[op.operand]; c != lit { + return nil, ErrNotMatch + } + } + stack = append(stack, c) + pos++ + case OpPushM: + end := len(components) + if end < pos+p.tailLen { + return nil, ErrNotMatch + } + end -= p.tailLen + stack = append(stack, strings.Join(components[pos:end], "/")) + pos = end + case OpConcatN: + n := op.operand + l := len(stack) - n + stack = append(stack[:l], strings.Join(stack[l:], "/")) + case OpCapture: + n := len(stack) - 1 + captured[op.operand] = stack[n] + stack = stack[:n] + } + } + if pos < l { + return nil, ErrNotMatch + } + bindings := make(map[string]string) + for i, val := range captured { + bindings[p.vars[i]] = val + } + return bindings, nil +} + +// Verb returns the verb part of the Pattern. +func (p Pattern) Verb() string { return p.verb } + +func (p Pattern) String() string { + var stack []string + for _, op := range p.ops { + switch op.code { + case OpNop: + continue + case OpPush: + stack = append(stack, "*") + case OpLitPush: + stack = append(stack, p.pool[op.operand]) + case OpPushM: + stack = append(stack, "**") + case OpConcatN: + n := op.operand + l := len(stack) - n + stack = append(stack[:l], strings.Join(stack[l:], "/")) + case OpCapture: + n := len(stack) - 1 + stack[n] = fmt.Sprintf("{%s=%s}", p.vars[op.operand], stack[n]) + } + } + segs := strings.Join(stack, "/") + if p.verb != "" { + return fmt.Sprintf("/%s:%s", segs, p.verb) + } + return "/" + segs +} + +// AssumeColonVerbOpt indicates whether a path suffix after a final +// colon may only be interpreted as a verb. +func AssumeColonVerbOpt(val bool) PatternOpt { + return PatternOpt(func(o *patternOptions) { + o.assumeColonVerb = val + }) +} diff --git a/api/router/util/types.go b/api/router/util/types.go new file mode 100644 index 00000000..e9ff047a --- /dev/null +++ b/api/router/util/types.go @@ -0,0 +1,62 @@ +package util + +// download from https://raw.githubusercontent.com/grpc-ecosystem/grpc-gateway/master/protoc-gen-grpc-gateway/httprule/types.go + +import ( + "fmt" + "strings" +) + +type template struct { + segments []segment + verb string + template string +} + +type segment interface { + fmt.Stringer + compile() (ops []op) +} + +type wildcard struct{} + +type deepWildcard struct{} + +type literal string + +type variable struct { + path string + segments []segment +} + +func (wildcard) String() string { + return "*" +} + +func (deepWildcard) String() string { + return "**" +} + +func (l literal) String() string { + return string(l) +} + +func (v variable) String() string { + var segs []string + for _, s := range v.segments { + segs = append(segs, s.String()) + } + return fmt.Sprintf("{%s=%s}", v.path, strings.Join(segs, "/")) +} + +func (t template) String() string { + var segs []string + for _, s := range t.segments { + segs = append(segs, s.String()) + } + str := strings.Join(segs, "/") + if t.verb != "" { + str = fmt.Sprintf("%s:%s", str, t.verb) + } + return "/" + str +} diff --git a/api/router/util/types_test.go b/api/router/util/types_test.go new file mode 100644 index 00000000..7f58e74c --- /dev/null +++ b/api/router/util/types_test.go @@ -0,0 +1,93 @@ +package util + +// download from https://raw.githubusercontent.com/grpc-ecosystem/grpc-gateway/master/protoc-gen-grpc-gateway/httprule/types_test.go + +import ( + "fmt" + "testing" +) + +func TestTemplateStringer(t *testing.T) { + for _, spec := range []struct { + segs []segment + want string + }{ + { + segs: []segment{ + literal("v1"), + }, + want: "/v1", + }, + { + segs: []segment{ + wildcard{}, + }, + want: "/*", + }, + { + segs: []segment{ + deepWildcard{}, + }, + want: "/**", + }, + { + segs: []segment{ + variable{ + path: "name", + segments: []segment{ + literal("a"), + }, + }, + }, + want: "/{name=a}", + }, + { + segs: []segment{ + variable{ + path: "name", + segments: []segment{ + literal("a"), + wildcard{}, + literal("b"), + }, + }, + }, + want: "/{name=a/*/b}", + }, + { + segs: []segment{ + literal("v1"), + variable{ + path: "name", + segments: []segment{ + literal("a"), + wildcard{}, + literal("b"), + }, + }, + literal("c"), + variable{ + path: "field.nested", + segments: []segment{ + wildcard{}, + literal("d"), + }, + }, + wildcard{}, + literal("e"), + deepWildcard{}, + }, + want: "/v1/{name=a/*/b}/c/{field.nested=*/d}/*/e/**", + }, + } { + tmpl := template{segments: spec.segs} + if got, want := tmpl.String(), spec.want; got != want { + t.Errorf("%#v.String() = %q; want %q", tmpl, got, want) + } + + tmpl.verb = "LOCK" + if got, want := tmpl.String(), fmt.Sprintf("%s:LOCK", spec.want); got != want { + t.Errorf("%#v.String() = %q; want %q", tmpl, got, want) + } + } +} diff --git a/go.mod b/go.mod index 78c51dff..f3ba49cd 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/gorilla/websocket v1.4.1 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect - github.com/grpc-ecosystem/grpc-gateway v1.9.5 + github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect github.com/hashicorp/hcl v1.0.0 github.com/hpcloud/tail v1.0.0 github.com/imdario/mergo v0.3.8 From 2dfaab439c20bbd8fe6850e15c967b108ff06255 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 16 Apr 2020 15:01:16 +0100 Subject: [PATCH 643/788] Set authorization header on grpc stream --- client/grpc/grpc.go | 46 ++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 9d2fd597..30dd97f8 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -131,21 +131,10 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R // set the content type for the request header["x-content-type"] = req.ContentType() - // if the caller specifies using service token or no token - // was passed with the request, set the service token - var srvToken string - if g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { - srvToken = g.opts.Auth.Options().Token.AccessToken - } - if (opts.ServiceToken || len(header["authorization"]) == 0) && len(srvToken) > 0 { - header["authorization"] = auth.BearerScheme + srvToken - } - - // fall back to using the authorization token set in config, - // this enables the CLI to provide a token - if len(header["authorization"]) == 0 { - if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 { - header["authorization"] = auth.BearerScheme + token + // set the authorization header + if opts.ServiceToken || len(header["authorization"]) == 0 { + if h := g.authorizationHeader(); len(h) > 0 { + header["authorization"] = h } } @@ -227,6 +216,13 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client // set the content type for the request header["x-content-type"] = req.ContentType() + // set the authorization header + if opts.ServiceToken || len(header["authorization"]) == 0 { + if h := g.authorizationHeader(); len(h) > 0 { + header["authorization"] = h + } + } + md := gmetadata.New(header) ctx = gmetadata.NewOutgoingContext(ctx, md) @@ -313,6 +309,26 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client }, nil } +func (g *grpcClient) authorizationHeader() string { + // if the caller specifies using service token or no token + // was passed with the request, set the service token + var srvToken string + if g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { + srvToken = g.opts.Auth.Options().Token.AccessToken + } + if len(srvToken) > 0 { + return auth.BearerScheme + srvToken + } + + // fall back to using the authorization token set in config, + // this enables the CLI to provide a token + if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 { + return auth.BearerScheme + token + } + + return "" +} + func (g *grpcClient) poolMaxStreams() int { if g.opts.Context == nil { return DefaultPoolMaxStreams From ac5822f1eec65e941b8c46629048dc8f052ec3c0 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Thu, 16 Apr 2020 17:50:24 +0200 Subject: [PATCH 644/788] Fix local runtime updates (#1543) --- runtime/default.go | 21 ++++++++------------- runtime/service.go | 6 ++++++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index 2ef813ff..28e752a8 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -332,22 +332,17 @@ func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) { // Update attemps to update the service func (r *runtime) Update(s *Service) error { - var opts []CreateOption - - // check if the service already exists - r.RLock() - if service, ok := r.services[s.Name]; ok { - opts = append(opts, WithOutput(service.output)) + r.Lock() + service, ok := r.services[s.Name] + r.Unlock() + if !ok { + return errors.New("Service not found") } - r.RUnlock() - - // delete the service - if err := r.Delete(s); err != nil { + err := service.Stop() + if err != nil { return err } - - // create new service - return r.Create(s, opts...) + return service.Start() } // Delete removes the service from the runtime and stops it diff --git a/runtime/service.go b/runtime/service.go index eb6c4154..aa12061c 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -100,6 +100,7 @@ func (s *service) Start() error { // reset s.err = nil s.closed = make(chan bool) + s.retries = 0 if s.Metadata == nil { s.Metadata = make(map[string]string) @@ -113,6 +114,7 @@ func (s *service) Start() error { if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Runtime service %s forking new process", s.Service.Name) } + p, err := s.Process.Fork(s.Exec) if err != nil { s.Metadata["status"] = "error" @@ -150,6 +152,7 @@ func (s *service) Stop() error { default: close(s.closed) s.running = false + s.retries = 0 if s.PID == nil { return nil } @@ -159,6 +162,9 @@ func (s *service) Stop() error { // kill the process err := s.Process.Kill(s.PID) + if err != nil { + return err + } // wait for it to exit s.Process.Wait(s.PID) From c0b0f63757f9d082a59294c9b1c301b9ba128db2 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 17 Apr 2020 10:50:44 +0100 Subject: [PATCH 645/788] Update docker workflow to push releases --- .github/workflows/docker.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 552d23b1..6520bf82 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -4,7 +4,9 @@ on: push: branches: - master - + tags: + - v2.* + - v3.* jobs: build: runs-on: ubuntu-latest From dca5305e8aa3fc440a918110829f5eb76cf1efca Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 17 Apr 2020 16:29:05 +0100 Subject: [PATCH 646/788] replaced build with updated timestamp in runtime --- runtime/kubernetes/kubernetes.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 12733bdb..e78e03df 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -259,16 +259,9 @@ func (k *kubernetes) run(events <-chan runtime.Event) { } - // check the existing build timestamp - if build, ok := service.Spec.Template.Metadata.Annotations["build"]; ok { - buildTime, err := time.Parse(time.RFC3339, build) - if err == nil && !event.Timestamp.After(buildTime) { - continue - } - } - // update the build time - service.Spec.Template.Metadata.Annotations["build"] = event.Timestamp.Format(time.RFC3339) + service.Spec.Template.Metadata.Annotations["updated"] = fmt.Sprintf("%d", event.Timestamp.Unix()) + if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Runtime updating service: %s deployment: %s", event.Service, service.Metadata.Name) } @@ -490,8 +483,9 @@ func (k *kubernetes) Update(s *runtime.Service) error { for k, v := range s.Metadata { service.kdeploy.Metadata.Annotations[k] = v } + // update build time annotation - service.kdeploy.Spec.Template.Metadata.Annotations["build"] = time.Now().Format(time.RFC3339) + service.kdeploy.Spec.Template.Metadata.Annotations["updated"] = fmt.Sprintf("%d", time.Now().Unix()) // update the service if err := service.Update(k.client); err != nil { From 16db76bee2fb74412afb15369255a368f6196dfd Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 17 Apr 2020 17:54:34 +0100 Subject: [PATCH 647/788] remove list endpoint from runtime and stop checking type in update --- runtime/kubernetes/kubernetes.go | 33 ++------------------------------ 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index e78e03df..7adbd301 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -422,39 +422,10 @@ func (k *kubernetes) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error return services, nil } -// List the managed services -func (k *kubernetes) List() ([]*runtime.Service, error) { - k.Lock() - defer k.Unlock() - - labels := map[string]string{ - "micro": k.options.Type, - } - - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime listing all micro services") - } - - srvs, err := k.getService(labels) - if err != nil { - return nil, err - } - - var services []*runtime.Service - for _, service := range srvs { - services = append(services, service.Service) - } - - return services, nil -} - // Update the service in place func (k *kubernetes) Update(s *runtime.Service) error { - // get the existing service - // set the default labels - labels := map[string]string{ - "micro": k.options.Type, - } + // TODO: set the type + labels := map[string]string{} if len(s.Name) > 0 { labels["name"] = client.Format(s.Name) From ecbc42755c4c42e876c8dc5968f318c9127205dd Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Apr 2020 21:00:00 +0100 Subject: [PATCH 648/788] set network nodes in http resolver --- network/resolver/http/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/resolver/http/http.go b/network/resolver/http/http.go index 3c316f62..d0260609 100644 --- a/network/resolver/http/http.go +++ b/network/resolver/http/http.go @@ -31,7 +31,7 @@ type Response struct { func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) { proto := "https" host := "api.micro.mu" - path := "/network" + path := "/network/nodes" if len(r.Proto) > 0 { proto = r.Proto From f00fd7a49ee6f97759b880a6ca8b1e19bd3d666b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 19 Apr 2020 00:31:34 +0300 Subject: [PATCH 649/788] api/router: support pcre and google.api pattern matching (#1549) * api/router: support pcre and google.api pattern matching Signed-off-by: Vasiliy Tolstov --- api/router/registry/registry.go | 42 +++++++++++++++++++------- api/router/router_test.go | 53 +++++++++++++++++++++++++++++---- api/router/static/static.go | 48 ++++++++++++++++++++++------- 3 files changed, 115 insertions(+), 28 deletions(-) diff --git a/api/router/registry/registry.go b/api/router/registry/registry.go index d5cd2569..b5ab4d87 100644 --- a/api/router/registry/registry.go +++ b/api/router/registry/registry.go @@ -23,6 +23,7 @@ import ( type endpoint struct { hostregs []*regexp.Regexp pathregs []util.Pattern + pcreregs []*regexp.Regexp } // router is the default router @@ -185,13 +186,23 @@ func (r *registryRouter) store(services []*registry.Service) { } for _, p := range ep.Endpoint.Path { + var pcreok bool + pcrereg, err := regexp.CompilePOSIX(p) + if err == nil { + cep.pcreregs = append(cep.pcreregs, pcrereg) + pcreok = true + } + rule, err := util.Parse(p) - if err != nil { + if err != nil && !pcreok { if logger.V(logger.TraceLevel, logger.DefaultLogger) { logger.Tracef("endpoint have invalid path pattern: %v", err) } continue + } else if err != nil && pcreok { + continue } + tpl := rule.Compile() pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "") if err != nil { @@ -303,11 +314,10 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) { ep := e.Endpoint var mMatch, hMatch, pMatch bool // 1. try method - methodLoop: for _, m := range ep.Method { if m == req.Method { mMatch = true - break methodLoop + break } } if !mMatch { @@ -321,15 +331,14 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) { if len(ep.Host) == 0 { hMatch = true } else { - hostLoop: for idx, h := range ep.Host { if h == "" || h == "*" { hMatch = true - break hostLoop + break } else { if cep.hostregs[idx].MatchString(req.URL.Host) { hMatch = true - break hostLoop + break } } } @@ -341,14 +350,12 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) { logger.Debugf("api host match %s", req.URL.Host) } - // 3. try path - // 3. try path - pathLoop: + // 3. try path via google.api path matching for _, pathreg := range cep.pathregs { matches, err := pathreg.Match(path, "") if err != nil { if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("api path not match %s != %v", path, pathreg) + logger.Debugf("api gpath not match %s != %v", path, pathreg) } continue } @@ -363,8 +370,21 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) { } md["x-api-body"] = ep.Body *req = *req.Clone(metadata.NewContext(ctx, md)) - break pathLoop + break } + + // 4. try path via pcre path matching + for _, pathreg := range cep.pcreregs { + if !pathreg.MatchString(req.URL.Path) { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api pcre path not match %s != %v", path, pathreg) + } + continue + } + pMatch = true + break + } + if !pMatch { continue } diff --git a/api/router/router_test.go b/api/router/router_test.go index ec1efc7e..9211a524 100644 --- a/api/router/router_test.go +++ b/api/router/router_test.go @@ -58,8 +58,8 @@ func initial(t *testing.T) (server.Server, client.Client) { return s, c } -func check(addr string, t *testing.T) { - req, err := http.NewRequest("POST", fmt.Sprintf("http://%s/api/v0/test/call/TEST", addr), nil) +func check(t *testing.T, addr string, path string, expected string) { + req, err := http.NewRequest("POST", fmt.Sprintf(path, addr), nil) if err != nil { t.Fatalf("Failed to created http.Request: %v", err) } @@ -75,7 +75,7 @@ func check(addr string, t *testing.T) { t.Fatal(err) } - jsonMsg := `{"msg":"Hello TEST"}` + jsonMsg := expected if string(buf) != jsonMsg { t.Fatalf("invalid message received, parsing error %s != %s", buf, jsonMsg) } @@ -108,10 +108,51 @@ func TestRouterRegistry(t *testing.T) { defer hsrv.Close() time.Sleep(1 * time.Second) - check(hsrv.Addr, t) + check(t, hsrv.Addr, "http://%s/api/v0/test/call/TEST", `{"msg":"Hello TEST"}`) } -func TestRouterStatic(t *testing.T) { +func TestRouterStaticPcre(t *testing.T) { + s, c := initial(t) + defer s.Stop() + + router := rstatic.NewRouter( + router.WithHandler(rpc.Handler), + router.WithRegistry(s.Options().Registry), + ) + + err := router.Register(&api.Endpoint{ + Name: "foo.Test.Call", + Method: []string{"POST"}, + Path: []string{"^/api/v0/test/call/?$"}, + Handler: "rpc", + }) + if err != nil { + t.Fatal(err) + } + + hrpc := rpc.NewHandler( + handler.WithClient(c), + handler.WithRouter(router), + ) + hsrv := &http.Server{ + Handler: hrpc, + Addr: "127.0.0.1:6543", + WriteTimeout: 15 * time.Second, + ReadTimeout: 15 * time.Second, + IdleTimeout: 20 * time.Second, + MaxHeaderBytes: 1024 * 1024 * 1, // 1Mb + } + + go func() { + log.Println(hsrv.ListenAndServe()) + }() + defer hsrv.Close() + + time.Sleep(1 * time.Second) + check(t, hsrv.Addr, "http://%s/api/v0/test/call", `{"msg":"Hello "}`) +} + +func TestRouterStaticG(t *testing.T) { s, c := initial(t) defer s.Stop() @@ -149,5 +190,5 @@ func TestRouterStatic(t *testing.T) { defer hsrv.Close() time.Sleep(1 * time.Second) - check(hsrv.Addr, t) + check(t, hsrv.Addr, "http://%s/api/v0/test/call/TEST", `{"msg":"Hello TEST"}`) } diff --git a/api/router/static/static.go b/api/router/static/static.go index 927969cb..367a53de 100644 --- a/api/router/static/static.go +++ b/api/router/static/static.go @@ -21,6 +21,7 @@ type endpoint struct { apiep *api.Endpoint hostregs []*regexp.Regexp pathregs []util.Pattern + pcreregs []*regexp.Regexp } // router is the default router @@ -94,6 +95,7 @@ func (r *staticRouter) Register(ep *api.Endpoint) error { var pathregs []util.Pattern var hostregs []*regexp.Regexp + var pcreregs []*regexp.Regexp for _, h := range ep.Host { if h == "" || h == "*" { @@ -107,9 +109,18 @@ func (r *staticRouter) Register(ep *api.Endpoint) error { } for _, p := range ep.Path { + var pcreok bool + pcrereg, err := regexp.CompilePOSIX(p) + if err == nil { + pcreregs = append(pcreregs, pcrereg) + pcreok = true + } + rule, err := util.Parse(p) - if err != nil { + if err != nil && !pcreok { return err + } else if err != nil && pcreok { + continue } tpl := rule.Compile() pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "") @@ -120,7 +131,12 @@ func (r *staticRouter) Register(ep *api.Endpoint) error { } r.Lock() - r.eps[ep.Name] = &endpoint{apiep: ep, pathregs: pathregs, hostregs: hostregs} + r.eps[ep.Name] = &endpoint{ + apiep: ep, + pcreregs: pcreregs, + pathregs: pathregs, + hostregs: hostregs, + } r.Unlock() return nil } @@ -219,11 +235,10 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { var mMatch, hMatch, pMatch bool // 1. try method - methodLoop: for _, m := range ep.apiep.Method { if m == req.Method { mMatch = true - break methodLoop + break } } if !mMatch { @@ -237,15 +252,14 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { if len(ep.apiep.Host) == 0 { hMatch = true } else { - hostLoop: for idx, h := range ep.apiep.Host { if h == "" || h == "*" { hMatch = true - break hostLoop + break } else { if ep.hostregs[idx].MatchString(req.URL.Host) { hMatch = true - break hostLoop + break } } } @@ -257,13 +271,12 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { logger.Debugf("api host match %s", req.URL.Host) } - // 3. try path - pathLoop: + // 3. try google.api path for _, pathreg := range ep.pathregs { matches, err := pathreg.Match(path, "") if err != nil { if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("api path not match %s != %v", path, pathreg) + logger.Debugf("api gpath not match %s != %v", path, pathreg) } continue } @@ -278,8 +291,21 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { } md["x-api-body"] = ep.apiep.Body *req = *req.Clone(metadata.NewContext(ctx, md)) - break pathLoop + break } + + // 4. try path via pcre path matching + for _, pathreg := range ep.pcreregs { + if !pathreg.MatchString(req.URL.Path) { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api pcre path not match %s != %v", req.URL.Path, pathreg) + } + continue + } + pMatch = true + break + } + if !pMatch { continue } From ae8404d760b31e813e978f12d958d3519cd3455e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Apr 2020 23:32:20 +0100 Subject: [PATCH 650/788] Log listening port --- web/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/service.go b/web/service.go index 737f801b..5fca74de 100644 --- a/web/service.go +++ b/web/service.go @@ -226,7 +226,7 @@ func (s *service) start() error { ch <- l.Close() }() - if logger.V(logger.DebugLevel, log) { + if logger.V(logger.InfoLevel, log) { log.Debugf("Listening on %v", l.Addr().String()) } return nil From a08ff90976f7ec302e8b734e9a57483fa41537c7 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 18 Apr 2020 23:36:00 +0100 Subject: [PATCH 651/788] fix this bs logging issue --- web/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/service.go b/web/service.go index 5fca74de..069a53e2 100644 --- a/web/service.go +++ b/web/service.go @@ -227,7 +227,7 @@ func (s *service) start() error { }() if logger.V(logger.InfoLevel, log) { - log.Debugf("Listening on %v", l.Addr().String()) + log.Infof("Listening on %v", l.Addr().String()) } return nil } From 226d6ad22b6eecadf0b4344a5964cd7fd499bc90 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Apr 2020 00:41:03 +0100 Subject: [PATCH 652/788] log whats happening in http handler --- api/server/http/http.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/api/server/http/http.go b/api/server/http/http.go index 6615232d..518977e6 100644 --- a/api/server/http/http.go +++ b/api/server/http/http.go @@ -51,18 +51,22 @@ func (s *httpServer) Init(opts ...server.Option) error { } func (s *httpServer) Handle(path string, handler http.Handler) { - h := handlers.CombinedLoggingHandler(os.Stdout, handler) + // TODO: move this stuff out to one place with ServeHTTP // apply the wrappers, e.g. auth for _, wrapper := range s.opts.Wrappers { - h = wrapper(h) + handler = wrapper(handler) } + // wrap with cors if s.opts.EnableCORS { - h = cors.CombinedCORSHandler(h) + handler = cors.CombinedCORSHandler(handler) } - s.mux.Handle(path, h) + // wrap with logger + handler = handlers.CombinedLoggingHandler(os.Stdout, handler) + + s.mux.Handle(path, handler) } func (s *httpServer) Start() error { From ab041012b2c96c6b65f9d4524edd0838d8174754 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Apr 2020 00:44:52 +0100 Subject: [PATCH 653/788] Update readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index a39364a1..21ad71a8 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,12 @@ are pluggable and allows Go Micro to be runtime agnostic. You can plugin any und ## Getting Started +To make use of Go Micro + +``` +import "github.com/micro/go-micro/v2" + +service := micro.NewService() +``` + See the [docs](https://micro.mu/docs/framework.html) for detailed information on the architecture, installation and use of go-micro. From 6071b74fb5ffe3b1efd1550bcdd5d45f4f2a87ec Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Apr 2020 00:45:29 +0100 Subject: [PATCH 654/788] Update readme --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 21ad71a8..cb7c13d9 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,8 @@ are pluggable and allows Go Micro to be runtime agnostic. You can plugin any und To make use of Go Micro -``` +```golang import "github.com/micro/go-micro/v2" - -service := micro.NewService() ``` See the [docs](https://micro.mu/docs/framework.html) for detailed information on the architecture, installation and use of go-micro. From dde8f18b52d44bf14e86e805994bd61bb79b43e3 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Apr 2020 00:46:33 +0100 Subject: [PATCH 655/788] Update readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index cb7c13d9..2a396444 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,8 @@ import "github.com/micro/go-micro/v2" ``` See the [docs](https://micro.mu/docs/framework.html) for detailed information on the architecture, installation and use of go-micro. + +## License + +Go Micro is Apache 2.0 licensed + From 53db26a614376c9c91d1c1297c5d683011aff854 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Apr 2020 17:03:25 +0100 Subject: [PATCH 656/788] Use go.micro.mu --- network/resolver/http/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/resolver/http/http.go b/network/resolver/http/http.go index d0260609..0523232f 100644 --- a/network/resolver/http/http.go +++ b/network/resolver/http/http.go @@ -30,7 +30,7 @@ type Response struct { // Resolve assumes ID is a domain which can be converted to a http://name/network request func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) { proto := "https" - host := "api.micro.mu" + host := "go.micro.mu" path := "/network/nodes" if len(r.Proto) > 0 { From c4acf3c2cb9490b06ccb33d81a29d0e336af0ebe Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Apr 2020 20:30:38 +0100 Subject: [PATCH 657/788] Static serving disabled --- web/service.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/web/service.go b/web/service.go index 069a53e2..a06d7782 100644 --- a/web/service.go +++ b/web/service.go @@ -316,6 +316,13 @@ func (s *service) HandleFunc(pattern string, handler func(http.ResponseWriter, * }) } + // disable static serving + if pattern == "/" { + s.Lock() + s.static = false + s.Unlock() + } + s.mux.HandleFunc(pattern, handler) } From 7c31edd5f8456d6dd94f470320dc76863bf797b0 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Mon, 20 Apr 2020 15:54:29 +0200 Subject: [PATCH 658/788] Enabling default runtime to run multiple versions (#1545) * Enabling default runtime to run multiple versions * Trigger build * Fix * Sprintf --- runtime/default.go | 18 +++++++++++------- runtime/service.go | 5 +++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index 28e752a8..dff3a235 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -142,7 +142,7 @@ func (r *runtime) run(events <-chan Event) { case Update: if len(event.Service) > 0 { r.RLock() - service, ok := r.services[event.Service] + service, ok := r.services[fmt.Sprintf("%v:%v", event.Service, event.Version)] r.RUnlock() if !ok { if logger.V(logger.DebugLevel, logger.DefaultLogger) { @@ -187,12 +187,16 @@ func logFile(serviceName string) string { return filepath.Join(path, fmt.Sprintf("%v.log", name)) } +func serviceKey(s *Service) string { + return fmt.Sprintf("%v:%v", s.Name, s.Version) +} + // Create creates a new service which is then started by runtime func (r *runtime) Create(s *Service, opts ...CreateOption) error { r.Lock() defer r.Unlock() - if _, ok := r.services[s.Name]; ok { + if _, ok := r.services[serviceKey(s)]; ok { return errors.New("service already running") } @@ -225,7 +229,7 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error { } // save service - r.services[s.Name] = service + r.services[serviceKey(s)] = service return nil } @@ -333,7 +337,7 @@ func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) { // Update attemps to update the service func (r *runtime) Update(s *Service) error { r.Lock() - service, ok := r.services[s.Name] + service, ok := r.services[serviceKey(s)] r.Unlock() if !ok { return errors.New("Service not found") @@ -353,10 +357,10 @@ func (r *runtime) Delete(s *Service) error { if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Runtime deleting service %s", s.Name) } - if s, ok := r.services[s.Name]; ok { + if s, ok := r.services[serviceKey(s)]; ok { // check if running if s.Running() { - delete(r.services, s.Name) + delete(r.services, s.key()) return nil } // otherwise stop it @@ -364,7 +368,7 @@ func (r *runtime) Delete(s *Service) error { return err } // delete it - delete(r.services, s.Name) + delete(r.services, s.key()) return nil } diff --git a/runtime/service.go b/runtime/service.go index aa12061c..2733b01e 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -1,6 +1,7 @@ package runtime import ( + "fmt" "io" "strconv" "strings" @@ -76,6 +77,10 @@ func (s *service) shouldStart() bool { return s.retries <= s.maxRetries } +func (s *service) key() string { + return fmt.Sprintf("%v:%v", s.Name, s.Version) +} + func (s *service) ShouldStart() bool { s.RLock() defer s.RUnlock() From e5c215556e4dd36197154c205fd4d14283160814 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Tue, 21 Apr 2020 14:00:12 +0200 Subject: [PATCH 659/788] Add SIGKILL to shutdown signals (#1552) * Add SIGKILL to shutdown signals * go mod tidy * Add missing file --- server/server.go | 4 ++-- service.go | 4 ++-- util/signal/signal.go | 13 +++++++++++++ web/service.go | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 util/signal/signal.go diff --git a/server/server.go b/server/server.go index 7b121b70..a22e90d2 100644 --- a/server/server.go +++ b/server/server.go @@ -5,13 +5,13 @@ import ( "context" "os" "os/signal" - "syscall" "time" "github.com/google/uuid" "github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" + signalutil "github.com/micro/go-micro/v2/util/signal" ) // Server is a simple micro server abstraction @@ -200,7 +200,7 @@ func Run() error { } ch := make(chan os.Signal, 1) - signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT) + signal.Notify(ch, signalutil.ShutdownSignals()...) if logger.V(logger.InfoLevel, log) { log.Infof("Received signal %s", <-ch) } diff --git a/service.go b/service.go index 5b34f2ae..982d7e17 100644 --- a/service.go +++ b/service.go @@ -6,7 +6,6 @@ import ( "runtime" "strings" "sync" - "syscall" "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/client" @@ -18,6 +17,7 @@ import ( "github.com/micro/go-micro/v2/plugin" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/store" + signalutil "github.com/micro/go-micro/v2/util/signal" "github.com/micro/go-micro/v2/util/wrapper" ) @@ -210,7 +210,7 @@ func (s *service) Run() error { ch := make(chan os.Signal, 1) if s.opts.Signal { - signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT) + signal.Notify(ch, signalutil.ShutdownSignals()...) } select { diff --git a/util/signal/signal.go b/util/signal/signal.go new file mode 100644 index 00000000..1060dc1a --- /dev/null +++ b/util/signal/signal.go @@ -0,0 +1,13 @@ +package signal + +import ( + "os" + "syscall" +) + +// ShutDownSingals returns all the singals that are being watched for to shut down services. +func ShutdownSignals() []os.Signal { + return []os.Signal{ + syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGKILL, + } +} diff --git a/web/service.go b/web/service.go index a06d7782..73b203db 100644 --- a/web/service.go +++ b/web/service.go @@ -10,7 +10,6 @@ import ( "path/filepath" "strings" "sync" - "syscall" "time" "github.com/micro/cli/v2" @@ -20,6 +19,7 @@ import ( maddr "github.com/micro/go-micro/v2/util/addr" mhttp "github.com/micro/go-micro/v2/util/http" mnet "github.com/micro/go-micro/v2/util/net" + signalutil "github.com/micro/go-micro/v2/util/signal" mls "github.com/micro/go-micro/v2/util/tls" ) @@ -404,7 +404,7 @@ func (s *service) Run() error { ch := make(chan os.Signal, 1) if s.opts.Signal { - signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT) + signal.Notify(ch, signalutil.ShutdownSignals()...) } select { From 075d7d4fefe41e82bf4c09bf57559c6cccd3287f Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Tue, 21 Apr 2020 14:14:20 +0200 Subject: [PATCH 660/788] Renaming ShutdownSignals -> Shutdown (#1553) --- server/server.go | 3 ++- service.go | 2 +- util/signal/signal.go | 2 +- web/service.go | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/server.go b/server/server.go index a22e90d2..21e05e9f 100644 --- a/server/server.go +++ b/server/server.go @@ -200,7 +200,8 @@ func Run() error { } ch := make(chan os.Signal, 1) - signal.Notify(ch, signalutil.ShutdownSignals()...) + signal.Notify(ch, signalutil.Shutdown()...) + if logger.V(logger.InfoLevel, log) { log.Infof("Received signal %s", <-ch) } diff --git a/service.go b/service.go index 982d7e17..a49c696f 100644 --- a/service.go +++ b/service.go @@ -210,7 +210,7 @@ func (s *service) Run() error { ch := make(chan os.Signal, 1) if s.opts.Signal { - signal.Notify(ch, signalutil.ShutdownSignals()...) + signal.Notify(ch, signalutil.Shutdown()...) } select { diff --git a/util/signal/signal.go b/util/signal/signal.go index 1060dc1a..bb5b7492 100644 --- a/util/signal/signal.go +++ b/util/signal/signal.go @@ -6,7 +6,7 @@ import ( ) // ShutDownSingals returns all the singals that are being watched for to shut down services. -func ShutdownSignals() []os.Signal { +func Shutdown() []os.Signal { return []os.Signal{ syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGKILL, } diff --git a/web/service.go b/web/service.go index 73b203db..81895f08 100644 --- a/web/service.go +++ b/web/service.go @@ -404,7 +404,7 @@ func (s *service) Run() error { ch := make(chan os.Signal, 1) if s.opts.Signal { - signal.Notify(ch, signalutil.ShutdownSignals()...) + signal.Notify(ch, signalutil.Shutdown()...) } select { From 19f0836e7006926e1f11300bf3fb27d7eae036a3 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 21 Apr 2020 13:37:26 +0100 Subject: [PATCH 661/788] Add oauth login hint param --- auth/provider/oauth/oauth.go | 4 ++++ auth/provider/provider.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/auth/provider/oauth/oauth.go b/auth/provider/oauth/oauth.go index 45b79c8e..d04d7cf7 100644 --- a/auth/provider/oauth/oauth.go +++ b/auth/provider/oauth/oauth.go @@ -41,6 +41,10 @@ func (o *oauth) Endpoint(opts ...provider.EndpointOption) string { params.Add("state", options.State) } + if len(options.LoginHint) > 0 { + params.Add("login_hint", options.LoginHint) + } + if clientID := o.opts.ClientID; len(clientID) > 0 { params.Add("client_id", clientID) } diff --git a/auth/provider/provider.go b/auth/provider/provider.go index 26f80034..09e78bdf 100644 --- a/auth/provider/provider.go +++ b/auth/provider/provider.go @@ -28,7 +28,10 @@ type Grant struct { } type EndpointOptions struct { + // State is a code to verify the req State string + // LoginHint prefils the user id on oauth clients + LoginHint string } type EndpointOption func(*EndpointOptions) @@ -38,3 +41,9 @@ func WithState(c string) EndpointOption { o.State = c } } + +func WithLoginHint(hint string) EndpointOption { + return func(o *EndpointOptions) { + o.LoginHint = hint + } +} From 05d2b34e10110bd3d5c622ddba4aa49d93d8bc6f Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 21 Apr 2020 15:03:33 +0100 Subject: [PATCH 662/788] Add util/pki for creating and signing certificates (#1555) --- util/pki/certoptions.go | 85 +++++++++++++++++++++ util/pki/pki.go | 164 ++++++++++++++++++++++++++++++++++++++++ util/pki/pki_test.go | 90 ++++++++++++++++++++++ 3 files changed, 339 insertions(+) create mode 100644 util/pki/certoptions.go create mode 100644 util/pki/pki.go create mode 100644 util/pki/pki_test.go diff --git a/util/pki/certoptions.go b/util/pki/certoptions.go new file mode 100644 index 00000000..61026967 --- /dev/null +++ b/util/pki/certoptions.go @@ -0,0 +1,85 @@ +package pki + +import ( + "crypto/ed25519" + "crypto/x509" + "crypto/x509/pkix" + "math/big" + "net" + "time" +) + +// CertOptions are passed to cert options +type CertOptions struct { + IsCA bool + Subject pkix.Name + DNSNames []string + IPAddresses []net.IP + SerialNumber *big.Int + NotBefore time.Time + NotAfter time.Time + + Parent *x509.Certificate + Pub ed25519.PublicKey + Priv ed25519.PrivateKey +} + +// CertOption sets CertOptions +type CertOption func(c *CertOptions) + +// Subject sets the Subject field +func Subject(subject pkix.Name) CertOption { + return func(c *CertOptions) { + c.Subject = subject + } +} + +// IsCA states the cert is a CA +func IsCA() CertOption { + return func(c *CertOptions) { + c.IsCA = true + } +} + +// DNSNames is a list of hosts to sign in to the certificate +func DNSNames(names ...string) CertOption { + return func(c *CertOptions) { + c.DNSNames = names + } +} + +// IPAddresses is a list of IPs to sign in to the certificate +func IPAddresses(ips ...net.IP) CertOption { + return func(c *CertOptions) { + c.IPAddresses = ips + } +} + +// KeyPair is the key pair to sign the certificate with +func KeyPair(pub ed25519.PublicKey, priv ed25519.PrivateKey) CertOption { + return func(c *CertOptions) { + c.Pub = pub + c.Priv = priv + } +} + +// SerialNumber is the Certificate Serial number +func SerialNumber(serial *big.Int) CertOption { + return func(c *CertOptions) { + c.SerialNumber = serial + } +} + +// NotBefore is the time the certificate is not valid before +func NotBefore(time time.Time) CertOption { + return func(c *CertOptions) { + c.NotBefore = time + } +} + +// NotAfter is the time the certificate is not valid after +func NotAfter(time time.Time) CertOption { + return func(c *CertOptions) { + c.NotAfter = time + } +} diff --git a/util/pki/pki.go b/util/pki/pki.go new file mode 100644 index 00000000..c4ac6f96 --- /dev/null +++ b/util/pki/pki.go @@ -0,0 +1,164 @@ +// Package pki provides PKI all the PKI functions necessary to run micro over an untrusted network +// including a CA +package pki + +import ( + "bytes" + "crypto/ed25519" + "crypto/rand" + "crypto/x509" + "encoding/pem" + + "github.com/pkg/errors" +) + +// GenerateKey returns an ed25519 key +func GenerateKey() (ed25519.PublicKey, ed25519.PrivateKey, error) { + return ed25519.GenerateKey(rand.Reader) +} + +// CA generates a self signed CA and returns cert, key in PEM format +func CA(opts ...CertOption) ([]byte, []byte, error) { + opts = append(opts, IsCA()) + options := CertOptions{} + for _, o := range opts { + o(&options) + } + template := &x509.Certificate{ + SignatureAlgorithm: x509.PureEd25519, + Subject: options.Subject, + DNSNames: options.DNSNames, + IPAddresses: options.IPAddresses, + KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, + NotBefore: options.NotBefore, + NotAfter: options.NotAfter, + SerialNumber: options.SerialNumber, + BasicConstraintsValid: true, + } + if options.IsCA { + template.IsCA = true + template.KeyUsage |= x509.KeyUsageCertSign + } + x509Cert, err := x509.CreateCertificate(rand.Reader, template, template, options.Pub, options.Priv) + if err != nil { + return nil, nil, err + } + cert, key := &bytes.Buffer{}, &bytes.Buffer{} + if err := pem.Encode(cert, &pem.Block{Type: "CERTIFICATE", Bytes: x509Cert}); err != nil { + return nil, nil, err + } + x509Key, err := x509.MarshalPKCS8PrivateKey(options.Priv) + if err != nil { + return nil, nil, err + } + if err := pem.Encode(key, &pem.Block{Type: "PRIVATE KEY", Bytes: x509Key}); err != nil { + return nil, nil, err + } + + return cert.Bytes(), key.Bytes(), nil +} + +// CSR generates a certificate request in PEM format +func CSR(opts ...CertOption) ([]byte, error) { + options := CertOptions{} + for _, o := range opts { + o(&options) + } + csrTemplate := &x509.CertificateRequest{ + Subject: options.Subject, + SignatureAlgorithm: x509.PureEd25519, + DNSNames: options.DNSNames, + IPAddresses: options.IPAddresses, + } + out := &bytes.Buffer{} + csr, err := x509.CreateCertificateRequest(rand.Reader, csrTemplate, options.Priv) + if err != nil { + return nil, err + } + if err := pem.Encode(out, &pem.Block{Type: "CERTIFICATE REQUEST", Bytes: csr}); err != nil { + return nil, err + } + + return out.Bytes(), nil +} + +// Sign decodes a CSR and signs it with the CA +func Sign(CACrt, CAKey, CSR []byte, opts ...CertOption) ([]byte, error) { + options := CertOptions{} + for _, o := range opts { + o(&options) + } + asn1CACrt, err := decodePEM(CACrt) + if err != nil { + return nil, errors.Wrap(err, "failed to decode CA Crt PEM") + } + if len(asn1CACrt) != 1 { + return nil, errors.Errorf("expected 1 CA Crt, got %d", len(asn1CACrt)) + } + caCrt, err := x509.ParseCertificate(asn1CACrt[0].Bytes) + if err != nil { + return nil, errors.Wrap(err, "ca is not a valid certificate") + } + asn1CAKey, err := decodePEM(CAKey) + if err != nil { + return nil, errors.Wrap(err, "failed to decode CA Key PEM") + } + if len(asn1CAKey) != 1 { + return nil, errors.Errorf("expected 1 CA Key, got %d", len(asn1CACrt)) + } + caKey, err := x509.ParsePKCS8PrivateKey(asn1CAKey[0].Bytes) + if err != nil { + return nil, errors.Wrap(err, "ca key is not a valid private key") + } + asn1CSR, err := decodePEM(CSR) + if err != nil { + return nil, errors.Wrap(err, "failed to decode CSR PEM") + } + if len(asn1CSR) != 1 { + return nil, errors.Errorf("expected 1 CSR, got %d", len(asn1CSR)) + } + csr, err := x509.ParseCertificateRequest(asn1CSR[0].Bytes) + if err != nil { + return nil, errors.Wrap(err, "csr is invalid") + } + template := &x509.Certificate{ + SignatureAlgorithm: x509.PureEd25519, + Subject: csr.Subject, + DNSNames: csr.DNSNames, + IPAddresses: csr.IPAddresses, + KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, + NotBefore: options.NotBefore, + NotAfter: options.NotAfter, + SerialNumber: options.SerialNumber, + BasicConstraintsValid: true, + } + + x509Cert, err := x509.CreateCertificate(rand.Reader, template, caCrt, caCrt.PublicKey, caKey) + if err != nil { + return nil, errors.Wrap(err, "Couldn't sign certificate") + } + out := &bytes.Buffer{} + if err := pem.Encode(out, &pem.Block{Type: "CERTIFICATE", Bytes: x509Cert}); err != nil { + return nil, errors.Wrap(err, "couldn't encode cert") + } + return out.Bytes(), nil +} + +func decodePEM(PEM []byte) ([]*pem.Block, error) { + var blocks []*pem.Block + var asn1 *pem.Block + var rest []byte + for { + asn1, rest = pem.Decode(PEM) + if asn1 == nil { + return nil, errors.New("PEM is not valid") + } + blocks = append(blocks, asn1) + if len(rest) == 0 { + break + } + } + return blocks, nil +} diff --git a/util/pki/pki_test.go b/util/pki/pki_test.go new file mode 100644 index 00000000..67e81d13 --- /dev/null +++ b/util/pki/pki_test.go @@ -0,0 +1,90 @@ +package pki + +import ( + "crypto/ed25519" + "crypto/rand" + "crypto/x509" + "crypto/x509/pkix" + "encoding/pem" + "math/big" + "net" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestPrivateKey(t *testing.T) { + _, _, err := GenerateKey() + assert.NoError(t, err) +} + +func TestCA(t *testing.T) { + pub, priv, err := GenerateKey() + assert.NoError(t, err) + + serialNumberMax := new(big.Int).Lsh(big.NewInt(1), 128) + serialNumber, err := rand.Int(rand.Reader, serialNumberMax) + assert.NoError(t, err, "Couldn't generate serial") + + cert, key, err := CA( + KeyPair(pub, priv), + Subject(pkix.Name{ + Organization: []string{"test"}, + }), + DNSNames("localhost"), + IPAddresses(net.ParseIP("127.0.0.1")), + SerialNumber(serialNumber), + NotBefore(time.Now().Add(time.Minute*-1)), + NotAfter(time.Now().Add(time.Minute)), + ) + assert.NoError(t, err, "Couldn't sign CA") + asn1Key, _ := pem.Decode(key) + assert.NotNil(t, asn1Key, "Couldn't decode key") + assert.Equal(t, "PRIVATE KEY", asn1Key.Type) + decodedKey, err := x509.ParsePKCS8PrivateKey(asn1Key.Bytes) + assert.NoError(t, err, "Couldn't decode ASN1 Key") + assert.Equal(t, priv, decodedKey.(ed25519.PrivateKey)) + + pool := x509.NewCertPool() + assert.True(t, pool.AppendCertsFromPEM(cert), "Coudn't parse cert") + + asn1Cert, _ := pem.Decode(cert) + assert.NotNil(t, asn1Cert, "Couldn't parse pem cert") + x509cert, err := x509.ParseCertificate(asn1Cert.Bytes) + assert.NoError(t, err, "Couldn't parse asn1 cert") + chains, err := x509cert.Verify(x509.VerifyOptions{ + Roots: pool, + }) + assert.NoError(t, err, "Cert didn't verify") + assert.Len(t, chains, 1, "CA should have 1 cert in chain") +} + +func TestCSR(t *testing.T) { + pub, priv, err := GenerateKey() + assert.NoError(t, err) + csr, err := CSR( + Subject( + pkix.Name{ + CommonName: "testnode", + Organization: []string{"microtest"}, + OrganizationalUnit: []string{"super-testers"}, + }, + ), + DNSNames("localhost"), + IPAddresses(net.ParseIP("127.0.0.1")), + KeyPair(pub, priv), + ) + assert.NoError(t, err, "CSR couldn't be encoded") + + asn1csr, _ := pem.Decode(csr) + assert.NotNil(t, asn1csr) + decodedcsr, err := x509.ParseCertificateRequest(asn1csr.Bytes) + assert.NoError(t, err) + expected := pkix.Name{ + CommonName: "testnode", + Organization: []string{"microtest"}, + OrganizationalUnit: []string{"super-testers"}, + } + assert.Equal(t, decodedcsr.Subject.String(), expected.String()) +} From d7ecb58f6cf60d9bed319f8d6850241f13d24eea Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 21 Apr 2020 15:54:40 +0100 Subject: [PATCH 663/788] Add network proxying (#1556) * Add network proxying * go fmt --- client/grpc/grpc.go | 22 ++++----------------- client/rpc_client.go | 46 +++++++++----------------------------------- util/net/net.go | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 55 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 30dd97f8..d41d977e 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -6,7 +6,6 @@ import ( "crypto/tls" "fmt" "net" - "os" "strings" "sync/atomic" "time" @@ -20,6 +19,7 @@ import ( "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/config" + pnet "github.com/micro/go-micro/v2/util/net" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -74,27 +74,13 @@ func (g *grpcClient) secure(addr string) grpc.DialOption { } func (g *grpcClient) next(request client.Request, opts client.CallOptions) (selector.Next, error) { - service := request.Service() - - // get proxy - if prx := os.Getenv("MICRO_PROXY"); len(prx) > 0 { - // default name - if prx == "service" { - prx = "go.micro.proxy" - } - service = prx - } - - // get proxy address - if prx := os.Getenv("MICRO_PROXY_ADDRESS"); len(prx) > 0 { - opts.Address = []string{prx} - } + service, address, _ := pnet.Proxy(request.Service(), opts.Address) // return remote address - if len(opts.Address) > 0 { + if len(address) > 0 { return func() (*registry.Node, error) { return ®istry.Node{ - Address: opts.Address[0], + Address: address[0], }, nil }, nil } diff --git a/client/rpc_client.go b/client/rpc_client.go index ea68bfb2..19a18bdb 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -3,7 +3,6 @@ package client import ( "context" "fmt" - "os" "sync/atomic" "time" @@ -17,6 +16,7 @@ import ( "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/transport" "github.com/micro/go-micro/v2/util/buf" + "github.com/micro/go-micro/v2/util/net" "github.com/micro/go-micro/v2/util/pool" ) @@ -322,46 +322,18 @@ func (r *rpcClient) Options() Options { return r.opts } -// hasProxy checks if we have proxy set in the environment -func (r *rpcClient) hasProxy() bool { - // get proxy - if prx := os.Getenv("MICRO_PROXY"); len(prx) > 0 { - return true - } - - // get proxy address - if prx := os.Getenv("MICRO_PROXY_ADDRESS"); len(prx) > 0 { - return true - } - - return false -} - // next returns an iterator for the next nodes to call func (r *rpcClient) next(request Request, opts CallOptions) (selector.Next, error) { - service := request.Service() - - // get proxy - if prx := os.Getenv("MICRO_PROXY"); len(prx) > 0 { - // default name - if prx == "service" { - prx = "go.micro.proxy" - } - service = prx - } - - // get proxy address - if prx := os.Getenv("MICRO_PROXY_ADDRESS"); len(prx) > 0 { - opts.Address = []string{prx} - } + // try get the proxy + service, address, _ := net.Proxy(request.Service(), opts.Address) // return remote address - if len(opts.Address) > 0 { - nodes := make([]*registry.Node, len(opts.Address)) + if len(address) > 0 { + nodes := make([]*registry.Node, len(address)) - for i, address := range opts.Address { + for i, addr := range address { nodes[i] = ®istry.Node{ - Address: address, + Address: addr, // Set the protocol Metadata: map[string]string{ "protocol": "mucp", @@ -461,7 +433,7 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac retries := callOpts.Retries // disable retries when using a proxy - if r.hasProxy() { + if _, _, ok := net.Proxy(request.Service(), callOpts.Address); ok { retries = 0 } @@ -552,7 +524,7 @@ func (r *rpcClient) Stream(ctx context.Context, request Request, opts ...CallOpt retries := callOpts.Retries // disable retries when using a proxy - if r.hasProxy() { + if _, _, ok := net.Proxy(request.Service(), callOpts.Address); ok { retries = 0 } diff --git a/util/net/net.go b/util/net/net.go index 0ce674fa..6a18aca7 100644 --- a/util/net/net.go +++ b/util/net/net.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "net" + "os" "strconv" "strings" ) @@ -77,3 +78,40 @@ func Listen(addr string, fn func(string) (net.Listener, error)) (net.Listener, e // why are we here? return nil, fmt.Errorf("unable to bind to %s", addr) } + +// Proxy returns the proxy and the address if it exits +func Proxy(service string, address []string) (string, []string, bool) { + var hasProxy bool + + // get proxy + if prx := os.Getenv("MICRO_PROXY"); len(prx) > 0 { + // default name + if prx == "service" { + prx = "go.micro.proxy" + } + service = prx + hasProxy = true + } + + // get proxy address + if prx := os.Getenv("MICRO_PROXY_ADDRESS"); len(prx) > 0 { + address = []string{prx} + hasProxy = true + } + + if prx := os.Getenv("MICRO_NETWORK"); len(prx) > 0 { + // default name + if prx == "service" { + prx = "go.micro.network" + } + service = prx + hasProxy = true + } + + if prx := os.Getenv("MICRO_NEWORK_ADDRESS"); len(prx) > 0 { + address = []string{prx} + hasProxy = true + } + + return service, address, hasProxy +} From bea092f082ecfbd3fcfe82dee8bedc74b02b628e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 21 Apr 2020 23:01:59 +0300 Subject: [PATCH 664/788] server: set registered only after configuring subscribers (#1557) Signed-off-by: Vasiliy Tolstov --- server/grpc/grpc.go | 10 +++++----- server/rpc_server.go | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 393f4f99..449455f2 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -692,11 +692,6 @@ func (g *grpcServer) Register() error { g.Lock() defer g.Unlock() - if cacheService { - g.rsvc = service - } - g.registered = true - for sb := range g.subscribers { handler := g.createSubHandler(sb, g.opts) var opts []broker.SubscribeOption @@ -722,6 +717,11 @@ func (g *grpcServer) Register() error { g.subscribers[sb] = []broker.Subscriber{sub} } + g.registered = true + if cacheService { + g.rsvc = service + } + return nil } diff --git a/server/rpc_server.go b/server/rpc_server.go index 5bb5740d..659b257c 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -650,10 +650,6 @@ func (s *rpcServer) Register() error { s.Lock() defer s.Unlock() - if cacheService { - s.rsvc = service - } - s.registered = true // set what we're advertising s.opts.Advertise = addr @@ -693,6 +689,10 @@ func (s *rpcServer) Register() error { } s.subscribers[sb] = []broker.Subscriber{sub} } + if cacheService { + s.rsvc = service + } + s.registered = true return nil } From e25ab9f4ca284a06c64701515e3076fd3d47afb1 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 22 Apr 2020 10:44:34 +0100 Subject: [PATCH 665/788] Fix typo for proxy --- util/net/net.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/net/net.go b/util/net/net.go index 6a18aca7..00230647 100644 --- a/util/net/net.go +++ b/util/net/net.go @@ -108,7 +108,7 @@ func Proxy(service string, address []string) (string, []string, bool) { hasProxy = true } - if prx := os.Getenv("MICRO_NEWORK_ADDRESS"); len(prx) > 0 { + if prx := os.Getenv("MICRO_NETWORK_ADDRESS"); len(prx) > 0 { address = []string{prx} hasProxy = true } From e55c23164a62fa6356fc117fa0e9960648b6dcc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=97=AD?= <120582243@qq.com> Date: Wed, 22 Apr 2020 21:10:59 +0800 Subject: [PATCH 666/788] fix prealloc in trace (#1558) --- debug/trace/memory/memory.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug/trace/memory/memory.go b/debug/trace/memory/memory.go index 99e67c03..497cc1b6 100644 --- a/debug/trace/memory/memory.go +++ b/debug/trace/memory/memory.go @@ -24,7 +24,7 @@ func (t *Tracer) Read(opts ...trace.ReadOption) ([]*trace.Span, error) { sp := t.buffer.Get(t.buffer.Size()) - var spans []*trace.Span + spans := make([]*trace.Span, 0, len(sp)) for _, span := range sp { val := span.Value.(*trace.Span) From 6fa27373edc2175556ebb2010d2f9374873ded92 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 23 Apr 2020 11:08:09 +0300 Subject: [PATCH 667/788] bundle qson lib in util (#1561) * copy qson from https://github.com/joncalhoun/qson as author not want to maintain repo * latest code contains our fix to proper decode strings with escaped & symbol * replace package in api/handler/rpc Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 2 +- go.mod | 1 - go.sum | 2 - util/qson/LICENSE | 21 +++++ util/qson/README.md | 55 +++++++++++++ util/qson/merge.go | 34 ++++++++ util/qson/merge_test.go | 37 +++++++++ util/qson/qson.go | 154 ++++++++++++++++++++++++++++++++++++ util/qson/qson_test.go | 170 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 472 insertions(+), 4 deletions(-) create mode 100644 util/qson/LICENSE create mode 100644 util/qson/README.md create mode 100644 util/qson/merge.go create mode 100644 util/qson/merge_test.go create mode 100644 util/qson/qson.go create mode 100644 util/qson/qson_test.go diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 64f0cf48..542a9dd4 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -10,7 +10,6 @@ import ( "strings" jsonpatch "github.com/evanphx/json-patch/v5" - "github.com/joncalhoun/qson" "github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/api/handler" "github.com/micro/go-micro/v2/api/internal/proto" @@ -24,6 +23,7 @@ import ( "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/ctx" + "github.com/micro/go-micro/v2/util/qson" "github.com/oxtoacart/bpool" ) diff --git a/go.mod b/go.mod index f3ba49cd..05e82553 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,6 @@ require ( github.com/hpcloud/tail v1.0.0 github.com/imdario/mergo v0.3.8 github.com/jonboulle/clockwork v0.1.0 // indirect - github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 github.com/json-iterator/go v1.1.9 // indirect github.com/kr/pretty v0.1.0 github.com/lib/pq v1.3.0 diff --git a/go.sum b/go.sum index db9453b6..a204a929 100644 --- a/go.sum +++ b/go.sum @@ -238,8 +238,6 @@ github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJS github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= -github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 h1:lnrOS18wZBYrzdDmnUeg1OVk+kQ3rxG8mZWU89DpMIA= -github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1/go.mod h1:DFXrEwSRX0p/aSvxE21319menCBFeQO0jXpRj7LEZUA= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= diff --git a/util/qson/LICENSE b/util/qson/LICENSE new file mode 100644 index 00000000..3e4ba4f7 --- /dev/null +++ b/util/qson/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Jon Calhoun + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/util/qson/README.md b/util/qson/README.md new file mode 100644 index 00000000..ad76ced5 --- /dev/null +++ b/util/qson/README.md @@ -0,0 +1,55 @@ +# qson + +This is copy from https://github.com/joncalhoun/qson +As author says he is not acrivelly maintains the repo and not plan to do that. + +## Usage + +You can either turn a URL query param into a JSON byte array, or unmarshal that directly into a Go object. + +Transforming the URL query param into a JSON byte array: + +```go +import "github.com/joncalhoun/qson" + +func main() { + b, err := qson.ToJSON("bar%5Bone%5D%5Btwo%5D=2&bar[one][red]=112") + if err != nil { + panic(err) + } + fmt.Println(string(b)) + // Should output: {"bar":{"one":{"red":112,"two":2}}} +} +``` + +Or unmarshalling directly into a Go object using JSON struct tags: + +```go +import "github.com/joncalhoun/qson" + +type unmarshalT struct { + A string `json:"a"` + B unmarshalB `json:"b"` +} +type unmarshalB struct { + C int `json:"c"` +} + +func main() { + var out unmarshalT + query := "a=xyz&b[c]=456" + err := Unmarshal(&out, query) + if err != nil { + t.Error(err) + } + // out should equal + // unmarshalT{ + // A: "xyz", + // B: unmarshalB{ + // C: 456, + // }, + // } +} +``` + +To get a query string like in the two previous examples you can use the `RawQuery` field on the [net/url.URL](https://golang.org/pkg/net/url/#URL) type. diff --git a/util/qson/merge.go b/util/qson/merge.go new file mode 100644 index 00000000..64078078 --- /dev/null +++ b/util/qson/merge.go @@ -0,0 +1,34 @@ +package qson + +// merge merges a with b if they are either both slices +// or map[string]interface{} types. Otherwise it returns b. +func merge(a interface{}, b interface{}) interface{} { + switch aT := a.(type) { + case map[string]interface{}: + return mergeMap(aT, b.(map[string]interface{})) + case []interface{}: + return mergeSlice(aT, b.([]interface{})) + default: + return b + } +} + +// mergeMap merges a with b, attempting to merge any nested +// values in nested maps but eventually overwriting anything +// in a that can't be merged with whatever is in b. +func mergeMap(a map[string]interface{}, b map[string]interface{}) map[string]interface{} { + for bK, bV := range b { + if _, ok := a[bK]; ok { + a[bK] = merge(a[bK], bV) + } else { + a[bK] = bV + } + } + return a +} + +// mergeSlice merges a with b and returns the result. +func mergeSlice(a []interface{}, b []interface{}) []interface{} { + a = append(a, b...) + return a +} diff --git a/util/qson/merge_test.go b/util/qson/merge_test.go new file mode 100644 index 00000000..9a144db8 --- /dev/null +++ b/util/qson/merge_test.go @@ -0,0 +1,37 @@ +package qson + +import "testing" + +func TestMergeSlice(t *testing.T) { + a := []interface{}{"a"} + b := []interface{}{"b"} + actual := mergeSlice(a, b) + if len(actual) != 2 { + t.Errorf("Expected size to be 2.") + } + if actual[0] != "a" { + t.Errorf("Expected index 0 to have value a. Actual: %s", actual[0]) + } + if actual[1] != "b" { + t.Errorf("Expected index 1 to have value b. Actual: %s", actual[1]) + } +} + +func TestMergeMap(t *testing.T) { + a := map[string]interface{}{ + "a": "b", + } + b := map[string]interface{}{ + "b": "c", + } + actual := mergeMap(a, b) + if len(actual) != 2 { + t.Errorf("Expected size to be 2.") + } + if actual["a"] != "b" { + t.Errorf("Expected key \"a\" to have value b. Actual: %s", actual["a"]) + } + if actual["b"] != "c" { + t.Errorf("Expected key \"b\" to have value c. Actual: %s", actual["b"]) + } +} diff --git a/util/qson/qson.go b/util/qson/qson.go new file mode 100644 index 00000000..b3926167 --- /dev/null +++ b/util/qson/qson.go @@ -0,0 +1,154 @@ +// Package qson implmenets decoding of URL query params +// into JSON and Go values (using JSON struct tags). +// +// See https://golang.org/pkg/encoding/json/ for more +// details on JSON struct tags. +package qson + +import ( + "encoding/json" + "errors" + "net/url" + "regexp" + "strings" +) + +var ( + // ErrInvalidParam is returned when invalid data is provided to the ToJSON or Unmarshal function. + // Specifically, this will be returned when there is no equals sign present in the URL query parameter. + ErrInvalidParam error = errors.New("qson: invalid url query param provided") + + bracketSplitter *regexp.Regexp +) + +func init() { + bracketSplitter = regexp.MustCompile("\\[|\\]") +} + +// Unmarshal will take a dest along with URL +// query params and attempt to first turn the query params +// into JSON and then unmarshal those into the dest variable +// +// BUG(joncalhoun): If a URL query param value is something +// like 123 but is expected to be parsed into a string this +// will currently result in an error because the JSON +// transformation will assume this is intended to be an int. +// This should only affect the Unmarshal function and +// could likely be fixed, but someone will need to submit a +// PR if they want that fixed. +func Unmarshal(dst interface{}, query string) error { + b, err := ToJSON(query) + if err != nil { + return err + } + return json.Unmarshal(b, dst) +} + +// ToJSON will turn a query string like: +// cat=1&bar%5Bone%5D%5Btwo%5D=2&bar[one][red]=112 +// Into a JSON object with all the data merged as nicely as +// possible. Eg the example above would output: +// {"bar":{"one":{"two":2,"red":112}}} +func ToJSON(query string) ([]byte, error) { + var ( + builder interface{} = make(map[string]interface{}) + ) + params := strings.Split(query, "&") + for _, part := range params { + tempMap, err := queryToMap(part) + if err != nil { + return nil, err + } + builder = merge(builder, tempMap) + } + return json.Marshal(builder) +} + +// queryToMap turns something like a[b][c]=4 into +// map[string]interface{}{ +// "a": map[string]interface{}{ +// "b": map[string]interface{}{ +// "c": 4, +// }, +// }, +// } +func queryToMap(param string) (map[string]interface{}, error) { + rawKey, rawValue, err := splitKeyAndValue(param) + if err != nil { + return nil, err + } + rawValue, err = url.QueryUnescape(rawValue) + if err != nil { + return nil, err + } + rawKey, err = url.QueryUnescape(rawKey) + if err != nil { + return nil, err + } + + pieces := bracketSplitter.Split(rawKey, -1) + key := pieces[0] + + // If len==1 then rawKey has no [] chars and we can just + // decode this as key=value into {key: value} + if len(pieces) == 1 { + var value interface{} + // First we try parsing it as an int, bool, null, etc + err = json.Unmarshal([]byte(rawValue), &value) + if err != nil { + // If we got an error we try wrapping the value in + // quotes and processing it as a string + err = json.Unmarshal([]byte("\""+rawValue+"\""), &value) + if err != nil { + // If we can't decode as a string we return the err + return nil, err + } + } + return map[string]interface{}{ + key: value, + }, nil + } + + // If len > 1 then we have something like a[b][c]=2 + // so we need to turn this into {"a": {"b": {"c": 2}}} + // To do this we break our key into two pieces: + // a and b[c] + // and then we set {"a": queryToMap("b[c]", value)} + ret := make(map[string]interface{}, 0) + ret[key], err = queryToMap(buildNewKey(rawKey) + "=" + rawValue) + if err != nil { + return nil, err + } + + // When URL params have a set of empty brackets (eg a[]=1) + // it is assumed to be an array. This will get us the + // correct value for the array item and return it as an + // []interface{} so that it can be merged properly. + if pieces[1] == "" { + temp := ret[key].(map[string]interface{}) + ret[key] = []interface{}{temp[""]} + } + return ret, nil +} + +// buildNewKey will take something like: +// origKey = "bar[one][two]" +// pieces = [bar one two ] +// and return "one[two]" +func buildNewKey(origKey string) string { + pieces := bracketSplitter.Split(origKey, -1) + ret := origKey[len(pieces[0])+1:] + ret = ret[:len(pieces[1])] + ret[len(pieces[1])+1:] + return ret +} + +// splitKeyAndValue splits a URL param at the last equal +// sign and returns the two strings. If no equal sign is +// found, the ErrInvalidParam error is returned. +func splitKeyAndValue(param string) (string, string, error) { + li := strings.LastIndex(param, "=") + if li == -1 { + return "", "", ErrInvalidParam + } + return param[:li], param[li+1:], nil +} diff --git a/util/qson/qson_test.go b/util/qson/qson_test.go new file mode 100644 index 00000000..491fe0e7 --- /dev/null +++ b/util/qson/qson_test.go @@ -0,0 +1,170 @@ +package qson + +import ( + "fmt" + "testing" +) + +func ExampleUnmarshal() { + type Ex struct { + A string `json:"a"` + B struct { + C int `json:"c"` + } `json:"b"` + } + var ex Ex + if err := Unmarshal(&ex, "a=xyz&b[c]=456"); err != nil { + panic(err) + } + fmt.Printf("%+v\n", ex) + // Output: {A:xyz B:{C:456}} +} + +type unmarshalT struct { + A string `json:"a"` + B unmarshalB `json:"b"` +} +type unmarshalB struct { + C int `json:"c"` + D string `json:"D"` +} + +func TestUnmarshal(t *testing.T) { + query := "a=xyz&b[c]=456" + expected := unmarshalT{ + A: "xyz", + B: unmarshalB{ + C: 456, + }, + } + var actual unmarshalT + err := Unmarshal(&actual, query) + if err != nil { + t.Error(err) + } + if expected != actual { + t.Errorf("Expected: %+v Actual: %+v", expected, actual) + } +} + +func ExampleToJSON() { + b, err := ToJSON("a=xyz&b[c]=456") + if err != nil { + panic(err) + } + fmt.Printf(string(b)) + // Output: {"a":"xyz","b":{"c":456}} +} + +func TestToJSONNested(t *testing.T) { + query := "bar%5Bone%5D%5Btwo%5D=2&bar[one][red]=112" + expected := `{"bar":{"one":{"red":112,"two":2}}}` + actual, err := ToJSON(query) + if err != nil { + t.Error(err) + } + actualStr := string(actual) + if actualStr != expected { + t.Errorf("Expected: %s Actual: %s", expected, actualStr) + } +} + +func TestToJSONPlain(t *testing.T) { + query := "cat=1&dog=2" + expected := `{"cat":1,"dog":2}` + actual, err := ToJSON(query) + if err != nil { + t.Error(err) + } + actualStr := string(actual) + if actualStr != expected { + t.Errorf("Expected: %s Actual: %s", expected, actualStr) + } +} + +func TestToJSONSlice(t *testing.T) { + query := "cat[]=1&cat[]=34" + expected := `{"cat":[1,34]}` + actual, err := ToJSON(query) + if err != nil { + t.Error(err) + } + actualStr := string(actual) + if actualStr != expected { + t.Errorf("Expected: %s Actual: %s", expected, actualStr) + } +} + +func TestToJSONBig(t *testing.T) { + query := "distinct_id=763_1495187301909_3495×tamp=1495187523&event=product_add_cart¶ms%5BproductRefId%5D=8284563078¶ms%5Bapps%5D%5B%5D=precommend¶ms%5Bapps%5D%5B%5D=bsales¶ms%5Bsource%5D=item¶ms%5Boptions%5D%5Bsegment%5D=cart_recommendation¶ms%5Boptions%5D%5Btype%5D=up_sell¶ms%5BtimeExpire%5D=1495187599642¶ms%5Brecommend_system_product_source%5D=item¶ms%5Bproduct_id%5D=8284563078¶ms%5Bvariant_id%5D=27661944134¶ms%5Bsku%5D=00483332%20(black)¶ms%5Bsources%5D%5B%5D=product_recommendation¶ms%5Bcart_token%5D=dc2c336a009edf2762128e65806dfb1d¶ms%5Bquantity%5D=1¶ms%5Bnew_popup_upsell_mobile%5D=false¶ms%5BclientDevice%5D=desktop¶ms%5BclientIsMobile%5D=false¶ms%5BclientIsSmallScreen%5D=false¶ms%5Bnew_popup_crossell_mobile%5D=false&api_key=14c5b7dacea9157029265b174491d340" + expected := `{"api_key":"14c5b7dacea9157029265b174491d340","distinct_id":"763_1495187301909_3495","event":"product_add_cart","params":{"apps":["precommend","bsales"],"cart_token":"dc2c336a009edf2762128e65806dfb1d","clientDevice":"desktop","clientIsMobile":false,"clientIsSmallScreen":false,"new_popup_crossell_mobile":false,"new_popup_upsell_mobile":false,"options":{"segment":"cart_recommendation","type":"up_sell"},"productRefId":8284563078,"product_id":8284563078,"quantity":1,"recommend_system_product_source":"item","sku":"00483332 (black)","source":"item","sources":["product_recommendation"],"timeExpire":1495187599642,"variant_id":27661944134},"timestamp":1495187523}` + actual, err := ToJSON(query) + if err != nil { + t.Error(err) + } + actualStr := string(actual) + if actualStr != expected { + t.Errorf("Expected: %s Actual: %s", expected, actualStr) + } +} + +func TestToJSONDuplicateKey(t *testing.T) { + query := "cat=1&cat=2" + expected := `{"cat":2}` + actual, err := ToJSON(query) + if err != nil { + t.Error(err) + } + actualStr := string(actual) + if actualStr != expected { + t.Errorf("Expected: %s Actual: %s", expected, actualStr) + } +} + +func TestSplitKeyAndValue(t *testing.T) { + param := "a[dog][=cat]=123" + eKey, eValue := "a[dog][=cat]", "123" + aKey, aValue, err := splitKeyAndValue(param) + if err != nil { + t.Error(err) + } + if eKey != aKey { + t.Errorf("Keys do not match. Expected: %s Actual: %s", eKey, aKey) + } + if eValue != aValue { + t.Errorf("Values do not match. Expected: %s Actual: %s", eValue, aValue) + } +} + +func TestEncodedAmpersand(t *testing.T) { + query := "a=xyz&b[d]=ben%26jerry" + expected := unmarshalT{ + A: "xyz", + B: unmarshalB{ + D: "ben&jerry", + }, + } + var actual unmarshalT + err := Unmarshal(&actual, query) + if err != nil { + t.Error(err) + } + if expected != actual { + t.Errorf("Expected: %+v Actual: %+v", expected, actual) + } +} + +func TestEncodedAmpersand2(t *testing.T) { + query := "filter=parent%3Dflow12345%26request%3Dreq12345&meta.limit=20&meta.offset=0" + expected := map[string]interface{}{"filter": "parent=flow12345&request=req12345", "meta.limit": float64(20), "meta.offset": float64(0)} + actual := make(map[string]interface{}) + err := Unmarshal(&actual, query) + if err != nil { + t.Error(err) + } + for k, v := range actual { + if nv, ok := expected[k]; !ok || nv != v { + t.Errorf("Expected: %+v Actual: %+v", expected, actual) + } + } +} From 7345ce9192d9e5e0734457429a0436d106cea5d1 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 23 Apr 2020 11:24:39 +0100 Subject: [PATCH 668/788] change logging for service startup --- server/grpc/grpc.go | 24 ++++++++++++------------ server/rpc_server.go | 28 ++++++++++++++-------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 449455f2..3de2332f 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -672,8 +672,8 @@ func (g *grpcServer) Register() error { g.RUnlock() if !registered { - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) } } @@ -707,8 +707,8 @@ func (g *grpcServer) Register() error { opts = append(opts, broker.DisableAutoAck()) } - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Subscribing to topic: %s", sb.Topic()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Subscribing to topic: %s", sb.Topic()) } sub, err := config.Broker.Subscribe(sb.Topic(), handler, opts...) if err != nil { @@ -768,8 +768,8 @@ func (g *grpcServer) Deregister() error { Nodes: []*registry.Node{node}, } - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Deregistering node: %s", node.Id) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Deregistering node: %s", node.Id) } if err := config.Registry.Deregister(service); err != nil { return err @@ -787,8 +787,8 @@ func (g *grpcServer) Deregister() error { for sb, subs := range g.subscribers { for _, sub := range subs { - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Unsubscribing from topic: %s", sub.Topic()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Unsubscribing from topic: %s", sub.Topic()) } sub.Unsubscribe() } @@ -852,8 +852,8 @@ func (g *grpcServer) Start() error { return err } - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address()) } } @@ -930,8 +930,8 @@ func (g *grpcServer) Start() error { // close transport ch <- nil - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address()) } // disconnect broker if err := config.Broker.Disconnect(); err != nil { diff --git a/server/rpc_server.go b/server/rpc_server.go index 659b257c..f1ce3ebb 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -630,8 +630,8 @@ func (s *rpcServer) Register() error { s.RUnlock() if !registered { - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - log.Debugf("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + log.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) } } @@ -684,8 +684,8 @@ func (s *rpcServer) Register() error { if err != nil { return err } - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - log.Debugf("Subscribing to topic: %s", sub.Topic()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + log.Infof("Subscribing to topic: %s", sub.Topic()) } s.subscribers[sb] = []broker.Subscriber{sub} } @@ -745,8 +745,8 @@ func (s *rpcServer) Deregister() error { Nodes: []*registry.Node{node}, } - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - log.Debugf("Registry [%s] Deregistering node: %s", config.Registry.String(), node.Id) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + log.Infof("Registry [%s] Deregistering node: %s", config.Registry.String(), node.Id) } if err := config.Registry.Deregister(service); err != nil { return err @@ -770,8 +770,8 @@ func (s *rpcServer) Deregister() error { for sb, subs := range s.subscribers { for _, sub := range subs { - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - log.Debugf("Unsubscribing %s from topic: %s", node.Id, sub.Topic()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + log.Infof("Unsubscribing %s from topic: %s", node.Id, sub.Topic()) } sub.Unsubscribe() } @@ -798,8 +798,8 @@ func (s *rpcServer) Start() error { return err } - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - log.Debugf("Transport [%s] Listening on %s", config.Transport.String(), ts.Addr()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + log.Infof("Transport [%s] Listening on %s", config.Transport.String(), ts.Addr()) } // swap address @@ -818,8 +818,8 @@ func (s *rpcServer) Start() error { return err } - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - log.Debugf("Broker [%s] Connected to %s", bname, config.Broker.Address()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + log.Infof("Broker [%s] Connected to %s", bname, config.Broker.Address()) } // use RegisterCheck func before register @@ -940,8 +940,8 @@ func (s *rpcServer) Start() error { // close transport listener ch <- ts.Close() - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - log.Debugf("Broker [%s] Disconnected from %s", bname, config.Broker.Address()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + log.Infof("Broker [%s] Disconnected from %s", bname, config.Broker.Address()) } // disconnect the broker if err := config.Broker.Disconnect(); err != nil { From 501a6bf3ea7e6115689e00d5921a07114251d327 Mon Sep 17 00:00:00 2001 From: Micro Date: Thu, 23 Apr 2020 12:27:36 +0100 Subject: [PATCH 669/788] Add imagePullSecrets to PodSpec --- runtime/kubernetes/service.go | 3 +++ runtime/options.go | 9 +++++++++ util/kubernetes/client/templates.go | 5 +++++ util/kubernetes/client/types.go | 3 ++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index f04f9a14..cb53cb1d 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -38,6 +38,9 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kdeploy.Spec.Template.Metadata.Annotations = make(map[string]string) } + // set the image pull secrets + kdeploy.Spec.Template.PodSpec.ImagePullSecrets = c.ImagePullSecrets + // create if non existent if s.Metadata == nil { s.Metadata = make(map[string]string) diff --git a/runtime/options.go b/runtime/options.go index 3ae7f506..0c4589dd 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -66,6 +66,8 @@ type CreateOptions struct { Retries int // Specify the image to use Image string + // Specify secrets to use when pulling the image + ImagePullSecrets []string } // ReadOptions queries runtime services @@ -92,6 +94,13 @@ func CreateImage(img string) CreateOption { } } +// CreateImagePullSecret sets a secret to use +func CreateImagePullSecret(secret string) CreateOption { + return func(o *CreateOptions) { + o.ImagePullSecrets = append(o.ImagePullSecrets, secret) + } +} + // WithCommand specifies the command to execute func WithCommand(cmd ...string) CreateOption { return func(o *CreateOptions) { diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index feddfffc..874b9292 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -50,6 +50,11 @@ spec: {{- end }} {{- end }} spec: + imagePullSecrets: + {{- with .Spec.Template.PodSpec.ImagePullSecrets }} + {{- range . }} + - {{ . }} + {{ end }} containers: {{- with .Spec.Template.PodSpec.Containers }} {{- range . }} diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index c19fff1c..783462bf 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -93,7 +93,8 @@ type Metadata struct { // PodSpec is a pod type PodSpec struct { - Containers []Container `json:"containers"` + Containers []Container `json:"containers"` + ImagePullSecrets []string `json:"imagePullSecrets"` } // PodList From 053fa0e457758cf6f5c13709be4d967fc6dc4f9a Mon Sep 17 00:00:00 2001 From: Micro Date: Thu, 23 Apr 2020 12:38:00 +0100 Subject: [PATCH 670/788] Fix template syntax --- util/kubernetes/client/templates.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index 874b9292..d979a417 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -54,7 +54,8 @@ spec: {{- with .Spec.Template.PodSpec.ImagePullSecrets }} {{- range . }} - {{ . }} - {{ end }} + {{- end }} + {{- end }} containers: {{- with .Spec.Template.PodSpec.Containers }} {{- range . }} From 5e3262a62c529a6de0f54458df8a136642dcd6ac Mon Sep 17 00:00:00 2001 From: Micro Date: Thu, 23 Apr 2020 12:52:59 +0100 Subject: [PATCH 671/788] Passs img pull secrets using name key --- util/kubernetes/client/templates.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index d979a417..897811f6 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -53,7 +53,7 @@ spec: imagePullSecrets: {{- with .Spec.Template.PodSpec.ImagePullSecrets }} {{- range . }} - - {{ . }} + - name: "{{.}}" {{- end }} {{- end }} containers: From 316b81f790a57eeb3db7640fd278eb0baa6688f0 Mon Sep 17 00:00:00 2001 From: Micro Date: Thu, 23 Apr 2020 13:11:00 +0100 Subject: [PATCH 672/788] Debugging --- runtime/kubernetes/service.go | 2 ++ util/kubernetes/client/templates.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index cb53cb1d..8118c08a 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -2,6 +2,7 @@ package kubernetes import ( "encoding/json" + "fmt" "strings" "github.com/micro/go-micro/v2/logger" @@ -40,6 +41,7 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { // set the image pull secrets kdeploy.Spec.Template.PodSpec.ImagePullSecrets = c.ImagePullSecrets + fmt.Printf("Setting ImagePullSecrets to %v\n", strings.Join(c.ImagePullSecrets, ", ")) // create if non existent if s.Metadata == nil { diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index 897811f6..dcd08d56 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -53,7 +53,7 @@ spec: imagePullSecrets: {{- with .Spec.Template.PodSpec.ImagePullSecrets }} {{- range . }} - - name: "{{.}}" + - name: "{{.}}" {{- end }} {{- end }} containers: From 692b27578cbaa3c84162bfd25a61ff415c550ec3 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Thu, 23 Apr 2020 13:53:42 +0100 Subject: [PATCH 673/788] Runtime Namespace (#1547) * Add context option to runtime; Add dynamic namespace to kubectl client * Add namespace runtime arg * Fixes & Debugging * Pass options in k8s runtime * Set namespace on k8s resources * Additional Logging * More debugging * Remove Debugging * Ensure namespace exists * Add debugging * Refactor namespaceExists check * Fix * Fix * Fix * Fix * Change the way we check for namespace * Fix * Tidying Up * Fix Test * Fix merge bugs * Serialize k8s namespaces * Add namespace to watch * Serialize namespace when creating k8s namespace Co-authored-by: Ben Toogood Co-authored-by: Asim Aslam --- debug/log/kubernetes/kubernetes.go | 2 +- runtime/default.go | 4 +- runtime/kubernetes/kubernetes.go | 111 ++++++++++++++++++++------ runtime/kubernetes/kubernetes_logs.go | 2 +- runtime/kubernetes/service.go | 22 ++--- runtime/options.go | 101 +++++++++++++++++++++++ runtime/runtime.go | 4 +- runtime/service/proto/runtime.proto | 14 ++-- runtime/service/service.go | 52 +++++++++--- util/kubernetes/api/request.go | 7 +- util/kubernetes/client/client.go | 106 ++++++++++++++---------- util/kubernetes/client/options.go | 85 +++++++++++++++++++- util/kubernetes/client/types.go | 5 ++ util/kubernetes/client/util_test.go | 5 +- 14 files changed, 411 insertions(+), 109 deletions(-) diff --git a/debug/log/kubernetes/kubernetes.go b/debug/log/kubernetes/kubernetes.go index d81aba23..cf886d06 100644 --- a/debug/log/kubernetes/kubernetes.go +++ b/debug/log/kubernetes/kubernetes.go @@ -67,7 +67,7 @@ func (k *klog) getMatchingPods() ([]string, error) { // TODO: specify micro:service // l["micro"] = "service" - if err := k.client.Get(r, l); err != nil { + if err := k.client.Get(r, client.GetLabels(l)); err != nil { return nil, err } diff --git a/runtime/default.go b/runtime/default.go index dff3a235..8ac00bb9 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -335,7 +335,7 @@ func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) { } // Update attemps to update the service -func (r *runtime) Update(s *Service) error { +func (r *runtime) Update(s *Service, opts ...UpdateOption) error { r.Lock() service, ok := r.services[serviceKey(s)] r.Unlock() @@ -350,7 +350,7 @@ func (r *runtime) Update(s *Service) error { } // Delete removes the service from the runtime and stops it -func (r *runtime) Delete(s *Service) error { +func (r *runtime) Delete(s *Service, opts ...DeleteOption) error { r.Lock() defer r.Unlock() diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 7adbd301..d4e5eaee 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/micro/go-micro/v2/logger" + log "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/util/kubernetes/client" ) @@ -24,11 +24,48 @@ type kubernetes struct { closed chan bool // client is kubernetes client client client.Client + // namespaces which exist + namespaces []client.Namespace +} + +// namespaceExists returns a boolean indicating if a namespace exists +func (k *kubernetes) namespaceExists(name string) (bool, error) { + // populate the cache + if k.namespaces == nil { + namespaceList := new(client.NamespaceList) + resource := &client.Resource{Kind: "namespace", Value: namespaceList} + if err := k.client.List(resource); err != nil { + return false, err + } + k.namespaces = namespaceList.Items + } + + // check if the namespace exists in the cache + for _, n := range k.namespaces { + if n.Metadata.Name == name { + return true, nil + } + } + + return false, nil +} + +// createNamespace creates a new k8s namespace +func (k *kubernetes) createNamespace(namespace string) error { + ns := client.Namespace{Metadata: &client.Metadata{Name: namespace}} + err := k.client.Create(&client.Resource{Kind: "namespace", Value: ns}) + + // add to cache + if err == nil && k.namespaces != nil { + k.namespaces = append(k.namespaces, ns) + } + + return err } // getService queries kubernetes for micro service // NOTE: this function is not thread-safe -func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { +func (k *kubernetes) getService(labels map[string]string, opts ...client.GetOption) ([]*service, error) { // get the service status serviceList := new(client.ServiceList) r := &client.Resource{ @@ -36,8 +73,10 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { Value: serviceList, } + opts = append(opts, client.GetLabels(labels)) + // get the service from k8s - if err := k.client.Get(r, labels); err != nil { + if err := k.client.Get(r, opts...); err != nil { return nil, err } @@ -47,7 +86,7 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { Kind: "deployment", Value: depList, } - if err := k.client.Get(d, labels); err != nil { + if err := k.client.Get(d, opts...); err != nil { return nil, err } @@ -57,7 +96,7 @@ func (k *kubernetes) getService(labels map[string]string) ([]*service, error) { Kind: "pod", Value: podList, } - if err := k.client.Get(p, labels); err != nil { + if err := k.client.Get(p, opts...); err != nil { return nil, err } @@ -206,8 +245,8 @@ func (k *kubernetes) run(events <-chan runtime.Event) { // - do we even need the ticker for k8s services? case event := <-events: // NOTE: we only handle Update events for now - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime received notification event: %v", event) + if log.V(log.DebugLevel, log.DefaultLogger) { + log.Debugf("Runtime received notification event: %v", event) } switch event.Type { case runtime.Update: @@ -237,11 +276,11 @@ func (k *kubernetes) run(events <-chan runtime.Event) { err := k.client.Get(&client.Resource{ Kind: "deployment", Value: deployed, - }, labels) + }, client.GetLabels(labels)) if err != nil { - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime update failed to get service %s: %v", event.Service, err) + if log.V(log.DebugLevel, log.DefaultLogger) { + log.Debugf("Runtime update failed to get service %s: %v", event.Service, err) } continue } @@ -262,20 +301,20 @@ func (k *kubernetes) run(events <-chan runtime.Event) { // update the build time service.Spec.Template.Metadata.Annotations["updated"] = fmt.Sprintf("%d", event.Timestamp.Unix()) - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime updating service: %s deployment: %s", event.Service, service.Metadata.Name) + if log.V(log.DebugLevel, log.DefaultLogger) { + log.Debugf("Runtime updating service: %s deployment: %s", event.Service, service.Metadata.Name) } if err := k.client.Update(deploymentResource(&service)); err != nil { - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime failed to update service %s: %v", event.Service, err) + if log.V(log.DebugLevel, log.DefaultLogger) { + log.Debugf("Runtime failed to update service %s: %v", event.Service, err) } continue } } } case <-k.closed: - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime stopped") + if log.V(log.DebugLevel, log.DefaultLogger) { + log.Debugf("Runtime stopped") } return } @@ -305,7 +344,7 @@ func (k *kubernetes) Logs(s *runtime.Service, options ...runtime.LogsOption) (ru go func() { records, err := klo.Read() if err != nil { - logger.Errorf("Failed to get logs for service '%v' from k8s: %v", err) + log.Errorf("Failed to get logs for service '%v' from k8s: %v", err) return } // @todo: this might actually not run before podLogStream starts @@ -371,6 +410,16 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er s.Source = k.options.Source } + // ensure the namespace exists + namespace := client.SerializeResourceName(options.Namespace) + if exist, err := k.namespaceExists(namespace); err == nil && !exist { + if err := k.createNamespace(namespace); err != nil { + return err + } + } else if err != nil { + return err + } + // determine the image from the source and options options.Image = k.getImage(s, options) @@ -378,7 +427,7 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er service := newService(s, options) // start the service - return service.Start(k.client) + return service.Start(k.client, client.CreateNamespace(options.Namespace)) } // Read returns all instances of given service @@ -423,8 +472,12 @@ func (k *kubernetes) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error } // Update the service in place -func (k *kubernetes) Update(s *runtime.Service) error { - // TODO: set the type +func (k *kubernetes) Update(s *runtime.Service, opts ...runtime.UpdateOption) error { + var options runtime.UpdateOptions + for _, o := range opts { + o(&options) + } + labels := map[string]string{} if len(s.Name) > 0 { @@ -459,7 +512,7 @@ func (k *kubernetes) Update(s *runtime.Service) error { service.kdeploy.Spec.Template.Metadata.Annotations["updated"] = fmt.Sprintf("%d", time.Now().Unix()) // update the service - if err := service.Update(k.client); err != nil { + if err := service.Update(k.client, client.UpdateNamespace(options.Namespace)); err != nil { return err } } @@ -468,16 +521,22 @@ func (k *kubernetes) Update(s *runtime.Service) error { } // Delete removes a service -func (k *kubernetes) Delete(s *runtime.Service) error { +func (k *kubernetes) Delete(s *runtime.Service, opts ...runtime.DeleteOption) error { + var options runtime.DeleteOptions + for _, o := range opts { + o(&options) + } + k.Lock() defer k.Unlock() // create new kubernetes micro service service := newService(s, runtime.CreateOptions{ - Type: k.options.Type, + Type: k.options.Type, + Namespace: options.Namespace, }) - return service.Stop(k.client) + return service.Stop(k.client, client.DeleteNamespace(options.Namespace)) } // Start starts the runtime @@ -500,8 +559,8 @@ func (k *kubernetes) Start() error { events, err = k.options.Scheduler.Notify() if err != nil { // TODO: should we bail here? - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime failed to start update notifier") + if log.V(log.DebugLevel, log.DefaultLogger) { + log.Debugf("Runtime failed to start update notifier") } } } diff --git a/runtime/kubernetes/kubernetes_logs.go b/runtime/kubernetes/kubernetes_logs.go index 3600170b..0c113f4e 100644 --- a/runtime/kubernetes/kubernetes_logs.go +++ b/runtime/kubernetes/kubernetes_logs.go @@ -70,7 +70,7 @@ func (k *klog) getMatchingPods() ([]string, error) { // TODO: specify micro:service // l["micro"] = "service" - if err := k.client.Get(r, l); err != nil { + if err := k.client.Get(r, client.GetLabels(l)); err != nil { return nil, err } diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index f04f9a14..b3c02395 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -30,8 +30,8 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { name := client.Format(s.Name) version := client.Format(s.Version) - kservice := client.NewService(name, version, c.Type) - kdeploy := client.NewDeployment(name, version, c.Type) + kservice := client.NewService(name, version, c.Type, c.Namespace) + kdeploy := client.NewDeployment(name, version, c.Type, c.Namespace) // ensure the metadata is set if kdeploy.Spec.Template.Metadata.Annotations == nil { @@ -112,9 +112,9 @@ func serviceResource(s *client.Service) *client.Resource { } // Start starts the Kubernetes service. It creates new kubernetes deployment and service API objects -func (s *service) Start(k client.Client) error { +func (s *service) Start(k client.Client, opts ...client.CreateOption) error { // create deployment first; if we fail, we dont create service - if err := k.Create(deploymentResource(s.kdeploy)); err != nil { + if err := k.Create(deploymentResource(s.kdeploy), opts...); err != nil { if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Runtime failed to create deployment: %v", err) } @@ -126,7 +126,7 @@ func (s *service) Start(k client.Client) error { return err } // create service now that the deployment has been created - if err := k.Create(serviceResource(s.kservice)); err != nil { + if err := k.Create(serviceResource(s.kservice), opts...); err != nil { if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Runtime failed to create service: %v", err) } @@ -143,9 +143,9 @@ func (s *service) Start(k client.Client) error { return nil } -func (s *service) Stop(k client.Client) error { +func (s *service) Stop(k client.Client, opts ...client.DeleteOption) error { // first attempt to delete service - if err := k.Delete(serviceResource(s.kservice)); err != nil { + if err := k.Delete(serviceResource(s.kservice), opts...); err != nil { if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Runtime failed to delete service: %v", err) } @@ -153,7 +153,7 @@ func (s *service) Stop(k client.Client) error { return err } // delete deployment once the service has been deleted - if err := k.Delete(deploymentResource(s.kdeploy)); err != nil { + if err := k.Delete(deploymentResource(s.kdeploy), opts...); err != nil { if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Runtime failed to delete deployment: %v", err) } @@ -166,15 +166,15 @@ func (s *service) Stop(k client.Client) error { return nil } -func (s *service) Update(k client.Client) error { - if err := k.Update(deploymentResource(s.kdeploy)); err != nil { +func (s *service) Update(k client.Client, opts ...client.UpdateOption) error { + if err := k.Update(deploymentResource(s.kdeploy), opts...); err != nil { if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Runtime failed to update deployment: %v", err) } s.Status("error", err) return err } - if err := k.Update(serviceResource(s.kservice)); err != nil { + if err := k.Update(serviceResource(s.kservice), opts...); err != nil { if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Runtime failed to update service: %v", err) } diff --git a/runtime/options.go b/runtime/options.go index 3ae7f506..d7d9fe90 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -1,6 +1,7 @@ package runtime import ( + "context" "io" ) @@ -66,6 +67,10 @@ type CreateOptions struct { Retries int // Specify the image to use Image string + // Namespace to create the service in + Namespace string + // Specify the context to use + Context context.Context } // ReadOptions queries runtime services @@ -76,6 +81,10 @@ type ReadOptions struct { Version string // Type of service Type string + // Namespace the service is running in + Namespace string + // Specify the context to use + Context context.Context } // CreateType sets the type of service to create @@ -92,6 +101,20 @@ func CreateImage(img string) CreateOption { } } +// CreateNamespace sets the namespace +func CreateNamespace(ns string) CreateOption { + return func(o *CreateOptions) { + o.Namespace = ns + } +} + +// CreateContext sets the context +func CreateContext(ctx context.Context) CreateOption { + return func(o *CreateOptions) { + o.Context = ctx + } +} + // WithCommand specifies the command to execute func WithCommand(cmd ...string) CreateOption { return func(o *CreateOptions) { @@ -150,6 +173,66 @@ func ReadType(t string) ReadOption { } } +// ReadNamespace sets the namespace +func ReadNamespace(ns string) ReadOption { + return func(o *ReadOptions) { + o.Namespace = ns + } +} + +// ReadContext sets the context +func ReadContext(ctx context.Context) ReadOption { + return func(o *ReadOptions) { + o.Context = ctx + } +} + +type UpdateOption func(o *UpdateOptions) + +type UpdateOptions struct { + // Namespace the service is running in + Namespace string + // Specify the context to use + Context context.Context +} + +// UpdateNamespace sets the namespace +func UpdateNamespace(ns string) UpdateOption { + return func(o *UpdateOptions) { + o.Namespace = ns + } +} + +// UpdateContext sets the context +func UpdateContext(ctx context.Context) UpdateOption { + return func(o *UpdateOptions) { + o.Context = ctx + } +} + +type DeleteOption func(o *DeleteOptions) + +type DeleteOptions struct { + // Namespace the service is running in + Namespace string + // Specify the context to use + Context context.Context +} + +// DeleteNamespace sets the namespace +func DeleteNamespace(ns string) DeleteOption { + return func(o *DeleteOptions) { + o.Namespace = ns + } +} + +// DeleteContext sets the context +func DeleteContext(ctx context.Context) DeleteOption { + return func(o *DeleteOptions) { + o.Context = ctx + } +} + // LogsOption configures runtime logging type LogsOption func(o *LogsOptions) @@ -159,6 +242,10 @@ type LogsOptions struct { Count int64 // Stream new lines? Stream bool + // Namespace the service is running in + Namespace string + // Specify the context to use + Context context.Context } // LogsExistingCount confiures how many existing lines to show @@ -174,3 +261,17 @@ func LogsStream(stream bool) LogsOption { l.Stream = stream } } + +// LogsNamespace sets the namespace +func LogsNamespace(ns string) LogsOption { + return func(o *LogsOptions) { + o.Namespace = ns + } +} + +// LogsContext sets the context +func LogsContext(ctx context.Context) LogsOption { + return func(o *LogsOptions) { + o.Context = ctx + } +} diff --git a/runtime/runtime.go b/runtime/runtime.go index 2df1530c..567e8c3b 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -24,9 +24,9 @@ type Runtime interface { // Read returns the service Read(...ReadOption) ([]*Service, error) // Update the service in place - Update(*Service) error + Update(*Service, ...UpdateOption) error // Remove a service - Delete(*Service) error + Delete(*Service, ...DeleteOption) error // Logs returns the logs for a service Logs(*Service, ...LogsOption) (LogStream, error) // Start starts the runtime diff --git a/runtime/service/proto/runtime.proto b/runtime/service/proto/runtime.proto index 65c2c497..6c7033c9 100644 --- a/runtime/service/proto/runtime.proto +++ b/runtime/service/proto/runtime.proto @@ -60,11 +60,11 @@ message ReadOptions { } message ReadRequest { - ReadOptions options = 1; + ReadOptions options = 1; } message ReadResponse { - repeated Service services = 1; + repeated Service services = 1; } message DeleteRequest { @@ -100,10 +100,10 @@ message LogsRequest{ message LogRecord { // timestamp of log record - int64 timestamp = 1; - // record metadata - map metadata = 2; - // message - string message = 3; + int64 timestamp = 1; + // record metadata + map metadata = 2; + // message + string message = 3; } diff --git a/runtime/service/service.go b/runtime/service/service.go index d065038c..06cfc2ad 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -30,11 +30,13 @@ func (s *svc) Init(opts ...runtime.Option) error { // Create registers a service in the runtime func (s *svc) Create(svc *runtime.Service, opts ...runtime.CreateOption) error { - options := runtime.CreateOptions{} - // apply requested options + var options runtime.CreateOptions for _, o := range opts { o(&options) } + if options.Context == nil { + options.Context = context.Background() + } // set the default source from MICRO_RUNTIME_SOURCE if len(svc.Source) == 0 { @@ -58,15 +60,23 @@ func (s *svc) Create(svc *runtime.Service, opts ...runtime.CreateOption) error { }, } - if _, err := s.runtime.Create(context.Background(), req); err != nil { + if _, err := s.runtime.Create(options.Context, req); err != nil { return err } return nil } -func (s *svc) Logs(service *runtime.Service, options ...runtime.LogsOption) (runtime.LogStream, error) { - ls, err := s.runtime.Logs(context.Background(), &pb.LogsRequest{ +func (s *svc) Logs(service *runtime.Service, opts ...runtime.LogsOption) (runtime.LogStream, error) { + var options runtime.LogsOptions + for _, o := range opts { + o(&options) + } + if options.Context == nil { + options.Context = context.Background() + } + + ls, err := s.runtime.Logs(options.Context, &pb.LogsRequest{ Service: service.Name, Stream: true, Count: 10, // @todo pass in actual options @@ -122,11 +132,13 @@ func (l *serviceLogStream) Stop() error { // Read returns the service with the given name from the runtime func (s *svc) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error) { - options := runtime.ReadOptions{} - // apply requested options + var options runtime.ReadOptions for _, o := range opts { o(&options) } + if options.Context == nil { + options.Context = context.Background() + } // runtime service create request req := &pb.ReadRequest{ @@ -137,7 +149,7 @@ func (s *svc) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error) { }, } - resp, err := s.runtime.Read(context.Background(), req) + resp, err := s.runtime.Read(options.Context, req) if err != nil { return nil, err } @@ -157,7 +169,15 @@ func (s *svc) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error) { } // Update updates the running service -func (s *svc) Update(svc *runtime.Service) error { +func (s *svc) Update(svc *runtime.Service, opts ...runtime.UpdateOption) error { + var options runtime.UpdateOptions + for _, o := range opts { + o(&options) + } + if options.Context == nil { + options.Context = context.Background() + } + // runtime service create request req := &pb.UpdateRequest{ Service: &pb.Service{ @@ -168,7 +188,7 @@ func (s *svc) Update(svc *runtime.Service) error { }, } - if _, err := s.runtime.Update(context.Background(), req); err != nil { + if _, err := s.runtime.Update(options.Context, req); err != nil { return err } @@ -176,7 +196,15 @@ func (s *svc) Update(svc *runtime.Service) error { } // Delete stops and removes the service from the runtime -func (s *svc) Delete(svc *runtime.Service) error { +func (s *svc) Delete(svc *runtime.Service, opts ...runtime.DeleteOption) error { + var options runtime.DeleteOptions + for _, o := range opts { + o(&options) + } + if options.Context == nil { + options.Context = context.Background() + } + // runtime service create request req := &pb.DeleteRequest{ Service: &pb.Service{ @@ -187,7 +215,7 @@ func (s *svc) Delete(svc *runtime.Service) error { }, } - if _, err := s.runtime.Delete(context.Background(), req); err != nil { + if _, err := s.runtime.Delete(options.Context, req); err != nil { return err } diff --git a/util/kubernetes/api/request.go b/util/kubernetes/api/request.go index 89b429b7..e5a96509 100644 --- a/util/kubernetes/api/request.go +++ b/util/kubernetes/api/request.go @@ -75,7 +75,9 @@ func (r *Request) Delete() *Request { // Namespace is to set the namespace to operate on func (r *Request) Namespace(s string) *Request { - r.namespace = s + if len(s) > 0 { + r.namespace = s + } return r } @@ -158,6 +160,9 @@ func (r *Request) SetHeader(key, value string) *Request { func (r *Request) request() (*http.Request, error) { var url string switch r.resource { + case "namespace": + // /api/v1/namespaces/ + url = fmt.Sprintf("%s/api/v1/namespaces/", r.host) case "pod", "service", "endpoint": // /api/v1/namespaces/{namespace}/pods url = fmt.Sprintf("%s/api/v1/namespaces/%s/%ss/", r.host, r.namespace, r.resource) diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index e3cfc110..6b579777 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -10,6 +10,7 @@ import ( "net/http" "os" "path" + "regexp" "strings" "github.com/micro/go-micro/v2/logger" @@ -23,6 +24,8 @@ var ( ErrReadNamespace = errors.New("Could not read namespace from service account secret") // DefaultImage is default micro image DefaultImage = "micro/go-micro" + // DefaultNamespace is the default k8s namespace + DefaultNamespace = "default" ) // Client ... @@ -33,41 +36,28 @@ type client struct { // Kubernetes client type Client interface { // Create creates new API resource - Create(*Resource) error + Create(*Resource, ...CreateOption) error // Get queries API resrouces - Get(*Resource, map[string]string) error + Get(*Resource, ...GetOption) error // Update patches existing API object - Update(*Resource) error + Update(*Resource, ...UpdateOption) error // Delete deletes API resource - Delete(*Resource) error + Delete(*Resource, ...DeleteOption) error // List lists API resources - List(*Resource) error + List(*Resource, ...ListOption) error // Log gets log for a pod Log(*Resource, ...LogOption) (io.ReadCloser, error) // Watch for events Watch(*Resource, ...WatchOption) (Watcher, error) } -func detectNamespace() (string, error) { - nsPath := path.Join(serviceAccountPath, "namespace") - - // Make sure it's a file and we can read it - if s, e := os.Stat(nsPath); e != nil { - return "", e - } else if s.IsDir() { - return "", ErrReadNamespace - } - - // Read the file, and cast to a string - if ns, e := ioutil.ReadFile(nsPath); e != nil { - return string(ns), e - } else { - return string(ns), nil - } -} - // Create creates new API object -func (c *client) Create(r *Resource) error { +func (c *client) Create(r *Resource, opts ...CreateOption) error { + var options CreateOptions + for _, o := range opts { + o(&options) + } + b := new(bytes.Buffer) if err := renderTemplate(r.Kind, b, r.Value); err != nil { return err @@ -76,18 +66,35 @@ func (c *client) Create(r *Resource) error { return api.NewRequest(c.opts). Post(). SetHeader("Content-Type", "application/yaml"). + Namespace(options.Namespace). Resource(r.Kind). Body(b). Do(). Error() } +var ( + nameRegex = regexp.MustCompile("[^a-zA-Z0-9]+") +) + +// SerializeResourceName removes all spacial chars from a string so it +// can be used as a k8s resource name +func SerializeResourceName(ns string) string { + return nameRegex.ReplaceAllString(ns, "-") +} + // Get queries API objects and stores the result in r -func (c *client) Get(r *Resource, labels map[string]string) error { +func (c *client) Get(r *Resource, opts ...GetOption) error { + var options GetOptions + for _, o := range opts { + o(&options) + } + return api.NewRequest(c.opts). Get(). Resource(r.Kind). - Params(&api.Params{LabelSelector: labels}). + Namespace(options.Namespace). + Params(&api.Params{LabelSelector: options.Labels}). Do(). Into(r.Value) } @@ -103,7 +110,8 @@ func (c *client) Log(r *Resource, opts ...LogOption) (io.ReadCloser, error) { Get(). Resource(r.Kind). SubResource("log"). - Name(r.Name) + Name(r.Name). + Namespace(options.Namespace) if options.Params != nil { req.Params(&api.Params{Additional: options.Params}) @@ -121,12 +129,18 @@ func (c *client) Log(r *Resource, opts ...LogOption) (io.ReadCloser, error) { } // Update updates API object -func (c *client) Update(r *Resource) error { +func (c *client) Update(r *Resource, opts ...UpdateOption) error { + var options UpdateOptions + for _, o := range opts { + o(&options) + } + req := api.NewRequest(c.opts). Patch(). SetHeader("Content-Type", "application/strategic-merge-patch+json"). Resource(r.Kind). - Name(r.Name) + Name(r.Name). + Namespace(options.Namespace) switch r.Kind { case "service": @@ -143,21 +157,33 @@ func (c *client) Update(r *Resource) error { } // Delete removes API object -func (c *client) Delete(r *Resource) error { +func (c *client) Delete(r *Resource, opts ...DeleteOption) error { + var options DeleteOptions + for _, o := range opts { + o(&options) + } + return api.NewRequest(c.opts). Delete(). Resource(r.Kind). Name(r.Name). + Namespace(options.Namespace). Do(). Error() } // List lists API objects and stores the result in r -func (c *client) List(r *Resource) error { +func (c *client) List(r *Resource, opts ...ListOption) error { + var options ListOptions + for _, o := range opts { + o(&options) + } + labels := map[string]string{ "micro": "service", } - return c.Get(r, labels) + + return c.Get(r, GetLabels(labels), GetNamespace(options.Namespace)) } // Watch returns an event stream @@ -183,13 +209,14 @@ func (c *client) Watch(r *Resource, opts ...WatchOption) (Watcher, error) { Get(). Resource(r.Kind). Name(r.Name). + Namespace(options.Namespace). Params(params) return newWatcher(req) } // NewService returns default micro kubernetes service definition -func NewService(name, version, typ string) *Service { +func NewService(name, version, typ, namespace string) *Service { if logger.V(logger.TraceLevel, logger.DefaultLogger) { logger.Tracef("kubernetes default service: name: %s, version: %s", name, version) } @@ -208,7 +235,7 @@ func NewService(name, version, typ string) *Service { Metadata := &Metadata{ Name: svcName, - Namespace: "default", + Namespace: SerializeResourceName(namespace), Version: version, Labels: Labels, } @@ -228,7 +255,7 @@ func NewService(name, version, typ string) *Service { } // NewService returns default micro kubernetes deployment definition -func NewDeployment(name, version, typ string) *Deployment { +func NewDeployment(name, version, typ, namespace string) *Deployment { if logger.V(logger.TraceLevel, logger.DefaultLogger) { logger.Tracef("kubernetes default deployment: name: %s, version: %s", name, version) } @@ -247,7 +274,7 @@ func NewDeployment(name, version, typ string) *Deployment { Metadata := &Metadata{ Name: depName, - Namespace: "default", + Namespace: SerializeResourceName(namespace), Version: version, Labels: Labels, Annotations: map[string]string{}, @@ -319,11 +346,6 @@ func NewClusterClient() *client { } t := string(token) - ns, err := detectNamespace() - if err != nil { - logger.Fatal(err) - } - crt, err := CertPoolFromFile(path.Join(serviceAccountPath, "ca.crt")) if err != nil { logger.Fatal(err) @@ -342,8 +364,8 @@ func NewClusterClient() *client { opts: &api.Options{ Client: c, Host: host, - Namespace: ns, BearerToken: &t, + Namespace: DefaultNamespace, }, } } diff --git a/util/kubernetes/client/options.go b/util/kubernetes/client/options.go index 0e293522..dd6b32a5 100644 --- a/util/kubernetes/client/options.go +++ b/util/kubernetes/client/options.go @@ -1,13 +1,38 @@ package client +type CreateOptions struct { + Namespace string +} + +type GetOptions struct { + Namespace string + Labels map[string]string +} +type UpdateOptions struct { + Namespace string +} +type DeleteOptions struct { + Namespace string +} +type ListOptions struct { + Namespace string +} + type LogOptions struct { - Params map[string]string + Namespace string + Params map[string]string } type WatchOptions struct { - Params map[string]string + Namespace string + Params map[string]string } +type CreateOption func(*CreateOptions) +type GetOption func(*GetOptions) +type UpdateOption func(*UpdateOptions) +type DeleteOption func(*DeleteOptions) +type ListOption func(*ListOptions) type LogOption func(*LogOptions) type WatchOption func(*WatchOptions) @@ -24,3 +49,59 @@ func WatchParams(p map[string]string) WatchOption { w.Params = p } } + +// CreateNamespace sets the namespace for creating a resource +func CreateNamespace(ns string) CreateOption { + return func(o *CreateOptions) { + o.Namespace = SerializeResourceName(ns) + } +} + +// GetNamespace sets the namespace for getting a resource +func GetNamespace(ns string) GetOption { + return func(o *GetOptions) { + o.Namespace = SerializeResourceName(ns) + } +} + +// GetLabels sets the labels for when getting a resource +func GetLabels(ls map[string]string) GetOption { + return func(o *GetOptions) { + o.Labels = ls + } +} + +// UpdateNamespace sets the namespace for updating a resource +func UpdateNamespace(ns string) UpdateOption { + return func(o *UpdateOptions) { + o.Namespace = SerializeResourceName(ns) + } +} + +// DeleteNamespace sets the namespace for deleting a resource +func DeleteNamespace(ns string) DeleteOption { + return func(o *DeleteOptions) { + o.Namespace = SerializeResourceName(ns) + } +} + +// ListNamespace sets the namespace for listing resources +func ListNamespace(ns string) ListOption { + return func(o *ListOptions) { + o.Namespace = SerializeResourceName(ns) + } +} + +// LogNamespace sets the namespace for logging a resource +func LogNamespace(ns string) LogOption { + return func(o *LogOptions) { + o.Namespace = SerializeResourceName(ns) + } +} + +// WatchNamespace sets the namespace for watching a resource +func WatchNamespace(ns string) WatchOption { + return func(o *WatchOptions) { + o.Namespace = SerializeResourceName(ns) + } +} diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index c19fff1c..5b58ab9f 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -183,3 +183,8 @@ type Template struct { type Namespace struct { Metadata *Metadata `json:"metadata,omitempty"` } + +// NamespaceList +type NamespaceList struct { + Items []Namespace `json:"items"` +} diff --git a/util/kubernetes/client/util_test.go b/util/kubernetes/client/util_test.go index 236f3185..8073a049 100644 --- a/util/kubernetes/client/util_test.go +++ b/util/kubernetes/client/util_test.go @@ -9,16 +9,17 @@ func TestTemplates(t *testing.T) { name := "foo" version := "123" typ := "service" + namespace := "default" // Render default service - s := NewService(name, version, typ) + s := NewService(name, version, typ, namespace) bs := new(bytes.Buffer) if err := renderTemplate(templates["service"], bs, s); err != nil { t.Errorf("Failed to render kubernetes service: %v", err) } // Render default deployment - d := NewDeployment(name, version, typ) + d := NewDeployment(name, version, typ, namespace) bd := new(bytes.Buffer) if err := renderTemplate(templates["deployment"], bd, d); err != nil { t.Errorf("Failed to render kubernetes deployment: %v", err) From 0f42346976c1c474ec47742849b6b7792d88db39 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 23 Apr 2020 14:03:04 +0100 Subject: [PATCH 674/788] Additonal Debugging --- runtime/kubernetes/kubernetes.go | 2 +- runtime/kubernetes/service.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 7adbd301..571c860d 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -256,7 +256,6 @@ func (k *kubernetes) run(events <-chan runtime.Event) { // update build time annotation if service.Spec.Template.Metadata.Annotations == nil { service.Spec.Template.Metadata.Annotations = make(map[string]string) - } // update the build time @@ -351,6 +350,7 @@ func (k *kubeStream) Stop() error { // Creates a service func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) error { + fmt.Println("KUBECTL CREATE") k.Lock() defer k.Unlock() diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 8118c08a..1a6b407c 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -27,6 +27,8 @@ func parseError(err error) *api.Status { } func newService(s *runtime.Service, c runtime.CreateOptions) *service { + fmt.Println("KUBECTL newService") + // use pre-formatted name/version name := client.Format(s.Name) version := client.Format(s.Version) From 020476614c3867715c38f571712d87c9553afdf8 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 23 Apr 2020 14:06:33 +0100 Subject: [PATCH 675/788] Tweak CreateImagePullSecret --- runtime/options.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/options.go b/runtime/options.go index 0c4589dd..07bf6039 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -95,9 +95,9 @@ func CreateImage(img string) CreateOption { } // CreateImagePullSecret sets a secret to use -func CreateImagePullSecret(secret string) CreateOption { +func CreateImagePullSecret(secrets ...string) CreateOption { return func(o *CreateOptions) { - o.ImagePullSecrets = append(o.ImagePullSecrets, secret) + o.ImagePullSecrets = append(o.ImagePullSecrets, secrets...) } } From 88176dca532c61ff7379f7990c458a6f6d77d547 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 23 Apr 2020 14:13:07 +0100 Subject: [PATCH 676/788] Remove debugging --- runtime/kubernetes/kubernetes.go | 1 - runtime/kubernetes/service.go | 4 ---- 2 files changed, 5 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 571c860d..d4eec782 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -350,7 +350,6 @@ func (k *kubeStream) Stop() error { // Creates a service func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) error { - fmt.Println("KUBECTL CREATE") k.Lock() defer k.Unlock() diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 1a6b407c..cb53cb1d 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -2,7 +2,6 @@ package kubernetes import ( "encoding/json" - "fmt" "strings" "github.com/micro/go-micro/v2/logger" @@ -27,8 +26,6 @@ func parseError(err error) *api.Status { } func newService(s *runtime.Service, c runtime.CreateOptions) *service { - fmt.Println("KUBECTL newService") - // use pre-formatted name/version name := client.Format(s.Name) version := client.Format(s.Version) @@ -43,7 +40,6 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { // set the image pull secrets kdeploy.Spec.Template.PodSpec.ImagePullSecrets = c.ImagePullSecrets - fmt.Printf("Setting ImagePullSecrets to %v\n", strings.Join(c.ImagePullSecrets, ", ")) // create if non existent if s.Metadata == nil { From b5f53595cab83e7aa7a40292ca7bfbaf9f603cff Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 23 Apr 2020 14:22:23 +0100 Subject: [PATCH 677/788] Pass image_pull_secrets in runtime service --- runtime/service/proto/runtime.pb.go | 392 ++++------------------ runtime/service/proto/runtime.pb.micro.go | 2 +- runtime/service/proto/runtime.proto | 2 + runtime/service/service.go | 11 +- 4 files changed, 83 insertions(+), 324 deletions(-) diff --git a/runtime/service/proto/runtime.pb.go b/runtime/service/proto/runtime.pb.go index 1c401b4a..3d309bc6 100644 --- a/runtime/service/proto/runtime.pb.go +++ b/runtime/service/proto/runtime.pb.go @@ -1,15 +1,11 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: runtime/service/proto/runtime.proto +// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto package go_micro_runtime import ( - context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" math "math" ) @@ -42,7 +38,7 @@ func (m *Service) Reset() { *m = Service{} } func (m *Service) String() string { return proto.CompactTextString(m) } func (*Service) ProtoMessage() {} func (*Service) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{0} + return fileDescriptor_976fccef828ab1f0, []int{0} } func (m *Service) XXX_Unmarshal(b []byte) error { @@ -105,7 +101,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{1} + return fileDescriptor_976fccef828ab1f0, []int{1} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -166,7 +162,9 @@ type CreateOptions struct { // create type of service Type string `protobuf:"bytes,5,opt,name=type,proto3" json:"type,omitempty"` // image to use - Image string `protobuf:"bytes,6,opt,name=image,proto3" json:"image,omitempty"` + Image string `protobuf:"bytes,6,opt,name=image,proto3" json:"image,omitempty"` + // image secrets to use + ImagePullSecrets []string `protobuf:"bytes,7,rep,name=image_pull_secrets,json=imagePullSecrets,proto3" json:"image_pull_secrets,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -176,7 +174,7 @@ func (m *CreateOptions) Reset() { *m = CreateOptions{} } func (m *CreateOptions) String() string { return proto.CompactTextString(m) } func (*CreateOptions) ProtoMessage() {} func (*CreateOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{2} + return fileDescriptor_976fccef828ab1f0, []int{2} } func (m *CreateOptions) XXX_Unmarshal(b []byte) error { @@ -239,6 +237,13 @@ func (m *CreateOptions) GetImage() string { return "" } +func (m *CreateOptions) GetImagePullSecrets() []string { + if m != nil { + return m.ImagePullSecrets + } + return nil +} + type CreateRequest struct { Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` Options *CreateOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` @@ -251,7 +256,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{3} + return fileDescriptor_976fccef828ab1f0, []int{3} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -296,7 +301,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{4} + return fileDescriptor_976fccef828ab1f0, []int{4} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -333,7 +338,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{5} + return fileDescriptor_976fccef828ab1f0, []int{5} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -386,7 +391,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{6} + return fileDescriptor_976fccef828ab1f0, []int{6} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -425,7 +430,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{7} + return fileDescriptor_976fccef828ab1f0, []int{7} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -464,7 +469,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{8} + return fileDescriptor_976fccef828ab1f0, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -502,7 +507,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{9} + return fileDescriptor_976fccef828ab1f0, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -534,7 +539,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{10} + return fileDescriptor_976fccef828ab1f0, []int{10} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -572,7 +577,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{11} + return fileDescriptor_976fccef828ab1f0, []int{11} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -603,7 +608,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{12} + return fileDescriptor_976fccef828ab1f0, []int{12} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -635,7 +640,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{13} + return fileDescriptor_976fccef828ab1f0, []int{13} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -683,7 +688,7 @@ func (m *LogsRequest) Reset() { *m = LogsRequest{} } func (m *LogsRequest) String() string { return proto.CompactTextString(m) } func (*LogsRequest) ProtoMessage() {} func (*LogsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{14} + return fileDescriptor_976fccef828ab1f0, []int{14} } func (m *LogsRequest) XXX_Unmarshal(b []byte) error { @@ -748,7 +753,7 @@ func (m *LogRecord) Reset() { *m = LogRecord{} } func (m *LogRecord) String() string { return proto.CompactTextString(m) } func (*LogRecord) ProtoMessage() {} func (*LogRecord) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{15} + return fileDescriptor_976fccef828ab1f0, []int{15} } func (m *LogRecord) XXX_Unmarshal(b []byte) error { @@ -812,302 +817,53 @@ func init() { } func init() { - proto.RegisterFile("runtime/service/proto/runtime.proto", fileDescriptor_2434d8152598889b) + proto.RegisterFile("github.com/micro/go-micro/runtime/service/proto/runtime.proto", fileDescriptor_976fccef828ab1f0) } -var fileDescriptor_2434d8152598889b = []byte{ - // 645 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xc9, 0x6e, 0xdb, 0x30, - 0x10, 0x8d, 0x2c, 0x2f, 0xc9, 0xa8, 0x2e, 0x02, 0x22, 0x28, 0xd4, 0x74, 0x33, 0xd4, 0x43, 0xd3, - 0x8b, 0x52, 0x38, 0x28, 0xba, 0x1d, 0x63, 0xa7, 0x17, 0x1b, 0x05, 0x54, 0xe4, 0x03, 0x58, 0x79, - 0x60, 0x08, 0x89, 0x44, 0x55, 0xa4, 0x0c, 0xf8, 0xd4, 0x63, 0xcf, 0xfd, 0xaa, 0x9e, 0xfb, 0x47, - 0x05, 0x17, 0x6d, 0xb6, 0x94, 0x8b, 0x6f, 0x9c, 0x11, 0xf9, 0xf8, 0xde, 0x9b, 0x19, 0x0a, 0x5e, - 0x67, 0x79, 0x22, 0xa2, 0x18, 0x2f, 0x39, 0x66, 0x9b, 0x28, 0xc4, 0xcb, 0x34, 0x63, 0x82, 0x5d, - 0x9a, 0xac, 0xaf, 0x22, 0x72, 0xba, 0x66, 0x7e, 0x1c, 0x85, 0x19, 0xf3, 0x4d, 0xde, 0xfb, 0x67, - 0xc1, 0xe8, 0xbb, 0x3e, 0x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 0x89, 0x50, 0xa5, 0xb6, 0x03, 0x1d, 0xc8, 0x2c, 0x8f, 0x92, 0x10, 0xd5, 0x58, 0xd8, - 0x81, 0x0e, 0xbc, 0xbf, 0x16, 0x9c, 0x2c, 0xd8, 0x3a, 0xc0, 0x90, 0x65, 0xab, 0xe6, 0x7c, 0x5b, - 0xbb, 0xf3, 0x3d, 0xaf, 0x3d, 0x4e, 0x3d, 0xa5, 0xe7, 0xed, 0xbe, 0x9e, 0x12, 0xac, 0xeb, 0x79, - 0x92, 0x82, 0x62, 0xe4, 0x5c, 0x8e, 0x9d, 0x79, 0x26, 0x4c, 0x78, 0xd0, 0xc3, 0x35, 0xfd, 0x6d, - 0xc3, 0x28, 0xd0, 0x24, 0xc8, 0x12, 0x86, 0x7a, 0x80, 0x48, 0xe7, 0xd0, 0x19, 0x7b, 0xcf, 0x27, - 0xdd, 0x1b, 0x4c, 0x95, 0x8f, 0xc8, 0x57, 0xe8, 0xcb, 0xf6, 0x26, 0x1d, 0xe3, 0x50, 0x40, 0xbd, - 0xec, 0xfa, 0x5c, 0x02, 0x2d, 0x61, 0xa8, 0x5b, 0xb3, 0x8d, 0x57, 0xa3, 0xf5, 0xdb, 0x78, 0xed, - 0x74, 0xb5, 0x82, 0xd3, 0x1d, 0xd9, 0x06, 0xd7, 0xe8, 0xf8, 0x36, 0xb8, 0x9d, 0x66, 0x3e, 0x22, - 0x37, 0xd0, 0x97, 0x8d, 0xd7, 0x26, 0xb3, 0xd6, 0x90, 0xe7, 0xcf, 0x1e, 0x28, 0xba, 0x77, 0xf4, - 0xce, 0xfa, 0x31, 0x54, 0xff, 0xcb, 0xab, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x20, 0x0e, 0x37, - 0xf1, 0x56, 0x07, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// RuntimeClient is the client API for Runtime service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type RuntimeClient interface { - Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) - Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) - Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) - Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) - Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Runtime_LogsClient, error) -} - -type runtimeClient struct { - cc *grpc.ClientConn -} - -func NewRuntimeClient(cc *grpc.ClientConn) RuntimeClient { - return &runtimeClient{cc} -} - -func (c *runtimeClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { - out := new(CreateResponse) - err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Create", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *runtimeClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { - out := new(ReadResponse) - err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Read", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *runtimeClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { - out := new(DeleteResponse) - err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Delete", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *runtimeClient) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) { - out := new(UpdateResponse) - err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Update", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *runtimeClient) Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Runtime_LogsClient, error) { - stream, err := c.cc.NewStream(ctx, &_Runtime_serviceDesc.Streams[0], "/go.micro.runtime.Runtime/Logs", opts...) - if err != nil { - return nil, err - } - x := &runtimeLogsClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type Runtime_LogsClient interface { - Recv() (*LogRecord, error) - grpc.ClientStream -} - -type runtimeLogsClient struct { - grpc.ClientStream -} - -func (x *runtimeLogsClient) Recv() (*LogRecord, error) { - m := new(LogRecord) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -// RuntimeServer is the server API for Runtime service. -type RuntimeServer interface { - Create(context.Context, *CreateRequest) (*CreateResponse, error) - Read(context.Context, *ReadRequest) (*ReadResponse, error) - Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) - Update(context.Context, *UpdateRequest) (*UpdateResponse, error) - Logs(*LogsRequest, Runtime_LogsServer) error -} - -// UnimplementedRuntimeServer can be embedded to have forward compatible implementations. -type UnimplementedRuntimeServer struct { -} - -func (*UnimplementedRuntimeServer) Create(ctx context.Context, req *CreateRequest) (*CreateResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") -} -func (*UnimplementedRuntimeServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") -} -func (*UnimplementedRuntimeServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") -} -func (*UnimplementedRuntimeServer) Update(ctx context.Context, req *UpdateRequest) (*UpdateResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Update not implemented") -} -func (*UnimplementedRuntimeServer) Logs(req *LogsRequest, srv Runtime_LogsServer) error { - return status.Errorf(codes.Unimplemented, "method Logs not implemented") -} - -func RegisterRuntimeServer(s *grpc.Server, srv RuntimeServer) { - s.RegisterService(&_Runtime_serviceDesc, srv) -} - -func _Runtime_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CreateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RuntimeServer).Create(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.runtime.Runtime/Create", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RuntimeServer).Create(ctx, req.(*CreateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Runtime_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ReadRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RuntimeServer).Read(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.runtime.Runtime/Read", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RuntimeServer).Read(ctx, req.(*ReadRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Runtime_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DeleteRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RuntimeServer).Delete(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.runtime.Runtime/Delete", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RuntimeServer).Delete(ctx, req.(*DeleteRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Runtime_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UpdateRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RuntimeServer).Update(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.runtime.Runtime/Update", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RuntimeServer).Update(ctx, req.(*UpdateRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Runtime_Logs_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(LogsRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(RuntimeServer).Logs(m, &runtimeLogsServer{stream}) -} - -type Runtime_LogsServer interface { - Send(*LogRecord) error - grpc.ServerStream -} - -type runtimeLogsServer struct { - grpc.ServerStream -} - -func (x *runtimeLogsServer) Send(m *LogRecord) error { - return x.ServerStream.SendMsg(m) -} - -var _Runtime_serviceDesc = grpc.ServiceDesc{ - ServiceName: "go.micro.runtime.Runtime", - HandlerType: (*RuntimeServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Create", - Handler: _Runtime_Create_Handler, - }, - { - MethodName: "Read", - Handler: _Runtime_Read_Handler, - }, - { - MethodName: "Delete", - Handler: _Runtime_Delete_Handler, - }, - { - MethodName: "Update", - Handler: _Runtime_Update_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "Logs", - Handler: _Runtime_Logs_Handler, - ServerStreams: true, - }, - }, - Metadata: "runtime/service/proto/runtime.proto", +var fileDescriptor_976fccef828ab1f0 = []byte{ + // 689 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x4b, 0x6f, 0xd3, 0x40, + 0x10, 0xae, 0xe3, 0x3c, 0xda, 0x09, 0x41, 0xd1, 0xaa, 0x42, 0xa6, 0xbc, 0x22, 0x5f, 0x28, 0x12, + 0x38, 0x28, 0x15, 0xe2, 0x25, 0x4e, 0x6d, 0xca, 0xa5, 0x15, 0xc8, 0x55, 0xcf, 0xd5, 0xd6, 0x19, + 0x19, 0xab, 0xb1, 0xd7, 0xec, 0xae, 0x23, 0xf5, 0xc4, 0x91, 0x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0x96, 0xbb, 0x54, 0xcb, 0x3f, 0x35, 0x65, 0x4b, 0x9e, 0xef, + 0x97, 0x90, 0x0d, 0xcf, 0x67, 0x77, 0x21, 0xd7, 0x60, 0x2c, 0x01, 0x4f, 0xe1, 0x81, 0xa9, 0x63, + 0xe0, 0x92, 0x77, 0xb0, 0x6b, 0x01, 0x09, 0xdd, 0xf2, 0x7b, 0x15, 0xab, 0x52, 0xfd, 0x13, 0x18, + 0x9c, 0xe0, 0x1c, 0xb7, 0x13, 0x5e, 0xa9, 0x57, 0x56, 0xb1, 0xea, 0x9d, 0xc0, 0xe0, 0x32, 0x9f, + 0xd1, 0xed, 0xeb, 0x96, 0x55, 0x6c, 0xdd, 0x01, 0xf4, 0xcf, 0x12, 0x21, 0x6d, 0x55, 0xa5, 0x82, + 0x71, 0xb7, 0x53, 0xe1, 0x06, 0xfa, 0x67, 0x2c, 0x16, 0x25, 0xd6, 0xe6, 0x5e, 0xab, 0x95, 0x23, + 0x39, 0xd2, 0x54, 0xb7, 0x7a, 0x37, 0xb4, 0x9e, 0x7a, 0x03, 0x11, 0x2b, 0x32, 0xa9, 0x5b, 0xed, + 0x86, 0xc6, 0x51, 0x51, 0x91, 0x64, 0x11, 0xea, 0x47, 0xe4, 0x86, 0xc6, 0xf1, 0xff, 0x3a, 0xb0, + 0x77, 0xc6, 0xe2, 0x10, 0x23, 0xc6, 0x67, 0xab, 0xdb, 0xc0, 0x59, 0xdf, 0x06, 0xd3, 0xda, 0x2a, + 0x6b, 0x69, 0x3e, 0xaf, 0xee, 0xf2, 0xa9, 0x8a, 0x35, 0x2d, 0x33, 0x45, 0x28, 0x45, 0x21, 0xd4, + 0x23, 0xb5, 0x4b, 0xc5, 0xba, 0x5b, 0xad, 0xb9, 0xc9, 0x6f, 0x17, 0x7a, 0xa1, 0x01, 0x41, 0xce, + 0xa1, 0x6b, 0x1e, 0x10, 0x69, 0x7c, 0x74, 0x56, 0xde, 0x83, 0x51, 0x73, 0x82, 0xed, 0xf2, 0x0e, + 0xf9, 0x0a, 0x6d, 0x35, 0xde, 0xa4, 0xe1, 0x39, 0x94, 0xa5, 0x9e, 0x37, 0x7d, 0xae, 0x0a, 0x9d, + 0x43, 0xd7, 0x8c, 0xe6, 0x26, 0x5c, 0x2b, 0xa3, 0xbf, 0x09, 0xd7, 0xda, 0x54, 0xeb, 0x72, 0x66, + 0x22, 0x37, 0x95, 0x5b, 0x99, 0xf8, 0x4d, 0xe5, 0xd6, 0x86, 0x79, 0x87, 0x9c, 0x42, 0x5b, 0x0d, + 0xde, 0x26, 0x9a, 0xb5, 0x81, 0x3c, 0x78, 0x72, 0x4f, 0xd3, 0xfd, 0x9d, 0xb7, 0xce, 0x75, 0x57, + 0xff, 0x5d, 0x8f, 0xfe, 0x07, 0x00, 0x00, 0xff, 0xff, 0x4c, 0x31, 0x4d, 0x46, 0x9e, 0x07, 0x00, + 0x00, } diff --git a/runtime/service/proto/runtime.pb.micro.go b/runtime/service/proto/runtime.pb.micro.go index 73b7c3ca..0f560a4d 100644 --- a/runtime/service/proto/runtime.pb.micro.go +++ b/runtime/service/proto/runtime.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: runtime/service/proto/runtime.proto +// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto package go_micro_runtime diff --git a/runtime/service/proto/runtime.proto b/runtime/service/proto/runtime.proto index 65c2c497..2a8b5aca 100644 --- a/runtime/service/proto/runtime.proto +++ b/runtime/service/proto/runtime.proto @@ -41,6 +41,8 @@ message CreateOptions { string type = 5; // image to use string image = 6; + // image secrets to use + repeated string image_pull_secrets = 7; } message CreateRequest { diff --git a/runtime/service/service.go b/runtime/service/service.go index d065038c..6177cb0c 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -50,11 +50,12 @@ func (s *svc) Create(svc *runtime.Service, opts ...runtime.CreateOption) error { Metadata: svc.Metadata, }, Options: &pb.CreateOptions{ - Command: options.Command, - Args: options.Args, - Env: options.Env, - Type: options.Type, - Image: options.Image, + Command: options.Command, + Args: options.Args, + Env: options.Env, + Type: options.Type, + Image: options.Image, + ImagePullSecrets: options.ImagePullSecrets, }, } From ff8ad7d4cad94ef856dcdc2dae251b3bed3f60d6 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Thu, 23 Apr 2020 16:30:43 +0200 Subject: [PATCH 678/788] Default runtime now checks out code on demand (#1563) * Default runtime now checks out code on demand * Go mod tidy --- go.mod | 3 +- go.sum | 27 ++- runtime/default.go | 18 ++ runtime/local/git/git.go | 333 ++++++++++++++++++++++++++++++++++ runtime/local/git/git_test.go | 95 ++++++++++ 5 files changed, 473 insertions(+), 3 deletions(-) create mode 100644 runtime/local/git/git.go create mode 100644 runtime/local/git/git_test.go diff --git a/go.mod b/go.mod index 05e82553..fe1ce6b0 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,7 @@ require ( github.com/fsouza/go-dockerclient v1.6.0 github.com/ghodss/yaml v1.0.0 github.com/go-acme/lego/v3 v3.3.0 + github.com/go-git/go-git/v5 v5.0.0 github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee github.com/gobwas/pool v0.2.0 // indirect @@ -61,7 +62,7 @@ require ( go.etcd.io/bbolt v1.3.4 go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 - golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 + golang.org/x/net v0.0.0-20200301022130-244492dfa37a golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1 google.golang.org/grpc v1.26.0 diff --git a/go.sum b/go.sum index a204a929..c86297fe 100644 --- a/go.sum +++ b/go.sum @@ -101,6 +101,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -146,6 +147,14 @@ github.com/go-acme/lego/v3 v3.3.0 h1:6BePZsOiYA4/w+M7QDytxQtMfCipMPGnWAHs9pWks98 github.com/go-acme/lego/v3 v3.3.0/go.mod h1:iGSY2vQrvQs3WezicSB/oVbO2eCrD88dpWPwb1qLqu0= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= +github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= +github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= +github.com/go-git/go-billy/v5 v5.0.0 h1:7NQHvd9FVid8VL4qVUMm8XifBK+2xCoZ2lSk0agRrHM= +github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= +github.com/go-git/go-git-fixtures/v4 v4.0.1 h1:q+IFMfLx200Q3scvt2hN79JsEzy4AmBTp/pqnefH+Bc= +github.com/go-git/go-git-fixtures/v4 v4.0.1/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw= +github.com/go-git/go-git/v5 v5.0.0 h1:k5RWPm4iJwYtfWoxIJy4wJX9ON7ihPeZZYC1fLYDnpg= +github.com/go-git/go-git/v5 v5.0.0/go.mod h1:oYD8y9kWsGINPFJoLdaScGCN6dlKg23blmClfZwtUVA= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -263,6 +272,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= @@ -317,6 +328,8 @@ github.com/nats-io/nkeys v0.1.4/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1t github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= @@ -385,6 +398,8 @@ github.com/sacloud/libsacloud v1.26.1/go.mod h1:79ZwATmHLIFZIMd7sxA3LwzVy/B77uj3 github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -456,6 +471,7 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -500,8 +516,8 @@ golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 h1:MsuvTghUPjX762sGLnGsxC3HM0B5r83wEtYcYR8/vRs= -golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -539,6 +555,8 @@ golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPT golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= @@ -612,6 +630,9 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= @@ -639,6 +660,8 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/runtime/default.go b/runtime/default.go index 8ac00bb9..c3c5c1ec 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -13,6 +13,7 @@ import ( "github.com/hpcloud/tail" "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/runtime/local/git" ) type runtime struct { @@ -52,6 +53,21 @@ func NewRuntime(opts ...Option) Runtime { } } +// @todo move this to runtime default +func (r *runtime) checkoutSourceIfNeeded(s *Service) error { + source, err := git.ParseSourceLocal("", s.Source) + if err != nil { + return err + } + source.Ref = s.Version + err = git.CheckoutSource(os.TempDir(), source) + if err != nil { + return err + } + s.Source = source.FullPath + return nil +} + // Init initializes runtime options func (r *runtime) Init(opts ...Option) error { r.Lock() @@ -193,6 +209,7 @@ func serviceKey(s *Service) string { // Create creates a new service which is then started by runtime func (r *runtime) Create(s *Service, opts ...CreateOption) error { + r.checkoutSourceIfNeeded(s) r.Lock() defer r.Unlock() @@ -336,6 +353,7 @@ func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) { // Update attemps to update the service func (r *runtime) Update(s *Service, opts ...UpdateOption) error { + r.checkoutSourceIfNeeded(s) r.Lock() service, ok := r.services[serviceKey(s)] r.Unlock() diff --git a/runtime/local/git/git.go b/runtime/local/git/git.go new file mode 100644 index 00000000..c23a8080 --- /dev/null +++ b/runtime/local/git/git.go @@ -0,0 +1,333 @@ +package git + +import ( + "fmt" + "os" + "os/exec" + "path/filepath" + "regexp" + "strings" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/config" + "github.com/go-git/go-git/v5/plumbing" +) + +type Gitter interface { + Clone(repo string) error + FetchAll(repo string) error + Checkout(repo, branchOrCommit string) error + RepoDir(repo string) string +} + +type libGitter struct { + folder string +} + +func (g libGitter) Clone(repo string) error { + fold := filepath.Join(g.folder, dirifyRepo(repo)) + exists, err := pathExists(fold) + if err != nil { + return err + } + if exists { + return nil + } + _, err = git.PlainClone(fold, false, &git.CloneOptions{ + URL: repo, + Progress: os.Stdout, + }) + return err +} + +func (g libGitter) FetchAll(repo string) error { + repos, err := git.PlainOpen(filepath.Join(g.folder, dirifyRepo(repo))) + if err != nil { + return err + } + remotes, err := repos.Remotes() + if err != nil { + return err + } + + err = remotes[0].Fetch(&git.FetchOptions{ + RefSpecs: []config.RefSpec{"refs/*:refs/*", "HEAD:refs/heads/HEAD"}, + Progress: os.Stdout, + Depth: 1, + }) + if err != nil && err != git.NoErrAlreadyUpToDate { + return err + } + return nil +} + +func (g libGitter) Checkout(repo, branchOrCommit string) error { + if branchOrCommit == "latest" { + branchOrCommit = "master" + } + repos, err := git.PlainOpen(filepath.Join(g.folder, dirifyRepo(repo))) + if err != nil { + return err + } + worktree, err := repos.Worktree() + if err != nil { + return err + } + isCommit := func(s string) bool { + return strings.ContainsAny(s, "0123456789") && len(s) == 40 + } + if isCommit(branchOrCommit) { + err = worktree.Checkout(&git.CheckoutOptions{ + Hash: plumbing.NewHash(branchOrCommit), + Force: true, + }) + if err != nil { + return err + } + } else { + err = worktree.Checkout(&git.CheckoutOptions{ + Branch: plumbing.NewBranchReferenceName(branchOrCommit), + Force: true, + }) + if err != nil { + return err + } + } + return nil +} + +func (g libGitter) RepoDir(repo string) string { + return filepath.Join(g.folder, dirifyRepo(repo)) +} + +type binaryGitter struct { + folder string +} + +func (g binaryGitter) Clone(repo string) error { + fold := filepath.Join(g.folder, dirifyRepo(repo)) + exists, err := pathExists(fold) + if err != nil { + return err + } + if exists { + return nil + } + cmd := exec.Command("git", "clone", repo, ".") + + err = os.MkdirAll(fold, 0777) + if err != nil { + return err + } + cmd.Dir = fold + _, err = cmd.Output() + if err != nil { + return err + } + return err +} + +func (g binaryGitter) FetchAll(repo string) error { + cmd := exec.Command("git", "fetch", "--all") + cmd.Dir = filepath.Join(g.folder, dirifyRepo(repo)) + _, err := cmd.Output() + if err != nil { + return err + } + return err +} + +func (g binaryGitter) Checkout(repo, branchOrCommit string) error { + if branchOrCommit == "latest" { + branchOrCommit = "master" + } + cmd := exec.Command("git", "checkout", "-f", branchOrCommit) + cmd.Dir = filepath.Join(g.folder, dirifyRepo(repo)) + _, err := cmd.Output() + if err != nil { + return err + } + return nil +} + +func (g binaryGitter) RepoDir(repo string) string { + return filepath.Join(g.folder, dirifyRepo(repo)) +} + +func NewGitter(folder string) Gitter { + if commandExists("git") { + return binaryGitter{folder} + } + return libGitter{folder} +} + +func commandExists(cmd string) bool { + _, err := exec.LookPath(cmd) + return err == nil +} + +func dirifyRepo(s string) string { + s = strings.ReplaceAll(s, "https://", "") + s = strings.ReplaceAll(s, "/", "-") + return s +} + +// exists returns whether the given file or directory exists +func pathExists(path string) (bool, error) { + _, err := os.Stat(path) + if err == nil { + return true, nil + } + if os.IsNotExist(err) { + return false, nil + } + return true, err +} + +// GetRepoRoot determines the repo root from a full path. +// Returns empty string and no error if not found +func GetRepoRoot(fullPath string) (string, error) { + // traverse parent directories + prev := fullPath + for { + current := prev + exists, err := pathExists(filepath.Join(current, ".git")) + if err != nil { + return "", err + } + if exists { + return current, nil + } + prev = filepath.Dir(current) + // reached top level, see: + // https://play.golang.org/p/rDgVdk3suzb + if current == prev { + break + } + } + return "", nil +} + +const defaultRepo = "github.com/micro/services" + +// Source is not just git related @todo move +type Source struct { + // is it a local folder intended for a local runtime? + Local bool + // absolute path to service folder in local mode + FullPath string + // path of folder to repo root + // be it local or github repo + Folder string + // github ref + Ref string + // for cloning purposes + // blank for local + Repo string + // dir to repo root + // blank for non local + LocalRepoRoot string +} + +// Name to be passed to RPC call runtime.Create Update Delete +// eg: `helloworld/api`, `crufter/myrepo/helloworld/api`, `localfolder` +func (s *Source) RuntimeName() string { + if s.Repo == "github.com/micro/services" || s.Repo == "" { + return s.Folder + } + return fmt.Sprintf("%v/%v", strings.ReplaceAll(s.Repo, "github.com/", ""), s.Folder) +} + +// Source to be passed to RPC call runtime.Create Update Delete +// eg: `helloworld`, `github.com/crufter/myrepo/helloworld`, `/path/to/localrepo/localfolder` +func (s *Source) RuntimeSource() string { + if s.Local { + return s.FullPath + } + if s.Repo == "github.com/micro/services" || s.Repo == "" { + return s.Folder + } + return fmt.Sprintf("%v/%v", s.Repo, s.Folder) +} + +// ParseSource parses a `micro run/update/kill` source. +func ParseSource(source string) (*Source, error) { + // If github is not present, we got a shorthand for `micro/services` + if !strings.Contains(source, "github.com") { + source = "github.com/micro/services/" + source + } + if !strings.Contains(source, "@") { + source += "@latest" + } + ret := &Source{} + refs := strings.Split(source, "@") + ret.Ref = refs[1] + parts := strings.Split(refs[0], "/") + ret.Repo = strings.Join(parts[0:3], "/") + if len(parts) > 1 { + ret.Folder = strings.Join(parts[3:], "/") + } + + return ret, nil +} + +// ParseSourceLocal detects and handles local pathes too +// workdir should be used only from the CLI @todo better interface for this function +func ParseSourceLocal(workDir, source string) (*Source, error) { + var localFullPath string + if len(workDir) > 0 { + localFullPath = filepath.Join(workDir, source) + } else { + localFullPath = source + } + if exists, err := pathExists(localFullPath); err == nil && exists { + localRepoRoot, err := GetRepoRoot(localFullPath) + if err != nil { + return nil, err + } + folder := strings.ReplaceAll(localFullPath, localRepoRoot+string(filepath.Separator), "") + return &Source{ + Local: true, + Folder: folder, + FullPath: localFullPath, + LocalRepoRoot: localRepoRoot, + Ref: "latest", // @todo consider extracting branch from git here + }, nil + } + return ParseSource(source) +} + +// CheckoutSource for the local runtime server +// folder is the folder to check out the source code to +// Modifies source path to set it to checked out repo absolute path locally. +func CheckoutSource(folder string, source *Source) error { + // if it's a local folder, do nothing + if exists, err := pathExists(source.FullPath); err == nil && exists { + return nil + } + gitter := NewGitter(folder) + repo := source.Repo + if !strings.Contains(repo, "https://") { + repo = "https://" + repo + } + // Always clone, it's idempotent and only clones if needed + err := gitter.Clone(repo) + if err != nil { + return err + } + source.FullPath = filepath.Join(gitter.RepoDir(source.Repo), source.Folder) + return gitter.Checkout(repo, source.Ref) +} + +// code below is not used yet + +var nameExtractRegexp = regexp.MustCompile(`((micro|web)\.Name\(")(.*)("\))`) + +func extractServiceName(fileContent []byte) string { + hits := nameExtractRegexp.FindAll(fileContent, 1) + if len(hits) == 0 { + return "" + } + hit := string(hits[0]) + return strings.Split(hit, "\"")[1] +} diff --git a/runtime/local/git/git_test.go b/runtime/local/git/git_test.go new file mode 100644 index 00000000..79561b80 --- /dev/null +++ b/runtime/local/git/git_test.go @@ -0,0 +1,95 @@ +package git + +import ( + "testing" +) + +type parseCase struct { + url string + expected *Source +} + +func TestParseSource(t *testing.T) { + cases := []parseCase{ + { + url: "helloworld", + expected: &Source{ + Repo: "github.com/micro/services", + Folder: "helloworld", + Ref: "latest", + }, + }, + { + url: "github.com/micro/services/helloworld", + expected: &Source{ + Repo: "github.com/micro/services", + Folder: "helloworld", + Ref: "latest", + }, + }, + { + url: "github.com/micro/services/helloworld@v1.12.1", + expected: &Source{ + Repo: "github.com/micro/services", + Folder: "helloworld", + Ref: "v1.12.1", + }, + }, + { + url: "github.com/micro/services/helloworld@branchname", + expected: &Source{ + Repo: "github.com/micro/services", + Folder: "helloworld", + Ref: "branchname", + }, + }, + { + url: "github.com/crufter/reponame/helloworld@branchname", + expected: &Source{ + Repo: "github.com/crufter/reponame", + Folder: "helloworld", + Ref: "branchname", + }, + }, + } + for i, c := range cases { + result, err := ParseSource(c.url) + if err != nil { + t.Fatalf("Failed case %v: %v", i, err) + } + if result.Folder != c.expected.Folder { + t.Fatalf("Folder does not match for '%v', expected '%v', got '%v'", i, c.expected.Folder, result.Folder) + } + if result.Repo != c.expected.Repo { + t.Fatalf("Repo address does not match for '%v', expected '%v', got '%v'", i, c.expected.Repo, result.Repo) + } + if result.Ref != c.expected.Ref { + t.Fatalf("Ref does not match for '%v', expected '%v', got '%v'", i, c.expected.Ref, result.Ref) + } + } +} + +type nameCase struct { + fileContent string + expected string +} + +func TestServiceNameExtract(t *testing.T) { + cases := []nameCase{ + { + fileContent: `func main() { + // New Service + service := micro.NewService( + micro.Name("go.micro.service.helloworld"), + micro.Version("latest"), + )`, + expected: "go.micro.service.helloworld", + }, + } + for i, c := range cases { + result := extractServiceName([]byte(c.fileContent)) + if result != c.expected { + t.Fatalf("Case %v, expected: %v, got: %v", i, c.expected, result) + } + } +} From 2299559397e1e32006b12e16016c07d7de805a0b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 23 Apr 2020 16:22:41 +0100 Subject: [PATCH 679/788] Check for namespace (#1564) --- runtime/kubernetes/kubernetes.go | 18 +++++++--- .../{kubernetes_logs.go => logs.go} | 36 ++++++++++++++----- util/kubernetes/client/client.go | 32 +++++++++++++---- 3 files changed, 68 insertions(+), 18 deletions(-) rename runtime/kubernetes/{kubernetes_logs.go => logs.go} (85%) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 1ec265c6..9ac90ce1 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -393,7 +393,8 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er defer k.Unlock() options := runtime.CreateOptions{ - Type: k.options.Type, + Type: k.options.Type, + Namespace: client.DefaultNamespace, } for _, o := range opts { o(&options) @@ -439,7 +440,10 @@ func (k *kubernetes) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error "micro": k.options.Type, } - var options runtime.ReadOptions + options := runtime.ReadOptions{ + Namespace: client.DefaultNamespace, + } + for _, o := range opts { o(&options) } @@ -472,7 +476,10 @@ func (k *kubernetes) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error // Update the service in place func (k *kubernetes) Update(s *runtime.Service, opts ...runtime.UpdateOption) error { - var options runtime.UpdateOptions + options := runtime.UpdateOptions{ + Namespace: client.DefaultNamespace, + } + for _, o := range opts { o(&options) } @@ -521,7 +528,10 @@ func (k *kubernetes) Update(s *runtime.Service, opts ...runtime.UpdateOption) er // Delete removes a service func (k *kubernetes) Delete(s *runtime.Service, opts ...runtime.DeleteOption) error { - var options runtime.DeleteOptions + options := runtime.DeleteOptions{ + Namespace: client.DefaultNamespace, + } + for _, o := range opts { o(&options) } diff --git a/runtime/kubernetes/kubernetes_logs.go b/runtime/kubernetes/logs.go similarity index 85% rename from runtime/kubernetes/kubernetes_logs.go rename to runtime/kubernetes/logs.go index 0c113f4e..ac57d50c 100644 --- a/runtime/kubernetes/kubernetes_logs.go +++ b/runtime/kubernetes/logs.go @@ -24,11 +24,16 @@ func (k *klog) podLogStream(podName string, stream *kubeStream) error { p := make(map[string]string) p["follow"] = "true" + opts := []client.LogOption{ + client.LogParams(p), + client.LogNamespace(k.options.Namespace), + } + // get the logs for the pod body, err := k.client.Log(&client.Resource{ Name: podName, Kind: "pod", - }, client.LogParams(p)) + }, opts...) if err != nil { stream.err = err @@ -70,7 +75,12 @@ func (k *klog) getMatchingPods() ([]string, error) { // TODO: specify micro:service // l["micro"] = "service" - if err := k.client.Get(r, client.GetLabels(l)); err != nil { + opts := []client.GetOption{ + client.GetLabels(l), + client.GetNamespace(k.options.Namespace), + } + + if err := k.client.Get(r, opts...); err != nil { return nil, err } @@ -109,10 +119,15 @@ func (k *klog) Read() ([]runtime.LogRecord, error) { logParams["follow"] = "true" } + opts := []client.LogOption{ + client.LogParams(logParams), + client.LogNamespace(k.options.Namespace), + } + logs, err := k.client.Log(&client.Resource{ Name: pod, Kind: "pod", - }, client.LogParams(logParams)) + }, opts...) if err != nil { return nil, err @@ -162,13 +177,18 @@ func (k *klog) Stream() (runtime.LogStream, error) { } // NewLog returns a configured Kubernetes logger -func newLog(client client.Client, serviceName string, opts ...runtime.LogsOption) *klog { - klog := &klog{ - serviceName: serviceName, - client: client, +func newLog(c client.Client, serviceName string, opts ...runtime.LogsOption) *klog { + options := runtime.LogsOptions{ + Namespace: client.DefaultNamespace, } for _, o := range opts { - o(&klog.options) + o(&options) + } + + klog := &klog{ + serviceName: serviceName, + client: c, + options: options, } return klog diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 6b579777..76e7c52f 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -85,7 +85,9 @@ func SerializeResourceName(ns string) string { // Get queries API objects and stores the result in r func (c *client) Get(r *Resource, opts ...GetOption) error { - var options GetOptions + options := GetOptions{ + Namespace: c.opts.Namespace, + } for _, o := range opts { o(&options) } @@ -101,7 +103,9 @@ func (c *client) Get(r *Resource, opts ...GetOption) error { // Log returns logs for a pod func (c *client) Log(r *Resource, opts ...LogOption) (io.ReadCloser, error) { - var options LogOptions + options := LogOptions{ + Namespace: c.opts.Namespace, + } for _, o := range opts { o(&options) } @@ -130,7 +134,9 @@ func (c *client) Log(r *Resource, opts ...LogOption) (io.ReadCloser, error) { // Update updates API object func (c *client) Update(r *Resource, opts ...UpdateOption) error { - var options UpdateOptions + options := UpdateOptions{ + Namespace: c.opts.Namespace, + } for _, o := range opts { o(&options) } @@ -158,7 +164,9 @@ func (c *client) Update(r *Resource, opts ...UpdateOption) error { // Delete removes API object func (c *client) Delete(r *Resource, opts ...DeleteOption) error { - var options DeleteOptions + options := DeleteOptions{ + Namespace: c.opts.Namespace, + } for _, o := range opts { o(&options) } @@ -174,7 +182,9 @@ func (c *client) Delete(r *Resource, opts ...DeleteOption) error { // List lists API objects and stores the result in r func (c *client) List(r *Resource, opts ...ListOption) error { - var options ListOptions + options := ListOptions{ + Namespace: c.opts.Namespace, + } for _, o := range opts { o(&options) } @@ -188,7 +198,9 @@ func (c *client) List(r *Resource, opts ...ListOption) error { // Watch returns an event stream func (c *client) Watch(r *Resource, opts ...WatchOption) (Watcher, error) { - var options WatchOptions + options := WatchOptions{ + Namespace: c.opts.Namespace, + } for _, o := range opts { o(&options) } @@ -233,6 +245,10 @@ func NewService(name, version, typ, namespace string) *Service { svcName = strings.Join([]string{name, version}, "-") } + if len(namespace) == 0 { + namespace = DefaultNamespace + } + Metadata := &Metadata{ Name: svcName, Namespace: SerializeResourceName(namespace), @@ -272,6 +288,10 @@ func NewDeployment(name, version, typ, namespace string) *Deployment { depName = strings.Join([]string{name, version}, "-") } + if len(namespace) == 0 { + namespace = DefaultNamespace + } + Metadata := &Metadata{ Name: depName, Namespace: SerializeResourceName(namespace), From ec929b3d2f044c8f08e6ca26bcc51e0f02482f1f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 23 Apr 2020 17:14:30 +0100 Subject: [PATCH 680/788] log error and ensure we pass through namespace --- runtime/kubernetes/kubernetes.go | 2 +- util/kubernetes/api/response.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 9ac90ce1..c26e2984 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -461,7 +461,7 @@ func (k *kubernetes) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error labels["micro"] = options.Type } - srvs, err := k.getService(labels) + srvs, err := k.getService(labels, client.GetNamespace(options.Namespace)) if err != nil { return nil, err } diff --git a/util/kubernetes/api/response.go b/util/kubernetes/api/response.go index 1d835ae9..bd486413 100644 --- a/util/kubernetes/api/response.go +++ b/util/kubernetes/api/response.go @@ -3,6 +3,7 @@ package api import ( "encoding/json" "errors" + "fmt" "io/ioutil" "net/http" ) @@ -50,9 +51,8 @@ func (r *Response) Into(data interface{}) error { defer r.res.Body.Close() decoder := json.NewDecoder(r.res.Body) - err := decoder.Decode(&data) - if err != nil { - return ErrDecode + if err := decoder.Decode(&data); err != nil { + return fmt.Errorf("%v: %v", ErrDecode, err) } return r.err From 4c05623a3cdbc3a1ce76dc7f01dbbf7bfa0b52a7 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 23 Apr 2020 17:26:59 +0100 Subject: [PATCH 681/788] Image pull secret fix --- runtime/kubernetes/service.go | 5 ++++- util/kubernetes/client/templates.go | 2 +- util/kubernetes/client/types.go | 9 +++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 3673b9ed..0efb2456 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -39,7 +39,10 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { } // set the image pull secrets - kdeploy.Spec.Template.PodSpec.ImagePullSecrets = c.ImagePullSecrets + kdeploy.Spec.Template.PodSpec.ImagePullSecrets = make([]client.ImagePullSecret, len(c.ImagePullSecrets)) + for i, s := range c.ImagePullSecrets { + kdeploy.Spec.Template.PodSpec.ImagePullSecrets[i] = client.ImagePullSecret{Name: s} + } // create if non existent if s.Metadata == nil { diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index dcd08d56..ebac3574 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -53,7 +53,7 @@ spec: imagePullSecrets: {{- with .Spec.Template.PodSpec.ImagePullSecrets }} {{- range . }} - - name: "{{.}}" + - name: "{{ .Name }}" {{- end }} {{- end }} containers: diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index 35febde0..745a2661 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -93,8 +93,8 @@ type Metadata struct { // PodSpec is a pod type PodSpec struct { - Containers []Container `json:"containers"` - ImagePullSecrets []string `json:"imagePullSecrets"` + Containers []Container `json:"containers"` + ImagePullSecrets []ImagePullSecret `json:"imagePullSecrets"` } // PodList @@ -189,3 +189,8 @@ type Namespace struct { type NamespaceList struct { Items []Namespace `json:"items"` } + +// ImagePullSecret +type ImagePullSecret struct { + Name string `json:"name"` +} From 616db3442a6da414078eea45cebf24abc30ce4c5 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 23 Apr 2020 17:44:40 +0100 Subject: [PATCH 682/788] Debugging --- runtime/kubernetes/kubernetes.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index c26e2984..6de713bb 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -38,6 +38,8 @@ func (k *kubernetes) namespaceExists(name string) (bool, error) { return false, err } k.namespaces = namespaceList.Items + fmt.Println("HERE") + fmt.Println(k.namespaces) } // check if the namespace exists in the cache From bb25bd94c8d2acd4bde3535b803a4aa0a0171d6a Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 23 Apr 2020 17:56:00 +0100 Subject: [PATCH 683/788] Log k8s requests --- runtime/kubernetes/kubernetes.go | 2 -- util/kubernetes/api/request.go | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 6de713bb..c26e2984 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -38,8 +38,6 @@ func (k *kubernetes) namespaceExists(name string) (bool, error) { return false, err } k.namespaces = namespaceList.Items - fmt.Println("HERE") - fmt.Println(k.namespaces) } // check if the namespace exists in the cache diff --git a/util/kubernetes/api/request.go b/util/kubernetes/api/request.go index e5a96509..2e4215ef 100644 --- a/util/kubernetes/api/request.go +++ b/util/kubernetes/api/request.go @@ -9,6 +9,8 @@ import ( "io" "net/http" "net/url" + + "github.com/micro/go-micro/v2/logger" ) // Request is used to construct a http request for the k8s API. @@ -217,6 +219,7 @@ func (r *Request) Do() *Response { } } + logger.Debugf("[%v] %v", req.Method, req.URL.String()) res, err := r.client.Do(req) if err != nil { return &Response{ From 8b3d223fc0eeb47a80dc86b222c2594ae0b7766a Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 23 Apr 2020 18:05:58 +0100 Subject: [PATCH 684/788] Remove hardcoded labels: --- util/kubernetes/client/client.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 76e7c52f..06df07fc 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -189,10 +189,6 @@ func (c *client) List(r *Resource, opts ...ListOption) error { o(&options) } - labels := map[string]string{ - "micro": "service", - } - return c.Get(r, GetLabels(labels), GetNamespace(options.Namespace)) } From cd35f503a03fd188bc2d7297dc782239d8860204 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 23 Apr 2020 18:08:02 +0100 Subject: [PATCH 685/788] Remove hardcoded labels --- util/kubernetes/client/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 06df07fc..632a5342 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -189,7 +189,7 @@ func (c *client) List(r *Resource, opts ...ListOption) error { o(&options) } - return c.Get(r, GetLabels(labels), GetNamespace(options.Namespace)) + return c.Get(r, GetNamespace(options.Namespace)) } // Watch returns an event stream From e0a651bfc3fd71a1f70569048299d707394a1923 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 23 Apr 2020 18:10:13 +0100 Subject: [PATCH 686/788] set namespace on create --- util/kubernetes/client/client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 76e7c52f..60e48aab 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -53,7 +53,9 @@ type Client interface { // Create creates new API object func (c *client) Create(r *Resource, opts ...CreateOption) error { - var options CreateOptions + options := CreateOptions{ + Namespace: c.opts.Namespace, + } for _, o := range opts { o(&options) } From f34d58cfbdfc0853fa89ba9898bc0a31e5586b45 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 23 Apr 2020 18:14:06 +0100 Subject: [PATCH 687/788] Remove Debug --- util/kubernetes/api/request.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/util/kubernetes/api/request.go b/util/kubernetes/api/request.go index 2e4215ef..e5a96509 100644 --- a/util/kubernetes/api/request.go +++ b/util/kubernetes/api/request.go @@ -9,8 +9,6 @@ import ( "io" "net/http" "net/url" - - "github.com/micro/go-micro/v2/logger" ) // Request is used to construct a http request for the k8s API. @@ -219,7 +217,6 @@ func (r *Request) Do() *Response { } } - logger.Debugf("[%v] %v", req.Method, req.URL.String()) res, err := r.client.Do(req) if err != nil { return &Response{ From c68226e9b0b1c53f14661ab8950999247154c914 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 23 Apr 2020 19:19:13 +0100 Subject: [PATCH 688/788] only do namespace check if not default --- runtime/kubernetes/kubernetes.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index c26e2984..17b15350 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -412,12 +412,15 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er // ensure the namespace exists namespace := client.SerializeResourceName(options.Namespace) - if exist, err := k.namespaceExists(namespace); err == nil && !exist { - if err := k.createNamespace(namespace); err != nil { + // only do this if the namespace is not default + if namespace != "default" { + if exist, err := k.namespaceExists(namespace); err == nil && !exist { + if err := k.createNamespace(namespace); err != nil { + return err + } + } else if err != nil { return err } - } else if err != nil { - return err } // determine the image from the source and options From d62ae23a9c303068570dc539ac48e0117291cd49 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 23 Apr 2020 20:20:48 +0100 Subject: [PATCH 689/788] Strip label --- runtime/kubernetes/kubernetes.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 17b15350..01f61769 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -439,9 +439,7 @@ func (k *kubernetes) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error defer k.Unlock() // set the default labels - labels := map[string]string{ - "micro": k.options.Type, - } + labels := map[string]string{} options := runtime.ReadOptions{ Namespace: client.DefaultNamespace, From edee3b67652719a7ceac5e7a73124ca97afc3396 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 24 Apr 2020 11:26:46 +0100 Subject: [PATCH 690/788] Add proxy env test (#1569) --- util/net/net_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/util/net/net_test.go b/util/net/net_test.go index d8516d88..85688c36 100644 --- a/util/net/net_test.go +++ b/util/net/net_test.go @@ -2,6 +2,7 @@ package net import ( "net" + "os" "testing" ) @@ -24,3 +25,39 @@ func TestListen(t *testing.T) { // Expect addr DO NOT has extra ":" at the end! } + +// TestProxyEnv checks whether we have proxy/network settings in env +func TestProxyEnv(t *testing.T) { + service := "foo" + address := []string{"bar"} + + s, a, ok := Proxy(service, address) + if ok { + t.Fatal("Should not have proxy", s, a, ok) + } + + test := func(key, val, expectSrv, expectAddr string) { + // set env + os.Setenv(key, val) + + s, a, ok := Proxy(service, address) + if !ok { + t.Fatal("Expected proxy") + } + if len(expectSrv) > 0 && s != expectSrv { + t.Fatal("Expected proxy service", expectSrv, "got", s) + } + if len(expectAddr) > 0 { + if len(a) == 0 || a[0] != expectAddr { + t.Fatal("Expected proxy address", expectAddr, "got", a) + } + } + + os.Unsetenv(key) + } + + test("MICRO_PROXY", "service", "go.micro.proxy", "") + test("MICRO_PROXY_ADDRESS", "10.0.0.1:8080", "", "10.0.0.1:8080") + test("MICRO_NETWORK", "service", "go.micro.network", "") + test("MICRO_NETWORK_ADDRESS", "10.0.0.1:8081", "", "10.0.0.1:8081") +} From 0a030f3d8ad82abc9a1cc5056e7ac406b55c28f8 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 24 Apr 2020 18:05:38 +0100 Subject: [PATCH 691/788] strip unused list endpoint --- runtime/default.go | 14 -------------- runtime/options.go | 4 ++-- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index c3c5c1ec..93c69739 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -393,20 +393,6 @@ func (r *runtime) Delete(s *Service, opts ...DeleteOption) error { return nil } -// List returns a slice of all services tracked by the runtime -func (r *runtime) List() ([]*Service, error) { - r.RLock() - defer r.RUnlock() - - services := make([]*Service, 0, len(r.services)) - - for _, service := range r.services { - services = append(services, service.Service) - } - - return services, nil -} - // Start starts the runtime func (r *runtime) Start() error { r.Lock() diff --git a/runtime/options.go b/runtime/options.go index 959639e3..74c8e926 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -107,9 +107,9 @@ func CreateImage(img string) CreateOption { func CreateImagePullSecret(secrets ...string) CreateOption { return func(o *CreateOptions) { o.ImagePullSecrets = append(o.ImagePullSecrets, secrets...) - } + } } - + // CreateNamespace sets the namespace func CreateNamespace(ns string) CreateOption { return func(o *CreateOptions) { From 7253635cd3bfc29426ba589547e94ef342af33f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=97=AD?= <120582243@qq.com> Date: Sun, 26 Apr 2020 19:44:59 +0800 Subject: [PATCH 692/788] delete invalid copy (#1573) * prealloc * delete invalid copy --- util/socket/socket.go | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/util/socket/socket.go b/util/socket/socket.go index d1338ab5..91fac4bc 100644 --- a/util/socket/socket.go +++ b/util/socket/socket.go @@ -67,23 +67,9 @@ func (s *Socket) Local() string { } func (s *Socket) Send(m *transport.Message) error { - // make copy - msg := &transport.Message{ - Header: make(map[string]string), - Body: make([]byte, len(m.Body)), - } - - // copy headers - for k, v := range m.Header { - msg.Header[k] = v - } - - // copy body - copy(msg.Body, m.Body) - // send a message select { - case s.send <- msg: + case s.send <- m: case <-s.closed: return io.EOF } From a22da39e1cd3fd54bd0ea30a06cc8575b786ab18 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 26 Apr 2020 17:11:53 +0300 Subject: [PATCH 693/788] logger: add caller info to default implementation (#1575) Signed-off-by: Vasiliy Tolstov --- logger/default.go | 18 ++++++++++++++---- logger/logger_test.go | 1 + logger/options.go | 9 +++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/logger/default.go b/logger/default.go index 0b3a432a..6b3f4652 100644 --- a/logger/default.go +++ b/logger/default.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "runtime" "sort" "sync" "time" @@ -64,6 +65,10 @@ func (l *defaultLogger) Log(level Level, v ...interface{}) { fields["level"] = level.String() + if _, file, line, ok := runtime.Caller(l.opts.CallerSkipCount); ok { + fields["caller"] = fmt.Sprintf("%s:%d", file, line) + } + rec := dlog.Record{ Timestamp: time.Now(), Message: fmt.Sprint(v...), @@ -101,6 +106,10 @@ func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) { fields["level"] = level.String() + if _, file, line, ok := runtime.Caller(l.opts.CallerSkipCount); ok { + fields["caller"] = fmt.Sprintf("%s:%d", file, line) + } + rec := dlog.Record{ Timestamp: time.Now(), Message: fmt.Sprintf(format, v...), @@ -134,10 +143,11 @@ func (n *defaultLogger) Options() Options { func NewLogger(opts ...Option) Logger { // Default options options := Options{ - Level: InfoLevel, - Fields: make(map[string]interface{}), - Out: os.Stderr, - Context: context.Background(), + Level: InfoLevel, + Fields: make(map[string]interface{}), + Out: os.Stderr, + CallerSkipCount: 1, + Context: context.Background(), } l := &defaultLogger{opts: options} diff --git a/logger/logger_test.go b/logger/logger_test.go index 846038eb..f36a3a3b 100644 --- a/logger/logger_test.go +++ b/logger/logger_test.go @@ -14,4 +14,5 @@ func TestLogger(t *testing.T) { h2.Trace("trace_msg2") h2.Warn("warn_msg2") + l.Fields(map[string]interface{}{"key3": "val4"}).Log(InfoLevel, "test_msg") } diff --git a/logger/options.go b/logger/options.go index ef13d49f..d0a03302 100644 --- a/logger/options.go +++ b/logger/options.go @@ -14,6 +14,8 @@ type Options struct { Fields map[string]interface{} // It's common to set this to a file, or leave it default which is `os.Stderr` Out io.Writer + // Caller skip frame count for file:line info + CallerSkipCount int // Alternative options Context context.Context } @@ -39,6 +41,13 @@ func WithOutput(out io.Writer) Option { } } +// WithCallerSkipCount set frame count to skip +func WithCallerSkipCount(c int) Option { + return func(args *Options) { + args.CallerSkipCount = c + } +} + func SetOption(k, v interface{}) Option { return func(o *Options) { if o.Context == nil { From 980b7728013567bf9cea0af5ffd7b2fdc07252a5 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 26 Apr 2020 17:41:36 +0300 Subject: [PATCH 694/788] fix races in web and logger (#1576) Signed-off-by: Vasiliy Tolstov --- logger/default.go | 7 ++++++- web/service.go | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/logger/default.go b/logger/default.go index 6b3f4652..e027502e 100644 --- a/logger/default.go +++ b/logger/default.go @@ -136,7 +136,12 @@ func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) { } func (n *defaultLogger) Options() Options { - return n.opts + // not guard against options Context values + n.RLock() + opts := n.opts + opts.Fields = copyFields(n.opts.Fields) + n.RUnlock() + return opts } // NewLogger builds a new logger based on options diff --git a/web/service.go b/web/service.go index 81895f08..62e0a31e 100644 --- a/web/service.go +++ b/web/service.go @@ -29,7 +29,7 @@ type service struct { mux *http.ServeMux srv *registry.Service - sync.Mutex + sync.RWMutex running bool static bool exit chan chan error @@ -90,11 +90,14 @@ func (s *service) genSrv() *registry.Service { } func (s *service) run(exit chan bool) { + s.RLock() if s.opts.RegisterInterval <= time.Duration(0) { + s.RUnlock() return } t := time.NewTicker(s.opts.RegisterInterval) + s.RUnlock() for { select { @@ -327,6 +330,9 @@ func (s *service) HandleFunc(pattern string, handler func(http.ResponseWriter, * } func (s *service) Init(opts ...Option) error { + s.Lock() + defer s.Unlock() + for _, o := range opts { o(&s.opts) } @@ -342,6 +348,9 @@ func (s *service) Init(opts ...Option) error { } serviceOpts = append(serviceOpts, micro.Action(func(ctx *cli.Context) error { + s.Lock() + defer s.Unlock() + if ttl := ctx.Int("register_ttl"); ttl > 0 { s.opts.RegisterTTL = time.Duration(ttl) * time.Second } From e0c9234c0ea0e4830c945356408035c3cae8134b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 27 Apr 2020 00:03:05 +0300 Subject: [PATCH 695/788] web: use default logger (#1577) Signed-off-by: Vasiliy Tolstov --- web/service.go | 30 +++++++++++++++--------------- web/web.go | 3 --- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/web/service.go b/web/service.go index 62e0a31e..faf43ee8 100644 --- a/web/service.go +++ b/web/service.go @@ -55,7 +55,7 @@ func (s *service) genSrv() *registry.Service { if len(s.opts.Address) > 0 { host, port, err = net.SplitHostPort(s.opts.Address) if err != nil { - log.Fatal(err) + logger.Fatal(err) } } @@ -65,13 +65,13 @@ func (s *service) genSrv() *registry.Service { if len(s.opts.Advertise) > 0 { host, port, err = net.SplitHostPort(s.opts.Address) if err != nil { - log.Fatal(err) + logger.Fatal(err) } } addr, err := maddr.Extract(host) if err != nil { - log.Fatal(err) + logger.Fatal(err) } if strings.Count(addr, ":") > 0 { @@ -128,8 +128,8 @@ func (s *service) register() error { // use RegisterCheck func before register if err := s.opts.RegisterCheck(s.opts.Context); err != nil { - if logger.V(logger.ErrorLevel, log) { - log.Errorf("Server %s-%s register check error: %s", s.opts.Name, s.opts.Id, err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("Server %s-%s register check error: %s", s.opts.Name, s.opts.Id, err) } return err } @@ -195,8 +195,8 @@ func (s *service) start() error { if s.static { _, err := os.Stat(static) if err == nil { - if logger.V(logger.InfoLevel, log) { - log.Infof("Enabling static file serving from %s", static) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Enabling static file serving from %s", static) } s.mux.Handle("/", http.FileServer(http.Dir(static))) } @@ -229,8 +229,8 @@ func (s *service) start() error { ch <- l.Close() }() - if logger.V(logger.InfoLevel, log) { - log.Infof("Listening on %v", l.Addr().String()) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Listening on %v", l.Addr().String()) } return nil } @@ -253,8 +253,8 @@ func (s *service) stop() error { s.exit <- ch s.running = false - if logger.V(logger.InfoLevel, log) { - log.Info("Stopping") + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Info("Stopping") } for _, fn := range s.opts.AfterStop { @@ -419,13 +419,13 @@ func (s *service) Run() error { select { // wait on kill signal case sig := <-ch: - if logger.V(logger.InfoLevel, log) { - log.Infof("Received signal %s", sig) + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Received signal %s", sig) } // wait on context cancel case <-s.opts.Context.Done(): - if logger.V(logger.InfoLevel, log) { - log.Info("Received context shutdown") + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Info("Received context shutdown") } } diff --git a/web/web.go b/web/web.go index 1da83fd3..72f653b9 100644 --- a/web/web.go +++ b/web/web.go @@ -7,7 +7,6 @@ import ( "time" "github.com/google/uuid" - "github.com/micro/go-micro/v2/logger" ) // Service is a web service with service discovery built in @@ -38,8 +37,6 @@ var ( // static directory DefaultStaticDir = "html" DefaultRegisterCheck = func(context.Context) error { return nil } - - log = logger.NewHelper(logger.DefaultLogger).WithFields(map[string]interface{}{"service": "web"}) ) // NewService returns a new web.Service From ec44b67e9f399801877e53c9dd5c1d9a35051bdf Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Mon, 27 Apr 2020 10:36:09 +0200 Subject: [PATCH 696/788] Fixing log file path in logs (#1578) --- logger/default.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/logger/default.go b/logger/default.go index e027502e..c71d3f4b 100644 --- a/logger/default.go +++ b/logger/default.go @@ -4,8 +4,10 @@ import ( "context" "fmt" "os" + "path" "runtime" "sort" + "strings" "sync" "time" @@ -53,6 +55,20 @@ func copyFields(src map[string]interface{}) map[string]interface{} { return dst } +var sourceControlSites = []string{"github.com"} + +func logCallerfilePath(filepath string) string { + for _, v := range sourceControlSites { + if strings.Contains(filepath, v) { + parts := strings.Split(filepath, v) + if len(parts) > 0 { + return path.Join(v, parts[1]) + } + } + } + return filepath +} + func (l *defaultLogger) Log(level Level, v ...interface{}) { // TODO decide does we need to write message if log level not used? if !l.opts.Level.Enabled(level) { @@ -66,7 +82,7 @@ func (l *defaultLogger) Log(level Level, v ...interface{}) { fields["level"] = level.String() if _, file, line, ok := runtime.Caller(l.opts.CallerSkipCount); ok { - fields["caller"] = fmt.Sprintf("%s:%d", file, line) + fields["caller"] = fmt.Sprintf("%s:%d", logCallerfilePath(file), line) } rec := dlog.Record{ @@ -107,7 +123,7 @@ func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) { fields["level"] = level.String() if _, file, line, ok := runtime.Caller(l.opts.CallerSkipCount); ok { - fields["caller"] = fmt.Sprintf("%s:%d", file, line) + fields["caller"] = fmt.Sprintf("%s:%d", logCallerfilePath(file), line) } rec := dlog.Record{ @@ -151,7 +167,7 @@ func NewLogger(opts ...Option) Logger { Level: InfoLevel, Fields: make(map[string]interface{}), Out: os.Stderr, - CallerSkipCount: 1, + CallerSkipCount: 2, Context: context.Background(), } From 434997e676451f1930e78f4eeac57f2f2e76ead9 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Mon, 27 Apr 2020 10:55:50 +0200 Subject: [PATCH 697/788] Display only logging file name as opposed to path in logs (#1580) --- logger/default.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/logger/default.go b/logger/default.go index c71d3f4b..828b4867 100644 --- a/logger/default.go +++ b/logger/default.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "os" - "path" + "path/filepath" "runtime" "sort" "strings" @@ -55,18 +55,9 @@ func copyFields(src map[string]interface{}) map[string]interface{} { return dst } -var sourceControlSites = []string{"github.com"} - -func logCallerfilePath(filepath string) string { - for _, v := range sourceControlSites { - if strings.Contains(filepath, v) { - parts := strings.Split(filepath, v) - if len(parts) > 0 { - return path.Join(v, parts[1]) - } - } - } - return filepath +func logCallerfilePath(loggingFilePath string) string { + parts := strings.Split(loggingFilePath, string(filepath.Separator)) + return parts[len(parts)-1] } func (l *defaultLogger) Log(level Level, v ...interface{}) { @@ -82,7 +73,7 @@ func (l *defaultLogger) Log(level Level, v ...interface{}) { fields["level"] = level.String() if _, file, line, ok := runtime.Caller(l.opts.CallerSkipCount); ok { - fields["caller"] = fmt.Sprintf("%s:%d", logCallerfilePath(file), line) + fields["file"] = fmt.Sprintf("%s:%d", logCallerfilePath(file), line) } rec := dlog.Record{ @@ -123,7 +114,7 @@ func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) { fields["level"] = level.String() if _, file, line, ok := runtime.Caller(l.opts.CallerSkipCount); ok { - fields["caller"] = fmt.Sprintf("%s:%d", logCallerfilePath(file), line) + fields["file"] = fmt.Sprintf("%s:%d", logCallerfilePath(file), line) } rec := dlog.Record{ From 494e0b50606c7c1debfb069109ee2f93eaf03d8f Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Mon, 27 Apr 2020 14:13:51 +0100 Subject: [PATCH 698/788] Runtime: Add Kubernetes ServiceAccounts & Remove imagePullSecrets --- runtime/kubernetes/service.go | 6 -- runtime/options.go | 9 --- runtime/service/proto/runtime.pb.go | 99 +++++++++++++---------------- runtime/service/proto/runtime.proto | 2 - runtime/service/service.go | 11 ++-- util/kubernetes/api/request.go | 2 +- util/kubernetes/client/client.go | 1 + util/kubernetes/client/templates.go | 35 +++++++--- util/kubernetes/client/types.go | 10 ++- 9 files changed, 84 insertions(+), 91 deletions(-) diff --git a/runtime/kubernetes/service.go b/runtime/kubernetes/service.go index 0efb2456..b3c02395 100644 --- a/runtime/kubernetes/service.go +++ b/runtime/kubernetes/service.go @@ -38,12 +38,6 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service { kdeploy.Spec.Template.Metadata.Annotations = make(map[string]string) } - // set the image pull secrets - kdeploy.Spec.Template.PodSpec.ImagePullSecrets = make([]client.ImagePullSecret, len(c.ImagePullSecrets)) - for i, s := range c.ImagePullSecrets { - kdeploy.Spec.Template.PodSpec.ImagePullSecrets[i] = client.ImagePullSecret{Name: s} - } - // create if non existent if s.Metadata == nil { s.Metadata = make(map[string]string) diff --git a/runtime/options.go b/runtime/options.go index 74c8e926..d7d9fe90 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -67,8 +67,6 @@ type CreateOptions struct { Retries int // Specify the image to use Image string - // Specify secrets to use when pulling the image - ImagePullSecrets []string // Namespace to create the service in Namespace string // Specify the context to use @@ -103,13 +101,6 @@ func CreateImage(img string) CreateOption { } } -// CreateImagePullSecret sets a secret to use -func CreateImagePullSecret(secrets ...string) CreateOption { - return func(o *CreateOptions) { - o.ImagePullSecrets = append(o.ImagePullSecrets, secrets...) - } -} - // CreateNamespace sets the namespace func CreateNamespace(ns string) CreateOption { return func(o *CreateOptions) { diff --git a/runtime/service/proto/runtime.pb.go b/runtime/service/proto/runtime.pb.go index 3d309bc6..09a56e9f 100644 --- a/runtime/service/proto/runtime.pb.go +++ b/runtime/service/proto/runtime.pb.go @@ -162,9 +162,7 @@ type CreateOptions struct { // create type of service Type string `protobuf:"bytes,5,opt,name=type,proto3" json:"type,omitempty"` // image to use - Image string `protobuf:"bytes,6,opt,name=image,proto3" json:"image,omitempty"` - // image secrets to use - ImagePullSecrets []string `protobuf:"bytes,7,rep,name=image_pull_secrets,json=imagePullSecrets,proto3" json:"image_pull_secrets,omitempty"` + Image string `protobuf:"bytes,6,opt,name=image,proto3" json:"image,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -237,13 +235,6 @@ func (m *CreateOptions) GetImage() string { return "" } -func (m *CreateOptions) GetImagePullSecrets() []string { - if m != nil { - return m.ImagePullSecrets - } - return nil -} - type CreateRequest struct { Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` Options *CreateOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` @@ -821,49 +812,47 @@ func init() { } var fileDescriptor_976fccef828ab1f0 = []byte{ - // 689 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x4b, 0x6f, 0xd3, 0x40, - 0x10, 0xae, 0xe3, 0x3c, 0xda, 0x09, 0x41, 0xd1, 0xaa, 0x42, 0xa6, 0xbc, 0x22, 0x5f, 0x28, 0x12, - 0x38, 0x28, 0x15, 0xe2, 0x25, 0x4e, 0x6d, 0xca, 0xa5, 0x15, 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, 0x41, 0xce, - 0xa1, 0x6b, 0x1e, 0x10, 0x69, 0x7c, 0x74, 0x56, 0xde, 0x83, 0x51, 0x73, 0x82, 0xed, 0xf2, 0x0e, - 0xf9, 0x0a, 0x6d, 0x35, 0xde, 0xa4, 0xe1, 0x39, 0x94, 0xa5, 0x9e, 0x37, 0x7d, 0xae, 0x0a, 0x9d, - 0x43, 0xd7, 0x8c, 0xe6, 0x26, 0x5c, 0x2b, 0xa3, 0xbf, 0x09, 0xd7, 0xda, 0x54, 0xeb, 0x72, 0x66, - 0x22, 0x37, 0x95, 0x5b, 0x99, 0xf8, 0x4d, 0xe5, 0xd6, 0x86, 0x79, 0x87, 0x9c, 0x42, 0x5b, 0x0d, - 0xde, 0x26, 0x9a, 0xb5, 0x81, 0x3c, 0x78, 0x72, 0x4f, 0xd3, 0xfd, 0x9d, 0xb7, 0xce, 0x75, 0x57, - 0xff, 0x5d, 0x8f, 0xfe, 0x07, 0x00, 0x00, 0xff, 0xff, 0x4c, 0x31, 0x4d, 0x46, 0x9e, 0x07, 0x00, - 0x00, + // 662 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xbb, 0x6e, 0xdb, 0x4a, + 0x10, 0x35, 0x45, 0x3d, 0xec, 0xd1, 0xd5, 0x85, 0xb1, 0x30, 0x02, 0xc6, 0x79, 0x09, 0x6c, 0xe2, + 0x14, 0xa1, 0x02, 0x19, 0x41, 0x5e, 0x48, 0x65, 0xcb, 0x69, 0x6c, 0x04, 0x60, 0xe0, 0x0f, 0x58, + 0x53, 0x03, 0x86, 0xb0, 0x97, 0xcb, 0x70, 0x97, 0x02, 0x5c, 0xa5, 0x4c, 0x9d, 0xaf, 0x4a, 0x9d, + 0x3f, 0x0a, 0xf6, 0x41, 0x8a, 0x94, 0x48, 0x37, 0xea, 0x76, 0x46, 0xb3, 0x87, 0xe7, 0x9c, 0x99, + 0x59, 0xc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0x5e, 0x9b, 0xcc, 0xda, 0x40, 0x1e, 0x3f, 0x79, 0xa0, 0xe9, 0xfe, + 0xde, 0x1b, 0xe7, 0x66, 0xa8, 0xff, 0x2f, 0x4f, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x40, 0x42, + 0xb3, 0x4e, 0x70, 0x07, 0x00, 0x00, } diff --git a/runtime/service/proto/runtime.proto b/runtime/service/proto/runtime.proto index bbb6aa67..6c7033c9 100644 --- a/runtime/service/proto/runtime.proto +++ b/runtime/service/proto/runtime.proto @@ -41,8 +41,6 @@ message CreateOptions { string type = 5; // image to use string image = 6; - // image secrets to use - repeated string image_pull_secrets = 7; } message CreateRequest { diff --git a/runtime/service/service.go b/runtime/service/service.go index 6890d27f..06cfc2ad 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -52,12 +52,11 @@ func (s *svc) Create(svc *runtime.Service, opts ...runtime.CreateOption) error { Metadata: svc.Metadata, }, Options: &pb.CreateOptions{ - Command: options.Command, - Args: options.Args, - Env: options.Env, - Type: options.Type, - Image: options.Image, - ImagePullSecrets: options.ImagePullSecrets, + Command: options.Command, + Args: options.Args, + Env: options.Env, + Type: options.Type, + Image: options.Image, }, } diff --git a/util/kubernetes/api/request.go b/util/kubernetes/api/request.go index e5a96509..5abbeb7d 100644 --- a/util/kubernetes/api/request.go +++ b/util/kubernetes/api/request.go @@ -163,7 +163,7 @@ func (r *Request) request() (*http.Request, error) { case "namespace": // /api/v1/namespaces/ url = fmt.Sprintf("%s/api/v1/namespaces/", r.host) - case "pod", "service", "endpoint": + case "pod", "service", "endpoint", "serviceaccount": // /api/v1/namespaces/{namespace}/pods url = fmt.Sprintf("%s/api/v1/namespaces/%s/%ss/", r.host, r.namespace, r.resource) case "deployment": diff --git a/util/kubernetes/client/client.go b/util/kubernetes/client/client.go index 1518ba13..f1c27087 100644 --- a/util/kubernetes/client/client.go +++ b/util/kubernetes/client/client.go @@ -312,6 +312,7 @@ func NewDeployment(name, version, typ, namespace string) *Deployment { Template: &Template{ Metadata: Metadata, PodSpec: &PodSpec{ + ServiceAccountName: namespace, Containers: []Container{{ Name: name, Image: DefaultImage, diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index ebac3574..2442caf3 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -1,9 +1,10 @@ package client var templates = map[string]string{ - "deployment": deploymentTmpl, - "service": serviceTmpl, - "namespace": namespaceTmpl, + "deployment": deploymentTmpl, + "service": serviceTmpl, + "namespace": namespaceTmpl, + "serviceaccount": serviceAccountTmpl, } // stripped image pull policy always @@ -49,13 +50,8 @@ spec: {{ $key }}: "{{ $value }}" {{- end }} {{- end }} - spec: - imagePullSecrets: - {{- with .Spec.Template.PodSpec.ImagePullSecrets }} - {{- range . }} - - name: "{{ .Name }}" - {{- end }} - {{- end }} + spec: + serviceAccountName: {{ .Spec.Template.PodSpec.ServiceAccountName }} containers: {{- with .Spec.Template.PodSpec.Containers }} {{- range . }} @@ -128,3 +124,22 @@ metadata: {{- end }} {{- end }} ` + +var serviceAccountTmpl = ` +apiVersion: v1 +kind: ServiceAccount +metadata: + name: "{{ .Metadata.Name }}" + labels: + {{- with .Metadata.Labels }} + {{- range $key, $value := . }} + {{ $key }}: "{{ $value }}" + {{- end }} + {{- end }} +imagePullSecrets: +{{- with .ImagePullSecrets }} +{{- range . }} +- name: "{{ .Name }}" +{{- end }} +{{- end }} +` diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index 745a2661..3c4e20d9 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -93,8 +93,8 @@ type Metadata struct { // PodSpec is a pod type PodSpec struct { - Containers []Container `json:"containers"` - ImagePullSecrets []ImagePullSecret `json:"imagePullSecrets"` + Containers []Container `json:"containers"` + ServiceAccountName string `json:"serviceAccountName"` } // PodList @@ -194,3 +194,9 @@ type NamespaceList struct { type ImagePullSecret struct { Name string `json:"name"` } + +// ServiceAccount +type ServiceAccount struct { + Metadata *Metadata `json:"metadata,omitempty"` + ImagePullSecrets []ImagePullSecret `json:"imagePullSecrets,omitempty"` +} From 8d7d6ef358c49820370de45f7dd243c7c4a68fee Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Mon, 27 Apr 2020 14:37:28 +0100 Subject: [PATCH 699/788] Add k8s secrets --- util/kubernetes/api/request.go | 6 +++--- util/kubernetes/client/templates.go | 21 +++++++++++++++++++++ util/kubernetes/client/types.go | 7 +++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/util/kubernetes/api/request.go b/util/kubernetes/api/request.go index 5abbeb7d..92bcbed6 100644 --- a/util/kubernetes/api/request.go +++ b/util/kubernetes/api/request.go @@ -163,12 +163,12 @@ func (r *Request) request() (*http.Request, error) { case "namespace": // /api/v1/namespaces/ url = fmt.Sprintf("%s/api/v1/namespaces/", r.host) - case "pod", "service", "endpoint", "serviceaccount": - // /api/v1/namespaces/{namespace}/pods - url = fmt.Sprintf("%s/api/v1/namespaces/%s/%ss/", r.host, r.namespace, r.resource) case "deployment": // /apis/apps/v1/namespaces/{namespace}/deployments/{name} url = fmt.Sprintf("%s/apis/apps/v1/namespaces/%s/%ss/", r.host, r.namespace, r.resource) + default: + // /api/v1/namespaces/{namespace}/{resource} + url = fmt.Sprintf("%s/api/v1/namespaces/%s/%ss/", r.host, r.namespace, r.resource) } // append resourceName if it is present diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index 2442caf3..9c2851c8 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -4,6 +4,7 @@ var templates = map[string]string{ "deployment": deploymentTmpl, "service": serviceTmpl, "namespace": namespaceTmpl, + "secret": secretTmpl, "serviceaccount": serviceAccountTmpl, } @@ -125,6 +126,26 @@ metadata: {{- end }} ` +var secretTmpl = ` +apiVersion: v1 +kind: Secret +metadata: + name: "{{ .Metadata.Name }}" + namespace: "{{ .Metadata.Namespace }}" + labels: + {{- with .Metadata.Labels }} + {{- range $key, $value := . }} + {{ $key }}: "{{ $value }}" + {{- end }} + {{- end }} +data: +{{- with .Data }} +{{- range $key, $value := . }} +{{ $key }}: "{{ $value }}" +{{- end }} +{{- end }} +` + var serviceAccountTmpl = ` apiVersion: v1 kind: ServiceAccount diff --git a/util/kubernetes/client/types.go b/util/kubernetes/client/types.go index 3c4e20d9..1dc13e4e 100644 --- a/util/kubernetes/client/types.go +++ b/util/kubernetes/client/types.go @@ -195,6 +195,13 @@ type ImagePullSecret struct { Name string `json:"name"` } +// Secret +type Secret struct { + Type string `json:"type,omitempty"` + Data map[string]string `json:"data"` + Metadata *Metadata `json:"metadata"` +} + // ServiceAccount type ServiceAccount struct { Metadata *Metadata `json:"metadata,omitempty"` From 83ab47333f6905d1dc9bcdc4ad6840569be3452c Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 27 Apr 2020 14:57:57 +0100 Subject: [PATCH 700/788] rename Codec to Secrets (#1581) --- config/secrets/box/box.go | 4 +-- config/secrets/box/box_test.go | 2 +- config/secrets/secretbox/secretbox.go | 10 +++--- config/secrets/secretbox/secretbox_test.go | 8 ++--- config/secrets/secrets.go | 40 +++++++++++++--------- 5 files changed, 35 insertions(+), 29 deletions(-) diff --git a/config/secrets/box/box.go b/config/secrets/box/box.go index 54192c3d..67c559ff 100644 --- a/config/secrets/box/box.go +++ b/config/secrets/box/box.go @@ -18,8 +18,8 @@ type box struct { privateKey [keyLength]byte } -// NewCodec returns a nacl-box codec -func NewCodec(opts ...secrets.Option) secrets.Codec { +// NewSecrets returns a nacl-box codec +func NewSecrets(opts ...secrets.Option) secrets.Secrets { b := &box{} for _, o := range opts { o(&b.options) diff --git a/config/secrets/box/box_test.go b/config/secrets/box/box_test.go index 43b3e141..3196ae8c 100644 --- a/config/secrets/box/box_test.go +++ b/config/secrets/box/box_test.go @@ -18,7 +18,7 @@ func TestBox(t *testing.T) { if err != nil { t.Fatal(err) } - alice, bob := NewCodec(secrets.PublicKey(alicePublicKey[:]), secrets.PrivateKey(alicePrivateKey[:])), NewCodec() + alice, bob := NewSecrets(secrets.PublicKey(alicePublicKey[:]), secrets.PrivateKey(alicePrivateKey[:])), NewSecrets() if err := alice.Init(); err != nil { t.Error(err) } diff --git a/config/secrets/secretbox/secretbox.go b/config/secrets/secretbox/secretbox.go index 31c36ea3..50dae519 100644 --- a/config/secrets/secretbox/secretbox.go +++ b/config/secrets/secretbox/secretbox.go @@ -18,8 +18,8 @@ type secretBox struct { secretKey [keyLength]byte } -// NewCodec returns a secretbox codec -func NewCodec(opts ...secrets.Option) secrets.Codec { +// NewSecrets returns a secretbox codec +func NewSecrets(opts ...secrets.Option) secrets.Secrets { sb := &secretBox{} for _, o := range opts { o(&sb.options) @@ -31,13 +31,13 @@ func (s *secretBox) Init(opts ...secrets.Option) error { for _, o := range opts { o(&s.options) } - if len(s.options.SecretKey) == 0 { + if len(s.options.Key) == 0 { return errors.New("no secret key is defined") } - if len(s.options.SecretKey) != keyLength { + if len(s.options.Key) != keyLength { return errors.Errorf("secret key must be %d bytes long", keyLength) } - copy(s.secretKey[:], s.options.SecretKey) + copy(s.secretKey[:], s.options.Key) return nil } diff --git a/config/secrets/secretbox/secretbox_test.go b/config/secrets/secretbox/secretbox_test.go index 04c3a2f5..a0c1e07a 100644 --- a/config/secrets/secretbox/secretbox_test.go +++ b/config/secrets/secretbox/secretbox_test.go @@ -14,21 +14,21 @@ func TestSecretBox(t *testing.T) { t.Fatal(err) } - s := NewCodec() + s := NewSecrets() if err := s.Init(); err == nil { t.Error("Secretbox accepted an empty secret key") } - if err := s.Init(secrets.SecretKey([]byte("invalid"))); err == nil { + if err := s.Init(secrets.Key([]byte("invalid"))); err == nil { t.Error("Secretbox accepted a secret key that is invalid") } - if err := s.Init(secrets.SecretKey(secretKey)); err != nil { + if err := s.Init(secrets.Key(secretKey)); err != nil { t.Fatal(err) } o := s.Options() - if !reflect.DeepEqual(o.SecretKey, secretKey) { + if !reflect.DeepEqual(o.Key, secretKey) { t.Error("Init() didn't set secret key correctly") } if s.String() != "nacl-secretbox" { diff --git a/config/secrets/secrets.go b/config/secrets/secrets.go index b2ec4c07..c8551355 100644 --- a/config/secrets/secrets.go +++ b/config/secrets/secrets.go @@ -3,33 +3,39 @@ package secrets import "context" -// Codec encrypts or decrypts arbitrary data. The data should be as small as possible -type Codec interface { +// Secrets encrypts or decrypts arbitrary data. The data should be as small as possible +type Secrets interface { + // Initialise options Init(...Option) error + // Return the options Options() Options - String() string + // Decrypt a value Decrypt([]byte, ...DecryptOption) ([]byte, error) + // Encrypt a value Encrypt([]byte, ...EncryptOption) ([]byte, error) + // Secrets implementation + String() string } -// Options is a codec's options -// SecretKey or both PublicKey and PrivateKey should be set depending on the -// underlying implementation type Options struct { - SecretKey []byte + // Key is a symmetric key for encoding + Key []byte + // Private key for decoding PrivateKey []byte - PublicKey []byte - Context context.Context + // Public key for encoding + PublicKey []byte + // Context for other opts + Context context.Context } // Option sets options type Option func(*Options) -// SecretKey sets the symmetric secret key -func SecretKey(key []byte) Option { +// Key sets the symmetric secret key +func Key(k []byte) Option { return func(o *Options) { - o.SecretKey = make([]byte, len(key)) - copy(o.SecretKey, key) + o.Key = make([]byte, len(k)) + copy(o.Key, k) } } @@ -49,7 +55,7 @@ func PrivateKey(key []byte) Option { } } -// DecryptOptions can be passed to Codec.Decrypt +// DecryptOptions can be passed to Secrets.Decrypt type DecryptOptions struct { SenderPublicKey []byte } @@ -57,7 +63,7 @@ type DecryptOptions struct { // DecryptOption sets DecryptOptions type DecryptOption func(*DecryptOptions) -// SenderPublicKey is the Public Key of the Codec that encrypted this message +// SenderPublicKey is the Public Key of the Secrets that encrypted this message func SenderPublicKey(key []byte) DecryptOption { return func(d *DecryptOptions) { d.SenderPublicKey = make([]byte, len(key)) @@ -65,7 +71,7 @@ func SenderPublicKey(key []byte) DecryptOption { } } -// EncryptOptions can be passed to Codec.Encrypt +// EncryptOptions can be passed to Secrets.Encrypt type EncryptOptions struct { RecipientPublicKey []byte } @@ -73,7 +79,7 @@ type EncryptOptions struct { // EncryptOption Sets EncryptOptions type EncryptOption func(*EncryptOptions) -// RecipientPublicKey is the Public Key of the Codec that will decrypt this message +// RecipientPublicKey is the Public Key of the Secrets that will decrypt this message func RecipientPublicKey(key []byte) EncryptOption { return func(e *EncryptOptions) { e.RecipientPublicKey = make([]byte, len(key)) From 8148e0a0f817cf2b9baecaf97be0b6af4b5d35cd Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Tue, 28 Apr 2020 09:49:39 +0200 Subject: [PATCH 701/788] Micro log fixes (#1570) --- runtime/default.go | 56 +++++++++++++++++++++++++++++++------- runtime/service/service.go | 42 ++++++++++++++++++++++------ 2 files changed, 80 insertions(+), 18 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index 93c69739..5b85a3a2 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -251,6 +251,18 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error { return nil } +// exists returns whether the given file or directory exists +func exists(path string) (bool, error) { + _, err := os.Stat(path) + if err == nil { + return true, nil + } + if os.IsNotExist(err) { + return false, nil + } + return true, err +} + // @todo: Getting existing lines is not supported yet. // The reason for this is because it's hard to calculate line offset // as opposed to character offset. @@ -265,18 +277,41 @@ func (r *runtime) Logs(s *Service, options ...LogsOption) (LogStream, error) { stream: make(chan LogRecord), stop: make(chan bool), } - t, err := tail.TailFile(logFile(s.Name), tail.Config{Follow: true, Location: &tail.SeekInfo{ - Whence: 2, - Offset: 0, + + fpath := logFile(s.Name) + if ex, err := exists(fpath); err != nil { + return nil, err + } else if !ex { + return nil, fmt.Errorf("Log file %v does not exists", fpath) + } + + whence := 2 + // Multiply by length of an average line of log in bytes + offset := -1 * lopts.Count * 200 + + t, err := tail.TailFile(logFile(s.Name), tail.Config{Follow: lopts.Stream, Location: &tail.SeekInfo{ + Whence: whence, + Offset: int64(offset), }, Logger: tail.DiscardingLogger}) if err != nil { return nil, err } + ret.tail = t go func() { - for line := range t.Lines { - ret.stream <- LogRecord{Message: line.Text} + for { + select { + case line, ok := <-t.Lines: + if !ok { + ret.Stop() + return + } + ret.stream <- LogRecord{Message: line.Text} + case <-ret.stop: + return + } } + }() return ret, nil } @@ -301,16 +336,17 @@ func (l *logStream) Error() error { func (l *logStream) Stop() error { l.Lock() defer l.Unlock() - // @todo seems like this is causing a hangup - //err := l.tail.Stop() - //if err != nil { - // return err - //} + select { case <-l.stop: return nil default: close(l.stop) + close(l.stream) + err := l.tail.Stop() + if err != nil { + return err + } } return nil } diff --git a/runtime/service/service.go b/runtime/service/service.go index 06cfc2ad..f2c5c95a 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -7,7 +7,6 @@ import ( "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/runtime" pb "github.com/micro/go-micro/v2/runtime/service/proto" - "github.com/micro/go-micro/v2/util/log" ) type svc struct { @@ -72,14 +71,15 @@ func (s *svc) Logs(service *runtime.Service, opts ...runtime.LogsOption) (runtim for _, o := range opts { o(&options) } + if options.Context == nil { options.Context = context.Background() } ls, err := s.runtime.Logs(options.Context, &pb.LogsRequest{ Service: service.Name, - Stream: true, - Count: 10, // @todo pass in actual options + Stream: options.Stream, + Count: options.Count, }) if err != nil { return nil, err @@ -89,14 +89,39 @@ func (s *svc) Logs(service *runtime.Service, opts ...runtime.LogsOption) (runtim stream: make(chan runtime.LogRecord), stop: make(chan bool), } + go func() { for { - record := runtime.LogRecord{} - err := ls.RecvMsg(&record) - if err != nil { - log.Error(err) + select { + // @todo this never seems to return, investigate + case <-ls.Context().Done(): + logStream.Stop() + } + } + }() + + go func() { + for { + select { + // @todo this never seems to return, investigate + case <-ls.Context().Done(): + return + case _, ok := <-logStream.stream: + if !ok { + return + } + default: + record := pb.LogRecord{} + err := ls.RecvMsg(&record) + if err != nil { + logStream.Stop() + return + } + logStream.stream <- runtime.LogRecord{ + Message: record.GetMessage(), + Metadata: record.GetMetadata(), + } } - logStream.stream <- record } }() return logStream, nil @@ -125,6 +150,7 @@ func (l *serviceLogStream) Stop() error { case <-l.stop: return nil default: + close(l.stream) close(l.stop) } return nil From b875868a395d174ce1ce093a834a68bd6aa88eb3 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Tue, 28 Apr 2020 10:51:39 +0200 Subject: [PATCH 702/788] Don't ignore errors from checkout source code (#1584) Don't check out code for builtin services. --- runtime/default.go | 18 +++++++++++++++--- runtime/local/git/git.go | 12 +++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index 5b85a3a2..2e36b3b6 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -55,11 +55,17 @@ func NewRuntime(opts ...Option) Runtime { // @todo move this to runtime default func (r *runtime) checkoutSourceIfNeeded(s *Service) error { + // Runtime service like config have no source. + // Skip checkout in that case + if len(s.Source) == 0 { + return nil + } source, err := git.ParseSourceLocal("", s.Source) if err != nil { return err } source.Ref = s.Version + err = git.CheckoutSource(os.TempDir(), source) if err != nil { return err @@ -209,7 +215,10 @@ func serviceKey(s *Service) string { // Create creates a new service which is then started by runtime func (r *runtime) Create(s *Service, opts ...CreateOption) error { - r.checkoutSourceIfNeeded(s) + err := r.checkoutSourceIfNeeded(s) + if err != nil { + return err + } r.Lock() defer r.Unlock() @@ -389,14 +398,17 @@ func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) { // Update attemps to update the service func (r *runtime) Update(s *Service, opts ...UpdateOption) error { - r.checkoutSourceIfNeeded(s) + err := r.checkoutSourceIfNeeded(s) + if err != nil { + return err + } r.Lock() service, ok := r.services[serviceKey(s)] r.Unlock() if !ok { return errors.New("Service not found") } - err := service.Stop() + err = service.Stop() if err != nil { return err } diff --git a/runtime/local/git/git.go b/runtime/local/git/git.go index c23a8080..956f02e7 100644 --- a/runtime/local/git/git.go +++ b/runtime/local/git/git.go @@ -1,6 +1,7 @@ package git import ( + "errors" "fmt" "os" "os/exec" @@ -105,7 +106,7 @@ type binaryGitter struct { } func (g binaryGitter) Clone(repo string) error { - fold := filepath.Join(g.folder, dirifyRepo(repo)) + fold := filepath.Join(g.folder, dirifyRepo(repo), ".git") exists, err := pathExists(fold) if err != nil { return err @@ -113,6 +114,7 @@ func (g binaryGitter) Clone(repo string) error { if exists { return nil } + fold = filepath.Join(g.folder, dirifyRepo(repo)) cmd := exec.Command("git", "clone", repo, ".") err = os.MkdirAll(fold, 0777) @@ -130,9 +132,9 @@ func (g binaryGitter) Clone(repo string) error { func (g binaryGitter) FetchAll(repo string) error { cmd := exec.Command("git", "fetch", "--all") cmd.Dir = filepath.Join(g.folder, dirifyRepo(repo)) - _, err := cmd.Output() + outp, err := cmd.CombinedOutput() if err != nil { - return err + return errors.New(string(outp)) } return err } @@ -143,9 +145,9 @@ func (g binaryGitter) Checkout(repo, branchOrCommit string) error { } cmd := exec.Command("git", "checkout", "-f", branchOrCommit) cmd.Dir = filepath.Join(g.folder, dirifyRepo(repo)) - _, err := cmd.Output() + outp, err := cmd.CombinedOutput() if err != nil { - return err + return errors.New(string(outp)) } return nil } From 414b2ec5f87a5d7cc39dc0dedaeadd49394e22bc Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 28 Apr 2020 14:23:52 +0300 Subject: [PATCH 703/788] web: fix deadlock (#1585) * web: fix deadlock Signed-off-by: Vasiliy Tolstov * add web tests Signed-off-by: Vasiliy Tolstov --- web/service.go | 24 ++++++++++++++++- web/web_test.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 web/web_test.go diff --git a/web/service.go b/web/service.go index faf43ee8..d8f01179 100644 --- a/web/service.go +++ b/web/service.go @@ -111,6 +111,9 @@ func (s *service) run(exit chan bool) { } func (s *service) register() error { + s.RLock() + defer s.RUnlock() + if s.srv == nil { return nil } @@ -138,6 +141,9 @@ func (s *service) register() error { } func (s *service) deregister() error { + s.RLock() + defer s.RUnlock() + if s.srv == nil { return nil } @@ -280,18 +286,22 @@ func (s *service) Client() *http.Client { func (s *service) Handle(pattern string, handler http.Handler) { var seen bool + s.RLock() for _, ep := range s.srv.Endpoints { if ep.Name == pattern { seen = true break } } + s.RUnlock() // if its unseen then add an endpoint if !seen { + s.Lock() s.srv.Endpoints = append(s.srv.Endpoints, ®istry.Endpoint{ Name: pattern, }) + s.Unlock() } // disable static serving @@ -306,17 +316,23 @@ func (s *service) Handle(pattern string, handler http.Handler) { } func (s *service) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) { + var seen bool + s.RLock() for _, ep := range s.srv.Endpoints { if ep.Name == pattern { seen = true break } } + s.RUnlock() + if !seen { + s.Lock() s.srv.Endpoints = append(s.srv.Endpoints, ®istry.Endpoint{ Name: pattern, }) + s.Unlock() } // disable static serving @@ -331,7 +347,6 @@ func (s *service) HandleFunc(pattern string, handler func(http.ResponseWriter, * func (s *service) Init(opts ...Option) error { s.Lock() - defer s.Unlock() for _, o := range opts { o(&s.opts) @@ -347,6 +362,8 @@ func (s *service) Init(opts ...Option) error { serviceOpts = append(serviceOpts, micro.Registry(s.opts.Registry)) } + s.Unlock() + serviceOpts = append(serviceOpts, micro.Action(func(ctx *cli.Context) error { s.Lock() defer s.Unlock() @@ -386,14 +403,19 @@ func (s *service) Init(opts ...Option) error { return nil })) + s.RLock() // pass in own name and version serviceOpts = append(serviceOpts, micro.Name(s.opts.Name)) serviceOpts = append(serviceOpts, micro.Version(s.opts.Version)) + s.RUnlock() s.opts.Service.Init(serviceOpts...) + + s.Lock() srv := s.genSrv() srv.Endpoints = s.srv.Endpoints s.srv = srv + s.Unlock() return nil } diff --git a/web/web_test.go b/web/web_test.go new file mode 100644 index 00000000..d385bdf4 --- /dev/null +++ b/web/web_test.go @@ -0,0 +1,72 @@ +package web_test + +import ( + "context" + "fmt" + "sync" + "testing" + "time" + + "github.com/micro/cli/v2" + "github.com/micro/go-micro/v2" + "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/web" +) + +func TestWeb(t *testing.T) { + for i := 0; i < 10; i++ { + fmt.Println("Test nr", i) + testFunc() + } +} + +func testFunc() { + ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*250) + defer cancel() + + s := micro.NewService( + micro.Name("test"), + micro.Context(ctx), + micro.HandleSignal(false), + micro.Flags( + &cli.StringFlag{ + Name: "test.timeout", + }, + &cli.BoolFlag{ + Name: "test.v", + }, + &cli.StringFlag{ + Name: "test.run", + }, + &cli.StringFlag{ + Name: "test.testlogfile", + }, + ), + ) + w := web.NewService( + web.MicroService(s), + web.Context(ctx), + web.HandleSignal(false), + ) + //s.Init() + //w.Init() + + var wg sync.WaitGroup + wg.Add(2) + go func() { + defer wg.Done() + err := s.Run() + if err != nil { + logger.Errorf("micro run error: %v", err) + } + }() + go func() { + defer wg.Done() + err := w.Run() + if err != nil { + logger.Errorf("web run error: %v", err) + } + }() + + wg.Wait() +} From 52861310b04345a0fee405f8438e7cccd8b6ef16 Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Tue, 28 Apr 2020 15:06:01 +0300 Subject: [PATCH 704/788] fix HTTP 401 Unauthorized, {"message": "401: Unauthorized", "code": 0} (#1586) fix file=bot.go:426 level=error service=bot error starting bot HTTP 401 Unauthorized, {"message": "401: Unauthorized", "code": 0} see https://github.com/bwmarrin/discordgo#usage --- agent/input/discord/discord.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/input/discord/discord.go b/agent/input/discord/discord.go index 3c25f568..991fc2d5 100644 --- a/agent/input/discord/discord.go +++ b/agent/input/discord/discord.go @@ -87,7 +87,7 @@ func (d *discordInput) Start() error { } var err error - d.session, err = discordgo.New(d.token) + d.session, err = discordgo.New("Bot " + d.token) if err != nil { return err } From da66561d1ee416858f3211d431123137a23497f3 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Tue, 28 Apr 2020 14:42:15 +0200 Subject: [PATCH 705/788] Fixing too large offsets for default runtime logs (#1587) --- runtime/default.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index 2e36b3b6..bd783f50 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -294,11 +294,23 @@ func (r *runtime) Logs(s *Service, options ...LogsOption) (LogStream, error) { return nil, fmt.Errorf("Log file %v does not exists", fpath) } + // have to check file size to avoid too big of a seek + fi, err := os.Stat(fpath) + if err != nil { + return nil, err + } + size := fi.Size() + whence := 2 // Multiply by length of an average line of log in bytes - offset := -1 * lopts.Count * 200 + offset := lopts.Count * 200 - t, err := tail.TailFile(logFile(s.Name), tail.Config{Follow: lopts.Stream, Location: &tail.SeekInfo{ + if offset > size { + offset = size + } + offset *= -1 + + t, err := tail.TailFile(fpath, tail.Config{Follow: lopts.Stream, Location: &tail.SeekInfo{ Whence: whence, Offset: int64(offset), }, Logger: tail.DiscardingLogger}) @@ -354,6 +366,7 @@ func (l *logStream) Stop() error { close(l.stream) err := l.tail.Stop() if err != nil { + logger.Errorf("Error stopping tail: %v", err) return err } } From 06220ab8c81c8447a29d656c249f09b790a1fc97 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 28 Apr 2020 19:03:37 +0300 Subject: [PATCH 706/788] client: add context publish option (#1588) Signed-off-by: Vasiliy Tolstov --- client/options.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client/options.go b/client/options.go index da3d592e..fed5992f 100644 --- a/client/options.go +++ b/client/options.go @@ -252,6 +252,13 @@ func WithExchange(e string) PublishOption { } } +// PublishContext sets the context in publish options +func PublishContext(ctx context.Context) PublishOption { + return func(o *PublishOptions) { + o.Context = ctx + } +} + // WithAddress sets the remote addresses to use rather than using service discovery func WithAddress(a ...string) CallOption { return func(o *CallOptions) { From 9bb1904a388dc9ef4fe35fab7388903a325ef17c Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 28 Apr 2020 19:29:00 +0300 Subject: [PATCH 707/788] broker: add publish context (#1590) Signed-off-by: Vasiliy Tolstov --- broker/options.go | 7 +++++++ client/grpc/grpc.go | 2 +- client/rpc_client.go | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/broker/options.go b/broker/options.go index b3317d24..18fd5935 100644 --- a/broker/options.go +++ b/broker/options.go @@ -49,6 +49,13 @@ type Option func(*Options) type PublishOption func(*PublishOptions) +// PublishContext set context +func PublishContext(ctx context.Context) PublishOption { + return func(o *PublishOptions) { + o.Context = ctx + } +} + type SubscribeOption func(*SubscribeOptions) func NewSubscribeOptions(opts ...SubscribeOption) SubscribeOptions { diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index d41d977e..9445eabe 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -653,7 +653,7 @@ func (g *grpcClient) Publish(ctx context.Context, p client.Message, opts ...clie return g.opts.Broker.Publish(topic, &broker.Message{ Header: md, Body: body, - }) + }, broker.PublishContext(options.Context)) } func (g *grpcClient) String() string { diff --git a/client/rpc_client.go b/client/rpc_client.go index 19a18bdb..d66a918a 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -628,7 +628,7 @@ func (r *rpcClient) Publish(ctx context.Context, msg Message, opts ...PublishOpt return r.opts.Broker.Publish(topic, &broker.Message{ Header: md, Body: body, - }) + }, broker.PublishContext(options.Context)) } func (r *rpcClient) NewMessage(topic string, message interface{}, opts ...MessageOption) Message { From f908110fb6849fec5c78d9a0ed332ac78645c6df Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 28 Apr 2020 17:35:18 +0100 Subject: [PATCH 708/788] swap out context access for account (#1589) --- auth/auth.go | 35 +++++++---------------------------- util/wrapper/wrapper.go | 5 +---- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index d18b0e38..761e742a 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -3,11 +3,8 @@ package auth import ( "context" - "encoding/json" "errors" "time" - - "github.com/micro/go-micro/v2/metadata" ) var ( @@ -90,8 +87,6 @@ type Token struct { const ( // DefaultNamespace used for auth DefaultNamespace = "go.micro" - // MetadataKey is the key used when storing the account in metadata - MetadataKey = "auth-account" // TokenCookieName is the name of the cookie which stores the auth token TokenCookieName = "micro-token" // SecretCookieName is the name of the cookie which stores the auth secret @@ -100,34 +95,18 @@ const ( BearerScheme = "Bearer " ) +type accountKey struct{} + // AccountFromContext gets the account from the context, which // is set by the auth wrapper at the start of a call. If the account // is not set, a nil account will be returned. The error is only returned // when there was a problem retrieving an account -func AccountFromContext(ctx context.Context) (*Account, error) { - str, ok := metadata.Get(ctx, MetadataKey) - // there was no account set - if !ok { - return nil, nil - } - - var acc *Account - // metadata is stored as a string, so unmarshal to an account - if err := json.Unmarshal([]byte(str), &acc); err != nil { - return nil, err - } - - return acc, nil +func AccountFromContext(ctx context.Context) (*Account, bool) { + acc, ok := ctx.Value(accountKey{}).(*Account) + return acc, ok } // ContextWithAccount sets the account in the context -func ContextWithAccount(ctx context.Context, account *Account) (context.Context, error) { - // metadata is stored as a string, so marshal to bytes - bytes, err := json.Marshal(account) - if err != nil { - return ctx, err - } - - // generate a new context with the MetadataKey set - return metadata.Set(ctx, MetadataKey, string(bytes)), nil +func ContextWithAccount(ctx context.Context, account *Account) context.Context { + return context.WithValue(ctx, accountKey{}, account) } diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index e5ce4bb1..bfd1ce9f 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -178,10 +178,7 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { } // There is an account, set it in the context - ctx, err = auth.ContextWithAccount(ctx, account) - if err != nil { - return err - } + ctx = auth.ContextWithAccount(ctx, account) // The user is authorised, allow the call return h(ctx, req, rsp) From 8ccbf53dfcd3e8bfb043a7fa415602bc61914ca6 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 28 Apr 2020 18:12:07 +0100 Subject: [PATCH 709/788] secret cookie unused --- auth/auth.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 761e742a..fbca70a6 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -89,8 +89,6 @@ const ( DefaultNamespace = "go.micro" // TokenCookieName is the name of the cookie which stores the auth token TokenCookieName = "micro-token" - // SecretCookieName is the name of the cookie which stores the auth secret - SecretCookieName = "micro-secret" // BearerScheme used for Authorization header BearerScheme = "Bearer " ) From c7440274dded6a1af3ce5ad76abe95b9ffd74991 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 28 Apr 2020 19:35:13 +0100 Subject: [PATCH 710/788] touch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a396444..491c42db 100644 --- a/README.md +++ b/README.md @@ -53,5 +53,5 @@ See the [docs](https://micro.mu/docs/framework.html) for detailed information on ## License -Go Micro is Apache 2.0 licensed +Go Micro is Apache 2.0 licensed. From 669364985e7b96f350dc489b3f30b513c7c0b569 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 29 Apr 2020 09:21:17 +0100 Subject: [PATCH 711/788] JWT auth implementation --- auth/jwt/jwt.go | 82 +++++++++++++++++++++++++++++++++++++++++++++++ config/cmd/cmd.go | 2 ++ 2 files changed, 84 insertions(+) create mode 100644 auth/jwt/jwt.go diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go new file mode 100644 index 00000000..9eb7b864 --- /dev/null +++ b/auth/jwt/jwt.go @@ -0,0 +1,82 @@ +package jwt + +import ( + "errors" + + "github.com/micro/go-micro/v2/auth" + "github.com/micro/go-micro/v2/auth/token" + jwtToken "github.com/micro/go-micro/v2/auth/token/jwt" +) + +// NewAuth returns a new instance of the Auth service +func NewAuth(opts ...auth.Option) auth.Auth { + j := new(jwt) + j.Init(opts...) + return j +} + +// jwt is the service implementation of the Auth interface +type jwt struct { + options auth.Options + jwt token.Provider +} + +func (j *jwt) String() string { + return "jwt" +} + +func (j *jwt) Init(opts ...auth.Option) { + for _, o := range opts { + o(&j.options) + } + + j.jwt = jwtToken.NewTokenProvider( + token.WithPrivateKey(j.options.PublicKey), + token.WithPublicKey(j.options.PublicKey), + ) +} + +func (j *jwt) Options() auth.Options { + return j.options +} + +func (j *jwt) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { + return nil, errors.New("JWT does not support Generate, use the Token method") +} + +func (j *jwt) Grant(role string, res *auth.Resource) error { + return errors.New("JWT does not support Grant") +} + +func (j *jwt) Revoke(role string, res *auth.Resource) error { + return errors.New("JWT does not support Revoke") +} + +func (j *jwt) Verify(acc *auth.Account, res *auth.Resource) error { + if acc == nil { + return auth.ErrForbidden + } + return nil +} + +func (j *jwt) Inspect(token string) (*auth.Account, error) { + return j.jwt.Inspect(token) +} + +func (j *jwt) Token(opts ...auth.TokenOption) (*auth.Token, error) { + options := auth.NewTokenOptions(opts...) + account := &auth.Account{ + ID: options.ID, + } + + tok, err := j.jwt.Generate(account, token.WithExpiry(options.Expiry)) + if err != nil { + return nil, err + } + + return &auth.Token{ + Created: tok.Created, + Expiry: tok.Expiry, + AccessToken: tok.Token, + }, nil +} diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index b5cd79f8..7cec8f99 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -70,6 +70,7 @@ import ( memTracer "github.com/micro/go-micro/v2/debug/trace/memory" // auth + jwtAuth "github.com/micro/go-micro/v2/auth/jwt" svcAuth "github.com/micro/go-micro/v2/auth/service" // auth providers @@ -369,6 +370,7 @@ var ( DefaultAuths = map[string]func(...auth.Option) auth.Auth{ "service": svcAuth.NewAuth, + "jwt": jwtAuth.NewAuth, } DefaultAuthProviders = map[string]func(...provider.Option) provider.Provider{ From 7e27c97c6cae8f966aba25bba567476d2459dc49 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 29 Apr 2020 09:22:15 +0100 Subject: [PATCH 712/788] Remove Comment --- auth/jwt/jwt.go | 1 - 1 file changed, 1 deletion(-) diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go index 9eb7b864..3854391d 100644 --- a/auth/jwt/jwt.go +++ b/auth/jwt/jwt.go @@ -15,7 +15,6 @@ func NewAuth(opts ...auth.Option) auth.Auth { return j } -// jwt is the service implementation of the Auth interface type jwt struct { options auth.Options jwt token.Provider From 0ed66d066461518e77f1b46280f55e6e11bda261 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 29 Apr 2020 09:38:39 +0100 Subject: [PATCH 713/788] Fix Typo --- auth/jwt/jwt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go index 3854391d..59cd3cdb 100644 --- a/auth/jwt/jwt.go +++ b/auth/jwt/jwt.go @@ -30,7 +30,7 @@ func (j *jwt) Init(opts ...auth.Option) { } j.jwt = jwtToken.NewTokenProvider( - token.WithPrivateKey(j.options.PublicKey), + token.WithPrivateKey(j.options.PrivateKey), token.WithPublicKey(j.options.PublicKey), ) } From 94971aee77f397382c31598e6cea09494f2be888 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 29 Apr 2020 13:21:51 +0100 Subject: [PATCH 714/788] Complete JWT implementation --- auth/jwt/jwt.go | 126 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 117 insertions(+), 9 deletions(-) diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go index 59cd3cdb..5907f2bf 100644 --- a/auth/jwt/jwt.go +++ b/auth/jwt/jwt.go @@ -1,7 +1,7 @@ package jwt import ( - "errors" + "sync" "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/auth/token" @@ -15,9 +15,17 @@ func NewAuth(opts ...auth.Option) auth.Auth { return j } +type rule struct { + role string + resource *auth.Resource +} + type jwt struct { options auth.Options jwt token.Provider + rules []*rule + + sync.Mutex } func (j *jwt) String() string { @@ -25,10 +33,17 @@ func (j *jwt) String() string { } func (j *jwt) Init(opts ...auth.Option) { + j.Lock() + defer j.Unlock() + for _, o := range opts { o(&j.options) } + if len(j.options.Namespace) == 0 { + j.options.Namespace = auth.DefaultNamespace + } + j.jwt = jwtToken.NewTokenProvider( token.WithPrivateKey(j.options.PrivateKey), token.WithPublicKey(j.options.PublicKey), @@ -36,26 +51,112 @@ func (j *jwt) Init(opts ...auth.Option) { } func (j *jwt) Options() auth.Options { + j.Lock() + defer j.Unlock() return j.options } func (j *jwt) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { - return nil, errors.New("JWT does not support Generate, use the Token method") + options := auth.NewGenerateOptions(opts...) + account := &auth.Account{ + ID: id, + Type: options.Type, + Roles: options.Roles, + Provider: options.Provider, + Metadata: options.Metadata, + Namespace: options.Namespace, + } + + // generate a JWT secret which can be provided to the Token() method + // and exchanged for an access token + secret, err := j.jwt.Generate(account) + if err != nil { + return nil, err + } + account.Secret = secret.Token + + // return the account + return account, nil } func (j *jwt) Grant(role string, res *auth.Resource) error { - return errors.New("JWT does not support Grant") + j.Lock() + defer j.Unlock() + j.rules = append(j.rules, &rule{role, res}) + return nil } func (j *jwt) Revoke(role string, res *auth.Resource) error { - return errors.New("JWT does not support Revoke") + j.Lock() + defer j.Unlock() + + rules := make([]*rule, 0, len(j.rules)) + + var ruleFound bool + for _, r := range rules { + if r.role == role && r.resource == res { + ruleFound = true + } else { + rules = append(rules, r) + } + } + + if !ruleFound { + return auth.ErrNotFound + } + + j.rules = rules + return nil } func (j *jwt) Verify(acc *auth.Account, res *auth.Resource) error { - if acc == nil { - return auth.ErrForbidden + j.Lock() + if len(res.Namespace) == 0 { + res.Namespace = j.options.Namespace } - return nil + rules := j.rules + j.Unlock() + + for _, rule := range rules { + // validate the rule applies to the requested resource + if rule.resource.Namespace != "*" && rule.resource.Namespace != res.Namespace { + continue + } + if rule.resource.Type != "*" && rule.resource.Type != res.Type { + continue + } + if rule.resource.Name != "*" && rule.resource.Name != res.Name { + continue + } + if rule.resource.Endpoint != "*" && rule.resource.Endpoint != res.Endpoint { + continue + } + + // a blank role indicates anyone can access the resource, even without an account + if rule.role == "" { + return nil + } + + // all furter checks require an account + if acc == nil { + continue + } + + // this rule allows any account access, allow the request + if rule.role == "*" { + return nil + } + + // if the account has the necessary role, allow the request + for _, r := range acc.Roles { + if r == rule.role { + return nil + } + } + } + + // no rules matched, forbid the request + return auth.ErrForbidden } func (j *jwt) Inspect(token string) (*auth.Account, error) { @@ -64,8 +165,15 @@ func (j *jwt) Inspect(token string) (*auth.Account, error) { func (j *jwt) Token(opts ...auth.TokenOption) (*auth.Token, error) { options := auth.NewTokenOptions(opts...) - account := &auth.Account{ - ID: options.ID, + + secret := options.RefreshToken + if len(options.Secret) > 0 { + secret = options.Secret + } + + account, err := j.jwt.Inspect(secret) + if err != nil { + return nil, err } tok, err := j.jwt.Generate(account, token.WithExpiry(options.Expiry)) From d44adafca561268e01a81fd8af57e0821c55692b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 29 Apr 2020 15:23:10 +0300 Subject: [PATCH 715/788] api/router: avoid unneeded loops and fix path match (#1594) * api/router: avoid unneeded loops and fix path match * if match found in google api path syntax, not try pcre loop * if path is not ending via $ sign, append it to pcre to avoid matching other strings like /api/account/register can be matched to /api/account * api: add tests and validations Signed-off-by: Vasiliy Tolstov --- api/api.go | 15 +- api/api_test.go | 39 +++ api/router/registry/registry.go | 35 +- api/router/router_test.go | 55 +++- api/router/static/static.go | 34 +- runtime/service/proto/runtime.pb.go | 379 ++++++++++++++++++---- runtime/service/proto/runtime.pb.micro.go | 2 +- server/grpc/grpc_test.go | 20 ++ server/grpc/proto/test.pb.go | 104 +++++- server/grpc/proto/test.pb.micro.go | 62 ++++ server/grpc/proto/test.proto | 7 +- 11 files changed, 645 insertions(+), 107 deletions(-) diff --git a/api/api.go b/api/api.go index 9dbca5ec..12a3d499 100644 --- a/api/api.go +++ b/api/api.go @@ -128,9 +128,18 @@ func Validate(e *Endpoint) error { } for _, p := range e.Path { - _, err := regexp.CompilePOSIX(p) - if err != nil { - return err + ps := p[0] + pe := p[len(p)-1] + + if ps == '^' && pe == '$' { + _, err := regexp.CompilePOSIX(p) + if err != nil { + return err + } + } else if ps == '^' && pe != '$' { + return errors.New("invalid path") + } else if ps != '^' && pe == '$' { + return errors.New("invalid path") } } diff --git a/api/api_test.go b/api/api_test.go index ddc94a26..2b3957e5 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -111,3 +111,42 @@ func TestEncoding(t *testing.T) { } } } + +func TestValidate(t *testing.T) { + epPcre := &Endpoint{ + Name: "Foo.Bar", + Description: "A test endpoint", + Handler: "meta", + Host: []string{"foo.com"}, + Method: []string{"GET"}, + Path: []string{"^/test/?$"}, + } + if err := Validate(epPcre); err != nil { + t.Fatal(err) + } + + epGpath := &Endpoint{ + Name: "Foo.Bar", + Description: "A test endpoint", + Handler: "meta", + Host: []string{"foo.com"}, + Method: []string{"GET"}, + Path: []string{"/test/{id}"}, + } + if err := Validate(epGpath); err != nil { + t.Fatal(err) + } + + epPcreInvalid := &Endpoint{ + Name: "Foo.Bar", + Description: "A test endpoint", + Handler: "meta", + Host: []string{"foo.com"}, + Method: []string{"GET"}, + Path: []string{"/test/?$"}, + } + if err := Validate(epPcreInvalid); err == nil { + t.Fatalf("invalid pcre %v", epPcreInvalid.Path[0]) + } + +} diff --git a/api/router/registry/registry.go b/api/router/registry/registry.go index b5ab4d87..478a2e43 100644 --- a/api/router/registry/registry.go +++ b/api/router/registry/registry.go @@ -187,10 +187,13 @@ func (r *registryRouter) store(services []*registry.Service) { for _, p := range ep.Endpoint.Path { var pcreok bool - pcrereg, err := regexp.CompilePOSIX(p) - if err == nil { - cep.pcreregs = append(cep.pcreregs, pcrereg) - pcreok = true + + if p[0] == '^' && p[len(p)-1] != '$' { + pcrereg, err := regexp.CompilePOSIX(p) + if err == nil { + cep.pcreregs = append(cep.pcreregs, pcrereg) + pcreok = true + } } rule, err := util.Parse(p) @@ -359,6 +362,9 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) { } continue } + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api gpath match %s = %v", path, pathreg) + } pMatch = true ctx := req.Context() md, ok := metadata.FromContext(ctx) @@ -373,16 +379,21 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) { break } - // 4. try path via pcre path matching - for _, pathreg := range cep.pcreregs { - if !pathreg.MatchString(req.URL.Path) { - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("api pcre path not match %s != %v", path, pathreg) + if !pMatch { + // 4. try path via pcre path matching + for _, pathreg := range cep.pcreregs { + if !pathreg.MatchString(req.URL.Path) { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api pcre path not match %s != %v", path, pathreg) + } + continue } - continue + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api pcre path match %s != %v", path, pathreg) + } + pMatch = true + break } - pMatch = true - break } if !pMatch { diff --git a/api/router/router_test.go b/api/router/router_test.go index 9211a524..a3c01fd2 100644 --- a/api/router/router_test.go +++ b/api/router/router_test.go @@ -34,6 +34,18 @@ func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response return nil } +// TestHello implements helloworld.GreeterServer +func (s *testServer) CallPcre(ctx context.Context, req *pb.Request, rsp *pb.Response) error { + rsp.Msg = "Hello " + req.Uuid + return nil +} + +// TestHello implements helloworld.GreeterServer +func (s *testServer) CallPcreInvalid(ctx context.Context, req *pb.Request, rsp *pb.Response) error { + rsp.Msg = "Hello " + req.Uuid + return nil +} + func initial(t *testing.T) (server.Server, client.Client) { r := rmemory.NewRegistry() @@ -81,7 +93,7 @@ func check(t *testing.T, addr string, path string, expected string) { } } -func TestRouterRegistry(t *testing.T) { +func TestRouterRegistryPcre(t *testing.T) { s, c := initial(t) defer s.Stop() @@ -152,7 +164,7 @@ func TestRouterStaticPcre(t *testing.T) { check(t, hsrv.Addr, "http://%s/api/v0/test/call", `{"msg":"Hello "}`) } -func TestRouterStaticG(t *testing.T) { +func TestRouterStaticGpath(t *testing.T) { s, c := initial(t) defer s.Stop() @@ -192,3 +204,42 @@ func TestRouterStaticG(t *testing.T) { time.Sleep(1 * time.Second) check(t, hsrv.Addr, "http://%s/api/v0/test/call/TEST", `{"msg":"Hello TEST"}`) } + +func TestRouterStaticPcreInvalid(t *testing.T) { + var ep *api.Endpoint + var err error + + s, c := initial(t) + defer s.Stop() + + router := rstatic.NewRouter( + router.WithHandler(rpc.Handler), + router.WithRegistry(s.Options().Registry), + ) + + ep = &api.Endpoint{ + Name: "foo.Test.Call", + Method: []string{"POST"}, + Path: []string{"^/api/v0/test/call/?"}, + Handler: "rpc", + } + + err = router.Register(ep) + if err == nil { + t.Fatalf("invalid endpoint %v", ep) + } + + ep = &api.Endpoint{ + Name: "foo.Test.Call", + Method: []string{"POST"}, + Path: []string{"/api/v0/test/call/?$"}, + Handler: "rpc", + } + + err = router.Register(ep) + if err == nil { + t.Fatalf("invalid endpoint %v", ep) + } + + _ = c +} diff --git a/api/router/static/static.go b/api/router/static/static.go index 367a53de..7bcf1d7f 100644 --- a/api/router/static/static.go +++ b/api/router/static/static.go @@ -110,10 +110,14 @@ func (r *staticRouter) Register(ep *api.Endpoint) error { for _, p := range ep.Path { var pcreok bool - pcrereg, err := regexp.CompilePOSIX(p) - if err == nil { - pcreregs = append(pcreregs, pcrereg) - pcreok = true + + // pcre only when we have start and end markers + if p[0] == '^' && p[len(p)-1] == '$' { + pcrereg, err := regexp.CompilePOSIX(p) + if err == nil { + pcreregs = append(pcreregs, pcrereg) + pcreok = true + } } rule, err := util.Parse(p) @@ -122,6 +126,7 @@ func (r *staticRouter) Register(ep *api.Endpoint) error { } else if err != nil && pcreok { continue } + tpl := rule.Compile() pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "") if err != nil { @@ -280,6 +285,9 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { } continue } + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api gpath match %s = %v", path, pathreg) + } pMatch = true ctx := req.Context() md, ok := metadata.FromContext(ctx) @@ -294,16 +302,18 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) { break } - // 4. try path via pcre path matching - for _, pathreg := range ep.pcreregs { - if !pathreg.MatchString(req.URL.Path) { - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("api pcre path not match %s != %v", req.URL.Path, pathreg) + if !pMatch { + // 4. try path via pcre path matching + for _, pathreg := range ep.pcreregs { + if !pathreg.MatchString(req.URL.Path) { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("api pcre path not match %s != %v", req.URL.Path, pathreg) + } + continue } - continue + pMatch = true + break } - pMatch = true - break } if !pMatch { diff --git a/runtime/service/proto/runtime.pb.go b/runtime/service/proto/runtime.pb.go index 09a56e9f..1c401b4a 100644 --- a/runtime/service/proto/runtime.pb.go +++ b/runtime/service/proto/runtime.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto +// source: runtime/service/proto/runtime.proto package go_micro_runtime import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -38,7 +42,7 @@ func (m *Service) Reset() { *m = Service{} } func (m *Service) String() string { return proto.CompactTextString(m) } func (*Service) ProtoMessage() {} func (*Service) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{0} + return fileDescriptor_2434d8152598889b, []int{0} } func (m *Service) XXX_Unmarshal(b []byte) error { @@ -101,7 +105,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{1} + return fileDescriptor_2434d8152598889b, []int{1} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -172,7 +176,7 @@ func (m *CreateOptions) Reset() { *m = CreateOptions{} } func (m *CreateOptions) String() string { return proto.CompactTextString(m) } func (*CreateOptions) ProtoMessage() {} func (*CreateOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{2} + return fileDescriptor_2434d8152598889b, []int{2} } func (m *CreateOptions) XXX_Unmarshal(b []byte) error { @@ -247,7 +251,7 @@ func (m *CreateRequest) Reset() { *m = CreateRequest{} } func (m *CreateRequest) String() string { return proto.CompactTextString(m) } func (*CreateRequest) ProtoMessage() {} func (*CreateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{3} + return fileDescriptor_2434d8152598889b, []int{3} } func (m *CreateRequest) XXX_Unmarshal(b []byte) error { @@ -292,7 +296,7 @@ func (m *CreateResponse) Reset() { *m = CreateResponse{} } func (m *CreateResponse) String() string { return proto.CompactTextString(m) } func (*CreateResponse) ProtoMessage() {} func (*CreateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{4} + return fileDescriptor_2434d8152598889b, []int{4} } func (m *CreateResponse) XXX_Unmarshal(b []byte) error { @@ -329,7 +333,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{5} + return fileDescriptor_2434d8152598889b, []int{5} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -382,7 +386,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{6} + return fileDescriptor_2434d8152598889b, []int{6} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -421,7 +425,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{7} + return fileDescriptor_2434d8152598889b, []int{7} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -460,7 +464,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{8} + return fileDescriptor_2434d8152598889b, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -498,7 +502,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{9} + return fileDescriptor_2434d8152598889b, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -530,7 +534,7 @@ func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{10} + return fileDescriptor_2434d8152598889b, []int{10} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -568,7 +572,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{11} + return fileDescriptor_2434d8152598889b, []int{11} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -599,7 +603,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{12} + return fileDescriptor_2434d8152598889b, []int{12} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -631,7 +635,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{13} + return fileDescriptor_2434d8152598889b, []int{13} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -679,7 +683,7 @@ func (m *LogsRequest) Reset() { *m = LogsRequest{} } func (m *LogsRequest) String() string { return proto.CompactTextString(m) } func (*LogsRequest) ProtoMessage() {} func (*LogsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{14} + return fileDescriptor_2434d8152598889b, []int{14} } func (m *LogsRequest) XXX_Unmarshal(b []byte) error { @@ -744,7 +748,7 @@ func (m *LogRecord) Reset() { *m = LogRecord{} } func (m *LogRecord) String() string { return proto.CompactTextString(m) } func (*LogRecord) ProtoMessage() {} func (*LogRecord) Descriptor() ([]byte, []int) { - return fileDescriptor_976fccef828ab1f0, []int{15} + return fileDescriptor_2434d8152598889b, []int{15} } func (m *LogRecord) XXX_Unmarshal(b []byte) error { @@ -808,51 +812,302 @@ func init() { } func init() { - proto.RegisterFile("github.com/micro/go-micro/runtime/service/proto/runtime.proto", fileDescriptor_976fccef828ab1f0) + proto.RegisterFile("runtime/service/proto/runtime.proto", fileDescriptor_2434d8152598889b) } -var fileDescriptor_976fccef828ab1f0 = []byte{ - // 662 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xbb, 0x6e, 0xdb, 0x4a, - 0x10, 0x35, 0x45, 0x3d, 0xec, 0xd1, 0xd5, 0x85, 0xb1, 0x30, 0x02, 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0xf7, 0x96, 0x9a, 0x3a, 0x92, 0x23, 0x18, 0xac, 0xe8, 0x5d, 0x81, 0x96, 0x97, 0x09, - 0x3e, 0xf6, 0xde, 0x3b, 0x3e, 0x83, 0xc1, 0x62, 0x85, 0xa9, 0x54, 0x82, 0xe4, 0x7d, 0x56, 0x09, - 0x52, 0x67, 0xf2, 0x14, 0x0e, 0x14, 0x03, 0x21, 0x29, 0xcb, 0xf4, 0x55, 0x37, 0x5c, 0x27, 0x94, - 0x5c, 0xeb, 0x9f, 0x55, 0x55, 0x86, 0x75, 0x23, 0xfa, 0x0d, 0x23, 0xfc, 0xdf, 0x0e, 0x4c, 0xce, - 0x72, 0xa4, 0x12, 0xbf, 0x66, 0x32, 0xe1, 0xa9, 0x50, 0xb5, 0x11, 0x67, 0x8c, 0xa6, 0x4b, 0xcf, - 0x99, 0xba, 0xaa, 0xd6, 0x86, 0x8a, 0x11, 0xcd, 0x63, 0xe1, 0xf5, 0x74, 0x5a, 0x9f, 0x95, 0x34, - 0x4c, 0x57, 0x9e, 0xab, 0x53, 0xea, 0xa8, 0xac, 0xe5, 0x85, 0xcc, 0x0a, 0x69, 0x3f, 0x65, 0xa3, - 0x4a, 0xcf, 0xa0, 0xa6, 0xe7, 0x08, 0x06, 0x09, 0xa3, 0x31, 0x7a, 0x43, 0x63, 0x83, 0x0e, 0xfc, - 0x9f, 0x25, 0xa5, 0x10, 0x7f, 0x14, 0x28, 0x24, 0x39, 0x5d, 0x0b, 0x53, 0x6e, 0x8c, 0xe7, 0x8f, - 0x3b, 0x9b, 0xb2, 0xd6, 0xfc, 0x01, 0x46, 0xdc, 0x48, 0xd2, 0x4e, 0x8d, 0xe7, 0x2f, 0xb6, 0x2f, - 0x35, 0x94, 0x87, 0x65, 0xbd, 0x7f, 0x08, 0xff, 0x97, 0x04, 0x44, 0xc6, 0x53, 0x81, 0xfe, 0x35, - 0x8c, 0x43, 0xa4, 0xcb, 0x9a, 0x47, 0x75, 0x42, 0xed, 0x4e, 0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 0x4f, 0xbb, 0x0b, 0x6c, 0x97, 0xf7, 0xc8, 0x17, 0xe8, 0xab, 0xf1, 0x26, 0x1d, 0xeb, 0x50, 0x42, - 0x3d, 0xef, 0xfa, 0xb9, 0x02, 0xba, 0x82, 0xa1, 0x19, 0xcd, 0x36, 0x5e, 0x8d, 0xd1, 0x6f, 0xe3, - 0xb5, 0x31, 0xd5, 0x1a, 0xce, 0x4c, 0x64, 0x1b, 0x5c, 0x63, 0xe2, 0xdb, 0xe0, 0x36, 0x86, 0x79, - 0x8f, 0x5c, 0x40, 0x5f, 0x0d, 0x5e, 0x9b, 0xcc, 0xda, 0x40, 0x1e, 0x3f, 0x79, 0xa0, 0xe9, 0xfe, - 0xde, 0x1b, 0xe7, 0x66, 0xa8, 0xff, 0x2f, 0x4f, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x40, 0x42, - 0xb3, 0x4e, 0x70, 0x07, 0x00, 0x00, +var fileDescriptor_2434d8152598889b = []byte{ + // 645 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xc9, 0x6e, 0xdb, 0x30, + 0x10, 0x8d, 0x2c, 0x2f, 0xc9, 0xa8, 0x2e, 0x02, 0x22, 0x28, 0xd4, 0x74, 0x33, 0xd4, 0x43, 0xd3, + 0x8b, 0x52, 0x38, 0x28, 0xba, 0x1d, 0x63, 0xa7, 0x17, 0x1b, 0x05, 0x54, 0xe4, 0x03, 0x58, 0x79, + 0x60, 0x08, 0x89, 0x44, 0x55, 0xa4, 0x0c, 0xf8, 0xd4, 0x63, 0xcf, 0xfd, 0xaa, 0x9e, 0xfb, 0x47, + 0x05, 0x17, 0x6d, 0xb6, 0x94, 0x8b, 0x6f, 0x9c, 0x11, 0xf9, 0xf8, 0xde, 0x9b, 0x19, 0x0a, 0x5e, + 0x67, 0x79, 0x22, 0xa2, 0x18, 0x2f, 0x39, 0x66, 0x9b, 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xff, 0x20, 0x0e, 0x37, + 0xf1, 0x56, 0x07, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// RuntimeClient is the client API for Runtime service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type RuntimeClient interface { + Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) + Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) + Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) + Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Runtime_LogsClient, error) +} + +type runtimeClient struct { + cc *grpc.ClientConn +} + +func NewRuntimeClient(cc *grpc.ClientConn) RuntimeClient { + return &runtimeClient{cc} +} + +func (c *runtimeClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { + out := new(CreateResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *runtimeClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { + out := new(ReadResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Read", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *runtimeClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { + out := new(DeleteResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *runtimeClient) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) { + out := new(UpdateResponse) + err := c.cc.Invoke(ctx, "/go.micro.runtime.Runtime/Update", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *runtimeClient) Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Runtime_LogsClient, error) { + stream, err := c.cc.NewStream(ctx, &_Runtime_serviceDesc.Streams[0], "/go.micro.runtime.Runtime/Logs", opts...) + if err != nil { + return nil, err + } + x := &runtimeLogsClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Runtime_LogsClient interface { + Recv() (*LogRecord, error) + grpc.ClientStream +} + +type runtimeLogsClient struct { + grpc.ClientStream +} + +func (x *runtimeLogsClient) Recv() (*LogRecord, error) { + m := new(LogRecord) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// RuntimeServer is the server API for Runtime service. +type RuntimeServer interface { + Create(context.Context, *CreateRequest) (*CreateResponse, error) + Read(context.Context, *ReadRequest) (*ReadResponse, error) + Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) + Update(context.Context, *UpdateRequest) (*UpdateResponse, error) + Logs(*LogsRequest, Runtime_LogsServer) error +} + +// UnimplementedRuntimeServer can be embedded to have forward compatible implementations. +type UnimplementedRuntimeServer struct { +} + +func (*UnimplementedRuntimeServer) Create(ctx context.Context, req *CreateRequest) (*CreateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") +} +func (*UnimplementedRuntimeServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") +} +func (*UnimplementedRuntimeServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} +func (*UnimplementedRuntimeServer) Update(ctx context.Context, req *UpdateRequest) (*UpdateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Update not implemented") +} +func (*UnimplementedRuntimeServer) Logs(req *LogsRequest, srv Runtime_LogsServer) error { + return status.Errorf(codes.Unimplemented, "method Logs not implemented") +} + +func RegisterRuntimeServer(s *grpc.Server, srv RuntimeServer) { + s.RegisterService(&_Runtime_serviceDesc, srv) +} + +func _Runtime_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).Create(ctx, req.(*CreateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Runtime_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReadRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).Read(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/Read", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).Read(ctx, req.(*ReadRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Runtime_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).Delete(ctx, req.(*DeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Runtime_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RuntimeServer).Update(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.runtime.Runtime/Update", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RuntimeServer).Update(ctx, req.(*UpdateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Runtime_Logs_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(LogsRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(RuntimeServer).Logs(m, &runtimeLogsServer{stream}) +} + +type Runtime_LogsServer interface { + Send(*LogRecord) error + grpc.ServerStream +} + +type runtimeLogsServer struct { + grpc.ServerStream +} + +func (x *runtimeLogsServer) Send(m *LogRecord) error { + return x.ServerStream.SendMsg(m) +} + +var _Runtime_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.runtime.Runtime", + HandlerType: (*RuntimeServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _Runtime_Create_Handler, + }, + { + MethodName: "Read", + Handler: _Runtime_Read_Handler, + }, + { + MethodName: "Delete", + Handler: _Runtime_Delete_Handler, + }, + { + MethodName: "Update", + Handler: _Runtime_Update_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "Logs", + Handler: _Runtime_Logs_Handler, + ServerStreams: true, + }, + }, + Metadata: "runtime/service/proto/runtime.proto", } diff --git a/runtime/service/proto/runtime.pb.micro.go b/runtime/service/proto/runtime.pb.micro.go index 0f560a4d..73b7c3ca 100644 --- a/runtime/service/proto/runtime.pb.micro.go +++ b/runtime/service/proto/runtime.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/runtime/service/proto/runtime.proto +// source: runtime/service/proto/runtime.proto package go_micro_runtime diff --git a/server/grpc/grpc_test.go b/server/grpc/grpc_test.go index 50035836..e82eab9a 100644 --- a/server/grpc/grpc_test.go +++ b/server/grpc/grpc_test.go @@ -33,6 +33,26 @@ func (s *testServer) HandleError(ctx context.Context, msg *pb.Request) error { return fmt.Errorf("fake") } +// TestHello implements helloworld.GreeterServer +func (s *testServer) CallPcre(ctx context.Context, req *pb.Request, rsp *pb.Response) error { + if req.Name == "Error" { + return &errors.Error{Id: "1", Code: 99, Detail: "detail"} + } + + rsp.Msg = "Hello " + req.Name + return nil +} + +// TestHello implements helloworld.GreeterServer +func (s *testServer) CallPcreInvalid(ctx context.Context, req *pb.Request, rsp *pb.Response) error { + if req.Name == "Error" { + return &errors.Error{Id: "1", Code: 99, Detail: "detail"} + } + + rsp.Msg = "Hello " + req.Name + return nil +} + // TestHello implements helloworld.GreeterServer func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error { if req.Name == "Error" { diff --git a/server/grpc/proto/test.pb.go b/server/grpc/proto/test.pb.go index 27232e75..43a9f0a0 100644 --- a/server/grpc/proto/test.pb.go +++ b/server/grpc/proto/test.pb.go @@ -119,20 +119,24 @@ func init() { func init() { proto.RegisterFile("server/grpc/proto/test.proto", fileDescriptor_bb9c685b7640cf1e) } var fileDescriptor_bb9c685b7640cf1e = []byte{ - // 198 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x29, 0x4e, 0x2d, 0x2a, - 0x4b, 0x2d, 0xd2, 0x4f, 0x2f, 0x2a, 0x48, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x2f, 0x49, - 0x2d, 0x2e, 0xd1, 0x03, 0x33, 0xa5, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b, - 0x32, 0xf5, 0x13, 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0x21, 0xb2, 0x4a, - 0x86, 0x5c, 0xec, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0x42, 0x5c, 0x2c, 0xa5, 0xa5, - 0x99, 0x29, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x60, 0x36, 0x48, 0x2c, 0x2f, 0x31, 0x37, - 0x55, 0x82, 0x09, 0x22, 0x06, 0x62, 0x2b, 0xc9, 0x70, 0x71, 0x04, 0xa5, 0x16, 0x17, 0xe4, 0xe7, - 0x15, 0xa7, 0x0a, 0x09, 0x70, 0x31, 0xe7, 0x16, 0xa7, 0x43, 0xb5, 0x80, 0x98, 0x46, 0x1e, 0x5c, - 0x2c, 0x21, 0x20, 0xd3, 0x1c, 0xb8, 0x58, 0x9c, 0x13, 0x73, 0x72, 0x84, 0x38, 0xf4, 0xa0, 0xe6, - 0x4b, 0x71, 0xea, 0xc1, 0xb4, 0x29, 0x29, 0x37, 0x5d, 0x7e, 0x32, 0x99, 0x49, 0x56, 0x49, 0x02, - 0xec, 0xaa, 0x32, 0x03, 0xb0, 0x7b, 0xf5, 0x93, 0x13, 0x73, 0x72, 0xf4, 0xab, 0x41, 0xf6, 0xd6, - 0x5a, 0x31, 0x6a, 0x25, 0xb1, 0x81, 0x5d, 0x68, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xd0, 0xc1, - 0x00, 0x50, 0xdf, 0x00, 0x00, 0x00, + // 261 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0xd0, 0xcf, 0x4a, 0x03, 0x31, + 0x10, 0x06, 0x70, 0xb6, 0x2e, 0xba, 0xcd, 0x45, 0xc9, 0x69, 0x59, 0x56, 0x2c, 0xd1, 0x82, 0x54, + 0xd8, 0xf1, 0xcf, 0xad, 0x97, 0x0a, 0x82, 0xe0, 0x4d, 0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41, + 0xf5, 0x5c, 0x8a, 0xe5, 0x76, 0xee, 0x22, 0x72, 0x53, 0x36, 0xd9, 0xa1, 0x89, 0xa1, 0x0c, 0x8b, + 0x79, 0x32, 0x7b, 0xdd, 0x8f, 0xff, 0x77, 0xf3, 0x17, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x25, 0x7a, + 0x7d, 0x7d, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -148,6 +152,8 @@ const _ = grpc.SupportPackageIsVersion4 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type TestClient interface { Call(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) + CallPcre(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) + CallPcreInvalid(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) } type testClient struct { @@ -167,9 +173,29 @@ func (c *testClient) Call(ctx context.Context, in *Request, opts ...grpc.CallOpt return out, nil } +func (c *testClient) CallPcre(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) { + out := new(Response) + err := c.cc.Invoke(ctx, "/Test/CallPcre", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *testClient) CallPcreInvalid(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) { + out := new(Response) + err := c.cc.Invoke(ctx, "/Test/CallPcreInvalid", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // TestServer is the server API for Test service. type TestServer interface { Call(context.Context, *Request) (*Response, error) + CallPcre(context.Context, *Request) (*Response, error) + CallPcreInvalid(context.Context, *Request) (*Response, error) } // UnimplementedTestServer can be embedded to have forward compatible implementations. @@ -179,6 +205,12 @@ type UnimplementedTestServer struct { func (*UnimplementedTestServer) Call(ctx context.Context, req *Request) (*Response, error) { return nil, status.Errorf(codes.Unimplemented, "method Call not implemented") } +func (*UnimplementedTestServer) CallPcre(ctx context.Context, req *Request) (*Response, error) { + return nil, status.Errorf(codes.Unimplemented, "method CallPcre not implemented") +} +func (*UnimplementedTestServer) CallPcreInvalid(ctx context.Context, req *Request) (*Response, error) { + return nil, status.Errorf(codes.Unimplemented, "method CallPcreInvalid not implemented") +} func RegisterTestServer(s *grpc.Server, srv TestServer) { s.RegisterService(&_Test_serviceDesc, srv) @@ -202,6 +234,42 @@ func _Test_Call_Handler(srv interface{}, ctx context.Context, dec func(interface return interceptor(ctx, in, info, handler) } +func _Test_CallPcre_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Request) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(TestServer).CallPcre(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Test/CallPcre", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(TestServer).CallPcre(ctx, req.(*Request)) + } + return interceptor(ctx, in, info, handler) +} + +func _Test_CallPcreInvalid_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Request) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(TestServer).CallPcreInvalid(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Test/CallPcreInvalid", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(TestServer).CallPcreInvalid(ctx, req.(*Request)) + } + return interceptor(ctx, in, info, handler) +} + var _Test_serviceDesc = grpc.ServiceDesc{ ServiceName: "Test", HandlerType: (*TestServer)(nil), @@ -210,6 +278,14 @@ var _Test_serviceDesc = grpc.ServiceDesc{ MethodName: "Call", Handler: _Test_Call_Handler, }, + { + MethodName: "CallPcre", + Handler: _Test_CallPcre_Handler, + }, + { + MethodName: "CallPcreInvalid", + Handler: _Test_CallPcreInvalid_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "server/grpc/proto/test.proto", diff --git a/server/grpc/proto/test.pb.micro.go b/server/grpc/proto/test.pb.micro.go index 0139530b..b80c670c 100644 --- a/server/grpc/proto/test.pb.micro.go +++ b/server/grpc/proto/test.pb.micro.go @@ -45,6 +45,20 @@ func NewTestEndpoints() []*api.Endpoint { Body: "*", Handler: "rpc", }, + &api.Endpoint{ + Name: "Test.CallPcre", + Path: []string{"^/api/v0/test/call/pcre/?$"}, + Method: []string{"POST"}, + Body: "*", + Handler: "rpc", + }, + &api.Endpoint{ + Name: "Test.CallPcreInvalid", + Path: []string{"/api/v0/test/call/pcre/invalid/?"}, + Method: []string{"POST"}, + Body: "*", + Handler: "rpc", + }, } } @@ -52,6 +66,8 @@ func NewTestEndpoints() []*api.Endpoint { type TestService interface { Call(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) + CallPcre(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) + CallPcreInvalid(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) } type testService struct { @@ -76,15 +92,39 @@ func (c *testService) Call(ctx context.Context, in *Request, opts ...client.Call return out, nil } +func (c *testService) CallPcre(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) { + req := c.c.NewRequest(c.name, "Test.CallPcre", in) + out := new(Response) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *testService) CallPcreInvalid(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) { + req := c.c.NewRequest(c.name, "Test.CallPcreInvalid", in) + out := new(Response) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for Test service type TestHandler interface { Call(context.Context, *Request, *Response) error + CallPcre(context.Context, *Request, *Response) error + CallPcreInvalid(context.Context, *Request, *Response) error } func RegisterTestHandler(s server.Server, hdlr TestHandler, opts ...server.HandlerOption) error { type test interface { Call(ctx context.Context, in *Request, out *Response) error + CallPcre(ctx context.Context, in *Request, out *Response) error + CallPcreInvalid(ctx context.Context, in *Request, out *Response) error } type Test struct { test @@ -97,6 +137,20 @@ func RegisterTestHandler(s server.Server, hdlr TestHandler, opts ...server.Handl Body: "*", Handler: "rpc", })) + opts = append(opts, api.WithEndpoint(&api.Endpoint{ + Name: "Test.CallPcre", + Path: []string{"^/api/v0/test/call/pcre/?$"}, + Method: []string{"POST"}, + Body: "*", + Handler: "rpc", + })) + opts = append(opts, api.WithEndpoint(&api.Endpoint{ + Name: "Test.CallPcreInvalid", + Path: []string{"/api/v0/test/call/pcre/invalid/?"}, + Method: []string{"POST"}, + Body: "*", + Handler: "rpc", + })) return s.Handle(s.NewHandler(&Test{h}, opts...)) } @@ -107,3 +161,11 @@ type testHandler struct { func (h *testHandler) Call(ctx context.Context, in *Request, out *Response) error { return h.TestHandler.Call(ctx, in, out) } + +func (h *testHandler) CallPcre(ctx context.Context, in *Request, out *Response) error { + return h.TestHandler.CallPcre(ctx, in, out) +} + +func (h *testHandler) CallPcreInvalid(ctx context.Context, in *Request, out *Response) error { + return h.TestHandler.CallPcreInvalid(ctx, in, out) +} diff --git a/server/grpc/proto/test.proto b/server/grpc/proto/test.proto index cbef20e1..4d745ecc 100644 --- a/server/grpc/proto/test.proto +++ b/server/grpc/proto/test.proto @@ -6,7 +6,12 @@ service Test { rpc Call(Request) returns (Response) { option (google.api.http) = { post: "/api/v0/test/call/{uuid}"; body:"*"; }; }; - + rpc CallPcre(Request) returns (Response) { + option (google.api.http) = { post: "^/api/v0/test/call/pcre/?$"; body:"*"; }; + }; + rpc CallPcreInvalid(Request) returns (Response) { + option (google.api.http) = { post: "^/api/v0/test/call/pcre/invalid/?"; body:"*"; }; + }; } message Request { From 70736e24c04a7c7906e53dee356700450e85ad6e Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 29 Apr 2020 13:33:22 +0100 Subject: [PATCH 716/788] Set RefreshToken --- auth/jwt/jwt.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go index 5907f2bf..86815bce 100644 --- a/auth/jwt/jwt.go +++ b/auth/jwt/jwt.go @@ -182,8 +182,9 @@ func (j *jwt) Token(opts ...auth.TokenOption) (*auth.Token, error) { } return &auth.Token{ - Created: tok.Created, - Expiry: tok.Expiry, - AccessToken: tok.Token, + Created: tok.Created, + Expiry: tok.Expiry, + AccessToken: tok.Token, + RefreshToken: tok.Token, }, nil } From 99f8be5b3dbf4ffffc0fdeb31d9fad0f59f01d63 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 29 Apr 2020 15:11:06 +0100 Subject: [PATCH 717/788] Auth Client Wrapper --- auth/options.go | 7 ++ auth/service/service.go | 56 ------------- client/grpc/grpc.go | 36 --------- service.go | 3 +- util/wrapper/wrapper.go | 175 +++++++++++++++++++++++++++++++--------- 5 files changed, 145 insertions(+), 132 deletions(-) diff --git a/auth/options.go b/auth/options.go index 3cd1bc69..cb395d04 100644 --- a/auth/options.go +++ b/auth/options.go @@ -79,6 +79,13 @@ func Credentials(id, secret string) Option { } } +// ClientToken sets the auth token to use when making requests +func ClientToken(token *Token) Option { + return func(o *Options) { + o.Token = token + } +} + // Provider set the auth provider func Provider(p provider.Provider) Option { return func(o *Options) { diff --git a/auth/service/service.go b/auth/service/service.go index 67c4d4ca..c0f7e7dd 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -70,35 +70,6 @@ func (s *svc) Init(opts ...auth.Option) { s.loadRules() } }() - - // we have client credentials and must load a new token - // periodically - if len(s.options.ID) > 0 || len(s.options.Secret) > 0 { - // get a token immediately - s.refreshToken() - - go func() { - tokenTimer := time.NewTicker(time.Minute) - - for { - <-tokenTimer.C - - // Do not get a new token if the current one has more than three - // minutes remaining. We do 3 minutes to allow multiple retires in - // the case one request fails - t := s.Options().Token - if t != nil && t.Expiry.Unix() > time.Now().Add(time.Minute*3).Unix() { - continue - } - - // jitter for up to 5 seconds, this stops - // all the services calling the auth service - // at the exact same time - time.Sleep(jitter.Do(time.Second * 5)) - s.refreshToken() - } - }() - } } func (s *svc) Options() auth.Options { @@ -313,33 +284,6 @@ func (s *svc) loadRules() { s.rules = rsp.Rules } -// refreshToken generates a new token for the service to use when making calls -func (s *svc) refreshToken() { - req := &pb.TokenRequest{ - TokenExpiry: int64((time.Minute * 15).Seconds()), - } - - if s.Options().Token == nil { - // we do not have a token, use the credentials to get one - req.Id = s.Options().ID - req.Secret = s.Options().Secret - } else { - // we have a token, refresh it - req.RefreshToken = s.Options().Token.RefreshToken - } - - rsp, err := s.auth.Token(context.TODO(), req) - s.Lock() - defer s.Unlock() - - if err != nil { - log.Errorf("Error generating token: %v", err) - return - } - - s.options.Token = serializeToken(rsp.Token) -} - func serializeToken(t *pb.Token) *auth.Token { return &auth.Token{ AccessToken: t.AccessToken, diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index 9445eabe..e25f3dd5 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -10,7 +10,6 @@ import ( "sync/atomic" "time" - "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" @@ -18,7 +17,6 @@ import ( "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" - "github.com/micro/go-micro/v2/util/config" pnet "github.com/micro/go-micro/v2/util/net" "google.golang.org/grpc" @@ -117,13 +115,6 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R // set the content type for the request header["x-content-type"] = req.ContentType() - // set the authorization header - if opts.ServiceToken || len(header["authorization"]) == 0 { - if h := g.authorizationHeader(); len(h) > 0 { - header["authorization"] = h - } - } - md := gmetadata.New(header) ctx = gmetadata.NewOutgoingContext(ctx, md) @@ -202,13 +193,6 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client // set the content type for the request header["x-content-type"] = req.ContentType() - // set the authorization header - if opts.ServiceToken || len(header["authorization"]) == 0 { - if h := g.authorizationHeader(); len(h) > 0 { - header["authorization"] = h - } - } - md := gmetadata.New(header) ctx = gmetadata.NewOutgoingContext(ctx, md) @@ -295,26 +279,6 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client }, nil } -func (g *grpcClient) authorizationHeader() string { - // if the caller specifies using service token or no token - // was passed with the request, set the service token - var srvToken string - if g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { - srvToken = g.opts.Auth.Options().Token.AccessToken - } - if len(srvToken) > 0 { - return auth.BearerScheme + srvToken - } - - // fall back to using the authorization token set in config, - // this enables the CLI to provide a token - if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 { - return auth.BearerScheme + token - } - - return "" -} - func (g *grpcClient) poolMaxStreams() int { if g.opts.Context == nil { return DefaultPoolMaxStreams diff --git a/service.go b/service.go index a49c696f..6cdb6b69 100644 --- a/service.go +++ b/service.go @@ -39,8 +39,9 @@ func newService(opts ...Option) Service { authFn := func() auth.Auth { return options.Server.Options().Auth } // wrap client to inject From-Service header on any calls - options.Client = wrapper.FromService(serviceName, options.Client, authFn) + options.Client = wrapper.FromService(serviceName, options.Client) options.Client = wrapper.TraceCall(serviceName, trace.DefaultTracer, options.Client) + options.Client = wrapper.AuthClient(serviceName, authFn, options.Client) // wrap the server to provide handler stats options.Server.Init( diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index bfd1ce9f..677061ef 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -3,6 +3,7 @@ package wrapper import ( "context" "strings" + "time" "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/client" @@ -11,68 +12,44 @@ import ( "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/util/config" ) -type clientWrapper struct { +type fromServiceWrapper struct { client.Client - // Auth interface - auth func() auth.Auth // headers to inject headers metadata.Metadata } -type traceWrapper struct { - client.Client - - name string - trace trace.Tracer -} - var ( HeaderPrefix = "Micro-" ) -func (c *clientWrapper) setHeaders(ctx context.Context) context.Context { +func (f *fromServiceWrapper) setHeaders(ctx context.Context) context.Context { // don't overwrite keys - return metadata.MergeContext(ctx, c.headers, false) + return metadata.MergeContext(ctx, f.headers, false) } -func (c *clientWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { - ctx = c.setHeaders(ctx) - return c.Client.Call(ctx, req, rsp, opts...) +func (f *fromServiceWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { + ctx = f.setHeaders(ctx) + return f.Client.Call(ctx, req, rsp, opts...) } -func (c *clientWrapper) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) { - ctx = c.setHeaders(ctx) - return c.Client.Stream(ctx, req, opts...) +func (f *fromServiceWrapper) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) { + ctx = f.setHeaders(ctx) + return f.Client.Stream(ctx, req, opts...) } -func (c *clientWrapper) Publish(ctx context.Context, p client.Message, opts ...client.PublishOption) error { - ctx = c.setHeaders(ctx) - return c.Client.Publish(ctx, p, opts...) -} - -func (c *traceWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { - newCtx, s := c.trace.Start(ctx, req.Service()+"."+req.Endpoint()) - - s.Type = trace.SpanTypeRequestOutbound - err := c.Client.Call(newCtx, req, rsp, opts...) - if err != nil { - s.Metadata["error"] = err.Error() - } - - // finish the trace - c.trace.Finish(s) - - return err +func (f *fromServiceWrapper) Publish(ctx context.Context, p client.Message, opts ...client.PublishOption) error { + ctx = f.setHeaders(ctx) + return f.Client.Publish(ctx, p, opts...) } // FromService wraps a client to inject service and auth metadata -func FromService(name string, c client.Client, fn func() auth.Auth) client.Client { - return &clientWrapper{ +func FromService(name string, c client.Client) client.Client { + return &fromServiceWrapper{ c, - fn, metadata.Metadata{ HeaderPrefix + "From-Service": name, }, @@ -95,6 +72,28 @@ func HandlerStats(stats stats.Stats) server.HandlerWrapper { } } +type traceWrapper struct { + client.Client + + name string + trace trace.Tracer +} + +func (c *traceWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { + newCtx, s := c.trace.Start(ctx, req.Service()+"."+req.Endpoint()) + + s.Type = trace.SpanTypeRequestOutbound + err := c.Client.Call(newCtx, req, rsp, opts...) + if err != nil { + s.Metadata["error"] = err.Error() + } + + // finish the trace + c.trace.Finish(s) + + return err +} + // TraceCall is a call tracing wrapper func TraceCall(name string, t trace.Tracer, c client.Client) client.Client { return &traceWrapper{ @@ -132,6 +131,104 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper { } } +type authWrapper struct { + client.Client + name string + auth func() auth.Auth +} + +func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error { + // parse the options + var options client.CallOptions + for _, o := range opts { + o(&options) + } + + // check to see if the authorization header has already been set. + // We dont't override the header unless the ServiceToken option has + // been specified. + if _, ok := metadata.Get(ctx, "Authorization"); ok && !options.ServiceToken { + return a.Client.Call(ctx, req, rsp, opts...) + } + + // if auth is nil we won't be able to get an access token, so we execute + // the request without one. + aa := a.auth() + if a == nil { + return a.Client.Call(ctx, req, rsp, opts...) + } + + // callWithToken performs the client call with the authorization header + // set to the token. + callWithToken := func(token string) error { + ctx := metadata.Set(ctx, "Authorization", auth.BearerScheme+token) + return a.Client.Call(ctx, req, rsp, opts...) + } + + // check to see if we have a valid access token + aaOpts := aa.Options() + if aaOpts.Token != nil && aaOpts.Token.Expiry.Unix() > time.Now().Unix() { + return callWithToken(aaOpts.Token.AccessToken) + } + + // if we have a refresh token we can use this to generate another access token + if aaOpts.Token != nil { + tok, err := aa.Token(auth.WithToken(aaOpts.Token.RefreshToken)) + if err != nil { + return err + } + aa.Init(auth.ClientToken(tok)) + return callWithToken(tok.AccessToken) + } + + // if we have credentials we can generate a new token for the exiting auth + // account. these credential would've been set by env vars. + if len(aaOpts.ID) > 0 && len(aaOpts.Secret) > 0 { + tok, err := aa.Token(auth.WithCredentials(aaOpts.ID, aaOpts.Secret)) + if err != nil { + return err + } + aa.Init(auth.ClientToken(tok)) + return callWithToken(tok.AccessToken) + } + + // before we generate a new auth account, check to see if a token was provided + // in config, this is normally used for setting the token when calling via the cli + if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 { + return callWithToken(token) + } + + // determine the type of service from the name. we do this so we can allocate + // different roles depending on the type of services. e.g. we don't want web + // services talking directly to the runtime. TODO: find a better way to determine + // the type of service + serviceType := "service" + if strings.Contains(a.name, "api") { + serviceType = "api" + } else if strings.Contains(a.name, "web") { + serviceType = "web" + } + + // generate a new auth account for the service + acc, err := aa.Generate(a.name, auth.WithNamespace(aaOpts.Namespace), auth.WithRoles(serviceType)) + if err != nil { + return err + } + token, err := aa.Token(auth.WithCredentials(acc.ID, acc.Secret)) + if err != nil { + return err + } + aa.Init(auth.ClientToken(token)) + + // use the token to execute the request + return callWithToken(token.AccessToken) +} + +// AuthClient wraps requests with the auth header +func AuthClient(name string, auth func() auth.Auth, c client.Client) client.Client { + return &authWrapper{c, name, auth} +} + // AuthHandler wraps a server handler to perform auth func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { return func(h server.HandlerFunc) server.HandlerFunc { From ef9f65c78b170ac83242037f9757e1663df264aa Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 29 Apr 2020 15:15:38 +0100 Subject: [PATCH 718/788] Improve Comments --- util/wrapper/wrapper.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 677061ef..c97c9e54 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -146,7 +146,7 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac // check to see if the authorization header has already been set. // We dont't override the header unless the ServiceToken option has - // been specified. + // been specified or the header wasn't provided if _, ok := metadata.Get(ctx, "Authorization"); ok && !options.ServiceToken { return a.Client.Call(ctx, req, rsp, opts...) } @@ -158,8 +158,7 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac return a.Client.Call(ctx, req, rsp, opts...) } - // callWithToken performs the client call with the authorization header - // set to the token. + // performs the call with the authorization token provided callWithToken := func(token string) error { ctx := metadata.Set(ctx, "Authorization", auth.BearerScheme+token) return a.Client.Call(ctx, req, rsp, opts...) @@ -181,8 +180,7 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac return callWithToken(tok.AccessToken) } - // if we have credentials we can generate a new token for the exiting auth - // account. these credential would've been set by env vars. + // if we have credentials we can generate a new token for the account if len(aaOpts.ID) > 0 && len(aaOpts.Secret) > 0 { tok, err := aa.Token(auth.WithCredentials(aaOpts.ID, aaOpts.Secret)) if err != nil { @@ -192,8 +190,8 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac return callWithToken(tok.AccessToken) } - // before we generate a new auth account, check to see if a token was provided - // in config, this is normally used for setting the token when calling via the cli + // check to see if a token was provided in config, this is normally used for + // setting the token when calling via the cli if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 { return callWithToken(token) } From f48dec1fb02418c16436ff96951a77b6814f85c1 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 29 Apr 2020 15:27:18 +0100 Subject: [PATCH 719/788] Use Server ID in account name --- service.go | 2 +- util/wrapper/wrapper.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/service.go b/service.go index 6cdb6b69..f7941e30 100644 --- a/service.go +++ b/service.go @@ -41,7 +41,7 @@ func newService(opts ...Option) Service { // wrap client to inject From-Service header on any calls options.Client = wrapper.FromService(serviceName, options.Client) options.Client = wrapper.TraceCall(serviceName, trace.DefaultTracer, options.Client) - options.Client = wrapper.AuthClient(serviceName, authFn, options.Client) + options.Client = wrapper.AuthClient(serviceName, options.Server.Options().Id, authFn, options.Client) // wrap the server to provide handler stats options.Server.Init( diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index c97c9e54..ee569ef2 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -2,6 +2,7 @@ package wrapper import ( "context" + "fmt" "strings" "time" @@ -134,6 +135,7 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper { type authWrapper struct { client.Client name string + id string auth func() auth.Auth } @@ -208,7 +210,8 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac } // generate a new auth account for the service - acc, err := aa.Generate(a.name, auth.WithNamespace(aaOpts.Namespace), auth.WithRoles(serviceType)) + name := fmt.Sprintf("%v-%v", a.name, a.id) + acc, err := aa.Generate(name, auth.WithNamespace(aaOpts.Namespace), auth.WithRoles(serviceType)) if err != nil { return err } @@ -223,8 +226,8 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac } // AuthClient wraps requests with the auth header -func AuthClient(name string, auth func() auth.Auth, c client.Client) client.Client { - return &authWrapper{c, name, auth} +func AuthClient(name string, id string, auth func() auth.Auth, c client.Client) client.Client { + return &authWrapper{c, name, id, auth} } // AuthHandler wraps a server handler to perform auth From bcddb9886703633e9c68ab389cf6f1f9b63b23e7 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 29 Apr 2020 15:37:02 +0100 Subject: [PATCH 720/788] Fix Tests --- util/wrapper/wrapper_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/util/wrapper/wrapper_test.go b/util/wrapper/wrapper_test.go index 7fb99bf3..fa03af21 100644 --- a/util/wrapper/wrapper_test.go +++ b/util/wrapper/wrapper_test.go @@ -4,7 +4,6 @@ import ( "context" "testing" - "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/metadata" ) @@ -33,8 +32,7 @@ func TestWrapper(t *testing.T) { } for _, d := range testData { - c := &clientWrapper{ - auth: func() auth.Auth { return nil }, + c := &fromServiceWrapper{ headers: d.headers, } From 7792dbc34d6a89fbc4bb157b4bc9e4c797129e8a Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 29 Apr 2020 18:45:55 +0100 Subject: [PATCH 721/788] Update FUNDING.yml --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index b6392e26..7928ee1c 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,3 @@ # These are supported funding model platforms -issuehunt: micro/development +github: asim From 46d09ec2bcbd9c575dc9f498ae1cc7c899c9c54c Mon Sep 17 00:00:00 2001 From: Socket <30768657+Socketsj@users.noreply.github.com> Date: Thu, 30 Apr 2020 17:42:13 +0800 Subject: [PATCH 722/788] unsubscribe can async (#1596) Co-authored-by: huangshaojie Co-authored-by: Asim Aslam --- server/grpc/grpc.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 3de2332f..a4501c05 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -785,15 +785,21 @@ func (g *grpcServer) Deregister() error { g.registered = false + wg := sync.WaitGroup{} for sb, subs := range g.subscribers { for _, sub := range subs { - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Infof("Unsubscribing from topic: %s", sub.Topic()) - } - sub.Unsubscribe() + wg.Add(1) + go func(s broker.Subscriber) { + defer wg.Done() + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Unsubscribing from topic: %s", s.Topic()) + } + s.Unsubscribe() + }(sub) } g.subscribers[sb] = nil } + wg.Wait() g.Unlock() return nil From fccab8ad27d13cc366180bbcaa9c1341b37b8b78 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Thu, 30 Apr 2020 18:20:51 +0200 Subject: [PATCH 723/788] Runtime name should be base folder outside repos (#1598) --- runtime/local/git/git.go | 23 +++++++++++++--- runtime/local/git/git_test.go | 52 ++++++++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/runtime/local/git/git.go b/runtime/local/git/git.go index 956f02e7..dbb282be 100644 --- a/runtime/local/git/git.go +++ b/runtime/local/git/git.go @@ -274,20 +274,35 @@ func ParseSource(source string) (*Source, error) { } // ParseSourceLocal detects and handles local pathes too -// workdir should be used only from the CLI @todo better interface for this function -func ParseSourceLocal(workDir, source string) (*Source, error) { +// workdir should be used only from the CLI @todo better interface for this function. +// PathExistsFunc exists only for testing purposes, to make the function side effect free. +func ParseSourceLocal(workDir, source string, pathExistsFunc ...func(path string) (bool, error)) (*Source, error) { + var pexists func(string) (bool, error) + if len(pathExistsFunc) == 0 { + pexists = pathExists + } else { + pexists = pathExistsFunc[0] + } var localFullPath string if len(workDir) > 0 { localFullPath = filepath.Join(workDir, source) } else { localFullPath = source } - if exists, err := pathExists(localFullPath); err == nil && exists { + if exists, err := pexists(localFullPath); err == nil && exists { localRepoRoot, err := GetRepoRoot(localFullPath) if err != nil { return nil, err } - folder := strings.ReplaceAll(localFullPath, localRepoRoot+string(filepath.Separator), "") + var folder string + // If the local repo root is a top level folder, we are not in a git repo. + // In this case, we should take the last folder as folder name. + if localRepoRoot == "" { + folder = filepath.Base(localFullPath) + } else { + folder = strings.ReplaceAll(localFullPath, localRepoRoot+string(filepath.Separator), "") + } + return &Source{ Local: true, Folder: folder, diff --git a/runtime/local/git/git_test.go b/runtime/local/git/git_test.go index 79561b80..aed18f89 100644 --- a/runtime/local/git/git_test.go +++ b/runtime/local/git/git_test.go @@ -5,14 +5,14 @@ import ( ) type parseCase struct { - url string + source string expected *Source } func TestParseSource(t *testing.T) { cases := []parseCase{ { - url: "helloworld", + source: "helloworld", expected: &Source{ Repo: "github.com/micro/services", Folder: "helloworld", @@ -20,7 +20,7 @@ func TestParseSource(t *testing.T) { }, }, { - url: "github.com/micro/services/helloworld", + source: "github.com/micro/services/helloworld", expected: &Source{ Repo: "github.com/micro/services", Folder: "helloworld", @@ -28,7 +28,7 @@ func TestParseSource(t *testing.T) { }, }, { - url: "github.com/micro/services/helloworld@v1.12.1", + source: "github.com/micro/services/helloworld@v1.12.1", expected: &Source{ Repo: "github.com/micro/services", Folder: "helloworld", @@ -36,7 +36,7 @@ func TestParseSource(t *testing.T) { }, }, { - url: "github.com/micro/services/helloworld@branchname", + source: "github.com/micro/services/helloworld@branchname", expected: &Source{ Repo: "github.com/micro/services", Folder: "helloworld", @@ -44,7 +44,7 @@ func TestParseSource(t *testing.T) { }, }, { - url: "github.com/crufter/reponame/helloworld@branchname", + source: "github.com/crufter/reponame/helloworld@branchname", expected: &Source{ Repo: "github.com/crufter/reponame", Folder: "helloworld", @@ -53,7 +53,45 @@ func TestParseSource(t *testing.T) { }, } for i, c := range cases { - result, err := ParseSource(c.url) + result, err := ParseSource(c.source) + if err != nil { + t.Fatalf("Failed case %v: %v", i, err) + } + if result.Folder != c.expected.Folder { + t.Fatalf("Folder does not match for '%v', expected '%v', got '%v'", i, c.expected.Folder, result.Folder) + } + if result.Repo != c.expected.Repo { + t.Fatalf("Repo address does not match for '%v', expected '%v', got '%v'", i, c.expected.Repo, result.Repo) + } + if result.Ref != c.expected.Ref { + t.Fatalf("Ref does not match for '%v', expected '%v', got '%v'", i, c.expected.Ref, result.Ref) + } + } +} + +type localParseCase struct { + source string + expected *Source + workDir string + pathExists bool +} + +func TestLocalParseSource(t *testing.T) { + cases := []localParseCase{ + { + source: ".", + expected: &Source{ + Folder: "folder2", + Ref: "latest", + }, + workDir: "/folder1/folder2", + pathExists: true, + }, + } + for i, c := range cases { + result, err := ParseSourceLocal(c.workDir, c.source, func(s string) (bool, error) { + return c.pathExists, nil + }) if err != nil { t.Fatalf("Failed case %v: %v", i, err) } From 359b8bc5030514b4c2a3178acb467dada3d3e823 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 30 Apr 2020 22:51:25 +0100 Subject: [PATCH 724/788] Add opts to service proto (#1517) * Add opts to service proto * Support database/table opts --- store/cockroach/cockroach.go | 559 ++++++++++++++------------ store/file/file.go | 190 +++++---- store/memory/memory.go | 257 ++++++------ store/memory/memory_test.go | 6 +- store/service/proto/store.pb.go | 492 ++++++----------------- store/service/proto/store.pb.micro.go | 2 +- store/service/proto/store.proto | 32 +- store/service/service.go | 66 ++- 8 files changed, 774 insertions(+), 830 deletions(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 4aa68ac5..144ce44d 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -7,6 +7,7 @@ import ( "net/url" "regexp" "strings" + "sync" "time" "github.com/lib/pq" @@ -21,214 +22,51 @@ var ( DefaultTable = "micro" ) +var ( + statements = map[string]string{ + "list": "SELECT key, value, expiry FROM %s.%s;", + "read": "SELECT key, value, expiry FROM %s.%s WHERE key = $1;", + "readMany": "SELECT key, value, expiry FROM %s.%s WHERE key LIKE $1;", + "readOffset": "SELECT key, value, expiry FROM %s.%s WHERE key LIKE $1 ORDER BY key DESC LIMIT $2 OFFSET $3;", + "write": "INSERT INTO %s.%s(key, value, expiry) VALUES ($1, $2::bytea, $3) ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, expiry = EXCLUDED.expiry;", + "delete": "DELETE FROM %s.%s WHERE key = $1;", + } +) + type sqlStore struct { - db *sql.DB - - database string - table string - - list *sql.Stmt - readOne *sql.Stmt - readMany *sql.Stmt - readOffset *sql.Stmt - write *sql.Stmt - delete *sql.Stmt - options store.Options + db *sql.DB + + sync.RWMutex + // known databases + databases map[string]bool } -func (s *sqlStore) Close() error { - closeStmt(s.delete) - closeStmt(s.list) - closeStmt(s.readMany) - closeStmt(s.readOffset) - closeStmt(s.readOne) - closeStmt(s.write) - if s.db != nil { - return s.db.Close() +func (s *sqlStore) createDB(database, table string) { + if len(database) == 0 { + database = s.options.Database } - return nil + if len(table) == 0 { + table = s.options.Table + } + + s.Lock() + _, ok := s.databases[database+":"+table] + if !ok { + s.initDB(database, table) + s.databases[database+":"+table] = true + } + s.Unlock() } -func (s *sqlStore) Init(opts ...store.Option) error { - for _, o := range opts { - o(&s.options) - } - // reconfigure - return s.configure() -} - -// List all the known records -func (s *sqlStore) List(opts ...store.ListOption) ([]string, error) { - rows, err := s.list.Query() - var keys []string - var timehelper pq.NullTime - if err != nil { - if err == sql.ErrNoRows { - return keys, nil - } - return nil, err - } - defer rows.Close() - for rows.Next() { - record := &store.Record{} - if err := rows.Scan(&record.Key, &record.Value, &timehelper); err != nil { - return keys, err - } - if timehelper.Valid { - if timehelper.Time.Before(time.Now()) { - // record has expired - go s.Delete(record.Key) - } else { - record.Expiry = time.Until(timehelper.Time) - keys = append(keys, record.Key) - } - } else { - keys = append(keys, record.Key) - } - - } - rowErr := rows.Close() - if rowErr != nil { - // transaction rollback or something - return keys, rowErr - } - if err := rows.Err(); err != nil { - return keys, err - } - return keys, nil -} - -// Read a single key -func (s *sqlStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { - var options store.ReadOptions - for _, o := range opts { - o(&options) - } - - if options.Prefix || options.Suffix { - return s.read(key, options) - } - - var records []*store.Record - var timehelper pq.NullTime - - row := s.readOne.QueryRow(key) - record := &store.Record{} - if err := row.Scan(&record.Key, &record.Value, &timehelper); err != nil { - if err == sql.ErrNoRows { - return records, store.ErrNotFound - } - return records, err - } - if timehelper.Valid { - if timehelper.Time.Before(time.Now()) { - // record has expired - go s.Delete(key) - return records, store.ErrNotFound - } - record.Expiry = time.Until(timehelper.Time) - records = append(records, record) - } else { - records = append(records, record) - } - - return records, nil -} - -// Read Many records -func (s *sqlStore) read(key string, options store.ReadOptions) ([]*store.Record, error) { - pattern := "%" - if options.Prefix { - pattern = key + pattern - } - if options.Suffix { - pattern = pattern + key - } - var rows *sql.Rows - var err error - if options.Limit != 0 { - rows, err = s.readOffset.Query(pattern, options.Limit, options.Offset) - } else { - rows, err = s.readMany.Query(pattern) - } - if err != nil { - if err == sql.ErrNoRows { - return []*store.Record{}, nil - } - return []*store.Record{}, errors.Wrap(err, "sqlStore.read failed") - } - defer rows.Close() - var records []*store.Record - var timehelper pq.NullTime - - for rows.Next() { - record := &store.Record{} - if err := rows.Scan(&record.Key, &record.Value, &timehelper); err != nil { - return records, err - } - if timehelper.Valid { - if timehelper.Time.Before(time.Now()) { - // record has expired - go s.Delete(record.Key) - } else { - record.Expiry = time.Until(timehelper.Time) - records = append(records, record) - } - } else { - records = append(records, record) - } - } - rowErr := rows.Close() - if rowErr != nil { - // transaction rollback or something - return records, rowErr - } - if err := rows.Err(); err != nil { - return records, err - } - - return records, nil -} - -// Write records -func (s *sqlStore) Write(r *store.Record, opts ...store.WriteOption) error { - var err error - if r.Expiry != 0 { - _, err = s.write.Exec(r.Key, r.Value, time.Now().Add(r.Expiry)) - } else { - _, err = s.write.Exec(r.Key, r.Value, nil) - } - - if err != nil { - return errors.Wrap(err, "Couldn't insert record "+r.Key) - } - - return nil -} - -// Delete records with keys -func (s *sqlStore) Delete(key string, opts ...store.DeleteOption) error { - result, err := s.delete.Exec(key) - if err != nil { - return err - } - _, err = result.RowsAffected() - if err != nil { - return err - } - - return nil -} - -func (s *sqlStore) initDB() error { +func (s *sqlStore) initDB(database, table string) error { // Create the namespace's database - _, err := s.db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s ;", s.database)) + _, err := s.db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s ;", database)) if err != nil { return err } - _, err = s.db.Exec(fmt.Sprintf("SET DATABASE = %s ;", s.database)) + _, err = s.db.Exec(fmt.Sprintf("SET DATABASE = %s ;", database)) if err != nil { return errors.Wrap(err, "Couldn't set database") } @@ -240,58 +78,17 @@ func (s *sqlStore) initDB() error { value bytea, expiry timestamp with time zone, CONSTRAINT %s_pkey PRIMARY KEY (key) - );`, s.table, s.table)) + );`, table, table)) if err != nil { return errors.Wrap(err, "Couldn't create table") } // Create Index - _, err = s.db.Exec(fmt.Sprintf(`CREATE INDEX IF NOT EXISTS "%s" ON %s.%s USING btree ("key");`, "key_index_"+s.table, s.database, s.table)) + _, err = s.db.Exec(fmt.Sprintf(`CREATE INDEX IF NOT EXISTS "%s" ON %s.%s USING btree ("key");`, "key_index_"+table, database, table)) if err != nil { return err } - list, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s;", s.database, s.table)) - if err != nil { - return errors.Wrap(err, "List statement couldn't be prepared") - } - closeStmt(s.list) - s.list = list - readOne, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key = $1;", s.database, s.table)) - if err != nil { - return errors.Wrap(err, "ReadOne statement couldn't be prepared") - } - closeStmt(s.readOne) - s.readOne = readOne - readMany, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key LIKE $1;", s.database, s.table)) - if err != nil { - return errors.Wrap(err, "ReadMany statement couldn't be prepared") - } - closeStmt(s.readMany) - s.readMany = readMany - readOffset, err := s.db.Prepare(fmt.Sprintf("SELECT key, value, expiry FROM %s.%s WHERE key LIKE $1 ORDER BY key DESC LIMIT $2 OFFSET $3;", s.database, s.table)) - if err != nil { - return errors.Wrap(err, "ReadOffset statement couldn't be prepared") - } - closeStmt(s.readOffset) - s.readOffset = readOffset - write, err := s.db.Prepare(fmt.Sprintf(`INSERT INTO %s.%s(key, value, expiry) - VALUES ($1, $2::bytea, $3) - ON CONFLICT (key) - DO UPDATE - SET value = EXCLUDED.value, expiry = EXCLUDED.expiry;`, s.database, s.table)) - if err != nil { - return errors.Wrap(err, "Write statement couldn't be prepared") - } - closeStmt(s.write) - s.write = write - delete, err := s.db.Prepare(fmt.Sprintf("DELETE FROM %s.%s WHERE key = $1;", s.database, s.table)) - if err != nil { - return errors.Wrap(err, "Delete statement couldn't be prepared") - } - closeStmt(s.delete) - s.delete = delete - return nil } @@ -344,21 +141,286 @@ func (s *sqlStore) configure() error { // save the values s.db = db - s.database = database - s.table = table // initialise the database - return s.initDB() + return s.initDB(s.options.Database, s.options.Table) } -func (s *sqlStore) String() string { - return "cockroach" +func (s *sqlStore) prepare(database, table, query string) (*sql.Stmt, error) { + st, ok := statements[query] + if !ok { + return nil, errors.New("unsupported statement") + } + if len(database) == 0 { + database = s.options.Database + } + if len(table) == 0 { + table = s.options.Table + } + + q := fmt.Sprintf(st, database, table) + stmt, err := s.db.Prepare(q) + if err != nil { + return nil, err + } + return stmt, nil +} + +func (s *sqlStore) Close() error { + if s.db != nil { + return s.db.Close() + } + return nil +} + +func (s *sqlStore) Init(opts ...store.Option) error { + for _, o := range opts { + o(&s.options) + } + // reconfigure + return s.configure() +} + +// List all the known records +func (s *sqlStore) List(opts ...store.ListOption) ([]string, error) { + var options store.ListOptions + for _, o := range opts { + o(&options) + } + + // create the db if not exists + s.createDB(options.Database, options.Table) + + st, err := s.prepare(options.Database, options.Table, "list") + if err != nil { + return nil, err + } + defer st.Close() + + rows, err := st.Query() + if err != nil { + if err == sql.ErrNoRows { + return nil, nil + } + return nil, err + } + defer rows.Close() + + var keys []string + var timehelper pq.NullTime + + for rows.Next() { + record := &store.Record{} + if err := rows.Scan(&record.Key, &record.Value, &timehelper); err != nil { + return keys, err + } + if timehelper.Valid { + if timehelper.Time.Before(time.Now()) { + // record has expired + go s.Delete(record.Key) + } else { + record.Expiry = time.Until(timehelper.Time) + keys = append(keys, record.Key) + } + } else { + keys = append(keys, record.Key) + } + + } + rowErr := rows.Close() + if rowErr != nil { + // transaction rollback or something + return keys, rowErr + } + if err := rows.Err(); err != nil { + return keys, err + } + return keys, nil +} + +// Read a single key +func (s *sqlStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { + var options store.ReadOptions + for _, o := range opts { + o(&options) + } + + // create the db if not exists + s.createDB(options.Database, options.Table) + + if options.Prefix || options.Suffix { + return s.read(key, options) + } + + var records []*store.Record + var timehelper pq.NullTime + + st, err := s.prepare(options.Database, options.Table, "read") + if err != nil { + return nil, err + } + defer st.Close() + + row := st.QueryRow(key) + record := &store.Record{} + if err := row.Scan(&record.Key, &record.Value, &timehelper); err != nil { + if err == sql.ErrNoRows { + return records, store.ErrNotFound + } + return records, err + } + if timehelper.Valid { + if timehelper.Time.Before(time.Now()) { + // record has expired + go s.Delete(key) + return records, store.ErrNotFound + } + record.Expiry = time.Until(timehelper.Time) + records = append(records, record) + } else { + records = append(records, record) + } + + return records, nil +} + +// Read Many records +func (s *sqlStore) read(key string, options store.ReadOptions) ([]*store.Record, error) { + pattern := "%" + if options.Prefix { + pattern = key + pattern + } + if options.Suffix { + pattern = pattern + key + } + + var rows *sql.Rows + var err error + + if options.Limit != 0 { + st, err := s.prepare(options.Database, options.Table, "readOffset") + if err != nil { + return nil, err + } + defer st.Close() + + rows, err = st.Query(pattern, options.Limit, options.Offset) + } else { + st, err := s.prepare(options.Database, options.Table, "readMany") + if err != nil { + return nil, err + } + defer st.Close() + + rows, err = st.Query(pattern) + } + if err != nil { + if err == sql.ErrNoRows { + return []*store.Record{}, nil + } + return []*store.Record{}, errors.Wrap(err, "sqlStore.read failed") + } + + defer rows.Close() + + var records []*store.Record + var timehelper pq.NullTime + + for rows.Next() { + record := &store.Record{} + if err := rows.Scan(&record.Key, &record.Value, &timehelper); err != nil { + return records, err + } + if timehelper.Valid { + if timehelper.Time.Before(time.Now()) { + // record has expired + go s.Delete(record.Key) + } else { + record.Expiry = time.Until(timehelper.Time) + records = append(records, record) + } + } else { + records = append(records, record) + } + } + rowErr := rows.Close() + if rowErr != nil { + // transaction rollback or something + return records, rowErr + } + if err := rows.Err(); err != nil { + return records, err + } + + return records, nil +} + +// Write records +func (s *sqlStore) Write(r *store.Record, opts ...store.WriteOption) error { + var options store.WriteOptions + for _, o := range opts { + o(&options) + } + + // create the db if not exists + s.createDB(options.Database, options.Table) + + st, err := s.prepare(options.Database, options.Table, "write") + if err != nil { + return err + } + defer st.Close() + + if r.Expiry != 0 { + _, err = st.Exec(r.Key, r.Value, time.Now().Add(r.Expiry)) + } else { + _, err = st.Exec(r.Key, r.Value, nil) + } + + if err != nil { + return errors.Wrap(err, "Couldn't insert record "+r.Key) + } + + return nil +} + +// Delete records with keys +func (s *sqlStore) Delete(key string, opts ...store.DeleteOption) error { + var options store.DeleteOptions + for _, o := range opts { + o(&options) + } + + // create the db if not exists + s.createDB(options.Database, options.Table) + + st, err := s.prepare(options.Database, options.Table, "delete") + if err != nil { + return err + } + defer st.Close() + + result, err := st.Exec(key) + if err != nil { + return err + } + + _, err = result.RowsAffected() + if err != nil { + return err + } + + return nil } func (s *sqlStore) Options() store.Options { return s.options } +func (s *sqlStore) String() string { + return "cockroach" +} + // NewStore returns a new micro Store backed by sql func NewStore(opts ...store.Option) store.Store { var options store.Options @@ -370,16 +432,11 @@ func NewStore(opts ...store.Option) store.Store { s := new(sqlStore) // set the options s.options = options - + // mark known databases + s.databases = make(map[string]bool) // best-effort configure the store s.configure() // return store return s } - -func closeStmt(s *sql.Stmt) { - if s != nil { - s.Close() - } -} diff --git a/store/file/file.go b/store/file/file.go index 5f0fc95e..5abd6da0 100644 --- a/store/file/file.go +++ b/store/file/file.go @@ -7,10 +7,10 @@ import ( "path/filepath" "sort" "strings" + "sync" "time" "github.com/micro/go-micro/v2/store" - "github.com/pkg/errors" bolt "go.etcd.io/bbolt" ) @@ -29,18 +29,25 @@ var ( // NewStore returns a memory store func NewStore(opts ...store.Option) store.Store { - s := &fileStore{} + s := &fileStore{ + handles: make(map[string]*fileHandle), + } s.init(opts...) return s } type fileStore struct { - options store.Options - dir string - fileName string - dbPath string + options store.Options + dir string + // the database handle - db *bolt.DB + sync.RWMutex + handles map[string]*fileHandle +} + +type fileHandle struct { + key string + db *bolt.DB } // record stored by us @@ -50,8 +57,12 @@ type record struct { ExpiresAt time.Time } -func (m *fileStore) delete(key string) error { - return m.db.Update(func(tx *bolt.Tx) error { +func key(database, table string) string { + return database + ":" + table +} + +func (m *fileStore) delete(fd *fileHandle, key string) error { + return fd.db.Update(func(tx *bolt.Tx) error { b := tx.Bucket([]byte(dataBucket)) if b == nil { return nil @@ -76,42 +87,63 @@ func (m *fileStore) init(opts ...store.Option) error { // create a directory /tmp/micro dir := filepath.Join(DefaultDir, m.options.Database) - // create the database handle - fname := m.options.Table + ".db" // Ignoring this as the folder might exist. // Reads/Writes updates will return with sensible error messages // about the dir not existing in case this cannot create the path anyway os.MkdirAll(dir, 0700) - m.dir = dir - m.fileName = fname - m.dbPath = filepath.Join(dir, fname) - - // close existing handle - if m.db != nil { - m.db.Close() - } - - // create new db handle - db, err := bolt.Open(m.dbPath, 0700, &bolt.Options{Timeout: 5 * time.Second}) - if err != nil { - return err - } - - // set the new db - m.db = db - - // create the table - return db.Update(func(tx *bolt.Tx) error { - _, err := tx.CreateBucketIfNotExists([]byte(dataBucket)) - return err - }) + return nil } -func (m *fileStore) list(limit, offset uint) []string { +func (f *fileStore) getDB(database, table string) (*fileHandle, error) { + if len(database) == 0 { + database = f.options.Database + } + if len(table) == 0 { + table = f.options.Table + } + + k := key(database, table) + + f.RLock() + fd, ok := f.handles[k] + f.RUnlock() + + // return the file handle + if ok { + return fd, nil + } + + // create a directory /tmp/micro + dir := filepath.Join(DefaultDir, database) + // create the database handle + fname := table + ".db" + // make the dir + os.MkdirAll(dir, 0700) + // database path + dbPath := filepath.Join(dir, fname) + + // create new db handle + db, err := bolt.Open(dbPath, 0700, &bolt.Options{Timeout: 5 * time.Second}) + if err != nil { + return nil, err + } + + f.Lock() + fd = &fileHandle{ + key: k, + db: db, + } + f.handles[k] = fd + f.Unlock() + + return fd, nil +} + +func (m *fileStore) list(fd *fileHandle, limit, offset uint) []string { var allItems []string - m.db.View(func(tx *bolt.Tx) error { + fd.db.View(func(tx *bolt.Tx) error { b := tx.Bucket([]byte(dataBucket)) // nothing to read if b == nil { @@ -162,10 +194,10 @@ func (m *fileStore) list(limit, offset uint) []string { return allKeys } -func (m *fileStore) get(k string) (*store.Record, error) { +func (m *fileStore) get(fd *fileHandle, k string) (*store.Record, error) { var value []byte - m.db.View(func(tx *bolt.Tx) error { + fd.db.View(func(tx *bolt.Tx) error { // @todo this is still very experimental... b := tx.Bucket([]byte(dataBucket)) if b == nil { @@ -200,7 +232,7 @@ func (m *fileStore) get(k string) (*store.Record, error) { return newRecord, nil } -func (m *fileStore) set(r *store.Record) error { +func (m *fileStore) set(fd *fileHandle, r *store.Record) error { // copy the incoming record and then // convert the expiry in to a hard timestamp item := &record{} @@ -213,7 +245,7 @@ func (m *fileStore) set(r *store.Record) error { // marshal the data data, _ := json.Marshal(item) - return m.db.Update(func(tx *bolt.Tx) error { + return fd.db.Update(func(tx *bolt.Tx) error { b := tx.Bucket([]byte(dataBucket)) if b == nil { var err error @@ -226,53 +258,63 @@ func (m *fileStore) set(r *store.Record) error { }) } -func (m *fileStore) Close() error { - if m.db != nil { - return m.db.Close() +func (f *fileStore) Close() error { + f.Lock() + defer f.Unlock() + for k, v := range f.handles { + v.db.Close() + delete(f.handles, k) } return nil } -func (m *fileStore) Init(opts ...store.Option) error { - return m.init(opts...) +func (f *fileStore) Init(opts ...store.Option) error { + return f.init(opts...) } func (m *fileStore) Delete(key string, opts ...store.DeleteOption) error { - deleteOptions := store.DeleteOptions{} + var deleteOptions store.DeleteOptions for _, o := range opts { o(&deleteOptions) } - return m.delete(key) + + fd, err := m.getDB(deleteOptions.Database, deleteOptions.Table) + if err != nil { + return err + } + + return m.delete(fd, key) } func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { - readOpts := store.ReadOptions{} + var readOpts store.ReadOptions for _, o := range opts { o(&readOpts) } + fd, err := m.getDB(readOpts.Database, readOpts.Table) + if err != nil { + return nil, err + } + var keys []string // Handle Prefix / suffix // TODO: do range scan here rather than listing all keys if readOpts.Prefix || readOpts.Suffix { - var opts []store.ListOption - if readOpts.Prefix { - opts = append(opts, store.ListPrefix(key)) - } - if readOpts.Suffix { - opts = append(opts, store.ListSuffix(key)) - } + // list the keys + k := m.list(fd, readOpts.Limit, readOpts.Offset) - opts = append(opts, store.ListLimit(readOpts.Limit)) - opts = append(opts, store.ListOffset(readOpts.Offset)) - - k, err := m.List(opts...) - if err != nil { - return nil, errors.Wrap(err, "FileStore: Read couldn't List()") + // check for prefix and suffix + for _, v := range k { + if readOpts.Prefix && !strings.HasPrefix(v, key) { + continue + } + if readOpts.Suffix && !strings.HasSuffix(v, key) { + continue + } + keys = append(keys, v) } - - keys = k } else { keys = []string{key} } @@ -280,7 +322,7 @@ func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, var results []*store.Record for _, k := range keys { - r, err := m.get(k) + r, err := m.get(fd, k) if err != nil { return results, err } @@ -291,11 +333,16 @@ func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, } func (m *fileStore) Write(r *store.Record, opts ...store.WriteOption) error { - writeOpts := store.WriteOptions{} + var writeOpts store.WriteOptions for _, o := range opts { o(&writeOpts) } + fd, err := m.getDB(writeOpts.Database, writeOpts.Table) + if err != nil { + return err + } + if len(opts) > 0 { // Copy the record before applying options, or the incoming record will be mutated newRecord := store.Record{} @@ -310,10 +357,10 @@ func (m *fileStore) Write(r *store.Record, opts ...store.WriteOption) error { newRecord.Expiry = writeOpts.TTL } - return m.set(&newRecord) + return m.set(fd, &newRecord) } - return m.set(r) + return m.set(fd, r) } func (m *fileStore) Options() store.Options { @@ -321,14 +368,19 @@ func (m *fileStore) Options() store.Options { } func (m *fileStore) List(opts ...store.ListOption) ([]string, error) { - listOptions := store.ListOptions{} + var listOptions store.ListOptions for _, o := range opts { o(&listOptions) } + fd, err := m.getDB(listOptions.Database, listOptions.Table) + if err != nil { + return nil, err + } + // TODO apply prefix/suffix in range query - allKeys := m.list(listOptions.Limit, listOptions.Offset) + allKeys := m.list(fd, listOptions.Limit, listOptions.Offset) if len(listOptions.Prefix) > 0 { var prefixKeys []string diff --git a/store/memory/memory.go b/store/memory/memory.go index 97d19072..cbe6e38d 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -2,12 +2,12 @@ package memory import ( + "path/filepath" "sort" "strings" "time" "github.com/micro/go-micro/v2/store" - "github.com/patrickmn/go-cache" "github.com/pkg/errors" ) @@ -15,8 +15,11 @@ import ( // NewStore returns a memory store func NewStore(opts ...store.Option) store.Store { s := &memoryStore{ - options: store.Options{}, - store: cache.New(cache.NoExpiration, 5*time.Minute), + options: store.Options{ + Database: "micro", + Table: "micro", + }, + store: cache.New(cache.NoExpiration, 5*time.Minute), } for _, o := range opts { o(&s.options) @@ -30,6 +33,101 @@ type memoryStore struct { store *cache.Cache } +type internalRecord struct { + key string + value []byte + expiresAt time.Time +} + +func (m *memoryStore) key(prefix, key string) string { + return filepath.Join(prefix, key) +} + +func (m *memoryStore) prefix(database, table string) string { + if len(database) == 0 { + database = m.options.Database + } + if len(table) == 0 { + table = m.options.Table + } + return filepath.Join(database, table) +} + +func (m *memoryStore) get(prefix, key string) (*store.Record, error) { + key = m.key(prefix, key) + + var storedRecord *internalRecord + r, found := m.store.Get(key) + if !found { + return nil, store.ErrNotFound + } + + storedRecord, ok := r.(*internalRecord) + if !ok { + return nil, errors.New("Retrieved a non *internalRecord from the cache") + } + + // Copy the record on the way out + newRecord := &store.Record{} + newRecord.Key = strings.TrimPrefix(storedRecord.key, prefix+"/") + newRecord.Value = make([]byte, len(storedRecord.value)) + copy(newRecord.Value, storedRecord.value) + if !storedRecord.expiresAt.IsZero() { + newRecord.Expiry = time.Until(storedRecord.expiresAt) + } + + return newRecord, nil +} + +func (m *memoryStore) set(prefix string, r *store.Record) { + key := m.key(prefix, r.Key) + + // copy the incoming record and then + // convert the expiry in to a hard timestamp + i := &internalRecord{} + i.key = r.Key + i.value = make([]byte, len(r.Value)) + copy(i.value, r.Value) + + if r.Expiry != 0 { + i.expiresAt = time.Now().Add(r.Expiry) + } + + m.store.Set(key, i, r.Expiry) +} + +func (m *memoryStore) delete(prefix, key string) { + key = m.key(prefix, key) + m.store.Delete(key) +} + +func (m *memoryStore) list(prefix string, limit, offset uint) []string { + allItems := m.store.Items() + allKeys := make([]string, len(allItems)) + i := 0 + + for k := range allItems { + if !strings.HasPrefix(k, prefix+"/") { + continue + } + allKeys[i] = strings.TrimPrefix(k, prefix+"/") + i++ + } + + if limit != 0 || offset != 0 { + sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] }) + min := func(i, j uint) uint { + if i < j { + return i + } + return j + } + return allKeys[offset:min(limit, uint(len(allKeys)))] + } + + return allKeys +} + func (m *memoryStore) Close() error { m.store.Flush() return nil @@ -53,31 +151,33 @@ func (m *memoryStore) Read(key string, opts ...store.ReadOption) ([]*store.Recor o(&readOpts) } + prefix := m.prefix(readOpts.Database, readOpts.Table) + var keys []string // Handle Prefix / suffix if readOpts.Prefix || readOpts.Suffix { - var opts []store.ListOption - if readOpts.Prefix { - opts = append(opts, store.ListPrefix(key)) + k := m.list(prefix, readOpts.Limit, readOpts.Offset) + + for _, kk := range k { + if readOpts.Prefix && !strings.HasPrefix(kk, key) { + continue + } + + if readOpts.Suffix && !strings.HasSuffix(kk, key) { + continue + } + + keys = append(keys, kk) } - if readOpts.Suffix { - opts = append(opts, store.ListSuffix(key)) - } - opts = append(opts, store.ListLimit(readOpts.Limit)) - opts = append(opts, store.ListOffset(readOpts.Offset)) - k, err := m.List(opts...) - if err != nil { - return nil, errors.Wrap(err, "Memory: Read couldn't List()") - } - keys = k } else { keys = []string{key} } var results []*store.Record + for _, k := range keys { - r, err := m.get(k) + r, err := m.get(prefix, k) if err != nil { return results, err } @@ -87,40 +187,14 @@ func (m *memoryStore) Read(key string, opts ...store.ReadOption) ([]*store.Recor return results, nil } -func (m *memoryStore) get(k string) (*store.Record, error) { - if len(m.options.Table) > 0 { - k = m.options.Table + "/" + k - } - if len(m.options.Database) > 0 { - k = m.options.Database + "/" + k - } - var storedRecord *internalRecord - r, found := m.store.Get(k) - if !found { - return nil, store.ErrNotFound - } - storedRecord, ok := r.(*internalRecord) - if !ok { - return nil, errors.New("Retrieved a non *internalRecord from the cache") - } - // Copy the record on the way out - newRecord := &store.Record{} - newRecord.Key = storedRecord.key - newRecord.Value = make([]byte, len(storedRecord.value)) - copy(newRecord.Value, storedRecord.value) - if !storedRecord.expiresAt.IsZero() { - newRecord.Expiry = time.Until(storedRecord.expiresAt) - } - - return newRecord, nil -} - func (m *memoryStore) Write(r *store.Record, opts ...store.WriteOption) error { writeOpts := store.WriteOptions{} for _, o := range opts { o(&writeOpts) } + prefix := m.prefix(writeOpts.Database, writeOpts.Table) + if len(opts) > 0 { // Copy the record before applying options, or the incoming record will be mutated newRecord := store.Record{} @@ -135,52 +209,25 @@ func (m *memoryStore) Write(r *store.Record, opts ...store.WriteOption) error { if writeOpts.TTL != 0 { newRecord.Expiry = writeOpts.TTL } - m.set(&newRecord) - } else { - m.set(r) + m.set(prefix, &newRecord) + return nil } + + // set + m.set(prefix, r) + return nil } -func (m *memoryStore) set(r *store.Record) { - key := r.Key - if len(m.options.Table) > 0 { - key = m.options.Table + "/" + key - } - if len(m.options.Database) > 0 { - key = m.options.Database + "/" + key - } - - // copy the incoming record and then - // convert the expiry in to a hard timestamp - i := &internalRecord{} - i.key = r.Key - i.value = make([]byte, len(r.Value)) - copy(i.value, r.Value) - if r.Expiry != 0 { - i.expiresAt = time.Now().Add(r.Expiry) - } - - m.store.Set(key, i, r.Expiry) -} - func (m *memoryStore) Delete(key string, opts ...store.DeleteOption) error { deleteOptions := store.DeleteOptions{} for _, o := range opts { o(&deleteOptions) } - m.delete(key) - return nil -} -func (m *memoryStore) delete(key string) { - if len(m.options.Table) > 0 { - key = m.options.Table + "/" + key - } - if len(m.options.Database) > 0 { - key = m.options.Database + "/" + key - } - m.store.Delete(key) + prefix := m.prefix(deleteOptions.Database, deleteOptions.Table) + m.delete(prefix, key) + return nil } func (m *memoryStore) Options() store.Options { @@ -193,59 +240,29 @@ func (m *memoryStore) List(opts ...store.ListOption) ([]string, error) { for _, o := range opts { o(&listOptions) } - allKeys := m.list(listOptions.Limit, listOptions.Offset) + + prefix := m.prefix(listOptions.Database, listOptions.Table) + keys := m.list(prefix, listOptions.Limit, listOptions.Offset) if len(listOptions.Prefix) > 0 { var prefixKeys []string - for _, k := range allKeys { + for _, k := range keys { if strings.HasPrefix(k, listOptions.Prefix) { prefixKeys = append(prefixKeys, k) } } - allKeys = prefixKeys + keys = prefixKeys } + if len(listOptions.Suffix) > 0 { var suffixKeys []string - for _, k := range allKeys { + for _, k := range keys { if strings.HasSuffix(k, listOptions.Suffix) { suffixKeys = append(suffixKeys, k) } } - allKeys = suffixKeys + keys = suffixKeys } - return allKeys, nil -} - -func (m *memoryStore) list(limit, offset uint) []string { - allItems := m.store.Items() - allKeys := make([]string, len(allItems)) - i := 0 - for k := range allItems { - if len(m.options.Database) > 0 { - k = strings.TrimPrefix(k, m.options.Database+"/") - } - if len(m.options.Table) > 0 { - k = strings.TrimPrefix(k, m.options.Table+"/") - } - allKeys[i] = k - i++ - } - if limit != 0 || offset != 0 { - sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] }) - min := func(i, j uint) uint { - if i < j { - return i - } - return j - } - return allKeys[offset:min(limit, uint(len(allKeys)))] - } - return allKeys -} - -type internalRecord struct { - key string - value []byte - expiresAt time.Time + return keys, nil } diff --git a/store/memory/memory_test.go b/store/memory/memory_test.go index 8d51ea0d..4598a667 100644 --- a/store/memory/memory_test.go +++ b/store/memory/memory_test.go @@ -259,13 +259,13 @@ func basictest(s store.Store, t *testing.T) { t.Error(err) } else { if len(results) != 5 { - t.Error("Expected 5 results, got ", len(results)) + t.Fatal("Expected 5 results, got ", len(results)) } if results[0].Key != "a0" { - t.Errorf("Expected a0, got %s", results[0].Key) + t.Fatalf("Expected a0, got %s", results[0].Key) } if results[4].Key != "a4" { - t.Errorf("Expected a4, got %s", results[4].Key) + t.Fatalf("Expected a4, got %s", results[4].Key) } } if results, err := s.Read("a", store.ReadLimit(30), store.ReadOffset(5), store.ReadPrefix()); err != nil { diff --git a/store/service/proto/store.pb.go b/store/service/proto/store.pb.go index e6ea5285..71af1132 100644 --- a/store/service/proto/store.pb.go +++ b/store/service/proto/store.pb.go @@ -1,15 +1,11 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: store/service/proto/store.proto +// source: github.com/micro/go-micro/store/service/proto/store.proto package go_micro_store import ( - context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" math "math" ) @@ -40,7 +36,7 @@ func (m *Record) Reset() { *m = Record{} } func (m *Record) String() string { return proto.CompactTextString(m) } func (*Record) ProtoMessage() {} func (*Record) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{0} + return fileDescriptor_42854049893ccb13, []int{0} } func (m *Record) XXX_Unmarshal(b []byte) error { @@ -83,10 +79,12 @@ func (m *Record) GetExpiry() int64 { } type ReadOptions struct { - Prefix bool `protobuf:"varint,1,opt,name=prefix,proto3" json:"prefix,omitempty"` - Suffix bool `protobuf:"varint,2,opt,name=suffix,proto3" json:"suffix,omitempty"` - Limit uint64 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` - Offset uint64 `protobuf:"varint,4,opt,name=offset,proto3" json:"offset,omitempty"` + Database string `protobuf:"bytes,1,opt,name=database,proto3" json:"database,omitempty"` + Table string `protobuf:"bytes,2,opt,name=table,proto3" json:"table,omitempty"` + Prefix bool `protobuf:"varint,3,opt,name=prefix,proto3" json:"prefix,omitempty"` + Suffix bool `protobuf:"varint,4,opt,name=suffix,proto3" json:"suffix,omitempty"` + Limit uint64 `protobuf:"varint,5,opt,name=limit,proto3" json:"limit,omitempty"` + Offset uint64 `protobuf:"varint,6,opt,name=offset,proto3" json:"offset,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -96,7 +94,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{1} + return fileDescriptor_42854049893ccb13, []int{1} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -117,6 +115,20 @@ func (m *ReadOptions) XXX_DiscardUnknown() { var xxx_messageInfo_ReadOptions proto.InternalMessageInfo +func (m *ReadOptions) GetDatabase() string { + if m != nil { + return m.Database + } + return "" +} + +func (m *ReadOptions) GetTable() string { + if m != nil { + return m.Table + } + return "" +} + func (m *ReadOptions) GetPrefix() bool { if m != nil { return m.Prefix @@ -157,7 +169,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{2} + return fileDescriptor_42854049893ccb13, []int{2} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -203,7 +215,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{3} + return fileDescriptor_42854049893ccb13, []int{3} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -232,10 +244,12 @@ func (m *ReadResponse) GetRecords() []*Record { } type WriteOptions struct { + Database string `protobuf:"bytes,1,opt,name=database,proto3" json:"database,omitempty"` + Table string `protobuf:"bytes,2,opt,name=table,proto3" json:"table,omitempty"` // time.Time - Expiry int64 `protobuf:"varint,1,opt,name=expiry,proto3" json:"expiry,omitempty"` + Expiry int64 `protobuf:"varint,3,opt,name=expiry,proto3" json:"expiry,omitempty"` // time.Duration - Ttl int64 `protobuf:"varint,2,opt,name=ttl,proto3" json:"ttl,omitempty"` + Ttl int64 `protobuf:"varint,4,opt,name=ttl,proto3" json:"ttl,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -245,7 +259,7 @@ func (m *WriteOptions) Reset() { *m = WriteOptions{} } func (m *WriteOptions) String() string { return proto.CompactTextString(m) } func (*WriteOptions) ProtoMessage() {} func (*WriteOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{4} + return fileDescriptor_42854049893ccb13, []int{4} } func (m *WriteOptions) XXX_Unmarshal(b []byte) error { @@ -266,6 +280,20 @@ func (m *WriteOptions) XXX_DiscardUnknown() { var xxx_messageInfo_WriteOptions proto.InternalMessageInfo +func (m *WriteOptions) GetDatabase() string { + if m != nil { + return m.Database + } + return "" +} + +func (m *WriteOptions) GetTable() string { + if m != nil { + return m.Table + } + return "" +} + func (m *WriteOptions) GetExpiry() int64 { if m != nil { return m.Expiry @@ -292,7 +320,7 @@ func (m *WriteRequest) Reset() { *m = WriteRequest{} } func (m *WriteRequest) String() string { return proto.CompactTextString(m) } func (*WriteRequest) ProtoMessage() {} func (*WriteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{5} + return fileDescriptor_42854049893ccb13, []int{5} } func (m *WriteRequest) XXX_Unmarshal(b []byte) error { @@ -337,7 +365,7 @@ func (m *WriteResponse) Reset() { *m = WriteResponse{} } func (m *WriteResponse) String() string { return proto.CompactTextString(m) } func (*WriteResponse) ProtoMessage() {} func (*WriteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{6} + return fileDescriptor_42854049893ccb13, []int{6} } func (m *WriteResponse) XXX_Unmarshal(b []byte) error { @@ -359,6 +387,8 @@ func (m *WriteResponse) XXX_DiscardUnknown() { var xxx_messageInfo_WriteResponse proto.InternalMessageInfo type DeleteOptions struct { + Database string `protobuf:"bytes,1,opt,name=database,proto3" json:"database,omitempty"` + Table string `protobuf:"bytes,2,opt,name=table,proto3" json:"table,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -368,7 +398,7 @@ func (m *DeleteOptions) Reset() { *m = DeleteOptions{} } func (m *DeleteOptions) String() string { return proto.CompactTextString(m) } func (*DeleteOptions) ProtoMessage() {} func (*DeleteOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{7} + return fileDescriptor_42854049893ccb13, []int{7} } func (m *DeleteOptions) XXX_Unmarshal(b []byte) error { @@ -389,6 +419,20 @@ func (m *DeleteOptions) XXX_DiscardUnknown() { var xxx_messageInfo_DeleteOptions proto.InternalMessageInfo +func (m *DeleteOptions) GetDatabase() string { + if m != nil { + return m.Database + } + return "" +} + +func (m *DeleteOptions) GetTable() string { + if m != nil { + return m.Table + } + return "" +} + type DeleteRequest struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` Options *DeleteOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` @@ -401,7 +445,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{8} + return fileDescriptor_42854049893ccb13, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -446,7 +490,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{9} + return fileDescriptor_42854049893ccb13, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -468,10 +512,12 @@ func (m *DeleteResponse) XXX_DiscardUnknown() { var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo type ListOptions struct { - Prefix string `protobuf:"bytes,1,opt,name=prefix,proto3" json:"prefix,omitempty"` - Suffix string `protobuf:"bytes,2,opt,name=suffix,proto3" json:"suffix,omitempty"` - Limit uint64 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` - Offset uint64 `protobuf:"varint,4,opt,name=offset,proto3" json:"offset,omitempty"` + Database string `protobuf:"bytes,1,opt,name=database,proto3" json:"database,omitempty"` + Table string `protobuf:"bytes,2,opt,name=table,proto3" json:"table,omitempty"` + Prefix string `protobuf:"bytes,3,opt,name=prefix,proto3" json:"prefix,omitempty"` + Suffix string `protobuf:"bytes,4,opt,name=suffix,proto3" json:"suffix,omitempty"` + Limit uint64 `protobuf:"varint,5,opt,name=limit,proto3" json:"limit,omitempty"` + Offset uint64 `protobuf:"varint,6,opt,name=offset,proto3" json:"offset,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -481,7 +527,7 @@ func (m *ListOptions) Reset() { *m = ListOptions{} } func (m *ListOptions) String() string { return proto.CompactTextString(m) } func (*ListOptions) ProtoMessage() {} func (*ListOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{10} + return fileDescriptor_42854049893ccb13, []int{10} } func (m *ListOptions) XXX_Unmarshal(b []byte) error { @@ -502,6 +548,20 @@ func (m *ListOptions) XXX_DiscardUnknown() { var xxx_messageInfo_ListOptions proto.InternalMessageInfo +func (m *ListOptions) GetDatabase() string { + if m != nil { + return m.Database + } + return "" +} + +func (m *ListOptions) GetTable() string { + if m != nil { + return m.Table + } + return "" +} + func (m *ListOptions) GetPrefix() string { if m != nil { return m.Prefix @@ -541,7 +601,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{11} + return fileDescriptor_42854049893ccb13, []int{11} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -580,7 +640,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{12} + return fileDescriptor_42854049893ccb13, []int{12} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -618,7 +678,7 @@ func (m *DatabasesRequest) Reset() { *m = DatabasesRequest{} } func (m *DatabasesRequest) String() string { return proto.CompactTextString(m) } func (*DatabasesRequest) ProtoMessage() {} func (*DatabasesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{13} + return fileDescriptor_42854049893ccb13, []int{13} } func (m *DatabasesRequest) XXX_Unmarshal(b []byte) error { @@ -650,7 +710,7 @@ func (m *DatabasesResponse) Reset() { *m = DatabasesResponse{} } func (m *DatabasesResponse) String() string { return proto.CompactTextString(m) } func (*DatabasesResponse) ProtoMessage() {} func (*DatabasesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{14} + return fileDescriptor_42854049893ccb13, []int{14} } func (m *DatabasesResponse) XXX_Unmarshal(b []byte) error { @@ -689,7 +749,7 @@ func (m *TablesRequest) Reset() { *m = TablesRequest{} } func (m *TablesRequest) String() string { return proto.CompactTextString(m) } func (*TablesRequest) ProtoMessage() {} func (*TablesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{15} + return fileDescriptor_42854049893ccb13, []int{15} } func (m *TablesRequest) XXX_Unmarshal(b []byte) error { @@ -728,7 +788,7 @@ func (m *TablesResponse) Reset() { *m = TablesResponse{} } func (m *TablesResponse) String() string { return proto.CompactTextString(m) } func (*TablesResponse) ProtoMessage() {} func (*TablesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1ba364858f5c3cdb, []int{16} + return fileDescriptor_42854049893ccb13, []int{16} } func (m *TablesResponse) XXX_Unmarshal(b []byte) error { @@ -776,332 +836,48 @@ func init() { proto.RegisterType((*TablesResponse)(nil), "go.micro.store.TablesResponse") } -func init() { proto.RegisterFile("store/service/proto/store.proto", fileDescriptor_1ba364858f5c3cdb) } - -var fileDescriptor_1ba364858f5c3cdb = []byte{ - // 563 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x5d, 0x8f, 0xd2, 0x40, - 0x14, 0xa5, 0xb4, 0x74, 0xe9, 0x85, 0x45, 0x9c, 0x18, 0x42, 0x90, 0x55, 0x9c, 0xa7, 0x26, 0x26, - 0x65, 0xc5, 0xf8, 0xf1, 0x68, 0x22, 0x1a, 0x35, 0x26, 0x26, 0xa3, 0xd1, 0xc4, 0xb7, 0x02, 0x83, - 0x69, 0x60, 0x77, 0x6a, 0x67, 0x20, 0xcb, 0x0f, 0xf4, 0x7f, 0x99, 0xf9, 0x2a, 0xa5, 0xb4, 0x3e, - 0xf8, 0x36, 0xf7, 0xcc, 0x9d, 0x73, 0xee, 0xb9, 0xf7, 0xb6, 0xf0, 0x98, 0x0b, 0x96, 0xd1, 0x29, - 0xa7, 0xd9, 0x3e, 0x59, 0xd2, 0x69, 0x9a, 0x31, 0xc1, 0xa6, 0x0a, 0x8b, 0xd4, 0x19, 0xf5, 0x7e, - 0xb1, 0xe8, 0x26, 0x59, 0x66, 0x2c, 0x52, 0x28, 0xfe, 0x00, 0x3e, 0xa1, 0x4b, 0x96, 0xad, 0x50, - 0x1f, 0xdc, 0x0d, 0x3d, 0x0c, 0x9d, 0x89, 0x13, 0x06, 0x44, 0x1e, 0xd1, 0x03, 0x68, 0xed, 0xe3, - 0xed, 0x8e, 0x0e, 0x9b, 0x13, 0x27, 0xec, 0x12, 0x1d, 0xa0, 0x01, 0xf8, 0xf4, 0x2e, 0x4d, 0xb2, - 0xc3, 0xd0, 0x9d, 0x38, 0xa1, 0x4b, 0x4c, 0x84, 0x37, 0xd0, 0x21, 0x34, 0x5e, 0x7d, 0x49, 0x45, - 0xc2, 0x6e, 0xb9, 0x4c, 0x4b, 0x33, 0xba, 0x4e, 0xee, 0x14, 0x63, 0x9b, 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xee, 0xf2, 0x64, 0xd6, 0xe7, 0x2e, 0x4f, 0xa7, 0x8b, 0x1b, - 0x0b, 0x5f, 0xfd, 0xec, 0x9f, 0xff, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xa8, 0x04, 0x5f, 0x7c, 0x0f, - 0x06, 0x00, 0x00, +func init() { + proto.RegisterFile("github.com/micro/go-micro/store/service/proto/store.proto", fileDescriptor_42854049893ccb13) } -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// StoreClient is the client API for Store service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type StoreClient interface { - Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) - Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) - Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) - List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (Store_ListClient, error) - Databases(ctx context.Context, in *DatabasesRequest, opts ...grpc.CallOption) (*DatabasesResponse, error) - Tables(ctx context.Context, in *TablesRequest, opts ...grpc.CallOption) (*TablesResponse, error) -} - -type storeClient struct { - cc *grpc.ClientConn -} - -func NewStoreClient(cc *grpc.ClientConn) StoreClient { - return &storeClient{cc} -} - -func (c *storeClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { - out := new(ReadResponse) - err := c.cc.Invoke(ctx, "/go.micro.store.Store/Read", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *storeClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) { - out := new(WriteResponse) - err := c.cc.Invoke(ctx, "/go.micro.store.Store/Write", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *storeClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { - out := new(DeleteResponse) - err := c.cc.Invoke(ctx, "/go.micro.store.Store/Delete", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *storeClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (Store_ListClient, error) { - stream, err := c.cc.NewStream(ctx, &_Store_serviceDesc.Streams[0], "/go.micro.store.Store/List", opts...) - if err != nil { - return nil, err - } - x := &storeListClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type Store_ListClient interface { - Recv() (*ListResponse, error) - grpc.ClientStream -} - -type storeListClient struct { - grpc.ClientStream -} - -func (x *storeListClient) Recv() (*ListResponse, error) { - m := new(ListResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *storeClient) Databases(ctx context.Context, in *DatabasesRequest, opts ...grpc.CallOption) (*DatabasesResponse, error) { - out := new(DatabasesResponse) - err := c.cc.Invoke(ctx, "/go.micro.store.Store/Databases", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *storeClient) Tables(ctx context.Context, in *TablesRequest, opts ...grpc.CallOption) (*TablesResponse, error) { - out := new(TablesResponse) - err := c.cc.Invoke(ctx, "/go.micro.store.Store/Tables", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// StoreServer is the server API for Store service. -type StoreServer interface { - Read(context.Context, *ReadRequest) (*ReadResponse, error) - Write(context.Context, *WriteRequest) (*WriteResponse, error) - Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) - List(*ListRequest, Store_ListServer) error - Databases(context.Context, *DatabasesRequest) (*DatabasesResponse, error) - Tables(context.Context, *TablesRequest) (*TablesResponse, error) -} - -// UnimplementedStoreServer can be embedded to have forward compatible implementations. -type UnimplementedStoreServer struct { -} - -func (*UnimplementedStoreServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") -} -func (*UnimplementedStoreServer) Write(ctx context.Context, req *WriteRequest) (*WriteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Write not implemented") -} -func (*UnimplementedStoreServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") -} -func (*UnimplementedStoreServer) List(req *ListRequest, srv Store_ListServer) error { - return status.Errorf(codes.Unimplemented, "method List not implemented") -} -func (*UnimplementedStoreServer) Databases(ctx context.Context, req *DatabasesRequest) (*DatabasesResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Databases not implemented") -} -func (*UnimplementedStoreServer) Tables(ctx context.Context, req *TablesRequest) (*TablesResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Tables not implemented") -} - -func RegisterStoreServer(s *grpc.Server, srv StoreServer) { - s.RegisterService(&_Store_serviceDesc, srv) -} - -func _Store_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ReadRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(StoreServer).Read(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.store.Store/Read", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(StoreServer).Read(ctx, req.(*ReadRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Store_Write_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(WriteRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(StoreServer).Write(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.store.Store/Write", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(StoreServer).Write(ctx, req.(*WriteRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Store_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DeleteRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(StoreServer).Delete(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.store.Store/Delete", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(StoreServer).Delete(ctx, req.(*DeleteRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Store_List_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(ListRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(StoreServer).List(m, &storeListServer{stream}) -} - -type Store_ListServer interface { - Send(*ListResponse) error - grpc.ServerStream -} - -type storeListServer struct { - grpc.ServerStream -} - -func (x *storeListServer) Send(m *ListResponse) error { - return x.ServerStream.SendMsg(m) -} - -func _Store_Databases_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DatabasesRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(StoreServer).Databases(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.store.Store/Databases", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(StoreServer).Databases(ctx, req.(*DatabasesRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Store_Tables_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(TablesRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(StoreServer).Tables(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.store.Store/Tables", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(StoreServer).Tables(ctx, req.(*TablesRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Store_serviceDesc = grpc.ServiceDesc{ - ServiceName: "go.micro.store.Store", - HandlerType: (*StoreServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Read", - Handler: _Store_Read_Handler, - }, - { - MethodName: "Write", - Handler: _Store_Write_Handler, - }, - { - MethodName: "Delete", - Handler: _Store_Delete_Handler, - }, - { - MethodName: "Databases", - Handler: _Store_Databases_Handler, - }, - { - MethodName: "Tables", - Handler: _Store_Tables_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "List", - Handler: _Store_List_Handler, - ServerStreams: true, - }, - }, - Metadata: "store/service/proto/store.proto", +var fileDescriptor_42854049893ccb13 = []byte{ + // 598 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0xdd, 0x8e, 0xd2, 0x40, + 0x14, 0xa6, 0xdb, 0xd2, 0xa5, 0x87, 0x1f, 0x71, 0x62, 0x48, 0x83, 0xac, 0xa9, 0x73, 0xd5, 0xc4, + 0x58, 0x56, 0x8c, 0x1a, 0xef, 0x34, 0xa2, 0x51, 0x63, 0x62, 0x32, 0x1a, 0x4d, 0xbc, 0x2b, 0x30, + 0x60, 0x5d, 0xd8, 0x62, 0x67, 0x20, 0xcb, 0xc3, 0xf8, 0x38, 0xbe, 0x97, 0x99, 0x3f, 0x28, 0xd0, + 0xee, 0x85, 0xbb, 0x77, 0x73, 0xce, 0x1c, 0xbe, 0x39, 0xdf, 0x4f, 0x03, 0xbc, 0x9c, 0x25, 0xfc, + 0xe7, 0x6a, 0x14, 0x8d, 0xd3, 0x45, 0x7f, 0x91, 0x8c, 0xb3, 0xb4, 0x3f, 0x4b, 0x1f, 0xab, 0x03, + 0xe3, 0x69, 0x46, 0xfb, 0x8c, 0x66, 0xeb, 0x64, 0x4c, 0xfb, 0xcb, 0x2c, 0xe5, 0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32, 0xc3, 0x1a, 0xbc, 0x03, 0xae, 0x14, 0xd7, + 0x20, 0xeb, 0x6a, 0xf0, 0xd7, 0x86, 0xea, 0x17, 0x41, 0x13, 0xbd, 0x01, 0x47, 0x7c, 0x9f, 0xa8, + 0xf0, 0x6b, 0xd6, 0x8f, 0x76, 0x7b, 0xc5, 0x97, 0xda, 0xfa, 0x0a, 0x7a, 0x07, 0x55, 0x19, 0x5f, + 0x54, 0x1c, 0x77, 0x03, 0x73, 0x56, 0x72, 0xbb, 0xc5, 0xf9, 0x00, 0xae, 0x8a, 0x15, 0x2a, 0x09, + 0xa2, 0x41, 0x7a, 0x50, 0x76, 0xbd, 0x85, 0x7a, 0x0b, 0x8e, 0x70, 0x0a, 0x15, 0xfa, 0x5a, 0xca, + 0x2b, 0x6f, 0x2e, 0xae, 0x9c, 0x5b, 0x88, 0x80, 0xb7, 0xb5, 0x0c, 0x05, 0x47, 0xaf, 0x1e, 0x38, + 0xdc, 0x7d, 0x78, 0xcd, 0x44, 0x9e, 0xa5, 0xb2, 0xe9, 0x98, 0xe5, 0x9e, 0xd7, 0xc7, 0x2c, 0xf7, + 0xdd, 0xc5, 0x95, 0x91, 0x2b, 0xff, 0xb6, 0x9e, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xab, 0xcb, + 0x6e, 0xac, 0xf3, 0x06, 0x00, 0x00, } diff --git a/store/service/proto/store.pb.micro.go b/store/service/proto/store.pb.micro.go index 0e622f09..668a5a87 100644 --- a/store/service/proto/store.pb.micro.go +++ b/store/service/proto/store.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: store/service/proto/store.proto +// source: github.com/micro/go-micro/store/service/proto/store.proto package go_micro_store diff --git a/store/service/proto/store.proto b/store/service/proto/store.proto index 460cf049..22056ef9 100644 --- a/store/service/proto/store.proto +++ b/store/service/proto/store.proto @@ -21,10 +21,12 @@ message Record { } message ReadOptions { - bool prefix = 1; - bool suffix = 2; - uint64 limit = 3; - uint64 offset = 4; + string database = 1; + string table = 2; + bool prefix = 3; + bool suffix = 4; + uint64 limit = 5; + uint64 offset = 6; } message ReadRequest { @@ -37,10 +39,12 @@ message ReadResponse { } message WriteOptions { + string database = 1; + string table = 2; // time.Time - int64 expiry = 1; + int64 expiry = 3; // time.Duration - int64 ttl = 2; + int64 ttl = 4; } message WriteRequest { @@ -50,7 +54,10 @@ message WriteRequest { message WriteResponse {} -message DeleteOptions {} +message DeleteOptions { + string database = 1; + string table = 2; +} message DeleteRequest { string key = 1; @@ -60,12 +67,15 @@ message DeleteRequest { message DeleteResponse {} message ListOptions { - string prefix = 1; - string suffix = 2; - uint64 limit = 3; - uint64 offset = 4; + string database = 1; + string table = 2; + string prefix = 3; + string suffix = 4; + uint64 limit = 5; + uint64 offset = 6; } + message ListRequest { ListOptions options = 1; } diff --git a/store/service/service.go b/store/service/service.go index f812082b..45775eb1 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -46,23 +46,27 @@ func (s *serviceStore) Init(opts ...store.Option) error { func (s *serviceStore) Context() context.Context { ctx := context.Background() - md := make(metadata.Metadata) - - if len(s.Database) > 0 { - md["Micro-Database"] = s.Database - } - - if len(s.Table) > 0 { - md["Micro-Table"] = s.Table - } - return metadata.NewContext(ctx, md) } // Sync all the known records func (s *serviceStore) List(opts ...store.ListOption) ([]string, error) { - stream, err := s.Client.List(s.Context(), &pb.ListRequest{}, client.WithAddress(s.Nodes...)) + var options store.ListOptions + for _, o := range opts { + o(&options) + } + + listOpts := &pb.ListOptions{ + Database: options.Database, + Table: options.Table, + Prefix: options.Prefix, + Suffix: options.Suffix, + Limit: uint64(options.Limit), + Offset: uint64(options.Offset), + } + + stream, err := s.Client.List(s.Context(), &pb.ListRequest{Options: listOpts}, client.WithAddress(s.Nodes...)) if err != nil && errors.Equal(err, errors.NotFound("", "")) { return nil, store.ErrNotFound } else if err != nil { @@ -96,11 +100,18 @@ func (s *serviceStore) Read(key string, opts ...store.ReadOption) ([]*store.Reco o(&options) } + readOpts := &pb.ReadOptions{ + Database: options.Database, + Table: options.Table, + Prefix: options.Prefix, + Suffix: options.Suffix, + Limit: uint64(options.Limit), + Offset: uint64(options.Offset), + } + rsp, err := s.Client.Read(s.Context(), &pb.ReadRequest{ - Key: key, - Options: &pb.ReadOptions{ - Prefix: options.Prefix, - }, + Key: key, + Options: readOpts, }, client.WithAddress(s.Nodes...)) if err != nil && errors.Equal(err, errors.NotFound("", "")) { return nil, store.ErrNotFound @@ -123,13 +134,23 @@ func (s *serviceStore) Read(key string, opts ...store.ReadOption) ([]*store.Reco // Write a record func (s *serviceStore) Write(record *store.Record, opts ...store.WriteOption) error { + var options store.WriteOptions + for _, o := range opts { + o(&options) + } + + writeOpts := &pb.WriteOptions{ + Database: options.Database, + Table: options.Table, + } + _, err := s.Client.Write(s.Context(), &pb.WriteRequest{ Record: &pb.Record{ Key: record.Key, Value: record.Value, Expiry: int64(record.Expiry.Seconds()), }, - }, client.WithAddress(s.Nodes...)) + Options: writeOpts}, client.WithAddress(s.Nodes...)) if err != nil && errors.Equal(err, errors.NotFound("", "")) { return store.ErrNotFound } @@ -139,8 +160,19 @@ func (s *serviceStore) Write(record *store.Record, opts ...store.WriteOption) er // Delete a record with key func (s *serviceStore) Delete(key string, opts ...store.DeleteOption) error { + var options store.DeleteOptions + for _, o := range opts { + o(&options) + } + + deleteOpts := &pb.DeleteOptions{ + Database: options.Database, + Table: options.Table, + } + _, err := s.Client.Delete(s.Context(), &pb.DeleteRequest{ - Key: key, + Key: key, + Options: deleteOpts, }, client.WithAddress(s.Nodes...)) if err != nil && errors.Equal(err, errors.NotFound("", "")) { return store.ErrNotFound From c76a5e608d55b575c9741b034bdb2382b527d143 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 30 Apr 2020 23:53:54 +0100 Subject: [PATCH 725/788] sql fixes --- store/cockroach/cockroach.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 144ce44d..397db67b 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -61,12 +61,12 @@ func (s *sqlStore) createDB(database, table string) { func (s *sqlStore) initDB(database, table string) error { // Create the namespace's database - _, err := s.db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s ;", database)) + _, err := s.db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s;", database)) if err != nil { return err } - _, err = s.db.Exec(fmt.Sprintf("SET DATABASE = %s ;", database)) + _, err = s.db.Exec(fmt.Sprintf("SET DATABASE = %s;", database)) if err != nil { return errors.Wrap(err, "Couldn't set database") } @@ -99,12 +99,12 @@ func (s *sqlStore) configure() error { database := s.options.Database if len(database) == 0 { - database = DefaultDatabase + s.options.Database = DefaultDatabase } table := s.options.Table if len(table) == 0 { - table = DefaultTable + s.options.Table = DefaultTable } // store.namespace must only contain letters, numbers and underscores @@ -423,7 +423,11 @@ func (s *sqlStore) String() string { // NewStore returns a new micro Store backed by sql func NewStore(opts ...store.Option) store.Store { - var options store.Options + options := store.Options{ + Database: DefaultDatabase, + Table: DefaultTable, + } + for _, o := range opts { o(&options) } From e8105d22adc63671adb666c2368745514599c48b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 1 May 2020 00:25:17 +0100 Subject: [PATCH 726/788] cruft --- store/service/service.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/store/service/service.go b/store/service/service.go index 45775eb1..9ac2e611 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -47,6 +47,13 @@ func (s *serviceStore) Init(opts ...store.Option) error { func (s *serviceStore) Context() context.Context { ctx := context.Background() md := make(metadata.Metadata) + if len(s.Database) > 0 { + md["Micro-Database"] = s.Database + } + + if len(s.Table) > 0 { + md["Micro-Table"] = s.Table + } return metadata.NewContext(ctx, md) } From 2a14feed93af777a95c8be541ec22111a18cf5ef Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 1 May 2020 14:59:50 +0100 Subject: [PATCH 727/788] force codec on call not on dial (#1599) --- client/grpc/grpc.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index e25f3dd5..1932f9ce 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -129,7 +129,6 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R var grr error grpcDialOptions := []grpc.DialOption{ - grpc.WithDefaultCallOptions(grpc.ForceCodec(cf)), grpc.WithTimeout(opts.DialTimeout), g.secure(address), grpc.WithDefaultCallOptions( @@ -154,7 +153,9 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R ch := make(chan error, 1) go func() { - grpcCallOptions := []grpc.CallOption{grpc.CallContentSubtype(cf.Name())} + grpcCallOptions := []grpc.CallOption{ + grpc.ForceCodec(cf), + grpc.CallContentSubtype(cf.Name())} if opts := g.getGrpcCallOptions(); opts != nil { grpcCallOptions = append(grpcCallOptions, opts...) } @@ -213,7 +214,6 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client wc := wrapCodec{cf} grpcDialOptions := []grpc.DialOption{ - grpc.WithDefaultCallOptions(grpc.ForceCodec(wc)), grpc.WithTimeout(opts.DialTimeout), g.secure(address), } @@ -233,7 +233,10 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client ServerStreams: true, } - grpcCallOptions := []grpc.CallOption{grpc.CallContentSubtype(cf.Name())} + grpcCallOptions := []grpc.CallOption{ + grpc.ForceCodec(wc), + grpc.CallContentSubtype(cf.Name()), + } if opts := g.getGrpcCallOptions(); opts != nil { grpcCallOptions = append(grpcCallOptions, opts...) } From 7a2dea6cc285068c51c7351c553ba13c4d3f4323 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 1 May 2020 15:22:44 +0100 Subject: [PATCH 728/788] Set database/table from init first --- store/service/service.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/store/service/service.go b/store/service/service.go index 9ac2e611..fbf04388 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -59,7 +59,11 @@ func (s *serviceStore) Context() context.Context { // Sync all the known records func (s *serviceStore) List(opts ...store.ListOption) ([]string, error) { - var options store.ListOptions + options := store.ListOptions{ + Database: s.Database, + Table: s.Table, + } + for _, o := range opts { o(&options) } @@ -102,7 +106,11 @@ func (s *serviceStore) List(opts ...store.ListOption) ([]string, error) { // Read a record with key func (s *serviceStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) { - var options store.ReadOptions + options := store.ReadOptions{ + Database: s.Database, + Table: s.Table, + } + for _, o := range opts { o(&options) } @@ -141,7 +149,11 @@ func (s *serviceStore) Read(key string, opts ...store.ReadOption) ([]*store.Reco // Write a record func (s *serviceStore) Write(record *store.Record, opts ...store.WriteOption) error { - var options store.WriteOptions + options := store.WriteOptions{ + Database: s.Database, + Table: s.Table, + } + for _, o := range opts { o(&options) } @@ -167,7 +179,11 @@ func (s *serviceStore) Write(record *store.Record, opts ...store.WriteOption) er // Delete a record with key func (s *serviceStore) Delete(key string, opts ...store.DeleteOption) error { - var options store.DeleteOptions + options := store.DeleteOptions{ + Database: s.Database, + Table: s.Table, + } + for _, o := range opts { o(&options) } From 08a2de1ef50a7cd0e59b92e250f4dda41987de8d Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 1 May 2020 15:31:55 +0100 Subject: [PATCH 729/788] Account for missing options database/table in cockroach store --- store/cockroach/cockroach.go | 63 +++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 397db67b..f55abbb4 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -23,6 +23,8 @@ var ( ) var ( + re = regexp.MustCompile("[^a-zA-Z0-9]+") + statements = map[string]string{ "list": "SELECT key, value, expiry FROM %s.%s;", "read": "SELECT key, value, expiry FROM %s.%s WHERE key = $1;", @@ -42,14 +44,33 @@ type sqlStore struct { databases map[string]bool } -func (s *sqlStore) createDB(database, table string) { +func (s *sqlStore) getDB(database, table string) (string, string) { if len(database) == 0 { - database = s.options.Database + if len(s.options.Database) > 0 { + database = s.options.Database + } else { + database = DefaultDatabase + } } + if len(table) == 0 { - table = s.options.Table + if len(s.options.Table) > 0 { + table = s.options.Table + } else { + database = DefaultTable + } } + // store.namespace must only contain letters, numbers and underscores + database = re.ReplaceAllString(database, "_") + table = re.ReplaceAllString(table, "_") + + return database, table +} + +func (s *sqlStore) createDB(database, table string) { + database, table = s.getDB(database, table) + s.Lock() _, ok := s.databases[database+":"+table] if !ok { @@ -97,28 +118,10 @@ func (s *sqlStore) configure() error { s.options.Nodes = []string{"postgresql://root@localhost:26257?sslmode=disable"} } - database := s.options.Database - if len(database) == 0 { - s.options.Database = DefaultDatabase - } - - table := s.options.Table - if len(table) == 0 { - s.options.Table = DefaultTable - } - - // store.namespace must only contain letters, numbers and underscores - reg, err := regexp.Compile("[^a-zA-Z0-9]+") - if err != nil { - return errors.New("error compiling regex for namespace") - } - database = reg.ReplaceAllString(database, "_") - table = reg.ReplaceAllString(table, "_") - source := s.options.Nodes[0] // check if it is a standard connection string eg: host=%s port=%d user=%s password=%s dbname=%s sslmode=disable // if err is nil which means it would be a URL like postgre://xxxx?yy=zz - _, err = url.Parse(source) + _, err := url.Parse(source) if err != nil { if !strings.Contains(source, " ") { source = fmt.Sprintf("host=%s", source) @@ -142,8 +145,11 @@ func (s *sqlStore) configure() error { // save the values s.db = db + // get DB + database, table := s.getDB(s.options.Database, s.options.Table) + // initialise the database - return s.initDB(s.options.Database, s.options.Table) + return s.initDB(database, table) } func (s *sqlStore) prepare(database, table, query string) (*sql.Stmt, error) { @@ -151,12 +157,9 @@ func (s *sqlStore) prepare(database, table, query string) (*sql.Stmt, error) { if !ok { return nil, errors.New("unsupported statement") } - if len(database) == 0 { - database = s.options.Database - } - if len(table) == 0 { - table = s.options.Table - } + + // get DB + database, table = s.getDB(database, table) q := fmt.Sprintf(st, database, table) stmt, err := s.db.Prepare(q) @@ -425,7 +428,7 @@ func (s *sqlStore) String() string { func NewStore(opts ...store.Option) store.Store { options := store.Options{ Database: DefaultDatabase, - Table: DefaultTable, + Table: DefaultTable, } for _, o := range opts { From b3915b602067ea07375902b98c0a4b31b7122ea7 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 1 May 2020 18:05:09 +0100 Subject: [PATCH 730/788] Add store to options (#1600) --- config/cmd/options.go | 6 ++++++ options.go | 10 ++++++++++ service.go | 1 + 3 files changed, 17 insertions(+) diff --git a/config/cmd/options.go b/config/cmd/options.go index d105ee2e..7ec9e2b4 100644 --- a/config/cmd/options.go +++ b/config/cmd/options.go @@ -118,6 +118,12 @@ func Server(s *server.Server) Option { } } +func Store(s *store.Store) Option { + return func(o *Options) { + o.Store = s + } +} + func Tracer(t *trace.Tracer) Option { return func(o *Options) { o.Tracer = t diff --git a/options.go b/options.go index 1ef8b955..d216b53e 100644 --- a/options.go +++ b/options.go @@ -15,6 +15,7 @@ import ( "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/server" + "github.com/micro/go-micro/v2/store" "github.com/micro/go-micro/v2/transport" ) @@ -26,6 +27,7 @@ type Options struct { Config config.Config Client client.Client Server server.Server + Store store.Store Registry registry.Registry Transport transport.Transport Profile profile.Profile @@ -51,6 +53,7 @@ func newOptions(opts ...Option) Options { Config: config.DefaultConfig, Client: client.DefaultClient, Server: server.DefaultServer, + Store: store.DefaultStore, Registry: registry.DefaultRegistry, Transport: transport.DefaultTransport, Context: context.Background(), @@ -118,6 +121,13 @@ func Server(s server.Server) Option { } } +// Store sets the store to use +func Store(s store.Store) Option { + return func(o *Options) { + o.Store = s + } +} + // Registry sets the registry for the service // and the underlying components func Registry(r registry.Registry) Option { diff --git a/service.go b/service.go index f7941e30..e8115d29 100644 --- a/service.go +++ b/service.go @@ -102,6 +102,7 @@ func (s *service) Init(opts ...Option) { cmd.Client(&s.opts.Client), cmd.Config(&s.opts.Config), cmd.Server(&s.opts.Server), + cmd.Store(&s.opts.Store), cmd.Profile(&s.opts.Profile), ); err != nil { logger.Fatal(err) From 38cdb9cc2fb5f0219d03d8a221142d5c08d5e9e5 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 1 May 2020 18:24:35 +0100 Subject: [PATCH 731/788] Set table name in store --- service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service.go b/service.go index e8115d29..c81127d2 100644 --- a/service.go +++ b/service.go @@ -110,7 +110,7 @@ func (s *service) Init(opts ...Option) { // Explicitly set the table name to the service name name := s.opts.Cmd.App().Name - store.DefaultStore.Init(store.Table(name)) + s.opts.Store.Init(store.Table(name)) // TODO: replace Cmd.Init with config.Load // Right now we're just going to load a token From 90dd1f63c853df47949eea242b9668f728053124 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 4 May 2020 15:50:53 +0300 Subject: [PATCH 732/788] api/handler/rpc: fix encoding of inner message (#1601) * api/handler/rpc: fix encoding of inner message Signed-off-by: Vasiliy Tolstov --- api/handler/rpc/rpc.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/api/handler/rpc/rpc.go b/api/handler/rpc/rpc.go index 542a9dd4..49fc4301 100644 --- a/api/handler/rpc/rpc.go +++ b/api/handler/rpc/rpc.go @@ -397,13 +397,29 @@ func requestPayload(r *http.Request) ([]byte, error) { return out, nil } } + var jsonbody map[string]interface{} + if json.Valid(bodybuf) { + if err = json.Unmarshal(bodybuf, &jsonbody); err != nil { + return nil, err + } + } dstmap := make(map[string]interface{}) ps := strings.Split(bodydst, ".") if len(ps) == 1 { - dstmap[ps[0]] = bodybuf + if jsonbody != nil { + dstmap[ps[0]] = jsonbody + } else { + // old unexpected behaviour + dstmap[ps[0]] = bodybuf + } } else { em := make(map[string]interface{}) - em[ps[len(ps)-1]] = bodybuf + if jsonbody != nil { + em[ps[len(ps)-1]] = jsonbody + } else { + // old unexpected behaviour + em[ps[len(ps)-1]] = bodybuf + } for i := len(ps) - 2; i > 0; i-- { nm := make(map[string]interface{}) nm[ps[i]] = em From 5387f73b5d8e7e0eba06d306e43ee852c5847fb9 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Wed, 6 May 2020 10:58:14 +0100 Subject: [PATCH 733/788] Handle cockroach createDB error (#1603) --- store/cockroach/cockroach.go | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index f55abbb4..13b12d9d 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -68,16 +68,22 @@ func (s *sqlStore) getDB(database, table string) (string, string) { return database, table } -func (s *sqlStore) createDB(database, table string) { +func (s *sqlStore) createDB(database, table string) error { database, table = s.getDB(database, table) s.Lock() - _, ok := s.databases[database+":"+table] - if !ok { - s.initDB(database, table) - s.databases[database+":"+table] = true + defer s.Unlock() + + if _, ok := s.databases[database+":"+table]; ok { + return nil } - s.Unlock() + + if err := s.initDB(database, table); err != nil { + return err + } + + s.databases[database+":"+table] = true + return nil } func (s *sqlStore) initDB(database, table string) error { @@ -192,7 +198,9 @@ func (s *sqlStore) List(opts ...store.ListOption) ([]string, error) { } // create the db if not exists - s.createDB(options.Database, options.Table) + if err := s.createDB(options.Database, options.Table); err != nil { + return nil, err + } st, err := s.prepare(options.Database, options.Table, "list") if err != nil { @@ -249,7 +257,9 @@ func (s *sqlStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, } // create the db if not exists - s.createDB(options.Database, options.Table) + if err := s.createDB(options.Database, options.Table); err != nil { + return nil, err + } if options.Prefix || options.Suffix { return s.read(key, options) @@ -366,7 +376,9 @@ func (s *sqlStore) Write(r *store.Record, opts ...store.WriteOption) error { } // create the db if not exists - s.createDB(options.Database, options.Table) + if err := s.createDB(options.Database, options.Table); err != nil { + return err + } st, err := s.prepare(options.Database, options.Table, "write") if err != nil { @@ -395,7 +407,9 @@ func (s *sqlStore) Delete(key string, opts ...store.DeleteOption) error { } // create the db if not exists - s.createDB(options.Database, options.Table) + if err := s.createDB(options.Database, options.Table); err != nil { + return err + } st, err := s.prepare(options.Database, options.Table, "delete") if err != nil { From 30dc29e17fb7ad16ecf204c506312e9b01f40f08 Mon Sep 17 00:00:00 2001 From: fztcjjl Date: Thu, 7 May 2020 17:45:48 +0800 Subject: [PATCH 734/788] fix ring buffer (#1606) --- util/ring/buffer.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/util/ring/buffer.go b/util/ring/buffer.go index e49f1312..45a7690a 100644 --- a/util/ring/buffer.go +++ b/util/ring/buffer.go @@ -67,17 +67,12 @@ func (b *Buffer) Get(n int) []*Entry { defer b.RUnlock() // reset any invalid values - if n > b.size || n < 0 { - n = b.size + if n > len(b.vals) || n < 0 { + n = len(b.vals) } // create a delta - delta := b.size - n - - // if all the values are less than delta - if len(b.vals) < delta { - return b.vals - } + delta := len(b.vals) - n // return the delta set return b.vals[delta:] From fea93a5b7a2a7470f6b15a9c9d1ec21e5a67a5e9 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 7 May 2020 11:35:56 +0100 Subject: [PATCH 735/788] Log k8s Requests --- util/kubernetes/api/request.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/kubernetes/api/request.go b/util/kubernetes/api/request.go index 92bcbed6..75456c90 100644 --- a/util/kubernetes/api/request.go +++ b/util/kubernetes/api/request.go @@ -9,6 +9,8 @@ import ( "io" "net/http" "net/url" + + "github.com/micro/go-micro/v2/logger" ) // Request is used to construct a http request for the k8s API. @@ -217,6 +219,7 @@ func (r *Request) Do() *Response { } } + logger.Debugf("[Kubernetes] %v %v", req.Method, req.URL.String()) res, err := r.client.Do(req) if err != nil { return &Response{ From d61df6363b34b9535baa496ad430fa598a889650 Mon Sep 17 00:00:00 2001 From: gggwvg Date: Fri, 8 May 2020 17:31:03 +0800 Subject: [PATCH 736/788] web: fix advertise address (#1608) * web: fix advertise address * web: fix test Signed-off-by: Vasiliy Tolstov Co-authored-by: Asim Aslam Co-authored-by: Vasiliy Tolstov --- web/service.go | 2 +- web/service_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/web/service.go b/web/service.go index d8f01179..4ca54f88 100644 --- a/web/service.go +++ b/web/service.go @@ -63,7 +63,7 @@ func (s *service) genSrv() *registry.Service { // if it exists then use it, otherwise // use the address if len(s.opts.Advertise) > 0 { - host, port, err = net.SplitHostPort(s.opts.Address) + host, port, err = net.SplitHostPort(s.opts.Advertise) if err != nil { logger.Fatal(err) } diff --git a/web/service_test.go b/web/service_test.go index 0d033038..ee7eba32 100644 --- a/web/service_test.go +++ b/web/service_test.go @@ -164,7 +164,7 @@ func TestOptions(t *testing.T) { id = "service-id" version = "service-version" address = "service-addr:8080" - advertise = "service-adv" + advertise = "service-adv:8080" reg = memory.NewRegistry() registerTTL = 123 * time.Second registerInterval = 456 * time.Second From 5a8f19589bcb0505972bbc1b002e1abe57f24f4a Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Mon, 11 May 2020 11:34:22 +0100 Subject: [PATCH 737/788] Auth account.HasRole --- auth/auth.go | 15 +++++++++++++++ auth/auth_test.go | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 auth/auth_test.go diff --git a/auth/auth.go b/auth/auth.go index fbca70a6..d7987a07 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -72,6 +72,21 @@ type Account struct { Secret string `json:"secret"` } +// HasRole returns a boolean indicating if the account has the given role +func (a *Account) HasRole(role string) bool { + if a.Roles == nil { + return false + } + + for _, r := range a.Roles { + if r == role { + return true + } + } + + return false +} + // Token can be short or long lived type Token struct { // The token to be used for accessing resources diff --git a/auth/auth_test.go b/auth/auth_test.go new file mode 100644 index 00000000..5283e81e --- /dev/null +++ b/auth/auth_test.go @@ -0,0 +1,17 @@ +package auth + +import "testing" + +func TestHasRole(t *testing.T) { + if new(Account).HasRole("foo") { + t.Errorf("Expected the blank account to not have a role") + } + + acc := Account{Roles: []string{"foo"}} + if !acc.HasRole("foo") { + t.Errorf("Expected the account to have the foo role") + } + if acc.HasRole("bar") { + t.Errorf("Expected the account to not have the bar role") + } +} From 506006f0fa45a05b76e550c7d617cc969908e07a Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Mon, 11 May 2020 11:47:59 +0100 Subject: [PATCH 738/788] Auth Options --- runtime/service/proto/runtime.pb.go | 341 +++++++++++++++++---- runtime/service/proto/runtime.proto | 32 +- runtime/service/service.go | 27 +- server/grpc/proto/test.pb.go | 34 +-- server/grpc/proto/test.pb.micro.go | 4 +- store/service/proto/store.pb.go | 409 ++++++++++++++++++++++---- store/service/proto/store.pb.micro.go | 2 +- 7 files changed, 699 insertions(+), 150 deletions(-) diff --git a/runtime/service/proto/runtime.pb.go b/runtime/service/proto/runtime.pb.go index 1c401b4a..de0f4e63 100644 --- a/runtime/service/proto/runtime.pb.go +++ b/runtime/service/proto/runtime.pb.go @@ -166,7 +166,9 @@ type CreateOptions struct { // create type of service Type string `protobuf:"bytes,5,opt,name=type,proto3" json:"type,omitempty"` // image to use - Image string `protobuf:"bytes,6,opt,name=image,proto3" json:"image,omitempty"` + Image string `protobuf:"bytes,6,opt,name=image,proto3" json:"image,omitempty"` + // namespace to use + Namespace string `protobuf:"bytes,7,opt,name=namespace,proto3" json:"namespace,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -239,6 +241,13 @@ func (m *CreateOptions) GetImage() string { return "" } +func (m *CreateOptions) GetNamespace() string { + if m != nil { + return m.Namespace + } + return "" +} + type CreateRequest struct { Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` Options *CreateOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` @@ -323,7 +332,9 @@ type ReadOptions struct { // version of the service Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // type of service - Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"` + Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"` + // namespace of service + Namespace string `protobuf:"bytes,4,opt,name=namespace,proto3" json:"namespace,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -375,6 +386,13 @@ func (m *ReadOptions) GetType() string { return "" } +func (m *ReadOptions) GetNamespace() string { + if m != nil { + return m.Namespace + } + return "" +} + type ReadRequest struct { Options *ReadOptions `protobuf:"bytes,1,opt,name=options,proto3" json:"options,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -453,18 +471,59 @@ func (m *ReadResponse) GetServices() []*Service { return nil } -type DeleteRequest struct { - Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` +type DeleteOptions struct { + // namespace of the service + Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } +func (m *DeleteOptions) Reset() { *m = DeleteOptions{} } +func (m *DeleteOptions) String() string { return proto.CompactTextString(m) } +func (*DeleteOptions) ProtoMessage() {} +func (*DeleteOptions) Descriptor() ([]byte, []int) { + return fileDescriptor_2434d8152598889b, []int{8} +} + +func (m *DeleteOptions) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteOptions.Unmarshal(m, b) +} +func (m *DeleteOptions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteOptions.Marshal(b, m, deterministic) +} +func (m *DeleteOptions) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteOptions.Merge(m, src) +} +func (m *DeleteOptions) XXX_Size() int { + return xxx_messageInfo_DeleteOptions.Size(m) +} +func (m *DeleteOptions) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteOptions.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteOptions proto.InternalMessageInfo + +func (m *DeleteOptions) GetNamespace() string { + if m != nil { + return m.Namespace + } + return "" +} + +type DeleteRequest struct { + Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` + Options *DeleteOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{8} + return fileDescriptor_2434d8152598889b, []int{9} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -492,6 +551,13 @@ func (m *DeleteRequest) GetService() *Service { return nil } +func (m *DeleteRequest) GetOptions() *DeleteOptions { + if m != nil { + return m.Options + } + return nil +} + type DeleteResponse struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -502,7 +568,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{9} + return fileDescriptor_2434d8152598889b, []int{10} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -523,18 +589,59 @@ func (m *DeleteResponse) XXX_DiscardUnknown() { var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo -type UpdateRequest struct { - Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` +type UpdateOptions struct { + // namespace of the service + Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } +func (m *UpdateOptions) Reset() { *m = UpdateOptions{} } +func (m *UpdateOptions) String() string { return proto.CompactTextString(m) } +func (*UpdateOptions) ProtoMessage() {} +func (*UpdateOptions) Descriptor() ([]byte, []int) { + return fileDescriptor_2434d8152598889b, []int{11} +} + +func (m *UpdateOptions) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateOptions.Unmarshal(m, b) +} +func (m *UpdateOptions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateOptions.Marshal(b, m, deterministic) +} +func (m *UpdateOptions) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateOptions.Merge(m, src) +} +func (m *UpdateOptions) XXX_Size() int { + return xxx_messageInfo_UpdateOptions.Size(m) +} +func (m *UpdateOptions) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateOptions.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateOptions proto.InternalMessageInfo + +func (m *UpdateOptions) GetNamespace() string { + if m != nil { + return m.Namespace + } + return "" +} + +type UpdateRequest struct { + Service *Service `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` + Options *UpdateOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} func (*UpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{10} + return fileDescriptor_2434d8152598889b, []int{12} } func (m *UpdateRequest) XXX_Unmarshal(b []byte) error { @@ -562,6 +669,13 @@ func (m *UpdateRequest) GetService() *Service { return nil } +func (m *UpdateRequest) GetOptions() *UpdateOptions { + if m != nil { + return m.Options + } + return nil +} + type UpdateResponse struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -572,7 +686,7 @@ func (m *UpdateResponse) Reset() { *m = UpdateResponse{} } func (m *UpdateResponse) String() string { return proto.CompactTextString(m) } func (*UpdateResponse) ProtoMessage() {} func (*UpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{11} + return fileDescriptor_2434d8152598889b, []int{13} } func (m *UpdateResponse) XXX_Unmarshal(b []byte) error { @@ -593,17 +707,58 @@ func (m *UpdateResponse) XXX_DiscardUnknown() { var xxx_messageInfo_UpdateResponse proto.InternalMessageInfo -type ListRequest struct { +type ListOptions struct { + // namespace to list from + Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } +func (m *ListOptions) Reset() { *m = ListOptions{} } +func (m *ListOptions) String() string { return proto.CompactTextString(m) } +func (*ListOptions) ProtoMessage() {} +func (*ListOptions) Descriptor() ([]byte, []int) { + return fileDescriptor_2434d8152598889b, []int{14} +} + +func (m *ListOptions) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListOptions.Unmarshal(m, b) +} +func (m *ListOptions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListOptions.Marshal(b, m, deterministic) +} +func (m *ListOptions) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListOptions.Merge(m, src) +} +func (m *ListOptions) XXX_Size() int { + return xxx_messageInfo_ListOptions.Size(m) +} +func (m *ListOptions) XXX_DiscardUnknown() { + xxx_messageInfo_ListOptions.DiscardUnknown(m) +} + +var xxx_messageInfo_ListOptions proto.InternalMessageInfo + +func (m *ListOptions) GetNamespace() string { + if m != nil { + return m.Namespace + } + return "" +} + +type ListRequest struct { + Options *ListOptions `protobuf:"bytes,1,opt,name=options,proto3" json:"options,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{12} + return fileDescriptor_2434d8152598889b, []int{15} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -624,6 +779,13 @@ func (m *ListRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ListRequest proto.InternalMessageInfo +func (m *ListRequest) GetOptions() *ListOptions { + if m != nil { + return m.Options + } + return nil +} + type ListResponse struct { Services []*Service `protobuf:"bytes,1,rep,name=services,proto3" json:"services,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -635,7 +797,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{13} + return fileDescriptor_2434d8152598889b, []int{16} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -663,6 +825,46 @@ func (m *ListResponse) GetServices() []*Service { return nil } +type LogsOptions struct { + // namespace of the service + Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *LogsOptions) Reset() { *m = LogsOptions{} } +func (m *LogsOptions) String() string { return proto.CompactTextString(m) } +func (*LogsOptions) ProtoMessage() {} +func (*LogsOptions) Descriptor() ([]byte, []int) { + return fileDescriptor_2434d8152598889b, []int{17} +} + +func (m *LogsOptions) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_LogsOptions.Unmarshal(m, b) +} +func (m *LogsOptions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_LogsOptions.Marshal(b, m, deterministic) +} +func (m *LogsOptions) XXX_Merge(src proto.Message) { + xxx_messageInfo_LogsOptions.Merge(m, src) +} +func (m *LogsOptions) XXX_Size() int { + return xxx_messageInfo_LogsOptions.Size(m) +} +func (m *LogsOptions) XXX_DiscardUnknown() { + xxx_messageInfo_LogsOptions.DiscardUnknown(m) +} + +var xxx_messageInfo_LogsOptions proto.InternalMessageInfo + +func (m *LogsOptions) GetNamespace() string { + if m != nil { + return m.Namespace + } + return "" +} + type LogsRequest struct { // service to request logs for Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` @@ -673,17 +875,19 @@ type LogsRequest struct { // relative time in seconds // before the current time // from which to show logs - Since int64 `protobuf:"varint,4,opt,name=since,proto3" json:"since,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Since int64 `protobuf:"varint,4,opt,name=since,proto3" json:"since,omitempty"` + // options to use + Options *LogsOptions `protobuf:"bytes,5,opt,name=options,proto3" json:"options,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *LogsRequest) Reset() { *m = LogsRequest{} } func (m *LogsRequest) String() string { return proto.CompactTextString(m) } func (*LogsRequest) ProtoMessage() {} func (*LogsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{14} + return fileDescriptor_2434d8152598889b, []int{18} } func (m *LogsRequest) XXX_Unmarshal(b []byte) error { @@ -732,6 +936,13 @@ func (m *LogsRequest) GetSince() int64 { return 0 } +func (m *LogsRequest) GetOptions() *LogsOptions { + if m != nil { + return m.Options + } + return nil +} + type LogRecord struct { // timestamp of log record Timestamp int64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` @@ -748,7 +959,7 @@ func (m *LogRecord) Reset() { *m = LogRecord{} } func (m *LogRecord) String() string { return proto.CompactTextString(m) } func (*LogRecord) ProtoMessage() {} func (*LogRecord) Descriptor() ([]byte, []int) { - return fileDescriptor_2434d8152598889b, []int{15} + return fileDescriptor_2434d8152598889b, []int{19} } func (m *LogRecord) XXX_Unmarshal(b []byte) error { @@ -800,12 +1011,16 @@ func init() { proto.RegisterType((*ReadOptions)(nil), "go.micro.runtime.ReadOptions") proto.RegisterType((*ReadRequest)(nil), "go.micro.runtime.ReadRequest") proto.RegisterType((*ReadResponse)(nil), "go.micro.runtime.ReadResponse") + proto.RegisterType((*DeleteOptions)(nil), "go.micro.runtime.DeleteOptions") proto.RegisterType((*DeleteRequest)(nil), "go.micro.runtime.DeleteRequest") proto.RegisterType((*DeleteResponse)(nil), "go.micro.runtime.DeleteResponse") + proto.RegisterType((*UpdateOptions)(nil), "go.micro.runtime.UpdateOptions") proto.RegisterType((*UpdateRequest)(nil), "go.micro.runtime.UpdateRequest") proto.RegisterType((*UpdateResponse)(nil), "go.micro.runtime.UpdateResponse") + proto.RegisterType((*ListOptions)(nil), "go.micro.runtime.ListOptions") proto.RegisterType((*ListRequest)(nil), "go.micro.runtime.ListRequest") proto.RegisterType((*ListResponse)(nil), "go.micro.runtime.ListResponse") + proto.RegisterType((*LogsOptions)(nil), "go.micro.runtime.LogsOptions") proto.RegisterType((*LogsRequest)(nil), "go.micro.runtime.LogsRequest") proto.RegisterType((*LogRecord)(nil), "go.micro.runtime.LogRecord") proto.RegisterMapType((map[string]string)(nil), "go.micro.runtime.LogRecord.MetadataEntry") @@ -816,48 +1031,52 @@ func init() { } var fileDescriptor_2434d8152598889b = []byte{ - // 645 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xc9, 0x6e, 0xdb, 0x30, - 0x10, 0x8d, 0x2c, 0x2f, 0xc9, 0xa8, 0x2e, 0x02, 0x22, 0x28, 0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 0x40, 0xbd, - 0xec, 0xfa, 0x5c, 0x02, 0x2d, 0x61, 0xa8, 0x5b, 0xb3, 0x8d, 0x57, 0xa3, 0xf5, 0xdb, 0x78, 0xed, - 0x74, 0xb5, 0x82, 0xd3, 0x1d, 0xd9, 0x06, 0xd7, 0xe8, 0xf8, 0x36, 0xb8, 0x9d, 0x66, 0x3e, 0x22, - 0x37, 0xd0, 0x97, 0x8d, 0xd7, 0x26, 0xb3, 0xd6, 0x90, 0xe7, 0xcf, 0x1e, 0x28, 0xba, 0x77, 0xf4, - 0xce, 0xfa, 0x31, 0x54, 0xff, 0xcb, 0xab, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x20, 0x0e, 0x37, - 0xf1, 0x56, 0x07, 0x00, 0x00, + // 711 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4d, 0x6f, 0xd3, 0x4c, + 0x10, 0xae, 0x63, 0x27, 0x69, 0x27, 0x6f, 0x5e, 0x55, 0xab, 0x0a, 0x99, 0xf2, 0x15, 0x99, 0x03, + 0x45, 0xa8, 0x2e, 0x4a, 0x85, 0xf8, 0x3a, 0x96, 0x94, 0x4b, 0x2b, 0x24, 0x23, 0x7e, 0xc0, 0xe2, + 0x8c, 0x22, 0x8b, 0xda, 0x6b, 0xbc, 0xeb, 0x48, 0x3d, 0x71, 0xe4, 0x8f, 0x70, 0xe7, 0x67, 0x70, + 0xe6, 0x1f, 0xa1, 0xfd, 0x8a, 0x3f, 0x1a, 0x47, 0xad, 0xaa, 0xde, 0x76, 0xc6, 0xb3, 0xb3, 0xcf, + 0xf3, 0xcc, 0xec, 0xac, 0xe1, 0x69, 0x51, 0x66, 0x22, 0x49, 0xf1, 0x88, 0x63, 0xb1, 0x4c, 0x62, + 0x3c, 0xca, 0x0b, 0x26, 0xd8, 0x91, 0xf1, 0x86, 0xca, 0x22, 0xbb, 0x0b, 0x16, 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e7, 0x14, + 0xd8, 0x80, 0xab, 0x35, 0x0c, 0x54, 0x3a, 0x7d, 0xbd, 0x48, 0xe7, 0x95, 0xdc, 0x90, 0xae, 0x75, + 0x33, 0xb7, 0xc8, 0x29, 0x78, 0xb2, 0x47, 0x48, 0x47, 0xef, 0xd8, 0x54, 0x0f, 0x36, 0x14, 0x3d, + 0xd8, 0x7a, 0xe9, 0x7c, 0x1d, 0xa8, 0x9f, 0xa1, 0xe3, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x8e, + 0x6c, 0x03, 0x59, 0x33, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/runtime/service/proto/runtime.proto b/runtime/service/proto/runtime.proto index 6c7033c9..b4464173 100644 --- a/runtime/service/proto/runtime.proto +++ b/runtime/service/proto/runtime.proto @@ -41,6 +41,8 @@ message CreateOptions { string type = 5; // image to use string image = 6; + // namespace to use + string namespace = 7; } message CreateRequest { @@ -57,6 +59,8 @@ message ReadOptions { string version = 2; // type of service string type = 3; + // namespace of service + string namespace = 4; } message ReadRequest { @@ -67,24 +71,48 @@ message ReadResponse { repeated Service services = 1; } +message DeleteOptions { + // namespace of the service + string namespace = 1; +} + message DeleteRequest { Service service = 1; + DeleteOptions options = 2; } message DeleteResponse {} +message UpdateOptions { + // namespace of the service + string namespace = 1; +} + message UpdateRequest { Service service = 1; + UpdateOptions options = 2; } message UpdateResponse {} -message ListRequest {} +message ListOptions { + // namespace to list from + string namespace = 1; +} + +message ListRequest { + ListOptions options = 1; +} message ListResponse { repeated Service services = 1; } +message LogsOptions { + // namespace of the service + string namespace = 1; +} + message LogsRequest{ // service to request logs for string service = 1; @@ -96,6 +124,8 @@ message LogsRequest{ // before the current time // from which to show logs int64 since = 4; + // options to use + LogsOptions options = 5; } message LogRecord { diff --git a/runtime/service/service.go b/runtime/service/service.go index f2c5c95a..e6bc03fc 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -51,11 +51,12 @@ func (s *svc) Create(svc *runtime.Service, opts ...runtime.CreateOption) error { Metadata: svc.Metadata, }, Options: &pb.CreateOptions{ - Command: options.Command, - Args: options.Args, - Env: options.Env, - Type: options.Type, - Image: options.Image, + Command: options.Command, + Args: options.Args, + Env: options.Env, + Type: options.Type, + Image: options.Image, + Namespace: options.Namespace, }, } @@ -80,6 +81,9 @@ func (s *svc) Logs(service *runtime.Service, opts ...runtime.LogsOption) (runtim Service: service.Name, Stream: options.Stream, Count: options.Count, + Options: &pb.LogsOptions{ + Namespace: options.Namespace, + }, }) if err != nil { return nil, err @@ -169,9 +173,10 @@ func (s *svc) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error) { // runtime service create request req := &pb.ReadRequest{ Options: &pb.ReadOptions{ - Service: options.Service, - Version: options.Version, - Type: options.Type, + Service: options.Service, + Version: options.Version, + Type: options.Type, + Namespace: options.Namespace, }, } @@ -212,6 +217,9 @@ func (s *svc) Update(svc *runtime.Service, opts ...runtime.UpdateOption) error { Source: svc.Source, Metadata: svc.Metadata, }, + Options: &pb.UpdateOptions{ + Namespace: options.Namespace, + }, } if _, err := s.runtime.Update(options.Context, req); err != nil { @@ -239,6 +247,9 @@ func (s *svc) Delete(svc *runtime.Service, opts ...runtime.DeleteOption) error { Source: svc.Source, Metadata: svc.Metadata, }, + Options: &pb.DeleteOptions{ + Namespace: options.Namespace, + }, } if _, err := s.runtime.Delete(options.Context, req); err != nil { diff --git a/server/grpc/proto/test.pb.go b/server/grpc/proto/test.pb.go index 43a9f0a0..125ae691 100644 --- a/server/grpc/proto/test.pb.go +++ b/server/grpc/proto/test.pb.go @@ -120,23 +120,23 @@ func init() { proto.RegisterFile("server/grpc/proto/test.proto", fileDescriptor_ var fileDescriptor_bb9c685b7640cf1e = []byte{ // 261 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0xd0, 0xcf, 0x4a, 0x03, 0x31, - 0x10, 0x06, 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 0xc7, 0xc6, 0xe2, 0x76, 0x65, 0x1a, 0x95, 0x13, - 0x56, 0xbc, 0xfc, 0x67, 0x4c, 0x63, 0x11, 0x16, 0x67, 0xc1, 0x79, 0x22, 0x87, 0x1b, 0xe7, 0x41, - 0xf5, 0x5c, 0x8a, 0xe5, 0x76, 0xee, 0x22, 0x72, 0x53, 0x36, 0xd9, 0xa1, 0x89, 0xa1, 0x0c, 0x8b, - 0x79, 0x32, 0x7b, 0xdd, 0x8f, 0xff, 0x77, 0xf3, 0x17, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x25, 0x7a, - 0x7d, 0x7d, 0x01, 0x00, 0x00, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x29, 0x4e, 0x2d, 0x2a, + 0x4b, 0x2d, 0xd2, 0x4f, 0x2f, 0x2a, 0x48, 0xd6, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x2f, 0x49, + 0x2d, 0x2e, 0xd1, 0x03, 0x33, 0xa5, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b, + 0x32, 0xf5, 0x13, 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0x21, 0xb2, 0x4a, + 0x86, 0x5c, 0xec, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0x42, 0x5c, 0x2c, 0xa5, 0xa5, + 0x99, 0x29, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x60, 0x36, 0x48, 0x2c, 0x2f, 0x31, 0x37, + 0x55, 0x82, 0x09, 0x22, 0x06, 0x62, 0x2b, 0xc9, 0x70, 0x71, 0x04, 0xa5, 0x16, 0x17, 0xe4, 0xe7, + 0x15, 0xa7, 0x0a, 0x09, 0x70, 0x31, 0xe7, 0x16, 0xa7, 0x43, 0xb5, 0x80, 0x98, 0x46, 0xcf, 0x18, + 0xb9, 0x58, 0x42, 0x40, 0xc6, 0x39, 0x70, 0xb1, 0x38, 0x27, 0xe6, 0xe4, 0x08, 0x71, 0xe8, 0x41, + 0x2d, 0x90, 0xe2, 0xd4, 0x83, 0xe9, 0x53, 0x52, 0x6e, 0xba, 0xfc, 0x64, 0x32, 0x93, 0xac, 0x92, + 0x04, 0xd8, 0x59, 0x65, 0x06, 0x60, 0x07, 0xeb, 0x27, 0x27, 0xe6, 0xe4, 0xe8, 0x57, 0x83, 0x2c, + 0xae, 0xb5, 0x62, 0xd4, 0x12, 0x72, 0xe3, 0xe2, 0x00, 0x99, 0x10, 0x90, 0x5c, 0x94, 0x8a, 0xdd, + 0x14, 0x55, 0xb0, 0x29, 0xf2, 0x4a, 0x52, 0x71, 0x98, 0xc6, 0x14, 0x24, 0x17, 0xa5, 0xea, 0xdb, + 0xab, 0x80, 0xcc, 0x09, 0xe1, 0xe2, 0x87, 0x99, 0xe3, 0x99, 0x57, 0x96, 0x98, 0x93, 0x99, 0x82, + 0xdd, 0x38, 0x1d, 0xb0, 0x71, 0x6a, 0x4a, 0x8a, 0xb8, 0x8c, 0xcb, 0x84, 0xe8, 0xd6, 0xb7, 0xb7, + 0x62, 0xd4, 0x4a, 0x62, 0x03, 0x07, 0xa0, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xf6, 0x32, 0x18, + 0x0f, 0x7e, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/server/grpc/proto/test.pb.micro.go b/server/grpc/proto/test.pb.micro.go index b80c670c..8ca37bfd 100644 --- a/server/grpc/proto/test.pb.micro.go +++ b/server/grpc/proto/test.pb.micro.go @@ -54,7 +54,7 @@ func NewTestEndpoints() []*api.Endpoint { }, &api.Endpoint{ Name: "Test.CallPcreInvalid", - Path: []string{"/api/v0/test/call/pcre/invalid/?"}, + Path: []string{"^/api/v0/test/call/pcre/invalid/?"}, Method: []string{"POST"}, Body: "*", Handler: "rpc", @@ -146,7 +146,7 @@ func RegisterTestHandler(s server.Server, hdlr TestHandler, opts ...server.Handl })) opts = append(opts, api.WithEndpoint(&api.Endpoint{ Name: "Test.CallPcreInvalid", - Path: []string{"/api/v0/test/call/pcre/invalid/?"}, + Path: []string{"^/api/v0/test/call/pcre/invalid/?"}, Method: []string{"POST"}, Body: "*", Handler: "rpc", diff --git a/store/service/proto/store.pb.go b/store/service/proto/store.pb.go index 71af1132..60eddeec 100644 --- a/store/service/proto/store.pb.go +++ b/store/service/proto/store.pb.go @@ -1,11 +1,15 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/micro/go-micro/store/service/proto/store.proto +// source: store/service/proto/store.proto package go_micro_store import ( + context "context" fmt "fmt" proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" math "math" ) @@ -36,7 +40,7 @@ func (m *Record) Reset() { *m = Record{} } func (m *Record) String() string { return proto.CompactTextString(m) } func (*Record) ProtoMessage() {} func (*Record) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{0} + return fileDescriptor_1ba364858f5c3cdb, []int{0} } func (m *Record) XXX_Unmarshal(b []byte) error { @@ -94,7 +98,7 @@ func (m *ReadOptions) Reset() { *m = ReadOptions{} } func (m *ReadOptions) String() string { return proto.CompactTextString(m) } func (*ReadOptions) ProtoMessage() {} func (*ReadOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{1} + return fileDescriptor_1ba364858f5c3cdb, []int{1} } func (m *ReadOptions) XXX_Unmarshal(b []byte) error { @@ -169,7 +173,7 @@ func (m *ReadRequest) Reset() { *m = ReadRequest{} } func (m *ReadRequest) String() string { return proto.CompactTextString(m) } func (*ReadRequest) ProtoMessage() {} func (*ReadRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{2} + return fileDescriptor_1ba364858f5c3cdb, []int{2} } func (m *ReadRequest) XXX_Unmarshal(b []byte) error { @@ -215,7 +219,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} } func (m *ReadResponse) String() string { return proto.CompactTextString(m) } func (*ReadResponse) ProtoMessage() {} func (*ReadResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{3} + return fileDescriptor_1ba364858f5c3cdb, []int{3} } func (m *ReadResponse) XXX_Unmarshal(b []byte) error { @@ -259,7 +263,7 @@ func (m *WriteOptions) Reset() { *m = WriteOptions{} } func (m *WriteOptions) String() string { return proto.CompactTextString(m) } func (*WriteOptions) ProtoMessage() {} func (*WriteOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{4} + return fileDescriptor_1ba364858f5c3cdb, []int{4} } func (m *WriteOptions) XXX_Unmarshal(b []byte) error { @@ -320,7 +324,7 @@ func (m *WriteRequest) Reset() { *m = WriteRequest{} } func (m *WriteRequest) String() string { return proto.CompactTextString(m) } func (*WriteRequest) ProtoMessage() {} func (*WriteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{5} + return fileDescriptor_1ba364858f5c3cdb, []int{5} } func (m *WriteRequest) XXX_Unmarshal(b []byte) error { @@ -365,7 +369,7 @@ func (m *WriteResponse) Reset() { *m = WriteResponse{} } func (m *WriteResponse) String() string { return proto.CompactTextString(m) } func (*WriteResponse) ProtoMessage() {} func (*WriteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{6} + return fileDescriptor_1ba364858f5c3cdb, []int{6} } func (m *WriteResponse) XXX_Unmarshal(b []byte) error { @@ -398,7 +402,7 @@ func (m *DeleteOptions) Reset() { *m = DeleteOptions{} } func (m *DeleteOptions) String() string { return proto.CompactTextString(m) } func (*DeleteOptions) ProtoMessage() {} func (*DeleteOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{7} + return fileDescriptor_1ba364858f5c3cdb, []int{7} } func (m *DeleteOptions) XXX_Unmarshal(b []byte) error { @@ -445,7 +449,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{8} + return fileDescriptor_1ba364858f5c3cdb, []int{8} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -490,7 +494,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} } func (m *DeleteResponse) String() string { return proto.CompactTextString(m) } func (*DeleteResponse) ProtoMessage() {} func (*DeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{9} + return fileDescriptor_1ba364858f5c3cdb, []int{9} } func (m *DeleteResponse) XXX_Unmarshal(b []byte) error { @@ -527,7 +531,7 @@ func (m *ListOptions) Reset() { *m = ListOptions{} } func (m *ListOptions) String() string { return proto.CompactTextString(m) } func (*ListOptions) ProtoMessage() {} func (*ListOptions) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{10} + return fileDescriptor_1ba364858f5c3cdb, []int{10} } func (m *ListOptions) XXX_Unmarshal(b []byte) error { @@ -601,7 +605,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} } func (m *ListRequest) String() string { return proto.CompactTextString(m) } func (*ListRequest) ProtoMessage() {} func (*ListRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{11} + return fileDescriptor_1ba364858f5c3cdb, []int{11} } func (m *ListRequest) XXX_Unmarshal(b []byte) error { @@ -640,7 +644,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} } func (m *ListResponse) String() string { return proto.CompactTextString(m) } func (*ListResponse) ProtoMessage() {} func (*ListResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{12} + return fileDescriptor_1ba364858f5c3cdb, []int{12} } func (m *ListResponse) XXX_Unmarshal(b []byte) error { @@ -678,7 +682,7 @@ func (m *DatabasesRequest) Reset() { *m = DatabasesRequest{} } func (m *DatabasesRequest) String() string { return proto.CompactTextString(m) } func (*DatabasesRequest) ProtoMessage() {} func (*DatabasesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{13} + return fileDescriptor_1ba364858f5c3cdb, []int{13} } func (m *DatabasesRequest) XXX_Unmarshal(b []byte) error { @@ -710,7 +714,7 @@ func (m *DatabasesResponse) Reset() { *m = DatabasesResponse{} } func (m *DatabasesResponse) String() string { return proto.CompactTextString(m) } func (*DatabasesResponse) ProtoMessage() {} func (*DatabasesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{14} + return fileDescriptor_1ba364858f5c3cdb, []int{14} } func (m *DatabasesResponse) XXX_Unmarshal(b []byte) error { @@ -749,7 +753,7 @@ func (m *TablesRequest) Reset() { *m = TablesRequest{} } func (m *TablesRequest) String() string { return proto.CompactTextString(m) } func (*TablesRequest) ProtoMessage() {} func (*TablesRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{15} + return fileDescriptor_1ba364858f5c3cdb, []int{15} } func (m *TablesRequest) XXX_Unmarshal(b []byte) error { @@ -788,7 +792,7 @@ func (m *TablesResponse) Reset() { *m = TablesResponse{} } func (m *TablesResponse) String() string { return proto.CompactTextString(m) } func (*TablesResponse) ProtoMessage() {} func (*TablesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_42854049893ccb13, []int{16} + return fileDescriptor_1ba364858f5c3cdb, []int{16} } func (m *TablesResponse) XXX_Unmarshal(b []byte) error { @@ -836,48 +840,333 @@ func init() { proto.RegisterType((*TablesResponse)(nil), "go.micro.store.TablesResponse") } -func init() { - proto.RegisterFile("github.com/micro/go-micro/store/service/proto/store.proto", fileDescriptor_42854049893ccb13) +func init() { proto.RegisterFile("store/service/proto/store.proto", fileDescriptor_1ba364858f5c3cdb) } + +var fileDescriptor_1ba364858f5c3cdb = []byte{ + // 583 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0xdd, 0x8e, 0xd2, 0x40, + 0x14, 0xa6, 0xdb, 0xd2, 0xa5, 0x87, 0x1f, 0x71, 0x62, 0x48, 0x83, 0xac, 0xd6, 0xb9, 0x6a, 0x62, + 0x52, 0x56, 0x8c, 0x7a, 0xab, 0x11, 0x8d, 0x1a, 0x13, 0x93, 0xd1, 0x68, 0xe2, 0x5d, 0x81, 0xc1, + 0xd4, 0x65, 0x77, 0xb0, 0x33, 0x90, 0xe5, 0x61, 0x7c, 0x1c, 0xdf, 0xcb, 0xcc, 0x1f, 0x14, 0x68, + 0xf7, 0xc2, 0xf5, 0x6e, 0xce, 0x99, 0xe1, 0x3b, 0xe7, 0xfb, 0x69, 0x80, 0x87, 0x5c, 0xb0, 0x9c, + 0x0e, 0x39, 0xcd, 0xd7, 0xd9, 0x94, 0x0e, 0x97, 0x39, 0x13, 0x6c, 0xa8, 0x7a, 0x89, 0x3a, 0xa3, + 0xce, 0x0f, 0x96, 0x5c, 0x66, 0xd3, 0x9c, 0x25, 0xaa, 0x8b, 0xdf, 0x81, 0x4f, 0xe8, 0x94, 0xe5, + 0x33, 0xd4, 0x05, 0xf7, 0x82, 0x6e, 0x42, 0x27, 0x72, 0xe2, 0x80, 0xc8, 0x23, 0xba, 0x07, 0xf5, + 0x75, 0xba, 0x58, 0xd1, 0xf0, 0x24, 0x72, 0xe2, 0x16, 0xd1, 0x05, 0xea, 0x81, 0x4f, 0xaf, 0x97, + 0x59, 0xbe, 0x09, 0xdd, 0xc8, 0x89, 0x5d, 0x62, 0x2a, 0xfc, 0xdb, 0x81, 0x26, 0xa1, 0xe9, 0xec, + 0xd3, 0x52, 0x64, 0xec, 0x8a, 0xa3, 0x3e, 0x34, 0x66, 0xa9, 0x48, 0x27, 0x29, 0xa7, 0x06, 0x74, + 0x5b, 0x4b, 0x64, 0x91, 0x4e, 0x16, 0x1a, 0x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 0x37, 0xbc, 0x28, 0xb2, 0xd4, 0x36, 0x1d, 0xb3, 0xdc, 0xf3, 0xfa, 0x98, 0xe5, + 0xbe, 0xbb, 0xb8, 0x36, 0xf1, 0xd5, 0xdf, 0xd6, 0xd3, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xc9, + 0x9b, 0x47, 0x1c, 0xd9, 0x06, 0x00, 0x00, } -var fileDescriptor_42854049893ccb13 = []byte{ - // 598 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0xdd, 0x8e, 0xd2, 0x40, - 0x14, 0xa6, 0xdb, 0xd2, 0xa5, 0x87, 0x1f, 0x71, 0x62, 0x48, 0x83, 0xac, 0xa9, 0x73, 0xd5, 0xc4, - 0x58, 0x56, 0x8c, 0x1a, 0xef, 0x34, 0xa2, 0x51, 0x63, 0x62, 0x32, 0x1a, 0x4d, 0xbc, 0x2b, 0x30, - 0x60, 0x5d, 0xd8, 0x62, 0x67, 0x20, 0xcb, 0xc3, 0xf8, 0x38, 0xbe, 0x97, 0x99, 0x3f, 0x28, 0xd0, - 0xee, 0x85, 0xbb, 0x77, 0x73, 0xce, 0x1c, 0xbe, 0x39, 0xdf, 0x4f, 0x03, 0xbc, 0x9c, 0x25, 0xfc, - 0xe7, 0x6a, 0x14, 0x8d, 0xd3, 0x45, 0x7f, 0x91, 0x8c, 0xb3, 0xb4, 0x3f, 0x4b, 0x1f, 0xab, 0x03, - 0xe3, 0x69, 0x46, 0xfb, 0x8c, 0x66, 0xeb, 0x64, 0x4c, 0xfb, 0xcb, 0x2c, 0xe5, 0xba, 0x17, 0xc9, - 0x33, 0x6a, 0xcd, 0xd2, 0x48, 0x4e, 0x46, 0xb2, 0x8b, 0xdf, 0x83, 0x4b, 0xe8, 0x38, 0xcd, 0x26, - 0xa8, 0x0d, 0xf6, 0x05, 0xdd, 0xf8, 0x56, 0x60, 0x85, 0x1e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0x7b, 0xc5, 0x97, 0xda, 0xfa, 0x0a, 0x7a, 0x07, 0x55, 0x19, 0x5f, - 0x54, 0x1c, 0x77, 0x03, 0x73, 0x56, 0x72, 0xbb, 0xc5, 0xf9, 0x00, 0xae, 0x8a, 0x15, 0x2a, 0x09, - 0xa2, 0x41, 0x7a, 0x50, 0x76, 0xbd, 0x85, 0x7a, 0x0b, 0x8e, 0x70, 0x0a, 0x15, 0xfa, 0x5a, 0xca, - 0x2b, 0x6f, 0x2e, 0xae, 0x9c, 0x5b, 0x88, 0x80, 0xb7, 0xb5, 0x0c, 0x05, 0x47, 0xaf, 0x1e, 0x38, - 0xdc, 0x7d, 0x78, 0xcd, 0x44, 0x9e, 0xa5, 0xb2, 0xe9, 0x98, 0xe5, 0x9e, 0xd7, 0xc7, 0x2c, 0xf7, - 0xdd, 0xc5, 0x95, 0x91, 0x2b, 0xff, 0xb6, 0x9e, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xab, 0xcb, - 0x6e, 0xac, 0xf3, 0x06, 0x00, 0x00, +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// StoreClient is the client API for Store service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type StoreClient interface { + Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) + Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) + List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (Store_ListClient, error) + Databases(ctx context.Context, in *DatabasesRequest, opts ...grpc.CallOption) (*DatabasesResponse, error) + Tables(ctx context.Context, in *TablesRequest, opts ...grpc.CallOption) (*TablesResponse, error) +} + +type storeClient struct { + cc *grpc.ClientConn +} + +func NewStoreClient(cc *grpc.ClientConn) StoreClient { + return &storeClient{cc} +} + +func (c *storeClient) Read(ctx context.Context, in *ReadRequest, opts ...grpc.CallOption) (*ReadResponse, error) { + out := new(ReadResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Read", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *storeClient) Write(ctx context.Context, in *WriteRequest, opts ...grpc.CallOption) (*WriteResponse, error) { + out := new(WriteResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Write", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *storeClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) { + out := new(DeleteResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *storeClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (Store_ListClient, error) { + stream, err := c.cc.NewStream(ctx, &_Store_serviceDesc.Streams[0], "/go.micro.store.Store/List", opts...) + if err != nil { + return nil, err + } + x := &storeListClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Store_ListClient interface { + Recv() (*ListResponse, error) + grpc.ClientStream +} + +type storeListClient struct { + grpc.ClientStream +} + +func (x *storeListClient) Recv() (*ListResponse, error) { + m := new(ListResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *storeClient) Databases(ctx context.Context, in *DatabasesRequest, opts ...grpc.CallOption) (*DatabasesResponse, error) { + out := new(DatabasesResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Databases", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *storeClient) Tables(ctx context.Context, in *TablesRequest, opts ...grpc.CallOption) (*TablesResponse, error) { + out := new(TablesResponse) + err := c.cc.Invoke(ctx, "/go.micro.store.Store/Tables", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// StoreServer is the server API for Store service. +type StoreServer interface { + Read(context.Context, *ReadRequest) (*ReadResponse, error) + Write(context.Context, *WriteRequest) (*WriteResponse, error) + Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) + List(*ListRequest, Store_ListServer) error + Databases(context.Context, *DatabasesRequest) (*DatabasesResponse, error) + Tables(context.Context, *TablesRequest) (*TablesResponse, error) +} + +// UnimplementedStoreServer can be embedded to have forward compatible implementations. +type UnimplementedStoreServer struct { +} + +func (*UnimplementedStoreServer) Read(ctx context.Context, req *ReadRequest) (*ReadResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Read not implemented") +} +func (*UnimplementedStoreServer) Write(ctx context.Context, req *WriteRequest) (*WriteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Write not implemented") +} +func (*UnimplementedStoreServer) Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") +} +func (*UnimplementedStoreServer) List(req *ListRequest, srv Store_ListServer) error { + return status.Errorf(codes.Unimplemented, "method List not implemented") +} +func (*UnimplementedStoreServer) Databases(ctx context.Context, req *DatabasesRequest) (*DatabasesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Databases not implemented") +} +func (*UnimplementedStoreServer) Tables(ctx context.Context, req *TablesRequest) (*TablesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Tables not implemented") +} + +func RegisterStoreServer(s *grpc.Server, srv StoreServer) { + s.RegisterService(&_Store_serviceDesc, srv) +} + +func _Store_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ReadRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Read(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Read", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Read(ctx, req.(*ReadRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Store_Write_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WriteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Write(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Write", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Write(ctx, req.(*WriteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Store_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Delete(ctx, req.(*DeleteRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Store_List_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(ListRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(StoreServer).List(m, &storeListServer{stream}) +} + +type Store_ListServer interface { + Send(*ListResponse) error + grpc.ServerStream +} + +type storeListServer struct { + grpc.ServerStream +} + +func (x *storeListServer) Send(m *ListResponse) error { + return x.ServerStream.SendMsg(m) +} + +func _Store_Databases_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DatabasesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Databases(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Databases", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Databases(ctx, req.(*DatabasesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Store_Tables_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TablesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StoreServer).Tables(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.micro.store.Store/Tables", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StoreServer).Tables(ctx, req.(*TablesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Store_serviceDesc = grpc.ServiceDesc{ + ServiceName: "go.micro.store.Store", + HandlerType: (*StoreServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Read", + Handler: _Store_Read_Handler, + }, + { + MethodName: "Write", + Handler: _Store_Write_Handler, + }, + { + MethodName: "Delete", + Handler: _Store_Delete_Handler, + }, + { + MethodName: "Databases", + Handler: _Store_Databases_Handler, + }, + { + MethodName: "Tables", + Handler: _Store_Tables_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "List", + Handler: _Store_List_Handler, + ServerStreams: true, + }, + }, + Metadata: "store/service/proto/store.proto", } diff --git a/store/service/proto/store.pb.micro.go b/store/service/proto/store.pb.micro.go index 668a5a87..0e622f09 100644 --- a/store/service/proto/store.pb.micro.go +++ b/store/service/proto/store.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: github.com/micro/go-micro/store/service/proto/store.proto +// source: store/service/proto/store.proto package go_micro_store From 1eb63635b5c0082059529535b88d0c23a2b2e3d2 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Mon, 11 May 2020 14:08:27 +0200 Subject: [PATCH 739/788] Adding file upload and download capabilities (#1610) --- go.mod | 19 +- go.sum | 82 +++ server/proto/server.pb.go | 552 +++++++++--------- server/proto/server.pb.micro.go | 2 +- util/file/client.go | 188 ++++++ util/file/handler.go | 150 +++++ util/file/proto/file.pb.go | 958 +++++++++++++++++++++++++++++++ util/file/proto/file.pb.micro.go | 161 ++++++ util/file/proto/file.proto | 68 +++ 9 files changed, 1900 insertions(+), 280 deletions(-) create mode 100644 util/file/client.go create mode 100644 util/file/handler.go create mode 100644 util/file/proto/file.pb.go create mode 100644 util/file/proto/file.pb.micro.go create mode 100644 util/file/proto/file.proto diff --git a/go.mod b/go.mod index fe1ce6b0..126d4415 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,8 @@ go 1.13 require ( github.com/BurntSushi/toml v0.3.1 github.com/bitly/go-simplejson v0.5.0 - github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect github.com/bwmarrin/discordgo v0.20.2 - github.com/coreos/bbolt v1.3.3 // indirect github.com/coreos/etcd v3.3.18+incompatible - github.com/coreos/go-semver v0.3.0 // indirect - github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect - github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/davecgh/go-spew v1.1.1 github.com/dgrijalva/jwt-go v3.2.0+incompatible @@ -23,29 +18,24 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/go-acme/lego/v3 v3.3.0 github.com/go-git/go-git/v5 v5.0.0 - github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee github.com/gobwas/pool v0.2.0 // indirect github.com/gobwas/ws v1.0.3 github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect - github.com/golang/protobuf v1.3.5 - github.com/google/go-cmp v0.4.0 // indirect + github.com/golang/protobuf v1.4.0 github.com/google/uuid v1.1.1 github.com/gorilla/handlers v1.4.2 - github.com/gorilla/websocket v1.4.1 // indirect - github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect - github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect github.com/hashicorp/hcl v1.0.0 github.com/hpcloud/tail v1.0.0 github.com/imdario/mergo v0.3.8 - github.com/jonboulle/clockwork v0.1.0 // indirect github.com/json-iterator/go v1.1.9 // indirect github.com/kr/pretty v0.1.0 github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 github.com/mholt/certmagic v0.9.3 github.com/micro/cli/v2 v2.1.2 + github.com/micro/go-micro v1.18.0 github.com/miekg/dns v1.1.27 github.com/mitchellh/hashstructure v1.0.0 github.com/nats-io/nats-server/v2 v2.1.6 // indirect @@ -54,11 +44,8 @@ require ( github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 - github.com/soheilhy/cmux v0.1.4 // indirect github.com/stretchr/testify v1.4.0 - github.com/technoweenie/multipartstreamer v1.0.1 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect - github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect go.etcd.io/bbolt v1.3.4 go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 @@ -66,7 +53,7 @@ require ( golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1 google.golang.org/grpc v1.26.0 + google.golang.org/protobuf v1.22.0 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/telegram-bot-api.v4 v4.6.4 - sigs.k8s.io/yaml v1.1.0 // indirect ) diff --git a/go.sum b/go.sum index c86297fe..32596903 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,10 @@ github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvd github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5 h1:ygIc8M6trr62pF5DucadTWGdEB4mEyvzi0e2nbcmcyA= github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw= +github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c h1:YMP6olTU903X3gxQJckdmiP8/zkSMq4kN3uipsU9XjU= github.com/Microsoft/hcsshim v0.8.7-0.20191101173118-65519b62243c/go.mod h1:7xhjOwRV2+0HXGmM0jxaEu+ZiXJFoVZOTfL/dmqbrD8= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= @@ -53,6 +55,7 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aws/aws-sdk-go v1.23.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= +github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -62,6 +65,8 @@ github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngE github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= +github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= +github.com/bwmarrin/discordgo v0.20.1/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= @@ -78,6 +83,7 @@ github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0 h1:xjvXQWABwS2uiv3TWgQt5Uth60Gu86LTGZXMJkjc7rY= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= +github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVlf61smEIq1nwLLAjQVEK2EADoW3CX9AuT+8= github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= @@ -86,6 +92,7 @@ github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDG github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc= github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.18+incompatible h1:Zz1aXgDrFFi1nadh58tA9ktt06cmPTwNNP3dXwIq1lE= github.com/coreos/etcd v3.3.18+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= @@ -105,6 +112,7 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decker502/dnspod-go v0.2.0/go.mod h1:qsurYu1FgxcDwfSwXJdLt4kRsBLZeosEb9uq4Sy+08g= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= @@ -112,6 +120,7 @@ github.com/dnaeon/go-vcr v0.0.0-20180814043457-aafff18a5cc2/go.mod h1:aBB1+wY4s9 github.com/dnsimple/dnsimple-go v0.30.0/go.mod h1:O5TJ0/U6r7AfT8niYNlmohpLbCSG+c71tQlGr9SeGrg= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v1.4.2-0.20190710153559-aa8249ae1b8b/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23 h1:oqgGT9O61YAYvI41EBsLePOr+LE6roB0xY4gpkZuFSE= github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= @@ -125,6 +134,7 @@ github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1 h1:jFGzikHboUMRXmMBt github.com/ef-ds/deque v1.0.4-0.20190904040645-54cb57c252a1/go.mod h1:HvODWzv6Y6kBf3Ah2WzN1bHjDUezGLaAhwuWVwfpEJs= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch/v5 v5.0.0 h1:dKTrUeykyQwKb/kx7Z+4ukDs6l+4L41HqG1XHnhX7WE= @@ -137,12 +147,14 @@ github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c h1:pBgVXWDXj github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c/go.mod h1:pFdJbAhRf7rh6YYMUdIQGyzne6zYL1tCUW8QV2B3UfY= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsouza/go-dockerclient v1.4.4/go.mod h1:PrwszSL5fbmsESocROrOGq/NULMXRw+bajY0ltzD6MA= github.com/fsouza/go-dockerclient v1.6.0 h1:f7j+AX94143JL1H3TiqSMkM4EcLDI0De1qD4GGn3Hig= github.com/fsouza/go-dockerclient v1.6.0/go.mod h1:YWwtNPuL4XTX1SKJQk86cWPmmqwx+4np9qfPbb+znGc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= +github.com/go-acme/lego/v3 v3.1.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= github.com/go-acme/lego/v3 v3.3.0 h1:6BePZsOiYA4/w+M7QDytxQtMfCipMPGnWAHs9pWks98= github.com/go-acme/lego/v3 v3.3.0/go.mod h1:iGSY2vQrvQs3WezicSB/oVbO2eCrD88dpWPwb1qLqu0= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= @@ -158,8 +170,13 @@ github.com/go-git/go-git/v5 v5.0.0/go.mod h1:oYD8y9kWsGINPFJoLdaScGCN6dlKg23blmC github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-ini/ini v1.44.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-log/log v0.1.0 h1:wudGTNsiGzrD5ZjgIkVZ517ugi2XRe9Q/xRCzwEO4/U= +github.com/go-log/log v0.1.0/go.mod h1:4mBwpdRMFLiuXZDCwU2lKQFsoSCo72j3HqBK9d81N2M= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= +github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU= github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM= @@ -178,6 +195,7 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -191,6 +209,12 @@ github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls= github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= @@ -239,6 +263,7 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4= +github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd/go.mod h1:3LVOLeyx9XVvwPgrt2be44XgSqndprz1G18rSk8KD84= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= @@ -247,9 +272,11 @@ github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJS github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1/go.mod h1:DFXrEwSRX0p/aSvxE21319menCBFeQO0jXpRj7LEZUA= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= @@ -276,15 +303,21 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= +github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= +github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= github.com/liquidweb/liquidweb-go v1.6.0/go.mod h1:UDcVnAMDkZxpw4Y7NOHkqoeiGacVLEIG/i5J9cyixzQ= +github.com/lucas-clemente/quic-go v0.12.1/go.mod h1:UXJJPE4RfFef/xPO5wQm0tITK8gNfqwTxjbE7s3Vb8s= +github.com/lucas-clemente/quic-go v0.13.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= github.com/lucas-clemente/quic-go v0.14.1 h1:c1aKoBZKOPA+49q96B1wGkibyPP0AxYh45WuAoq+87E= github.com/lucas-clemente/quic-go v0.14.1/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU= github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ= github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE= github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI= +github.com/marten-seemann/qtls v0.3.2/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks= github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -293,11 +326,23 @@ github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mholt/certmagic v0.7.5/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= +github.com/mholt/certmagic v0.8.3/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU= github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= +github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= +github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= +github.com/micro/go-micro v1.16.0/go.mod h1:A0F58bHLh2m0LAI9QyhvmbN8c1cxhAZo3cM6s+iDsrM= +github.com/micro/go-micro v1.18.0 h1:gP70EZVHpJuUIT0YWth192JmlIci+qMOEByHm83XE9E= +github.com/micro/go-micro v1.18.0/go.mod h1:klwUJL1gkdY1MHFyz+fFJXn52dKcty4hoe95Mp571AA= +github.com/micro/mdns v0.3.0 h1:bYycYe+98AXR3s8Nq5qvt6C573uFTDPIYzJemWON0QE= +github.com/micro/mdns v0.3.0/go.mod h1:KJ0dW7KmicXU2BV++qkLlmHYcVv7/hHnbtguSWt9Aoc= +github.com/micro/protoc-gen-micro v1.0.0/go.mod h1:C8ij4DJhapBmypcT00AXdb0cZ675/3PqUO02buWWqbE= +github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -316,12 +361,18 @@ github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8d github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= +github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= +github.com/nats-io/nats-server/v2 v2.1.0/go.mod h1:r5y0WgCag0dTj/qiHkHrXAcKQ/f5GMOZaEGdoxxnJ4I= github.com/nats-io/nats-server/v2 v2.1.6 h1:qAaHZaS8pRRNQLFaiBA1rq5WynyEGp9DFgmMfoaiXGY= github.com/nats-io/nats-server/v2 v2.1.6/go.mod h1:BL1NOtaBQ5/y97djERRVWNouMW7GT3gxnmbE/eC8u8A= +github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= +github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= github.com/nats-io/nats.go v1.9.2 h1:oDeERm3NcZVrPpdR/JpGdWHMv3oJ8yY30YwxKq+DU2s= github.com/nats-io/nats.go v1.9.2/go.mod h1:AjGArbfyR50+afOUotNX2Xs5SYHf+CoOa5HH1eEl2HE= +github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4= +github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nkeys v0.1.4 h1:aEsHIssIk6ETN5m2/MD8Y4B2X7FfXrBAUdkyRvbVYzA= github.com/nats-io/nkeys v0.1.4/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s= @@ -330,6 +381,7 @@ github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OS github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= @@ -424,6 +476,7 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc h1:yUaosFVTJwnltaHbSNC3i82I92quFs+OFPRl8kNMVwo= github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= @@ -439,6 +492,7 @@ github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg= go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= @@ -450,27 +504,35 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.2.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.12.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20190927123631-a832865fa7ad/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191108234033-bd318be0434a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -515,7 +577,9 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -535,9 +599,11 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -547,12 +613,15 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So= @@ -584,6 +653,7 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -615,6 +685,7 @@ google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1 h1:aQktFqmDE2yjveXJlVIfslDFmFnUXSqG0i6KRcJAeMc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= @@ -624,8 +695,17 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0 h1:cJv5/xdbk1NnMPR1VP9+HU6gupuG9MLBoH1r6RHZ2MY= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= @@ -636,6 +716,8 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.44.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/server/proto/server.pb.go b/server/proto/server.pb.go index 5813ff28..ea21354b 100644 --- a/server/proto/server.pb.go +++ b/server/proto/server.pb.go @@ -1,324 +1,350 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: server/proto/server.proto +// versions: +// protoc-gen-go v1.22.0 +// protoc v3.6.1 +// source: github.com/micro/go-micro/server/proto/server.proto package go_micro_server import ( - context "context" - fmt "fmt" proto "github.com/golang/protobuf/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - math "math" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +// This is a compile-time assertion that a sufficiently up-to-date version +// of the legacy proto package is being used. +const _ = proto.ProtoPackageIsVersion4 type HandleRequest struct { - Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` - Endpoint string `protobuf:"bytes,2,opt,name=endpoint,proto3" json:"endpoint,omitempty"` - Protocol string `protobuf:"bytes,3,opt,name=protocol,proto3" json:"protocol,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` + Endpoint string `protobuf:"bytes,2,opt,name=endpoint,proto3" json:"endpoint,omitempty"` + Protocol string `protobuf:"bytes,3,opt,name=protocol,proto3" json:"protocol,omitempty"` } -func (m *HandleRequest) Reset() { *m = HandleRequest{} } -func (m *HandleRequest) String() string { return proto.CompactTextString(m) } -func (*HandleRequest) ProtoMessage() {} +func (x *HandleRequest) Reset() { + *x = HandleRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_micro_go_micro_server_proto_server_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HandleRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HandleRequest) ProtoMessage() {} + +func (x *HandleRequest) ProtoReflect() protoreflect.Message { + mi := &file_github_com_micro_go_micro_server_proto_server_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HandleRequest.ProtoReflect.Descriptor instead. func (*HandleRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1959cecd4d1121a1, []int{0} + return file_github_com_micro_go_micro_server_proto_server_proto_rawDescGZIP(), []int{0} } -func (m *HandleRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_HandleRequest.Unmarshal(m, b) -} -func (m *HandleRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_HandleRequest.Marshal(b, m, deterministic) -} -func (m *HandleRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_HandleRequest.Merge(m, src) -} -func (m *HandleRequest) XXX_Size() int { - return xxx_messageInfo_HandleRequest.Size(m) -} -func (m *HandleRequest) XXX_DiscardUnknown() { - xxx_messageInfo_HandleRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_HandleRequest proto.InternalMessageInfo - -func (m *HandleRequest) GetService() string { - if m != nil { - return m.Service +func (x *HandleRequest) GetService() string { + if x != nil { + return x.Service } return "" } -func (m *HandleRequest) GetEndpoint() string { - if m != nil { - return m.Endpoint +func (x *HandleRequest) GetEndpoint() string { + if x != nil { + return x.Endpoint } return "" } -func (m *HandleRequest) GetProtocol() string { - if m != nil { - return m.Protocol +func (x *HandleRequest) GetProtocol() string { + if x != nil { + return x.Protocol } return "" } type HandleResponse struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields } -func (m *HandleResponse) Reset() { *m = HandleResponse{} } -func (m *HandleResponse) String() string { return proto.CompactTextString(m) } -func (*HandleResponse) ProtoMessage() {} +func (x *HandleResponse) Reset() { + *x = HandleResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_micro_go_micro_server_proto_server_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HandleResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HandleResponse) ProtoMessage() {} + +func (x *HandleResponse) ProtoReflect() protoreflect.Message { + mi := &file_github_com_micro_go_micro_server_proto_server_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HandleResponse.ProtoReflect.Descriptor instead. func (*HandleResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1959cecd4d1121a1, []int{1} + return file_github_com_micro_go_micro_server_proto_server_proto_rawDescGZIP(), []int{1} } -func (m *HandleResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_HandleResponse.Unmarshal(m, b) -} -func (m *HandleResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_HandleResponse.Marshal(b, m, deterministic) -} -func (m *HandleResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_HandleResponse.Merge(m, src) -} -func (m *HandleResponse) XXX_Size() int { - return xxx_messageInfo_HandleResponse.Size(m) -} -func (m *HandleResponse) XXX_DiscardUnknown() { - xxx_messageInfo_HandleResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_HandleResponse proto.InternalMessageInfo - type SubscribeRequest struct { - Topic string `protobuf:"bytes,1,opt,name=topic,proto3" json:"topic,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Topic string `protobuf:"bytes,1,opt,name=topic,proto3" json:"topic,omitempty"` } -func (m *SubscribeRequest) Reset() { *m = SubscribeRequest{} } -func (m *SubscribeRequest) String() string { return proto.CompactTextString(m) } -func (*SubscribeRequest) ProtoMessage() {} +func (x *SubscribeRequest) Reset() { + *x = SubscribeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_micro_go_micro_server_proto_server_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SubscribeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SubscribeRequest) ProtoMessage() {} + +func (x *SubscribeRequest) ProtoReflect() protoreflect.Message { + mi := &file_github_com_micro_go_micro_server_proto_server_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SubscribeRequest.ProtoReflect.Descriptor instead. func (*SubscribeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_1959cecd4d1121a1, []int{2} + return file_github_com_micro_go_micro_server_proto_server_proto_rawDescGZIP(), []int{2} } -func (m *SubscribeRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_SubscribeRequest.Unmarshal(m, b) -} -func (m *SubscribeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_SubscribeRequest.Marshal(b, m, deterministic) -} -func (m *SubscribeRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_SubscribeRequest.Merge(m, src) -} -func (m *SubscribeRequest) XXX_Size() int { - return xxx_messageInfo_SubscribeRequest.Size(m) -} -func (m *SubscribeRequest) XXX_DiscardUnknown() { - xxx_messageInfo_SubscribeRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_SubscribeRequest proto.InternalMessageInfo - -func (m *SubscribeRequest) GetTopic() string { - if m != nil { - return m.Topic +func (x *SubscribeRequest) GetTopic() string { + if x != nil { + return x.Topic } return "" } type SubscribeResponse struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields } -func (m *SubscribeResponse) Reset() { *m = SubscribeResponse{} } -func (m *SubscribeResponse) String() string { return proto.CompactTextString(m) } -func (*SubscribeResponse) ProtoMessage() {} +func (x *SubscribeResponse) Reset() { + *x = SubscribeResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_micro_go_micro_server_proto_server_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SubscribeResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SubscribeResponse) ProtoMessage() {} + +func (x *SubscribeResponse) ProtoReflect() protoreflect.Message { + mi := &file_github_com_micro_go_micro_server_proto_server_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SubscribeResponse.ProtoReflect.Descriptor instead. func (*SubscribeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_1959cecd4d1121a1, []int{3} + return file_github_com_micro_go_micro_server_proto_server_proto_rawDescGZIP(), []int{3} } -func (m *SubscribeResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_SubscribeResponse.Unmarshal(m, b) -} -func (m *SubscribeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_SubscribeResponse.Marshal(b, m, deterministic) -} -func (m *SubscribeResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_SubscribeResponse.Merge(m, src) -} -func (m *SubscribeResponse) XXX_Size() int { - return xxx_messageInfo_SubscribeResponse.Size(m) -} -func (m *SubscribeResponse) XXX_DiscardUnknown() { - xxx_messageInfo_SubscribeResponse.DiscardUnknown(m) +var File_github_com_micro_go_micro_server_proto_server_proto protoreflect.FileDescriptor + +var file_github_com_micro_go_micro_server_proto_server_proto_rawDesc = []byte{ + 0x0a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, 0x69, 0x63, + 0x72, 0x6f, 0x2f, 0x67, 0x6f, 0x2d, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2f, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x22, 0x61, 0x0a, 0x0d, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x1a, 0x0a, + 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x22, 0x10, 0x0a, 0x0e, 0x48, 0x61, 0x6e, + 0x64, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x28, 0x0a, 0x10, 0x53, + 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x74, 0x6f, 0x70, 0x69, 0x63, 0x22, 0x13, 0x0a, 0x11, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, + 0x62, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xab, 0x01, 0x0a, 0x06, 0x53, + 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x4b, 0x0a, 0x06, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x12, + 0x1e, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, + 0x72, 0x2e, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x1f, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, + 0x72, 0x2e, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x00, 0x12, 0x54, 0x0a, 0x09, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x12, + 0x21, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, + 0x72, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } -var xxx_messageInfo_SubscribeResponse proto.InternalMessageInfo +var ( + file_github_com_micro_go_micro_server_proto_server_proto_rawDescOnce sync.Once + file_github_com_micro_go_micro_server_proto_server_proto_rawDescData = file_github_com_micro_go_micro_server_proto_server_proto_rawDesc +) -func init() { - proto.RegisterType((*HandleRequest)(nil), "go.micro.server.HandleRequest") - proto.RegisterType((*HandleResponse)(nil), "go.micro.server.HandleResponse") - proto.RegisterType((*SubscribeRequest)(nil), "go.micro.server.SubscribeRequest") - proto.RegisterType((*SubscribeResponse)(nil), "go.micro.server.SubscribeResponse") +func file_github_com_micro_go_micro_server_proto_server_proto_rawDescGZIP() []byte { + file_github_com_micro_go_micro_server_proto_server_proto_rawDescOnce.Do(func() { + file_github_com_micro_go_micro_server_proto_server_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_micro_go_micro_server_proto_server_proto_rawDescData) + }) + return file_github_com_micro_go_micro_server_proto_server_proto_rawDescData } -func init() { proto.RegisterFile("server/proto/server.proto", fileDescriptor_1959cecd4d1121a1) } - -var fileDescriptor_1959cecd4d1121a1 = []byte{ - // 223 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2c, 0x4e, 0x2d, 0x2a, - 0x4b, 0x2d, 0xd2, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x87, 0x70, 0xf4, 0xc0, 0x1c, 0x21, 0xfe, - 0xf4, 0x7c, 0xbd, 0xdc, 0xcc, 0xe4, 0xa2, 0x7c, 0x3d, 0x88, 0xb0, 0x52, 0x22, 0x17, 0xaf, 0x47, - 0x62, 0x5e, 0x4a, 0x4e, 0x6a, 0x50, 0x6a, 0x61, 0x69, 0x6a, 0x71, 0x89, 0x90, 0x04, 0x17, 0x3b, - 0x48, 0x2a, 0x33, 0x39, 0x55, 0x82, 0x51, 0x81, 0x51, 0x83, 0x33, 0x08, 0xc6, 0x15, 0x92, 0xe2, - 0xe2, 0x48, 0xcd, 0x4b, 0x29, 0xc8, 0xcf, 0xcc, 0x2b, 0x91, 0x60, 0x02, 0x4b, 0xc1, 0xf9, 0x20, - 0x39, 0xb0, 0x05, 0xc9, 0xf9, 0x39, 0x12, 0xcc, 0x10, 0x39, 0x18, 0x5f, 0x49, 0x80, 0x8b, 0x0f, - 0x66, 0x45, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0xaa, 0x92, 0x06, 0x97, 0x40, 0x70, 0x69, 0x52, 0x71, - 0x72, 0x51, 0x66, 0x12, 0xdc, 0x5e, 0x11, 0x2e, 0xd6, 0x92, 0xfc, 0x82, 0xcc, 0x64, 0xa8, 0xad, - 0x10, 0x8e, 0x92, 0x30, 0x97, 0x20, 0x92, 0x4a, 0x88, 0x76, 0xa3, 0xd5, 0x8c, 0x5c, 0x6c, 0xc1, - 0x60, 0xe7, 0x0b, 0x79, 0x73, 0xb1, 0x41, 0xcc, 0x16, 0x92, 0xd3, 0x43, 0xf3, 0x9a, 0x1e, 0x8a, - 0xbf, 0xa4, 0xe4, 0x71, 0xca, 0x43, 0x1d, 0xc5, 0x20, 0x14, 0xc2, 0xc5, 0x09, 0xb7, 0x4c, 0x48, - 0x11, 0x43, 0x3d, 0xba, 0x93, 0xa5, 0x94, 0xf0, 0x29, 0x81, 0x99, 0x9a, 0xc4, 0x06, 0x0e, 0x08, - 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa4, 0x3f, 0x79, 0x80, 0x96, 0x01, 0x00, 0x00, +var file_github_com_micro_go_micro_server_proto_server_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_github_com_micro_go_micro_server_proto_server_proto_goTypes = []interface{}{ + (*HandleRequest)(nil), // 0: go.micro.server.HandleRequest + (*HandleResponse)(nil), // 1: go.micro.server.HandleResponse + (*SubscribeRequest)(nil), // 2: go.micro.server.SubscribeRequest + (*SubscribeResponse)(nil), // 3: go.micro.server.SubscribeResponse +} +var file_github_com_micro_go_micro_server_proto_server_proto_depIdxs = []int32{ + 0, // 0: go.micro.server.Server.Handle:input_type -> go.micro.server.HandleRequest + 2, // 1: go.micro.server.Server.Subscribe:input_type -> go.micro.server.SubscribeRequest + 1, // 2: go.micro.server.Server.Handle:output_type -> go.micro.server.HandleResponse + 3, // 3: go.micro.server.Server.Subscribe:output_type -> go.micro.server.SubscribeResponse + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// ServerClient is the client API for Server service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type ServerClient interface { - Handle(ctx context.Context, in *HandleRequest, opts ...grpc.CallOption) (*HandleResponse, error) - Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (*SubscribeResponse, error) -} - -type serverClient struct { - cc *grpc.ClientConn -} - -func NewServerClient(cc *grpc.ClientConn) ServerClient { - return &serverClient{cc} -} - -func (c *serverClient) Handle(ctx context.Context, in *HandleRequest, opts ...grpc.CallOption) (*HandleResponse, error) { - out := new(HandleResponse) - err := c.cc.Invoke(ctx, "/go.micro.server.Server/Handle", in, out, opts...) - if err != nil { - return nil, err +func init() { file_github_com_micro_go_micro_server_proto_server_proto_init() } +func file_github_com_micro_go_micro_server_proto_server_proto_init() { + if File_github_com_micro_go_micro_server_proto_server_proto != nil { + return } - return out, nil -} - -func (c *serverClient) Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (*SubscribeResponse, error) { - out := new(SubscribeResponse) - err := c.cc.Invoke(ctx, "/go.micro.server.Server/Subscribe", in, out, opts...) - if err != nil { - return nil, err + if !protoimpl.UnsafeEnabled { + file_github_com_micro_go_micro_server_proto_server_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HandleRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_github_com_micro_go_micro_server_proto_server_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HandleResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_github_com_micro_go_micro_server_proto_server_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SubscribeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_github_com_micro_go_micro_server_proto_server_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SubscribeResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } - return out, nil -} - -// ServerServer is the server API for Server service. -type ServerServer interface { - Handle(context.Context, *HandleRequest) (*HandleResponse, error) - Subscribe(context.Context, *SubscribeRequest) (*SubscribeResponse, error) -} - -// UnimplementedServerServer can be embedded to have forward compatible implementations. -type UnimplementedServerServer struct { -} - -func (*UnimplementedServerServer) Handle(ctx context.Context, req *HandleRequest) (*HandleResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Handle not implemented") -} -func (*UnimplementedServerServer) Subscribe(ctx context.Context, req *SubscribeRequest) (*SubscribeResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Subscribe not implemented") -} - -func RegisterServerServer(s *grpc.Server, srv ServerServer) { - s.RegisterService(&_Server_serviceDesc, srv) -} - -func _Server_Handle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(HandleRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ServerServer).Handle(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.server.Server/Handle", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ServerServer).Handle(ctx, req.(*HandleRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Server_Subscribe_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SubscribeRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ServerServer).Subscribe(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/go.micro.server.Server/Subscribe", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ServerServer).Subscribe(ctx, req.(*SubscribeRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Server_serviceDesc = grpc.ServiceDesc{ - ServiceName: "go.micro.server.Server", - HandlerType: (*ServerServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Handle", - Handler: _Server_Handle_Handler, + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_github_com_micro_go_micro_server_proto_server_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, }, - { - MethodName: "Subscribe", - Handler: _Server_Subscribe_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "server/proto/server.proto", + GoTypes: file_github_com_micro_go_micro_server_proto_server_proto_goTypes, + DependencyIndexes: file_github_com_micro_go_micro_server_proto_server_proto_depIdxs, + MessageInfos: file_github_com_micro_go_micro_server_proto_server_proto_msgTypes, + }.Build() + File_github_com_micro_go_micro_server_proto_server_proto = out.File + file_github_com_micro_go_micro_server_proto_server_proto_rawDesc = nil + file_github_com_micro_go_micro_server_proto_server_proto_goTypes = nil + file_github_com_micro_go_micro_server_proto_server_proto_depIdxs = nil } diff --git a/server/proto/server.pb.micro.go b/server/proto/server.pb.micro.go index 5d84eda9..61ba016f 100644 --- a/server/proto/server.pb.micro.go +++ b/server/proto/server.pb.micro.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-micro. DO NOT EDIT. -// source: server/proto/server.proto +// source: github.com/micro/go-micro/server/proto/server.proto package go_micro_server diff --git a/util/file/client.go b/util/file/client.go new file mode 100644 index 00000000..ad09c42f --- /dev/null +++ b/util/file/client.go @@ -0,0 +1,188 @@ +package file + +import ( + "bufio" + "context" + "errors" + "fmt" + "io" + "log" + "os" + + "github.com/micro/go-micro/v2/client" + proto "github.com/micro/go-micro/v2/util/file/proto" +) + +// Client is the client interface to access files +type Client interface { + Open(filename string) (int64, error) + Stat(filename string) (*proto.StatResponse, error) + GetBlock(sessionId, blockId int64) ([]byte, error) + ReadAt(sessionId, offset, size int64) ([]byte, error) + Read(sessionId int64, buf []byte) (int, error) + Write(sessionId, offset int64, data []byte) error + Close(sessionId int64) error + Download(filename, saveFile string) error + Upload(filename, localFile string) error + DownloadAt(filename, saveFile string, blockId int) error +} + +// NewClient returns a new Client which uses a micro Client +func NewClient(service string, c client.Client) Client { + return &fc{proto.NewFileService(service, c)} +} + +const ( + blockSize = 512 * 1024 +) + +type fc struct { + c proto.FileService +} + +func (c *fc) Open(filename string) (int64, error) { + rsp, err := c.c.Open(context.TODO(), &proto.OpenRequest{Filename: filename}) + if err != nil { + return 0, err + } + return rsp.Id, nil +} + +func (c *fc) Stat(filename string) (*proto.StatResponse, error) { + return c.c.Stat(context.TODO(), &proto.StatRequest{Filename: filename}) +} + +func (c *fc) GetBlock(sessionId, blockId int64) ([]byte, error) { + return c.ReadAt(sessionId, blockId*blockSize, blockSize) +} + +func (c *fc) ReadAt(sessionId, offset, size int64) ([]byte, error) { + rsp, err := c.c.Read(context.TODO(), &proto.ReadRequest{Id: sessionId, Size: size, Offset: offset}) + if err != nil { + return nil, err + } + + if rsp.Eof { + err = io.EOF + } + + if rsp.Data == nil { + rsp.Data = make([]byte, size) + } + + if size != rsp.Size { + return rsp.Data[:rsp.Size], err + } + + return rsp.Data, nil +} + +func (c *fc) Read(sessionId int64, buf []byte) (int, error) { + b, err := c.ReadAt(sessionId, 0, int64(cap(buf))) + if err != nil { + return 0, err + } + copy(buf, b) + return len(b), nil +} + +func (c *fc) Write(sessionId, offset int64, data []byte) error { + _, err := c.c.Write(context.TODO(), &proto.WriteRequest{ + Id: sessionId, + Offset: offset, + Data: data}) + return err +} + +func (c *fc) Close(sessionId int64) error { + _, err := c.c.Close(context.TODO(), &proto.CloseRequest{Id: sessionId}) + return err +} + +func (c *fc) Download(filename, saveFile string) error { + return c.DownloadAt(filename, saveFile, 0) +} + +func (c *fc) Upload(filename, localFile string) error { + file, err := os.Open(localFile) + if err != nil { + return err + } + defer file.Close() + + offset := 0 + sessionId, err := c.Open(filename) + defer c.Close(sessionId) + if err != nil { + return err + } + reader := bufio.NewReader(file) + part := make([]byte, blockSize) + + for { + count, err := reader.Read(part) + if err != nil { + break + } + err = c.Write(sessionId, int64(offset), part) + if err != nil { + return err + } + offset += count + } + if err != nil && err != io.EOF { + return fmt.Errorf("Error reading %v: %v", localFile, err) + } + return nil +} + +func (c *fc) DownloadAt(filename, saveFile string, blockId int) error { + stat, err := c.Stat(filename) + if err != nil { + return err + } + if stat.Type == "Directory" { + return errors.New(fmt.Sprintf("%s is directory.", filename)) + } + + blocks := int(stat.Size / blockSize) + if stat.Size%blockSize != 0 { + blocks += 1 + } + + log.Printf("Download %s in %d blocks\n", filename, blocks-blockId) + + file, err := os.OpenFile(saveFile, os.O_CREATE|os.O_WRONLY, 0666) + if err != nil { + return err + } + defer file.Close() + + sessionId, err := c.Open(filename) + if err != nil { + return err + } + + for i := blockId; i < blocks; i++ { + buf, rerr := c.GetBlock(sessionId, int64(i)) + if rerr != nil && rerr != io.EOF { + return rerr + } + if _, werr := file.WriteAt(buf, int64(i)*blockSize); werr != nil { + return werr + } + + if i%((blocks-blockId)/100+1) == 0 { + log.Printf("Downloading %s [%d/%d] blocks", filename, i-blockId+1, blocks-blockId) + } + + if rerr == io.EOF { + break + } + } + log.Printf("Download %s completed", filename) + + c.Close(sessionId) + + return nil +} diff --git a/util/file/handler.go b/util/file/handler.go new file mode 100644 index 00000000..e01f723b --- /dev/null +++ b/util/file/handler.go @@ -0,0 +1,150 @@ +package file + +import ( + "io" + "os" + "path/filepath" + "sync" + + "github.com/micro/go-micro/errors" + "github.com/micro/go-micro/v2/logger" + "github.com/micro/go-micro/v2/server" + proto "github.com/micro/go-micro/v2/util/file/proto" + "golang.org/x/net/context" +) + +// NewHandler is a handler that can be registered with a micro Server +func NewHandler(readDir string) proto.FileHandler { + return &handler{ + readDir: readDir, + session: &session{ + files: make(map[int64]*os.File), + }, + } +} + +// RegisterHandler is a convenience method for registering a handler +func RegisterHandler(s server.Server, readDir string) { + proto.RegisterFileHandler(s, NewHandler(readDir)) +} + +type handler struct { + readDir string + session *session +} + +func (h *handler) Open(ctx context.Context, req *proto.OpenRequest, rsp *proto.OpenResponse) error { + path := filepath.Join(h.readDir, req.Filename) + file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0666) + if err != nil { + return errors.InternalServerError("go.micro.server", err.Error()) + } + + rsp.Id = h.session.Add(file) + rsp.Result = true + + logger.Debugf("Open %s, sessionId=%d", req.Filename, rsp.Id) + + return nil +} + +func (h *handler) Close(ctx context.Context, req *proto.CloseRequest, rsp *proto.CloseResponse) error { + h.session.Delete(req.Id) + logger.Debugf("Close sessionId=%d", req.Id) + return nil +} + +func (h *handler) Stat(ctx context.Context, req *proto.StatRequest, rsp *proto.StatResponse) error { + path := filepath.Join(h.readDir, req.Filename) + fi, err := os.Stat(path) + if os.IsNotExist(err) { + return errors.InternalServerError("go.micro.srv.file", err.Error()) + } + + if fi.IsDir() { + rsp.Type = "Directory" + } else { + rsp.Type = "File" + rsp.Size = fi.Size() + } + + rsp.LastModified = fi.ModTime().Unix() + logger.Debugf("Stat %s, %#v", req.Filename, rsp) + + return nil +} + +func (h *handler) Read(ctx context.Context, req *proto.ReadRequest, rsp *proto.ReadResponse) error { + file := h.session.Get(req.Id) + if file == nil { + return errors.InternalServerError("go.micro.srv.file", "You must call open first.") + } + + rsp.Data = make([]byte, req.Size) + n, err := file.ReadAt(rsp.Data, req.Offset) + if err != nil && err != io.EOF { + return errors.InternalServerError("go.micro.srv.file", err.Error()) + } + + if err == io.EOF { + rsp.Eof = true + } + + rsp.Size = int64(n) + rsp.Data = rsp.Data[:n] + + logger.Debugf("Read sessionId=%d, Offset=%d, n=%d", req.Id, req.Offset, rsp.Size) + + return nil +} + +func (h *handler) Write(ctx context.Context, req *proto.WriteRequest, rsp *proto.WriteResponse) error { + file := h.session.Get(req.Id) + if file == nil { + return errors.InternalServerError("go.micro.srv.file", "You must call open first.") + } + + if _, err := file.WriteAt(req.GetData(), req.GetOffset()); err != nil { + return err + } + + logger.Debugf("Write sessionId=%d, Offset=%d, n=%d", req.Id, req.Offset) + + return nil +} + +type session struct { + sync.Mutex + files map[int64]*os.File + counter int64 +} + +func (s *session) Add(file *os.File) int64 { + s.Lock() + defer s.Unlock() + + s.counter += 1 + s.files[s.counter] = file + + return s.counter +} + +func (s *session) Get(id int64) *os.File { + s.Lock() + defer s.Unlock() + return s.files[id] +} + +func (s *session) Delete(id int64) { + s.Lock() + defer s.Unlock() + + if file, exist := s.files[id]; exist { + file.Close() + delete(s.files, id) + } +} + +func (s *session) Len() int { + return len(s.files) +} diff --git a/util/file/proto/file.pb.go b/util/file/proto/file.pb.go new file mode 100644 index 00000000..227669d4 --- /dev/null +++ b/util/file/proto/file.pb.go @@ -0,0 +1,958 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.22.0 +// protoc v3.6.1 +// source: micro/go-micro/util/file/proto/file.proto + +package go_micro_server + +import ( + proto "github.com/golang/protobuf/proto" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// This is a compile-time assertion that a sufficiently up-to-date version +// of the legacy proto package is being used. +const _ = proto.ProtoPackageIsVersion4 + +type OpenRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Filename string `protobuf:"bytes,1,opt,name=filename,proto3" json:"filename,omitempty"` +} + +func (x *OpenRequest) Reset() { + *x = OpenRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OpenRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OpenRequest) ProtoMessage() {} + +func (x *OpenRequest) ProtoReflect() protoreflect.Message { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OpenRequest.ProtoReflect.Descriptor instead. +func (*OpenRequest) Descriptor() ([]byte, []int) { + return file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP(), []int{0} +} + +func (x *OpenRequest) GetFilename() string { + if x != nil { + return x.Filename + } + return "" +} + +type OpenResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Result bool `protobuf:"varint,2,opt,name=result,proto3" json:"result,omitempty"` +} + +func (x *OpenResponse) Reset() { + *x = OpenResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OpenResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OpenResponse) ProtoMessage() {} + +func (x *OpenResponse) ProtoReflect() protoreflect.Message { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OpenResponse.ProtoReflect.Descriptor instead. +func (*OpenResponse) Descriptor() ([]byte, []int) { + return file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP(), []int{1} +} + +func (x *OpenResponse) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *OpenResponse) GetResult() bool { + if x != nil { + return x.Result + } + return false +} + +type CloseRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *CloseRequest) Reset() { + *x = CloseRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CloseRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CloseRequest) ProtoMessage() {} + +func (x *CloseRequest) ProtoReflect() protoreflect.Message { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CloseRequest.ProtoReflect.Descriptor instead. +func (*CloseRequest) Descriptor() ([]byte, []int) { + return file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP(), []int{2} +} + +func (x *CloseRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type CloseResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *CloseResponse) Reset() { + *x = CloseResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CloseResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CloseResponse) ProtoMessage() {} + +func (x *CloseResponse) ProtoReflect() protoreflect.Message { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CloseResponse.ProtoReflect.Descriptor instead. +func (*CloseResponse) Descriptor() ([]byte, []int) { + return file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP(), []int{3} +} + +type StatRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Filename string `protobuf:"bytes,1,opt,name=filename,proto3" json:"filename,omitempty"` +} + +func (x *StatRequest) Reset() { + *x = StatRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StatRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatRequest) ProtoMessage() {} + +func (x *StatRequest) ProtoReflect() protoreflect.Message { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StatRequest.ProtoReflect.Descriptor instead. +func (*StatRequest) Descriptor() ([]byte, []int) { + return file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP(), []int{4} +} + +func (x *StatRequest) GetFilename() string { + if x != nil { + return x.Filename + } + return "" +} + +type StatResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` + Size int64 `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"` + LastModified int64 `protobuf:"varint,3,opt,name=last_modified,json=lastModified,proto3" json:"last_modified,omitempty"` +} + +func (x *StatResponse) Reset() { + *x = StatResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StatResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatResponse) ProtoMessage() {} + +func (x *StatResponse) ProtoReflect() protoreflect.Message { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StatResponse.ProtoReflect.Descriptor instead. +func (*StatResponse) Descriptor() ([]byte, []int) { + return file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP(), []int{5} +} + +func (x *StatResponse) GetType() string { + if x != nil { + return x.Type + } + return "" +} + +func (x *StatResponse) GetSize() int64 { + if x != nil { + return x.Size + } + return 0 +} + +func (x *StatResponse) GetLastModified() int64 { + if x != nil { + return x.LastModified + } + return 0 +} + +type ReadRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Offset int64 `protobuf:"varint,2,opt,name=offset,proto3" json:"offset,omitempty"` + Size int64 `protobuf:"varint,3,opt,name=size,proto3" json:"size,omitempty"` +} + +func (x *ReadRequest) Reset() { + *x = ReadRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReadRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReadRequest) ProtoMessage() {} + +func (x *ReadRequest) ProtoReflect() protoreflect.Message { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReadRequest.ProtoReflect.Descriptor instead. +func (*ReadRequest) Descriptor() ([]byte, []int) { + return file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP(), []int{6} +} + +func (x *ReadRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *ReadRequest) GetOffset() int64 { + if x != nil { + return x.Offset + } + return 0 +} + +func (x *ReadRequest) GetSize() int64 { + if x != nil { + return x.Size + } + return 0 +} + +type ReadResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Size int64 `protobuf:"varint,1,opt,name=size,proto3" json:"size,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + Eof bool `protobuf:"varint,3,opt,name=eof,proto3" json:"eof,omitempty"` +} + +func (x *ReadResponse) Reset() { + *x = ReadResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ReadResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ReadResponse) ProtoMessage() {} + +func (x *ReadResponse) ProtoReflect() protoreflect.Message { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ReadResponse.ProtoReflect.Descriptor instead. +func (*ReadResponse) Descriptor() ([]byte, []int) { + return file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP(), []int{7} +} + +func (x *ReadResponse) GetSize() int64 { + if x != nil { + return x.Size + } + return 0 +} + +func (x *ReadResponse) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +func (x *ReadResponse) GetEof() bool { + if x != nil { + return x.Eof + } + return false +} + +type GetRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + BlockId int64 `protobuf:"varint,2,opt,name=block_id,json=blockId,proto3" json:"block_id,omitempty"` +} + +func (x *GetRequest) Reset() { + *x = GetRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetRequest) ProtoMessage() {} + +func (x *GetRequest) ProtoReflect() protoreflect.Message { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetRequest.ProtoReflect.Descriptor instead. +func (*GetRequest) Descriptor() ([]byte, []int) { + return file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP(), []int{8} +} + +func (x *GetRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *GetRequest) GetBlockId() int64 { + if x != nil { + return x.BlockId + } + return 0 +} + +type GetResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + BlockId int64 `protobuf:"varint,1,opt,name=block_id,json=blockId,proto3" json:"block_id,omitempty"` + Size int64 `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"` + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` +} + +func (x *GetResponse) Reset() { + *x = GetResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetResponse) ProtoMessage() {} + +func (x *GetResponse) ProtoReflect() protoreflect.Message { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetResponse.ProtoReflect.Descriptor instead. +func (*GetResponse) Descriptor() ([]byte, []int) { + return file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP(), []int{9} +} + +func (x *GetResponse) GetBlockId() int64 { + if x != nil { + return x.BlockId + } + return 0 +} + +func (x *GetResponse) GetSize() int64 { + if x != nil { + return x.Size + } + return 0 +} + +func (x *GetResponse) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +type WriteRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Offset int64 `protobuf:"varint,2,opt,name=offset,proto3" json:"offset,omitempty"` + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` +} + +func (x *WriteRequest) Reset() { + *x = WriteRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *WriteRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WriteRequest) ProtoMessage() {} + +func (x *WriteRequest) ProtoReflect() protoreflect.Message { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use WriteRequest.ProtoReflect.Descriptor instead. +func (*WriteRequest) Descriptor() ([]byte, []int) { + return file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP(), []int{10} +} + +func (x *WriteRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *WriteRequest) GetOffset() int64 { + if x != nil { + return x.Offset + } + return 0 +} + +func (x *WriteRequest) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +type WriteResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *WriteResponse) Reset() { + *x = WriteResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *WriteResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WriteResponse) ProtoMessage() {} + +func (x *WriteResponse) ProtoReflect() protoreflect.Message { + mi := &file_micro_go_micro_util_file_proto_file_proto_msgTypes[11] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use WriteResponse.ProtoReflect.Descriptor instead. +func (*WriteResponse) Descriptor() ([]byte, []int) { + return file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP(), []int{11} +} + +var File_micro_go_micro_util_file_proto_file_proto protoreflect.FileDescriptor + +var file_micro_go_micro_util_file_proto_file_proto_rawDesc = []byte{ + 0x0a, 0x29, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2f, 0x67, 0x6f, 0x2d, 0x6d, 0x69, 0x63, 0x72, 0x6f, + 0x2f, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x67, 0x6f, 0x2e, + 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x22, 0x29, 0x0a, 0x0b, + 0x4f, 0x70, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x66, + 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, + 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x36, 0x0a, 0x0c, 0x4f, 0x70, 0x65, 0x6e, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, + 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, + 0x1e, 0x0a, 0x0c, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, + 0x0f, 0x0a, 0x0d, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x29, 0x0a, 0x0b, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1a, 0x0a, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x5b, 0x0a, 0x0c, 0x53, + 0x74, 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, + 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, + 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, + 0x69, 0x7a, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x6f, 0x64, 0x69, + 0x66, 0x69, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x6c, 0x61, 0x73, 0x74, + 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x22, 0x49, 0x0a, 0x0b, 0x52, 0x65, 0x61, 0x64, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, + 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, + 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, + 0x69, 0x7a, 0x65, 0x22, 0x48, 0x0a, 0x0c, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x65, + 0x6f, 0x66, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x65, 0x6f, 0x66, 0x22, 0x37, 0x0a, + 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x22, 0x50, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x49, 0x64, + 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, + 0x73, 0x69, 0x7a, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x4a, 0x0a, 0x0c, 0x57, 0x72, 0x69, 0x74, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, + 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, + 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x22, 0x0f, 0x0a, 0x0d, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xef, 0x02, 0x0a, 0x04, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x45, + 0x0a, 0x04, 0x4f, 0x70, 0x65, 0x6e, 0x12, 0x1c, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, + 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x4f, 0x70, 0x65, 0x6e, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x4f, 0x70, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x04, 0x53, 0x74, 0x61, 0x74, 0x12, 0x1c, 0x2e, + 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, + 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x67, 0x6f, + 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x53, 0x74, + 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x04, + 0x52, 0x65, 0x61, 0x64, 0x12, 0x1c, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x05, 0x57, 0x72, 0x69, 0x74, 0x65, 0x12, 0x1d, 0x2e, 0x67, + 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x57, + 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x67, 0x6f, + 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x57, 0x72, + 0x69, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x48, 0x0a, + 0x05, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, + 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, + 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_micro_go_micro_util_file_proto_file_proto_rawDescOnce sync.Once + file_micro_go_micro_util_file_proto_file_proto_rawDescData = file_micro_go_micro_util_file_proto_file_proto_rawDesc +) + +func file_micro_go_micro_util_file_proto_file_proto_rawDescGZIP() []byte { + file_micro_go_micro_util_file_proto_file_proto_rawDescOnce.Do(func() { + file_micro_go_micro_util_file_proto_file_proto_rawDescData = protoimpl.X.CompressGZIP(file_micro_go_micro_util_file_proto_file_proto_rawDescData) + }) + return file_micro_go_micro_util_file_proto_file_proto_rawDescData +} + +var file_micro_go_micro_util_file_proto_file_proto_msgTypes = make([]protoimpl.MessageInfo, 12) +var file_micro_go_micro_util_file_proto_file_proto_goTypes = []interface{}{ + (*OpenRequest)(nil), // 0: go.micro.server.OpenRequest + (*OpenResponse)(nil), // 1: go.micro.server.OpenResponse + (*CloseRequest)(nil), // 2: go.micro.server.CloseRequest + (*CloseResponse)(nil), // 3: go.micro.server.CloseResponse + (*StatRequest)(nil), // 4: go.micro.server.StatRequest + (*StatResponse)(nil), // 5: go.micro.server.StatResponse + (*ReadRequest)(nil), // 6: go.micro.server.ReadRequest + (*ReadResponse)(nil), // 7: go.micro.server.ReadResponse + (*GetRequest)(nil), // 8: go.micro.server.GetRequest + (*GetResponse)(nil), // 9: go.micro.server.GetResponse + (*WriteRequest)(nil), // 10: go.micro.server.WriteRequest + (*WriteResponse)(nil), // 11: go.micro.server.WriteResponse +} +var file_micro_go_micro_util_file_proto_file_proto_depIdxs = []int32{ + 0, // 0: go.micro.server.File.Open:input_type -> go.micro.server.OpenRequest + 4, // 1: go.micro.server.File.Stat:input_type -> go.micro.server.StatRequest + 6, // 2: go.micro.server.File.Read:input_type -> go.micro.server.ReadRequest + 10, // 3: go.micro.server.File.Write:input_type -> go.micro.server.WriteRequest + 2, // 4: go.micro.server.File.Close:input_type -> go.micro.server.CloseRequest + 1, // 5: go.micro.server.File.Open:output_type -> go.micro.server.OpenResponse + 5, // 6: go.micro.server.File.Stat:output_type -> go.micro.server.StatResponse + 7, // 7: go.micro.server.File.Read:output_type -> go.micro.server.ReadResponse + 11, // 8: go.micro.server.File.Write:output_type -> go.micro.server.WriteResponse + 3, // 9: go.micro.server.File.Close:output_type -> go.micro.server.CloseResponse + 5, // [5:10] is the sub-list for method output_type + 0, // [0:5] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_micro_go_micro_util_file_proto_file_proto_init() } +func file_micro_go_micro_util_file_proto_file_proto_init() { + if File_micro_go_micro_util_file_proto_file_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_micro_go_micro_util_file_proto_file_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OpenRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_micro_go_micro_util_file_proto_file_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OpenResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_micro_go_micro_util_file_proto_file_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CloseRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_micro_go_micro_util_file_proto_file_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CloseResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_micro_go_micro_util_file_proto_file_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StatRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_micro_go_micro_util_file_proto_file_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StatResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_micro_go_micro_util_file_proto_file_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReadRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_micro_go_micro_util_file_proto_file_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ReadResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_micro_go_micro_util_file_proto_file_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_micro_go_micro_util_file_proto_file_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_micro_go_micro_util_file_proto_file_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*WriteRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_micro_go_micro_util_file_proto_file_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*WriteResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_micro_go_micro_util_file_proto_file_proto_rawDesc, + NumEnums: 0, + NumMessages: 12, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_micro_go_micro_util_file_proto_file_proto_goTypes, + DependencyIndexes: file_micro_go_micro_util_file_proto_file_proto_depIdxs, + MessageInfos: file_micro_go_micro_util_file_proto_file_proto_msgTypes, + }.Build() + File_micro_go_micro_util_file_proto_file_proto = out.File + file_micro_go_micro_util_file_proto_file_proto_rawDesc = nil + file_micro_go_micro_util_file_proto_file_proto_goTypes = nil + file_micro_go_micro_util_file_proto_file_proto_depIdxs = nil +} diff --git a/util/file/proto/file.pb.micro.go b/util/file/proto/file.pb.micro.go new file mode 100644 index 00000000..fc4e6928 --- /dev/null +++ b/util/file/proto/file.pb.micro.go @@ -0,0 +1,161 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: micro/go-micro/util/file/proto/file.proto + +package go_micro_server + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +import ( + context "context" + api "github.com/micro/go-micro/v2/api" + client "github.com/micro/go-micro/v2/client" + server "github.com/micro/go-micro/v2/server" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +// Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint +var _ context.Context +var _ client.Option +var _ server.Option + +// Api Endpoints for File service + +func NewFileEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + +// Client API for File service + +type FileService interface { + Open(ctx context.Context, in *OpenRequest, opts ...client.CallOption) (*OpenResponse, error) + Stat(ctx context.Context, in *StatRequest, opts ...client.CallOption) (*StatResponse, error) + Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) + Write(ctx context.Context, in *WriteRequest, opts ...client.CallOption) (*WriteResponse, error) + Close(ctx context.Context, in *CloseRequest, opts ...client.CallOption) (*CloseResponse, error) +} + +type fileService struct { + c client.Client + name string +} + +func NewFileService(name string, c client.Client) FileService { + return &fileService{ + c: c, + name: name, + } +} + +func (c *fileService) Open(ctx context.Context, in *OpenRequest, opts ...client.CallOption) (*OpenResponse, error) { + req := c.c.NewRequest(c.name, "File.Open", in) + out := new(OpenResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *fileService) Stat(ctx context.Context, in *StatRequest, opts ...client.CallOption) (*StatResponse, error) { + req := c.c.NewRequest(c.name, "File.Stat", in) + out := new(StatResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *fileService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) { + req := c.c.NewRequest(c.name, "File.Read", in) + out := new(ReadResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *fileService) Write(ctx context.Context, in *WriteRequest, opts ...client.CallOption) (*WriteResponse, error) { + req := c.c.NewRequest(c.name, "File.Write", in) + out := new(WriteResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *fileService) Close(ctx context.Context, in *CloseRequest, opts ...client.CallOption) (*CloseResponse, error) { + req := c.c.NewRequest(c.name, "File.Close", in) + out := new(CloseResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for File service + +type FileHandler interface { + Open(context.Context, *OpenRequest, *OpenResponse) error + Stat(context.Context, *StatRequest, *StatResponse) error + Read(context.Context, *ReadRequest, *ReadResponse) error + Write(context.Context, *WriteRequest, *WriteResponse) error + Close(context.Context, *CloseRequest, *CloseResponse) error +} + +func RegisterFileHandler(s server.Server, hdlr FileHandler, opts ...server.HandlerOption) error { + type file interface { + Open(ctx context.Context, in *OpenRequest, out *OpenResponse) error + Stat(ctx context.Context, in *StatRequest, out *StatResponse) error + Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error + Write(ctx context.Context, in *WriteRequest, out *WriteResponse) error + Close(ctx context.Context, in *CloseRequest, out *CloseResponse) error + } + type File struct { + file + } + h := &fileHandler{hdlr} + return s.Handle(s.NewHandler(&File{h}, opts...)) +} + +type fileHandler struct { + FileHandler +} + +func (h *fileHandler) Open(ctx context.Context, in *OpenRequest, out *OpenResponse) error { + return h.FileHandler.Open(ctx, in, out) +} + +func (h *fileHandler) Stat(ctx context.Context, in *StatRequest, out *StatResponse) error { + return h.FileHandler.Stat(ctx, in, out) +} + +func (h *fileHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error { + return h.FileHandler.Read(ctx, in, out) +} + +func (h *fileHandler) Write(ctx context.Context, in *WriteRequest, out *WriteResponse) error { + return h.FileHandler.Write(ctx, in, out) +} + +func (h *fileHandler) Close(ctx context.Context, in *CloseRequest, out *CloseResponse) error { + return h.FileHandler.Close(ctx, in, out) +} diff --git a/util/file/proto/file.proto b/util/file/proto/file.proto new file mode 100644 index 00000000..b1cb025b --- /dev/null +++ b/util/file/proto/file.proto @@ -0,0 +1,68 @@ +syntax = "proto3"; + +package go.micro.server; + +service File { + rpc Open(OpenRequest) returns(OpenResponse) {}; + rpc Stat(StatRequest) returns(StatResponse) {}; + rpc Read(ReadRequest) returns(ReadResponse) {}; + rpc Write(WriteRequest) returns(WriteResponse) {}; + rpc Close(CloseRequest) returns(CloseResponse) {}; +} + +message OpenRequest { + string filename = 1; +} + +message OpenResponse { + int64 id = 1; + bool result = 2; +} + +message CloseRequest { + int64 id = 1; +} + +message CloseResponse { +} + +message StatRequest { + string filename = 1; +} + +message StatResponse { + string type = 1; + int64 size = 2; + int64 last_modified = 3; +} + +message ReadRequest { + int64 id = 1; + int64 offset = 2; + int64 size = 3; +} + +message ReadResponse { + int64 size = 1; + bytes data = 2; + bool eof = 3; +} + +message GetRequest { + int64 id = 1; + int64 block_id = 2; +} + +message GetResponse { + int64 block_id = 1; + int64 size = 2; + bytes data = 3; +} + +message WriteRequest { + int64 id = 1; + int64 offset = 2; + bytes data = 3; +} + +message WriteResponse {} \ No newline at end of file From f892b41299b8e6d40f24ffb221f809b39e47e01f Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Mon, 11 May 2020 17:09:28 +0100 Subject: [PATCH 740/788] Add runtime to service.Options() --- api/resolver/vpath/vpath.go | 3 --- config/cmd/options.go | 6 ++++++ options.go | 10 ++++++++++ runtime/options.go | 11 +++++++++++ runtime/service/service.go | 15 ++++++++------- service.go | 17 +++++++---------- 6 files changed, 42 insertions(+), 20 deletions(-) diff --git a/api/resolver/vpath/vpath.go b/api/resolver/vpath/vpath.go index cf407ded..f653a86f 100644 --- a/api/resolver/vpath/vpath.go +++ b/api/resolver/vpath/vpath.go @@ -3,7 +3,6 @@ package vpath import ( "errors" - "fmt" "net/http" "regexp" "strings" @@ -28,8 +27,6 @@ func (r *Resolver) Resolve(req *http.Request) (*resolver.Endpoint, error) { return nil, errors.New("unknown name") } - fmt.Println(req.URL.Path) - parts := strings.Split(req.URL.Path[1:], "/") if len(parts) == 1 { return &resolver.Endpoint{ diff --git a/config/cmd/options.go b/config/cmd/options.go index 7ec9e2b4..1dfc8076 100644 --- a/config/cmd/options.go +++ b/config/cmd/options.go @@ -100,6 +100,12 @@ func Registry(r *registry.Registry) Option { } } +func Runtime(r *runtime.Runtime) Option { + return func(o *Options) { + o.Runtime = r + } +} + func Transport(t *transport.Transport) Option { return func(o *Options) { o.Transport = t diff --git a/options.go b/options.go index d216b53e..b5e6372f 100644 --- a/options.go +++ b/options.go @@ -14,6 +14,7 @@ import ( "github.com/micro/go-micro/v2/debug/profile" "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/registry" + "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/store" "github.com/micro/go-micro/v2/transport" @@ -29,6 +30,7 @@ type Options struct { Server server.Server Store store.Store Registry registry.Registry + Runtime runtime.Runtime Transport transport.Transport Profile profile.Profile @@ -55,6 +57,7 @@ func newOptions(opts ...Option) Options { Server: server.DefaultServer, Store: store.DefaultStore, Registry: registry.DefaultRegistry, + Runtime: runtime.DefaultRuntime, Transport: transport.DefaultTransport, Context: context.Background(), Signal: true, @@ -182,6 +185,13 @@ func Transport(t transport.Transport) Option { } } +// Runtime sets the runtime +func Runtime(r runtime.Runtime) Option { + return func(o *Options) { + o.Runtime = r + } +} + // Convenience options // Address sets the address of the server diff --git a/runtime/options.go b/runtime/options.go index d7d9fe90..dea936b9 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -3,6 +3,8 @@ package runtime import ( "context" "io" + + "github.com/micro/go-micro/v2/client" ) type Option func(o *Options) @@ -17,6 +19,8 @@ type Options struct { Source string // Base image to use Image string + // Client to use when making requests + Client client.Client } // WithSource sets the base image / repository @@ -47,6 +51,13 @@ func WithImage(t string) Option { } } +// WithClient sets the client to use +func WithClient(c client.Client) Option { + return func(o *Options) { + o.Client = c + } +} + type CreateOption func(o *CreateOptions) type ReadOption func(o *ReadOptions) diff --git a/runtime/service/service.go b/runtime/service/service.go index e6bc03fc..90451028 100644 --- a/runtime/service/service.go +++ b/runtime/service/service.go @@ -24,6 +24,9 @@ func (s *svc) Init(opts ...runtime.Option) error { o(&s.options) } + // reset the runtime as the client could have changed + s.runtime = pb.NewRuntimeService(runtime.DefaultName, s.options.Client) + return nil } @@ -278,19 +281,17 @@ func (s *svc) String() string { // NewRuntime creates new service runtime and returns it func NewRuntime(opts ...runtime.Option) runtime.Runtime { - // get default options - options := runtime.Options{} + var options runtime.Options - // apply requested options for _, o := range opts { o(&options) } - - // create default client - cli := client.DefaultClient + if options.Client == nil { + options.Client = client.DefaultClient + } return &svc{ options: options, - runtime: pb.NewRuntimeService(runtime.DefaultName, cli), + runtime: pb.NewRuntimeService(runtime.DefaultName, options.Client), } } diff --git a/service.go b/service.go index c81127d2..02c8ef6b 100644 --- a/service.go +++ b/service.go @@ -3,7 +3,7 @@ package micro import ( "os" "os/signal" - "runtime" + rtime "runtime" "strings" "sync" @@ -15,6 +15,7 @@ import ( "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/plugin" + "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/store" signalutil "github.com/micro/go-micro/v2/util/signal" @@ -98,6 +99,7 @@ func (s *service) Init(opts ...Option) { cmd.Auth(&s.opts.Auth), cmd.Broker(&s.opts.Broker), cmd.Registry(&s.opts.Registry), + cmd.Runtime(&s.opts.Runtime), cmd.Transport(&s.opts.Transport), cmd.Client(&s.opts.Client), cmd.Config(&s.opts.Config), @@ -112,13 +114,8 @@ func (s *service) Init(opts ...Option) { name := s.opts.Cmd.App().Name s.opts.Store.Init(store.Table(name)) - // TODO: replace Cmd.Init with config.Load - // Right now we're just going to load a token - // May need to re-read value on change - // TODO: should be scoped to micro/auth/token - // if tk, _ := config.Get("token"); len(tk) > 0 { - // s.opts.Auth.Init(auth.ServiceToken(tk)) - // } + // Set the client for the micro clients + s.opts.Runtime.Init(runtime.WithClient(s.Client())) }) } @@ -192,9 +189,9 @@ func (s *service) Run() error { // start the profiler if s.opts.Profile != nil { // to view mutex contention - runtime.SetMutexProfileFraction(5) + rtime.SetMutexProfileFraction(5) // to view blocking profile - runtime.SetBlockProfileRate(1) + rtime.SetBlockProfileRate(1) if err := s.opts.Profile.Start(); err != nil { return err From efb64b7dbba752cd4db4c7be6a490c086912baf8 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Mon, 11 May 2020 17:57:39 +0100 Subject: [PATCH 741/788] Pass client to more of the runtime --- auth/options.go | 14 +++++++++++++- auth/service/service.go | 8 +++++--- client/options.go | 10 ---------- config/cmd/cmd.go | 4 ++-- config/source/options.go | 12 ++++++++++++ config/source/service/service.go | 8 ++++++-- options.go | 1 - service.go | 2 ++ store/options.go | 11 +++++++++++ store/service/service.go | 6 +++++- 10 files changed, 56 insertions(+), 20 deletions(-) diff --git a/auth/options.go b/auth/options.go index cb395d04..da0982b7 100644 --- a/auth/options.go +++ b/auth/options.go @@ -4,6 +4,7 @@ import ( "time" "github.com/micro/go-micro/v2/auth/provider" + "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/store" ) @@ -12,10 +13,12 @@ func NewOptions(opts ...Option) Options { for _, o := range opts { o(&options) } - if len(options.Namespace) == 0 { options.Namespace = DefaultNamespace } + if options.Client == nil { + options.Client = client.DefaultClient + } return options } @@ -39,6 +42,8 @@ type Options struct { LoginURL string // Store to back auth Store store.Store + // Client to use for RPC + Client client.Client } type Option func(o *Options) @@ -100,6 +105,13 @@ func LoginURL(url string) Option { } } +// WithClient sets the client to use when making requests +func WithClient(c client.Client) Option { + return func(o *Options) { + o.Client = c + } +} + type GenerateOptions struct { // Metadata associated with the account Metadata map[string]string diff --git a/auth/service/service.go b/auth/service/service.go index c0f7e7dd..fbec81d0 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -42,9 +42,11 @@ func (s *svc) Init(opts ...auth.Option) { o(&s.options) } - dc := client.DefaultClient - s.auth = pb.NewAuthService("go.micro.auth", dc) - s.rule = pb.NewRulesService("go.micro.auth", dc) + if s.options.Client == nil { + s.options.Client = client.DefaultClient + } + s.auth = pb.NewAuthService("go.micro.auth", s.options.Client) + s.rule = pb.NewRulesService("go.micro.auth", s.options.Client) // if we have a JWT public key passed as an option, // we can decode tokens with the type "JWT" locally diff --git a/client/options.go b/client/options.go index fed5992f..5c8f833d 100644 --- a/client/options.go +++ b/client/options.go @@ -4,7 +4,6 @@ import ( "context" "time" - "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client/selector" "github.com/micro/go-micro/v2/codec" @@ -17,7 +16,6 @@ type Options struct { ContentType string // Plugged interfaces - Auth auth.Auth Broker broker.Broker Codecs map[string]codec.NewCodec Registry registry.Registry @@ -105,7 +103,6 @@ func NewOptions(options ...Option) Options { }, PoolSize: DefaultPoolSize, PoolTTL: DefaultPoolTTL, - Auth: auth.DefaultAuth, Broker: broker.DefaultBroker, Selector: selector.DefaultSelector, Registry: registry.DefaultRegistry, @@ -126,13 +123,6 @@ func Broker(b broker.Broker) Option { } } -// Auth to be used when making a request -func Auth(a auth.Auth) Option { - return func(o *Options) { - o.Auth = a - } -} - // Codec to be used to encode/decode requests for a given content type func Codec(contentType string, c codec.NewCodec) Option { return func(o *Options) { diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 7cec8f99..c2476a7e 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -13,6 +13,7 @@ import ( "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" "github.com/micro/go-micro/v2/config" + configSrc "github.com/micro/go-micro/v2/config/source" configSrv "github.com/micro/go-micro/v2/config/source/service" "github.com/micro/go-micro/v2/debug/profile" "github.com/micro/go-micro/v2/debug/profile/http" @@ -500,7 +501,6 @@ func (c *cmd) Before(ctx *cli.Context) error { } *c.opts.Auth = a() - clientOpts = append(clientOpts, client.Auth(*c.opts.Auth)) serverOpts = append(serverOpts, server.Auth(*c.opts.Auth)) } @@ -716,7 +716,7 @@ func (c *cmd) Before(ctx *cli.Context) error { (*c.opts.Auth).Init(authOpts...) if ctx.String("config") == "service" { - opt := config.WithSource(configSrv.NewSource()) + opt := config.WithSource(configSrv.NewSource(configSrc.WithClient(*c.opts.Client))) if err := (*c.opts.Config).Init(opt); err != nil { logger.Fatalf("Error configuring config: %v", err) } diff --git a/config/source/options.go b/config/source/options.go index d4a2ba09..cd694a77 100644 --- a/config/source/options.go +++ b/config/source/options.go @@ -3,6 +3,7 @@ package source import ( "context" + "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/config/encoder" "github.com/micro/go-micro/v2/config/encoder/json" ) @@ -13,6 +14,9 @@ type Options struct { // for alternative data Context context.Context + + // Client to use for RPC + Client client.Client } type Option func(o *Options) @@ -21,6 +25,7 @@ func NewOptions(opts ...Option) Options { options := Options{ Encoder: json.NewEncoder(), Context: context.Background(), + Client: client.DefaultClient, } for _, o := range opts { @@ -36,3 +41,10 @@ func WithEncoder(e encoder.Encoder) Option { o.Encoder = e } } + +// WithClient sets the source client +func WithClient(c client.Client) Option { + return func(o *Options) { + o.Client = c + } +} diff --git a/config/source/service/service.go b/config/source/service/service.go index cc5499eb..9bacdf63 100644 --- a/config/source/service/service.go +++ b/config/source/service/service.go @@ -24,7 +24,7 @@ type service struct { } func (m *service) Read() (set *source.ChangeSet, err error) { - client := proto.NewConfigService(m.serviceName, client.DefaultClient) + client := proto.NewConfigService(m.serviceName, m.opts.Client) req, err := client.Read(context.Background(), &proto.ReadRequest{ Namespace: m.namespace, Path: m.path, @@ -37,7 +37,7 @@ func (m *service) Read() (set *source.ChangeSet, err error) { } func (m *service) Watch() (w source.Watcher, err error) { - client := proto.NewConfigService(m.serviceName, client.DefaultClient) + client := proto.NewConfigService(m.serviceName, m.opts.Client) stream, err := client.Watch(context.Background(), &proto.WatchRequest{ Namespace: m.namespace, Path: m.path, @@ -87,6 +87,10 @@ func NewSource(opts ...source.Option) source.Source { } } + if options.Client == nil { + options.Client = client.DefaultClient + } + s := &service{ serviceName: addr, opts: options, diff --git a/options.go b/options.go index b5e6372f..e807e496 100644 --- a/options.go +++ b/options.go @@ -155,7 +155,6 @@ func Tracer(t trace.Tracer) Option { func Auth(a auth.Auth) Option { return func(o *Options) { o.Auth = a - o.Client.Init(client.Auth(a)) o.Server.Init(server.Auth(a)) } } diff --git a/service.go b/service.go index 02c8ef6b..f3ba2086 100644 --- a/service.go +++ b/service.go @@ -115,7 +115,9 @@ func (s *service) Init(opts ...Option) { s.opts.Store.Init(store.Table(name)) // Set the client for the micro clients + s.opts.Auth.Init(auth.WithClient(s.Client())) s.opts.Runtime.Init(runtime.WithClient(s.Client())) + s.opts.Store.Init(store.WithClient(s.Client())) }) } diff --git a/store/options.go b/store/options.go index 27224731..d89cb766 100644 --- a/store/options.go +++ b/store/options.go @@ -3,6 +3,8 @@ package store import ( "context" "time" + + "github.com/micro/go-micro/v2/client" ) // Options contains configuration for the Store @@ -17,6 +19,8 @@ type Options struct { Table string // Context should contain all implementation specific options, using context.WithValue. Context context.Context + // Client to use for RPC + Client client.Client } // Option sets values in Options @@ -52,6 +56,13 @@ func WithContext(c context.Context) Option { } } +// WithClient sets the stores client to use for RPC +func WithClient(c client.Client) Option { + return func(o *Options) { + o.Client = c + } +} + // ReadOptions configures an individual Read operation type ReadOptions struct { Database, Table string diff --git a/store/service/service.go b/store/service/service.go index fbf04388..60adbb9e 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -219,12 +219,16 @@ func NewStore(opts ...store.Option) store.Store { o(&options) } + if options.Client == nil { + options.Client = client.DefaultClient + } + service := &serviceStore{ options: options, Database: options.Database, Table: options.Table, Nodes: options.Nodes, - Client: pb.NewStoreService("go.micro.store", client.DefaultClient), + Client: pb.NewStoreService("go.micro.store", options.Client), } return service From 937ecc8d2f0910dfd3565e22dea6bc3dae9d4010 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Mon, 11 May 2020 20:38:05 +0100 Subject: [PATCH 742/788] Disable auth service client --- service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service.go b/service.go index f3ba2086..00967ea6 100644 --- a/service.go +++ b/service.go @@ -115,7 +115,7 @@ func (s *service) Init(opts ...Option) { s.opts.Store.Init(store.Table(name)) // Set the client for the micro clients - s.opts.Auth.Init(auth.WithClient(s.Client())) + // s.opts.Auth.Init(auth.WithClient(s.Client())) s.opts.Runtime.Init(runtime.WithClient(s.Client())) s.opts.Store.Init(store.WithClient(s.Client())) }) From 19a03babc468d4ca9fd8aa7ef461537fd83b7e8a Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 12 May 2020 11:32:01 +0100 Subject: [PATCH 743/788] Update server.go --- server/server.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/server/server.go b/server/server.go index 21e05e9f..136ae6f9 100644 --- a/server/server.go +++ b/server/server.go @@ -16,14 +16,23 @@ import ( // Server is a simple micro server abstraction type Server interface { - Options() Options + // Initialise options Init(...Option) error + // Retrieve the options + Options() Options + // Register a handler Handle(Handler) error + // Create a new handler NewHandler(interface{}, ...HandlerOption) Handler + // Create a new subscriber NewSubscriber(string, interface{}, ...SubscriberOption) Subscriber + // Register a subscriber Subscribe(Subscriber) error + // Start the server Start() error + // Stop the server Stop() error + // Server implementation String() string } @@ -116,7 +125,8 @@ type Handler interface { } // Subscriber interface represents a subscription to a given topic using -// a specific subscriber function or object with endpoints. +// a specific subscriber function or object with endpoints. It mirrors +// the handler in its behaviour. type Subscriber interface { Topic() string Subscriber() interface{} From 66d3e4a595efc78383636f64e81a264383e9f10b Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 12 May 2020 11:40:54 +0100 Subject: [PATCH 744/788] Fix k8s secret template (yaml) --- util/kubernetes/client/templates.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index 9c2851c8..5e5721d3 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -139,11 +139,11 @@ metadata: {{- end }} {{- end }} data: -{{- with .Data }} -{{- range $key, $value := . }} -{{ $key }}: "{{ $value }}" -{{- end }} -{{- end }} + {{- with .Data }} + {{- range $key, $value := . }} + {{ $key }}: "{{ $value }}" + {{- end }} + {{- end }} ` var serviceAccountTmpl = ` From e0863bb7eb5557a90fe6afd6cee66cfb2d30e6df Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 12 May 2020 14:10:39 +0100 Subject: [PATCH 745/788] K8s: Add Secret Type to yaml template --- util/kubernetes/client/templates.go | 1 + 1 file changed, 1 insertion(+) diff --git a/util/kubernetes/client/templates.go b/util/kubernetes/client/templates.go index 5e5721d3..ce0e3b0e 100644 --- a/util/kubernetes/client/templates.go +++ b/util/kubernetes/client/templates.go @@ -129,6 +129,7 @@ metadata: var secretTmpl = ` apiVersion: v1 kind: Secret +type: "{{ .Type }}" metadata: name: "{{ .Metadata.Name }}" namespace: "{{ .Metadata.Namespace }}" From d39b723511b4623275cdb680add11b165fc518c4 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 12 May 2020 16:41:29 +0100 Subject: [PATCH 746/788] Auth Namespace Flag --- config/cmd/cmd.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index c2476a7e..1dfd87c5 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -271,6 +271,11 @@ var ( EnvVars: []string{"MICRO_AUTH_SECRET"}, Usage: "Account secret used for client authentication", }, + &cli.StringFlag{ + Name: "auth_namespace", + EnvVars: []string{"MICRO_AUTH_NAMESPACE"}, + Usage: "Namespace for the services auth account", + }, &cli.StringFlag{ Name: "auth_public_key", EnvVars: []string{"MICRO_AUTH_PUBLIC_KEY"}, @@ -681,6 +686,10 @@ func (c *cmd) Before(ctx *cli.Context) error { )) } + if len(ctx.String("auth_namespace")) > 0 { + authOpts = append(authOpts, auth.Namespace(ctx.String("auth_namespace"))) + } + if len(ctx.String("auth_public_key")) > 0 { authOpts = append(authOpts, auth.PublicKey(ctx.String("auth_public_key"))) } From 116cc1e9eef608bcb9504bad2662c9fd71d80df8 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 12 May 2020 17:38:22 +0100 Subject: [PATCH 747/788] Stop parsing proxy address (#1619) --- util/net/net.go | 15 +++++++++------ util/net/net_test.go | 1 - 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/util/net/net.go b/util/net/net.go index 00230647..02d6ad2f 100644 --- a/util/net/net.go +++ b/util/net/net.go @@ -83,20 +83,23 @@ func Listen(addr string, fn func(string) (net.Listener, error)) (net.Listener, e func Proxy(service string, address []string) (string, []string, bool) { var hasProxy bool - // get proxy + // get proxy. we parse out address if present if prx := os.Getenv("MICRO_PROXY"); len(prx) > 0 { // default name if prx == "service" { prx = "go.micro.proxy" + address = nil } + + // check if its an address + if v := strings.Split(prx, ":"); len(v) > 1 { + address = []string{prx} + } + service = prx hasProxy = true - } - // get proxy address - if prx := os.Getenv("MICRO_PROXY_ADDRESS"); len(prx) > 0 { - address = []string{prx} - hasProxy = true + return service, address, hasProxy } if prx := os.Getenv("MICRO_NETWORK"); len(prx) > 0 { diff --git a/util/net/net_test.go b/util/net/net_test.go index 85688c36..28d490d4 100644 --- a/util/net/net_test.go +++ b/util/net/net_test.go @@ -57,7 +57,6 @@ func TestProxyEnv(t *testing.T) { } test("MICRO_PROXY", "service", "go.micro.proxy", "") - test("MICRO_PROXY_ADDRESS", "10.0.0.1:8080", "", "10.0.0.1:8080") test("MICRO_NETWORK", "service", "go.micro.network", "") test("MICRO_NETWORK_ADDRESS", "10.0.0.1:8081", "", "10.0.0.1:8081") } From 346e034d0a55560fc52238c81a94181bc80de45b Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 10:40:08 +0100 Subject: [PATCH 748/788] Add mutli-tenancy support to the registry --- registry/service/util.go | 46 +++++++++++++++++++++++++++++++++++++--- util/wrapper/wrapper.go | 4 +++- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/registry/service/util.go b/registry/service/util.go index 4ba5f4da..3d6c681d 100644 --- a/registry/service/util.go +++ b/registry/service/util.go @@ -1,6 +1,8 @@ package service import ( + "strings" + "github.com/micro/go-micro/v2/registry" pb "github.com/micro/go-micro/v2/registry/service/proto" ) @@ -37,6 +39,10 @@ func toValues(v []*pb.Value) []*registry.Value { return vs } +// NameSeperator is the string which is used as a seperator when joinin +// namespace to the service name +const NameSeperator = "/" + func ToProto(s *registry.Service) *pb.Service { endpoints := make([]*pb.Endpoint, 0, len(s.Endpoints)) for _, ep := range s.Endpoints { @@ -76,8 +82,14 @@ func ToProto(s *registry.Service) *pb.Service { }) } + // the service name will contain the namespace, e.g. + // 'default/go.micro.service.foo'. Remove the namespace + // using the following: + comps := strings.Split(s.Name, NameSeperator) + name := comps[len(comps)-1] + return &pb.Service{ - Name: s.Name, + Name: name, Version: s.Version, Metadata: s.Metadata, Endpoints: endpoints, @@ -86,7 +98,12 @@ func ToProto(s *registry.Service) *pb.Service { } } -func ToService(s *pb.Service) *registry.Service { +func ToService(s *pb.Service, opts ...Option) *registry.Service { + var options Options + for _, o := range opts { + o(&options) + } + endpoints := make([]*registry.Endpoint, 0, len(s.Endpoints)) for _, ep := range s.Endpoints { var request, response *registry.Value @@ -124,11 +141,34 @@ func ToService(s *pb.Service) *registry.Service { }) } + // add the namespace to the name + var name string + if len(options.Namespace) > 0 { + name = strings.Join([]string{options.Namespace, s.Name}, NameSeperator) + } else { + name = s.Name + } + return ®istry.Service{ - Name: s.Name, + Name: name, Version: s.Version, Metadata: s.Metadata, Endpoints: endpoints, Nodes: nodes, } } + +// Options for marshaling / unmarshaling services +type Options struct { + Namespace string +} + +// Option is a function which sets options +type Option func(o *Options) + +// WithNamespace sets the namespace option +func WithNamespace(ns string) Option { + return func(o *Options) { + o.Namespace = ns + } +} diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index ee569ef2..dba8d274 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -276,7 +276,9 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper { } // There is an account, set it in the context - ctx = auth.ContextWithAccount(ctx, account) + if len(account.ID) > 0 { + ctx = auth.ContextWithAccount(ctx, account) + } // The user is authorised, allow the call return h(ctx, req, rsp) From 0fb4734e67e47fb0b6e0402321a5f8d05108f2c4 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Wed, 13 May 2020 12:07:53 +0200 Subject: [PATCH 749/788] Upload local source code to micro server (#1613) --- runtime/default.go | 98 +++++++++++++++++++++++++++ util/file/client.go | 17 +++-- util/file/handler.go | 6 +- util/file/proto/file.pb.go | 134 ++++++++++++++++++++----------------- util/file/proto/file.proto | 1 + 5 files changed, 186 insertions(+), 70 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index bd783f50..fa75ec8f 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -1,6 +1,8 @@ package runtime import ( + "archive/tar" + "compress/gzip" "errors" "fmt" "io" @@ -60,6 +62,25 @@ func (r *runtime) checkoutSourceIfNeeded(s *Service) error { if len(s.Source) == 0 { return nil } + // @todo make this come from config + cpath := filepath.Join(os.TempDir(), "micro", "uploads", s.Source) + path := strings.ReplaceAll(cpath, ".tar.gz", "") + if ex, _ := exists(cpath); ex { + err := os.RemoveAll(path) + if err != nil { + return err + } + err = os.MkdirAll(path, 0777) + if err != nil { + return err + } + err = uncompress(cpath, path) + if err != nil { + return err + } + s.Source = path + return nil + } source, err := git.ParseSourceLocal("", s.Source) if err != nil { return err @@ -74,6 +95,83 @@ func (r *runtime) checkoutSourceIfNeeded(s *Service) error { return nil } +// modified version of: https://gist.github.com/mimoo/25fc9716e0f1353791f5908f94d6e726 +func uncompress(src string, dst string) error { + file, err := os.OpenFile(src, os.O_RDWR|os.O_CREATE, 0666) + defer file.Close() + if err != nil { + return err + } + // ungzip + zr, err := gzip.NewReader(file) + if err != nil { + return err + } + // untar + tr := tar.NewReader(zr) + + // uncompress each element + for { + header, err := tr.Next() + if err == io.EOF { + break // End of archive + } + if err != nil { + return err + } + target := header.Name + + // validate name against path traversal + if !validRelPath(header.Name) { + return fmt.Errorf("tar contained invalid name error %q\n", target) + } + + // add dst + re-format slashes according to system + target = filepath.Join(dst, header.Name) + // if no join is needed, replace with ToSlash: + // target = filepath.ToSlash(header.Name) + + // check the type + switch header.Typeflag { + + // if its a dir and it doesn't exist create it (with 0755 permission) + case tar.TypeDir: + if _, err := os.Stat(target); err != nil { + // @todo think about this: + // if we don't nuke the folder, we might end up with files from + // the previous decompress. + if err := os.MkdirAll(target, 0755); err != nil { + return err + } + } + // if it's a file create it (with same permission) + case tar.TypeReg: + // the truncating is probably unnecessary due to the `RemoveAll` of folders + // above + fileToWrite, err := os.OpenFile(target, os.O_TRUNC|os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode)) + if err != nil { + return err + } + // copy over contents + if _, err := io.Copy(fileToWrite, tr); err != nil { + return err + } + // manually close here after each file operation; defering would cause each file close + // to wait until all operations have completed. + fileToWrite.Close() + } + } + return nil +} + +// check for path traversal and correct forward slashes +func validRelPath(p string) bool { + if p == "" || strings.Contains(p, `\`) || strings.HasPrefix(p, "/") || strings.Contains(p, "../") { + return false + } + return true +} + // Init initializes runtime options func (r *runtime) Init(opts ...Option) error { r.Lock() diff --git a/util/file/client.go b/util/file/client.go index ad09c42f..a25739b9 100644 --- a/util/file/client.go +++ b/util/file/client.go @@ -14,8 +14,8 @@ import ( ) // Client is the client interface to access files -type Client interface { - Open(filename string) (int64, error) +type File interface { + Open(filename string, truncate bool) (int64, error) Stat(filename string) (*proto.StatResponse, error) GetBlock(sessionId, blockId int64) ([]byte, error) ReadAt(sessionId, offset, size int64) ([]byte, error) @@ -28,7 +28,7 @@ type Client interface { } // NewClient returns a new Client which uses a micro Client -func NewClient(service string, c client.Client) Client { +func New(service string, c client.Client) File { return &fc{proto.NewFileService(service, c)} } @@ -40,8 +40,11 @@ type fc struct { c proto.FileService } -func (c *fc) Open(filename string) (int64, error) { - rsp, err := c.c.Open(context.TODO(), &proto.OpenRequest{Filename: filename}) +func (c *fc) Open(filename string, truncate bool) (int64, error) { + rsp, err := c.c.Open(context.TODO(), &proto.OpenRequest{ + Filename: filename, + Truncate: truncate, + }) if err != nil { return 0, err } @@ -111,7 +114,7 @@ func (c *fc) Upload(filename, localFile string) error { defer file.Close() offset := 0 - sessionId, err := c.Open(filename) + sessionId, err := c.Open(filename, true) defer c.Close(sessionId) if err != nil { return err @@ -158,7 +161,7 @@ func (c *fc) DownloadAt(filename, saveFile string, blockId int) error { } defer file.Close() - sessionId, err := c.Open(filename) + sessionId, err := c.Open(filename, false) if err != nil { return err } diff --git a/util/file/handler.go b/util/file/handler.go index e01f723b..f68890c5 100644 --- a/util/file/handler.go +++ b/util/file/handler.go @@ -35,7 +35,11 @@ type handler struct { func (h *handler) Open(ctx context.Context, req *proto.OpenRequest, rsp *proto.OpenResponse) error { path := filepath.Join(h.readDir, req.Filename) - file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0666) + flags := os.O_CREATE | os.O_RDWR + if req.GetTruncate() { + flags = flags | os.O_TRUNC + } + file, err := os.OpenFile(path, flags, 0666) if err != nil { return errors.InternalServerError("go.micro.server", err.Error()) } diff --git a/util/file/proto/file.pb.go b/util/file/proto/file.pb.go index 227669d4..3e2e7799 100644 --- a/util/file/proto/file.pb.go +++ b/util/file/proto/file.pb.go @@ -31,6 +31,7 @@ type OpenRequest struct { unknownFields protoimpl.UnknownFields Filename string `protobuf:"bytes,1,opt,name=filename,proto3" json:"filename,omitempty"` + Truncate bool `protobuf:"varint,2,opt,name=truncate,proto3" json:"truncate,omitempty"` } func (x *OpenRequest) Reset() { @@ -72,6 +73,13 @@ func (x *OpenRequest) GetFilename() string { return "" } +func (x *OpenRequest) GetTruncate() bool { + if x != nil { + return x.Truncate + } + return false +} + type OpenResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -673,72 +681,74 @@ var file_micro_go_micro_util_file_proto_file_proto_rawDesc = []byte{ 0x0a, 0x29, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2f, 0x67, 0x6f, 0x2d, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2f, 0x75, 0x74, 0x69, 0x6c, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x67, 0x6f, 0x2e, - 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x22, 0x29, 0x0a, 0x0b, + 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x22, 0x45, 0x0a, 0x0b, 0x4f, 0x70, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, - 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x36, 0x0a, 0x0c, 0x4f, 0x70, 0x65, 0x6e, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, - 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, - 0x1e, 0x0a, 0x0c, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, - 0x0f, 0x0a, 0x0d, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x29, 0x0a, 0x0b, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x1a, 0x0a, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x5b, 0x0a, 0x0c, 0x53, - 0x74, 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, - 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, - 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, - 0x69, 0x7a, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x6f, 0x64, 0x69, - 0x66, 0x69, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x6c, 0x61, 0x73, 0x74, - 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x22, 0x49, 0x0a, 0x0b, 0x52, 0x65, 0x61, 0x64, + 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x72, 0x75, 0x6e, 0x63, + 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x74, 0x72, 0x75, 0x6e, 0x63, + 0x61, 0x74, 0x65, 0x22, 0x36, 0x0a, 0x0c, 0x4f, 0x70, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x1e, 0x0a, 0x0c, 0x43, + 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, 0x0f, 0x0a, 0x0d, 0x43, + 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x29, 0x0a, 0x0b, + 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x66, + 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, + 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x5b, 0x0a, 0x0c, 0x53, 0x74, 0x61, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, + 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x12, + 0x23, 0x0a, 0x0d, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x6c, 0x61, 0x73, 0x74, 0x4d, 0x6f, 0x64, 0x69, + 0x66, 0x69, 0x65, 0x64, 0x22, 0x49, 0x0a, 0x0b, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x73, + 0x69, 0x7a, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x22, + 0x48, 0x0a, 0x0c, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, + 0x69, 0x7a, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6f, 0x66, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x65, 0x6f, 0x66, 0x22, 0x37, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, - 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, - 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, - 0x69, 0x7a, 0x65, 0x22, 0x48, 0x0a, 0x0c, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x03, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x65, - 0x6f, 0x66, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x65, 0x6f, 0x66, 0x22, 0x37, 0x0a, - 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x62, - 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x62, - 0x6c, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x22, 0x50, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x49, 0x64, - 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, - 0x73, 0x69, 0x7a, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x4a, 0x0a, 0x0c, 0x57, 0x72, 0x69, 0x74, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, - 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, + 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x49, 0x64, 0x22, 0x50, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x19, 0x0a, 0x08, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x07, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, + 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, - 0x64, 0x61, 0x74, 0x61, 0x22, 0x0f, 0x0a, 0x0d, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xef, 0x02, 0x0a, 0x04, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x45, - 0x0a, 0x04, 0x4f, 0x70, 0x65, 0x6e, 0x12, 0x1c, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, - 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x4f, 0x70, 0x65, 0x6e, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, - 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x4f, 0x70, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x04, 0x53, 0x74, 0x61, 0x74, 0x12, 0x1c, 0x2e, - 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, - 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x67, 0x6f, - 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x53, 0x74, - 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x04, - 0x52, 0x65, 0x61, 0x64, 0x12, 0x1c, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, - 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, - 0x72, 0x76, 0x65, 0x72, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x05, 0x57, 0x72, 0x69, 0x74, 0x65, 0x12, 0x1d, 0x2e, 0x67, - 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x57, - 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x67, 0x6f, - 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x57, 0x72, - 0x69, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x48, 0x0a, - 0x05, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, - 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, - 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x61, 0x74, 0x61, 0x22, 0x4a, 0x0a, 0x0c, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x12, 0x0a, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x22, 0x0f, 0x0a, 0x0d, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x32, 0xef, 0x02, 0x0a, 0x04, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x45, 0x0a, 0x04, 0x4f, 0x70, + 0x65, 0x6e, 0x12, 0x1c, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x2e, 0x4f, 0x70, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1d, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x72, 0x2e, 0x4f, 0x70, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x45, 0x0a, 0x04, 0x53, 0x74, 0x61, 0x74, 0x12, 0x1c, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, + 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x53, 0x74, 0x61, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, + 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x04, 0x52, 0x65, 0x61, 0x64, + 0x12, 0x1c, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x72, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, + 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, + 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, + 0x48, 0x0a, 0x05, 0x57, 0x72, 0x69, 0x74, 0x65, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, + 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, + 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x05, 0x43, 0x6c, 0x6f, + 0x73, 0x65, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x1e, 0x2e, 0x67, 0x6f, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2e, 0x73, 0x65, 0x72, + 0x76, 0x65, 0x72, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/util/file/proto/file.proto b/util/file/proto/file.proto index b1cb025b..01395f2c 100644 --- a/util/file/proto/file.proto +++ b/util/file/proto/file.proto @@ -12,6 +12,7 @@ service File { message OpenRequest { string filename = 1; + bool truncate = 2; } message OpenResponse { From 54951740bfb4997a6851da9180bb3d0660af8049 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 13:13:11 +0100 Subject: [PATCH 750/788] Authenticate on service start --- registry/service/options.go | 21 +++++++++++++++ registry/service/service.go | 53 +++++++++++++++++++++++-------------- service.go | 44 +++++++++++++++++++++++++++++- util/wrapper/wrapper.go | 38 ++------------------------ 4 files changed, 99 insertions(+), 57 deletions(-) create mode 100644 registry/service/options.go diff --git a/registry/service/options.go b/registry/service/options.go new file mode 100644 index 00000000..fd251d77 --- /dev/null +++ b/registry/service/options.go @@ -0,0 +1,21 @@ +package service + +import ( + "context" + + "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/registry" +) + +type clientKey struct{} + +// WithClient sets the RPC client +func WithClient(c client.Client) registry.Option { + return func(o *registry.Options) { + if o.Context == nil { + o.Context = context.Background() + } + + o.Context = context.WithValue(o.Context, clientKey{}, c) + } +} diff --git a/registry/service/service.go b/registry/service/service.go index acf42d3a..9e2829f4 100644 --- a/registry/service/service.go +++ b/registry/service/service.go @@ -22,8 +22,8 @@ type serviceRegistry struct { name string // address address []string - // client to call registry - client pb.RegistryService + // registry is the proto client + registry pb.RegistryService } func (s *serviceRegistry) callOpts() []client.CallOption { @@ -46,6 +46,17 @@ func (s *serviceRegistry) Init(opts ...registry.Option) error { for _, o := range opts { o(&s.opts) } + + // extract the client from the context, fallback to grpc + var cli client.Client + if c, ok := s.opts.Context.Value(clientKey{}).(client.Client); ok { + cli = c + } else { + cli = grpc.NewClient() + } + + s.registry = pb.NewRegistryService(DefaultService, cli) + return nil } @@ -67,7 +78,7 @@ func (s *serviceRegistry) Register(srv *registry.Service, opts ...registry.Regis pbSrv.Options.Ttl = int64(options.TTL.Seconds()) // register the service - _, err := s.client.Register(options.Context, pbSrv, s.callOpts()...) + _, err := s.registry.Register(options.Context, pbSrv, s.callOpts()...) if err != nil { return err } @@ -85,7 +96,7 @@ func (s *serviceRegistry) Deregister(srv *registry.Service, opts ...registry.Der } // deregister the service - _, err := s.client.Deregister(options.Context, ToProto(srv), s.callOpts()...) + _, err := s.registry.Deregister(options.Context, ToProto(srv), s.callOpts()...) if err != nil { return err } @@ -101,7 +112,7 @@ func (s *serviceRegistry) GetService(name string, opts ...registry.GetOption) ([ options.Context = context.TODO() } - rsp, err := s.client.GetService(options.Context, &pb.GetRequest{ + rsp, err := s.registry.GetService(options.Context, &pb.GetRequest{ Service: name, }, s.callOpts()...) @@ -125,7 +136,7 @@ func (s *serviceRegistry) ListServices(opts ...registry.ListOption) ([]*registry options.Context = context.TODO() } - rsp, err := s.client.ListServices(options.Context, &pb.ListRequest{}, s.callOpts()...) + rsp, err := s.registry.ListServices(options.Context, &pb.ListRequest{}, s.callOpts()...) if err != nil { return nil, err } @@ -147,7 +158,7 @@ func (s *serviceRegistry) Watch(opts ...registry.WatchOption) (registry.Watcher, options.Context = context.TODO() } - stream, err := s.client.Watch(options.Context, &pb.WatchRequest{ + stream, err := s.registry.Watch(options.Context, &pb.WatchRequest{ Service: options.Service, }, s.callOpts()...) @@ -171,27 +182,29 @@ func NewRegistry(opts ...registry.Option) registry.Registry { // the registry address addrs := options.Addrs - if len(addrs) == 0 { addrs = []string{"127.0.0.1:8000"} } - // use mdns as a fall back in case its used - mReg := registry.NewRegistry() + if options.Context == nil { + options.Context = context.TODO() + } - // create new client with mdns - cli := grpc.NewClient( - client.Registry(mReg), - ) + // extract the client from the context, fallback to grpc + var cli client.Client + if c, ok := options.Context.Value(clientKey{}).(client.Client); ok { + cli = c + } else { + cli = grpc.NewClient() + } - // service name - // TODO: accept option + // service name. TODO: accept option name := DefaultService return &serviceRegistry{ - opts: options, - name: name, - address: addrs, - client: pb.NewRegistryService(name, cli), + opts: options, + name: name, + address: addrs, + registry: pb.NewRegistryService(name, cli), } } diff --git a/service.go b/service.go index 00967ea6..2a330870 100644 --- a/service.go +++ b/service.go @@ -1,6 +1,7 @@ package micro import ( + "fmt" "os" "os/signal" rtime "runtime" @@ -15,6 +16,7 @@ import ( "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/plugin" + srvRegistry "github.com/micro/go-micro/v2/registry/service" "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/store" @@ -115,7 +117,8 @@ func (s *service) Init(opts ...Option) { s.opts.Store.Init(store.Table(name)) // Set the client for the micro clients - // s.opts.Auth.Init(auth.WithClient(s.Client())) + s.opts.Auth.Init(auth.WithClient(s.Client())) + s.opts.Registry.Init(srvRegistry.WithClient(s.Client())) s.opts.Runtime.Init(runtime.WithClient(s.Client())) s.opts.Store.Init(store.WithClient(s.Client())) }) @@ -205,6 +208,11 @@ func (s *service) Run() error { logger.Infof("Starting [service] %s", s.Name()) } + // generate an auth account + if err := s.registerAuthAccount(); err != nil { + return err + } + if err := s.Start(); err != nil { return err } @@ -223,3 +231,37 @@ func (s *service) Run() error { return s.Stop() } + +func (s *service) registerAuthAccount() error { + // determine the type of service from the name. we do this so we can allocate + // different roles depending on the type of services. e.g. we don't want web + // services talking directly to the runtime. TODO: find a better way to determine + // the type of service + serviceType := "service" + if strings.Contains(s.Name(), "api") { + serviceType = "api" + } else if strings.Contains(s.Name(), "web") { + serviceType = "web" + } + + // generate a new auth account for the service + name := fmt.Sprintf("%v-%v", s.Name(), s.Server().Options().Id) + opts := []auth.GenerateOption{ + auth.WithRoles(serviceType), + auth.WithNamespace(s.Options().Auth.Options().Namespace), + } + acc, err := s.Options().Auth.Generate(name, opts...) + if err != nil { + return err + } + + // generate a token + token, err := s.Options().Auth.Token(auth.WithCredentials(acc.ID, acc.Secret)) + if err != nil { + return err + } + s.Options().Auth.Init(auth.ClientToken(token)) + + logger.Infof("Auth [%v] Authenticated as %v", s.Options().Auth, name) + return nil +} diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index dba8d274..8dde56f0 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -2,7 +2,6 @@ package wrapper import ( "context" - "fmt" "strings" "time" @@ -182,47 +181,14 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac return callWithToken(tok.AccessToken) } - // if we have credentials we can generate a new token for the account - if len(aaOpts.ID) > 0 && len(aaOpts.Secret) > 0 { - tok, err := aa.Token(auth.WithCredentials(aaOpts.ID, aaOpts.Secret)) - if err != nil { - return err - } - aa.Init(auth.ClientToken(tok)) - return callWithToken(tok.AccessToken) - } - // check to see if a token was provided in config, this is normally used for // setting the token when calling via the cli if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 { return callWithToken(token) } - // determine the type of service from the name. we do this so we can allocate - // different roles depending on the type of services. e.g. we don't want web - // services talking directly to the runtime. TODO: find a better way to determine - // the type of service - serviceType := "service" - if strings.Contains(a.name, "api") { - serviceType = "api" - } else if strings.Contains(a.name, "web") { - serviceType = "web" - } - - // generate a new auth account for the service - name := fmt.Sprintf("%v-%v", a.name, a.id) - acc, err := aa.Generate(name, auth.WithNamespace(aaOpts.Namespace), auth.WithRoles(serviceType)) - if err != nil { - return err - } - token, err := aa.Token(auth.WithCredentials(acc.ID, acc.Secret)) - if err != nil { - return err - } - aa.Init(auth.ClientToken(token)) - - // use the token to execute the request - return callWithToken(token.AccessToken) + // call without an auth token + return a.Client.Call(ctx, req, rsp, opts...) } // AuthClient wraps requests with the auth header From d781c9ae2d3ac9ed6bd3868a38d70a87e44e4e75 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 13:35:34 +0100 Subject: [PATCH 751/788] Remove namespace specific logic --- registry/service/util.go | 46 +++------------------------------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/registry/service/util.go b/registry/service/util.go index 3d6c681d..4ba5f4da 100644 --- a/registry/service/util.go +++ b/registry/service/util.go @@ -1,8 +1,6 @@ package service import ( - "strings" - "github.com/micro/go-micro/v2/registry" pb "github.com/micro/go-micro/v2/registry/service/proto" ) @@ -39,10 +37,6 @@ func toValues(v []*pb.Value) []*registry.Value { return vs } -// NameSeperator is the string which is used as a seperator when joinin -// namespace to the service name -const NameSeperator = "/" - func ToProto(s *registry.Service) *pb.Service { endpoints := make([]*pb.Endpoint, 0, len(s.Endpoints)) for _, ep := range s.Endpoints { @@ -82,14 +76,8 @@ func ToProto(s *registry.Service) *pb.Service { }) } - // the service name will contain the namespace, e.g. - // 'default/go.micro.service.foo'. Remove the namespace - // using the following: - comps := strings.Split(s.Name, NameSeperator) - name := comps[len(comps)-1] - return &pb.Service{ - Name: name, + Name: s.Name, Version: s.Version, Metadata: s.Metadata, Endpoints: endpoints, @@ -98,12 +86,7 @@ func ToProto(s *registry.Service) *pb.Service { } } -func ToService(s *pb.Service, opts ...Option) *registry.Service { - var options Options - for _, o := range opts { - o(&options) - } - +func ToService(s *pb.Service) *registry.Service { endpoints := make([]*registry.Endpoint, 0, len(s.Endpoints)) for _, ep := range s.Endpoints { var request, response *registry.Value @@ -141,34 +124,11 @@ func ToService(s *pb.Service, opts ...Option) *registry.Service { }) } - // add the namespace to the name - var name string - if len(options.Namespace) > 0 { - name = strings.Join([]string{options.Namespace, s.Name}, NameSeperator) - } else { - name = s.Name - } - return ®istry.Service{ - Name: name, + Name: s.Name, Version: s.Version, Metadata: s.Metadata, Endpoints: endpoints, Nodes: nodes, } } - -// Options for marshaling / unmarshaling services -type Options struct { - Namespace string -} - -// Option is a function which sets options -type Option func(o *Options) - -// WithNamespace sets the namespace option -func WithNamespace(ns string) Option { - return func(o *Options) { - o.Namespace = ns - } -} From 25c937fd0edf9e2ff5c4c1779dcfc09628809163 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 13:38:13 +0100 Subject: [PATCH 752/788] Naming changes --- registry/service/service.go | 24 ++++++++++++------------ service.go | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/registry/service/service.go b/registry/service/service.go index 9e2829f4..ddf6fd00 100644 --- a/registry/service/service.go +++ b/registry/service/service.go @@ -22,8 +22,8 @@ type serviceRegistry struct { name string // address address []string - // registry is the proto client - registry pb.RegistryService + // client to call registry + client pb.RegistryService } func (s *serviceRegistry) callOpts() []client.CallOption { @@ -55,7 +55,7 @@ func (s *serviceRegistry) Init(opts ...registry.Option) error { cli = grpc.NewClient() } - s.registry = pb.NewRegistryService(DefaultService, cli) + s.client = pb.NewRegistryService(DefaultService, cli) return nil } @@ -78,7 +78,7 @@ func (s *serviceRegistry) Register(srv *registry.Service, opts ...registry.Regis pbSrv.Options.Ttl = int64(options.TTL.Seconds()) // register the service - _, err := s.registry.Register(options.Context, pbSrv, s.callOpts()...) + _, err := s.client.Register(options.Context, pbSrv, s.callOpts()...) if err != nil { return err } @@ -96,7 +96,7 @@ func (s *serviceRegistry) Deregister(srv *registry.Service, opts ...registry.Der } // deregister the service - _, err := s.registry.Deregister(options.Context, ToProto(srv), s.callOpts()...) + _, err := s.client.Deregister(options.Context, ToProto(srv), s.callOpts()...) if err != nil { return err } @@ -112,7 +112,7 @@ func (s *serviceRegistry) GetService(name string, opts ...registry.GetOption) ([ options.Context = context.TODO() } - rsp, err := s.registry.GetService(options.Context, &pb.GetRequest{ + rsp, err := s.client.GetService(options.Context, &pb.GetRequest{ Service: name, }, s.callOpts()...) @@ -136,7 +136,7 @@ func (s *serviceRegistry) ListServices(opts ...registry.ListOption) ([]*registry options.Context = context.TODO() } - rsp, err := s.registry.ListServices(options.Context, &pb.ListRequest{}, s.callOpts()...) + rsp, err := s.client.ListServices(options.Context, &pb.ListRequest{}, s.callOpts()...) if err != nil { return nil, err } @@ -158,7 +158,7 @@ func (s *serviceRegistry) Watch(opts ...registry.WatchOption) (registry.Watcher, options.Context = context.TODO() } - stream, err := s.registry.Watch(options.Context, &pb.WatchRequest{ + stream, err := s.client.Watch(options.Context, &pb.WatchRequest{ Service: options.Service, }, s.callOpts()...) @@ -202,9 +202,9 @@ func NewRegistry(opts ...registry.Option) registry.Registry { name := DefaultService return &serviceRegistry{ - opts: options, - name: name, - address: addrs, - registry: pb.NewRegistryService(name, cli), + opts: options, + name: name, + address: addrs, + client: pb.NewRegistryService(name, cli), } } diff --git a/service.go b/service.go index 2a330870..c1458810 100644 --- a/service.go +++ b/service.go @@ -16,7 +16,7 @@ import ( "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/plugin" - srvRegistry "github.com/micro/go-micro/v2/registry/service" + registrySrv "github.com/micro/go-micro/v2/registry/service" "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/store" @@ -118,7 +118,7 @@ func (s *service) Init(opts ...Option) { // Set the client for the micro clients s.opts.Auth.Init(auth.WithClient(s.Client())) - s.opts.Registry.Init(srvRegistry.WithClient(s.Client())) + s.opts.Registry.Init(registrySrv.WithClient(s.Client())) s.opts.Runtime.Init(runtime.WithClient(s.Client())) s.opts.Store.Init(store.WithClient(s.Client())) }) From 3fac7d79ab317081961a7ec64eea26e8b3c6d778 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 13:42:56 +0100 Subject: [PATCH 753/788] Remove service type role --- service.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/service.go b/service.go index c1458810..17b614d1 100644 --- a/service.go +++ b/service.go @@ -233,21 +233,11 @@ func (s *service) Run() error { } func (s *service) registerAuthAccount() error { - // determine the type of service from the name. we do this so we can allocate - // different roles depending on the type of services. e.g. we don't want web - // services talking directly to the runtime. TODO: find a better way to determine - // the type of service - serviceType := "service" - if strings.Contains(s.Name(), "api") { - serviceType = "api" - } else if strings.Contains(s.Name(), "web") { - serviceType = "web" - } - // generate a new auth account for the service name := fmt.Sprintf("%v-%v", s.Name(), s.Server().Options().Id) opts := []auth.GenerateOption{ - auth.WithRoles(serviceType), + auth.WithType("service"), + auth.WithRoles("service"), auth.WithNamespace(s.Options().Auth.Options().Namespace), } acc, err := s.Options().Auth.Generate(name, opts...) From 47c1cb433e3c2728288a48e5480ba86662d6579f Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 13:48:25 +0100 Subject: [PATCH 754/788] Store account credentials --- service.go | 2 +- util/wrapper/wrapper.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/service.go b/service.go index 17b614d1..75de60fa 100644 --- a/service.go +++ b/service.go @@ -250,8 +250,8 @@ func (s *service) registerAuthAccount() error { if err != nil { return err } - s.Options().Auth.Init(auth.ClientToken(token)) + s.Options().Auth.Init(auth.ClientToken(token), auth.Credentials(acc.ID, acc.Secret)) logger.Infof("Auth [%v] Authenticated as %v", s.Options().Auth, name) return nil } diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 8dde56f0..285a775f 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -181,6 +181,16 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac return callWithToken(tok.AccessToken) } + // generate a new token if we have credentials + if len(aaOpts.ID) > 0 && len(aaOpts.Secret) > 0 { + tok, err := aa.Token(auth.WithCredentials(aaOpts.ID, aaOpts.Secret)) + if err != nil { + return err + } + aa.Init(auth.ClientToken(tok)) + return callWithToken(tok.AccessToken) + } + // check to see if a token was provided in config, this is normally used for // setting the token when calling via the cli if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 { From af2db0a0d9a6ffbcea295c0dfd9c27133ca8856a Mon Sep 17 00:00:00 2001 From: x1nchen Date: Wed, 13 May 2020 22:00:13 +0800 Subject: [PATCH 755/788] fix: update dependency certmagic (#1625) module github.com/mholt/certmagic has been renamed github.com/caddyserver/certmagic, so upgrade on this module will fail. fix: micro/micro#835 caddyserver/certmagic@v0.10.6 is Maximum upgradeable version with go version 1.13 Higher version use *tls.ClientHelloInfo.SupportsCertificate which only supported in go 1.14 --- api/server/acme/certmagic/certmagic.go | 13 +++++++------ api/server/acme/certmagic/storage.go | 2 +- go.mod | 4 ++-- go.sum | 14 +++++++++----- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/api/server/acme/certmagic/certmagic.go b/api/server/acme/certmagic/certmagic.go index e9daf62e..678add5e 100644 --- a/api/server/acme/certmagic/certmagic.go +++ b/api/server/acme/certmagic/certmagic.go @@ -1,4 +1,4 @@ -// Package certmagic is the ACME provider from github.com/mholt/certmagic +// Package certmagic is the ACME provider from github.com/caddyserver/certmagic package certmagic import ( @@ -7,7 +7,7 @@ import ( "net" "time" - "github.com/mholt/certmagic" + "github.com/caddyserver/certmagic" "github.com/micro/go-micro/v2/api/server/acme" "github.com/micro/go-micro/v2/logger" ) @@ -18,10 +18,10 @@ type certmagicProvider struct { // TODO: set self-contained options func (c *certmagicProvider) setup() { - certmagic.Default.CA = c.opts.CA + certmagic.DefaultACME.CA = c.opts.CA if c.opts.ChallengeProvider != nil { // Enabling DNS Challenge disables the other challenges - certmagic.Default.DNSProvider = c.opts.ChallengeProvider + certmagic.DefaultACME.DNSProvider = c.opts.ChallengeProvider } if c.opts.OnDemand { certmagic.Default.OnDemand = new(certmagic.OnDemandConfig) @@ -32,9 +32,10 @@ func (c *certmagicProvider) setup() { } // If multiple instances of the provider are running, inject some // randomness so they don't collide + // RenewalWindowRatio [0.33 - 0.50) rand.Seed(time.Now().UnixNano()) - randomDuration := (7 * 24 * time.Hour) + (time.Duration(rand.Intn(504)) * time.Hour) - certmagic.Default.RenewDurationBefore = randomDuration + randomRatio := float64(rand.Intn(17) + 33) * 0.01 + certmagic.Default.RenewalWindowRatio = randomRatio } func (c *certmagicProvider) Listen(hosts ...string) (net.Listener, error) { diff --git a/api/server/acme/certmagic/storage.go b/api/server/acme/certmagic/storage.go index 4e26b888..e9ac1ad1 100644 --- a/api/server/acme/certmagic/storage.go +++ b/api/server/acme/certmagic/storage.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/mholt/certmagic" + "github.com/caddyserver/certmagic" "github.com/micro/go-micro/v2/store" "github.com/micro/go-micro/v2/sync" ) diff --git a/go.mod b/go.mod index 126d4415..4baf1ac9 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/bitly/go-simplejson v0.5.0 github.com/bwmarrin/discordgo v0.20.2 + github.com/caddyserver/certmagic v0.10.6 github.com/coreos/etcd v3.3.18+incompatible github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/davecgh/go-spew v1.1.1 @@ -16,7 +17,7 @@ require ( github.com/fsnotify/fsnotify v1.4.7 github.com/fsouza/go-dockerclient v1.6.0 github.com/ghodss/yaml v1.0.0 - github.com/go-acme/lego/v3 v3.3.0 + github.com/go-acme/lego/v3 v3.4.0 github.com/go-git/go-git/v5 v5.0.0 github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee github.com/gobwas/pool v0.2.0 // indirect @@ -33,7 +34,6 @@ require ( github.com/kr/pretty v0.1.0 github.com/lib/pq v1.3.0 github.com/lucas-clemente/quic-go v0.14.1 - github.com/mholt/certmagic v0.9.3 github.com/micro/cli/v2 v2.1.2 github.com/micro/go-micro v1.18.0 github.com/miekg/dns v1.1.27 diff --git a/go.sum b/go.sum index 32596903..345168c5 100644 --- a/go.sum +++ b/go.sum @@ -69,8 +69,12 @@ github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVO github.com/bwmarrin/discordgo v0.20.1/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20= github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q= +github.com/caddyserver/certmagic v0.10.6 h1:sCya6FmfaN74oZE46kqfaFOVoROD/mF36rTQfjN7TZc= +github.com/caddyserver/certmagic v0.10.6/go.mod h1:Y8jcUBctgk/IhpAzlHKfimZNyXCkfGgRTC0orl8gROQ= github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c= github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= +github.com/cenkalti/backoff/v4 v4.0.0 h1:6VeaLF9aI+MAUQ95106HwWzYZgJJpZ4stumjj6RFYAU= +github.com/cenkalti/backoff/v4 v4.0.0/go.mod h1:eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg= github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= @@ -155,8 +159,8 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-acme/lego/v3 v3.1.0/go.mod h1:074uqt+JS6plx+c9Xaiz6+L+GBb+7itGtzfcDM2AhEE= -github.com/go-acme/lego/v3 v3.3.0 h1:6BePZsOiYA4/w+M7QDytxQtMfCipMPGnWAHs9pWks98= -github.com/go-acme/lego/v3 v3.3.0/go.mod h1:iGSY2vQrvQs3WezicSB/oVbO2eCrD88dpWPwb1qLqu0= +github.com/go-acme/lego/v3 v3.4.0 h1:deB9NkelA+TfjGHVw8J7iKl/rMtffcGMWSMmptvMv0A= +github.com/go-acme/lego/v3 v3.4.0/go.mod h1:xYbLDuxq3Hy4bMUT1t9JIuz6GWIWb3m5X+TeTHYaT7M= github.com/go-cmd/cmd v1.0.5/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= @@ -288,6 +292,8 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/klauspost/cpuid v1.2.3 h1:CCtW0xUnWGVINKvE/WWOYKdsPV6mawAtvQuSl8guwQs= +github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/kolo/xmlrpc v0.0.0-20190717152603-07c4ee3fd181/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= @@ -328,8 +334,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mholt/certmagic v0.7.5/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= github.com/mholt/certmagic v0.8.3/go.mod h1:91uJzK5K8IWtYQqTi5R2tsxV1pCde+wdGfaRaOZi6aQ= -github.com/mholt/certmagic v0.9.3 h1:RmzuNJ5mpFplDbyS41z+gGgE/py24IX6m0nHZ0yNTQU= -github.com/mholt/certmagic v0.9.3/go.mod h1:nu8jbsbtwK4205EDH/ZUMTKsfYpJA1Q7MKXHfgTihNw= github.com/micro/cli v0.2.0 h1:ut3rV5JWqZjsXIa2MvGF+qMUP8DAUTvHX9Br5gO4afA= github.com/micro/cli v0.2.0/go.mod h1:jRT9gmfVKWSS6pkKcXQ8YhUyj6bzwxK8Fp5b0Y7qNnk= github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM= @@ -385,7 +389,7 @@ github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249 h1:Pr5gZa2VcmktVwq0lyC39MsN5tz356vC/pQHKvq+QBo= github.com/nlopes/slack v0.6.1-0.20191106133607-d06c2a2b3249/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= github.com/nrdcg/auroradns v1.0.0/go.mod h1:6JPXKzIRzZzMqtTDgueIhTi6rFf1QvYE/HzqidhOhjw= -github.com/nrdcg/dnspod-go v0.3.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgPTGKr6KQ= +github.com/nrdcg/dnspod-go v0.4.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgPTGKr6KQ= github.com/nrdcg/goinwx v0.6.1/go.mod h1:XPiut7enlbEdntAqalBIqcYcTEVhpv/dKWgDCX2SwKQ= github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= From b14d63b4a12dda13bc4a8a2bbfeb53d6e8cdffe5 Mon Sep 17 00:00:00 2001 From: Pieter Voorwinden Date: Wed, 13 May 2020 16:13:23 +0200 Subject: [PATCH 756/788] Check if auth is nil to prevent nilpointer --- util/wrapper/wrapper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 285a775f..8b501b12 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -155,7 +155,7 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac // if auth is nil we won't be able to get an access token, so we execute // the request without one. aa := a.auth() - if a == nil { + if aa == nil { return a.Client.Call(ctx, req, rsp, opts...) } From 290595f88e22af4a80c15b1f960d41ac6aeaded2 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 13 May 2020 16:13:36 +0100 Subject: [PATCH 757/788] Strip down router code (#1627) --- router/default.go | 125 ++++------------------------------------------ 1 file changed, 9 insertions(+), 116 deletions(-) diff --git a/router/default.go b/router/default.go index 9026886b..f3b329a4 100644 --- a/router/default.go +++ b/router/default.go @@ -3,7 +3,6 @@ package router import ( "errors" "fmt" - "math" "sort" "strings" "sync" @@ -19,18 +18,6 @@ var ( AdvertiseEventsTick = 10 * time.Second // DefaultAdvertTTL is default advertisement TTL DefaultAdvertTTL = 2 * time.Minute - // AdvertSuppress is advert suppression threshold - AdvertSuppress = 200.0 - // AdvertRecover is advert recovery threshold - AdvertRecover = 20.0 - // Penalty for routes processed multiple times - Penalty = 100.0 - // PenaltyHalfLife is the time the advert penalty decays to half its value - PenaltyHalfLife = 30.0 - // MaxSuppressTime defines time after which the suppressed advert is deleted - MaxSuppressTime = 90 * time.Second - // PenaltyDecay is a coefficient which controls the speed the advert penalty decays - PenaltyDecay = math.Log(2) / PenaltyHalfLife ) // router implements default router @@ -269,68 +256,8 @@ func (r *router) publishAdvert(advType AdvertType, events []*Event) { r.sub.RUnlock() } -// advert contains a route event to be advertised -type advert struct { - // event received from routing table - event *Event - // lastSeen records the time of the last advert update - lastSeen time.Time - // penalty is current advert penalty - penalty float64 - // isSuppressed flags the advert suppression - isSuppressed bool - // suppressTime records the time interval the advert has been suppressed for - suppressTime time.Time -} - // adverts maintains a map of router adverts -type adverts map[uint64]*advert - -// process processes advert -// It updates advert timestamp, increments its penalty and -// marks upresses or recovers it if it reaches configured thresholds -func (m adverts) process(a *advert) error { - // lookup advert in adverts - hash := a.event.Route.Hash() - a, ok := m[hash] - if !ok { - return fmt.Errorf("advert not found") - } - - // decay the event penalty - delta := time.Since(a.lastSeen).Seconds() - - // decay advert penalty - a.penalty = a.penalty * math.Exp(-delta*PenaltyDecay) - service := a.event.Route.Service - address := a.event.Route.Address - - // suppress/recover the event based on its penalty level - switch { - case a.penalty > AdvertSuppress && !a.isSuppressed: - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Router suppressing advert %d %.2f for route %s %s", hash, a.penalty, service, address) - } - a.isSuppressed = true - a.suppressTime = time.Now() - case a.penalty < AdvertRecover && a.isSuppressed: - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Router recovering advert %d %.2f for route %s %s", hash, a.penalty, service, address) - } - a.isSuppressed = false - } - - // if suppressed, checked how long has it been suppressed for - if a.isSuppressed { - // max suppression time threshold has been reached, delete the advert - if time.Since(a.suppressTime) > MaxSuppressTime { - delete(m, hash) - return nil - } - } - - return nil -} +type adverts map[uint64]*Event // advertiseEvents advertises routing table events // It suppresses unhealthy flapping events and advertises healthy events upstream. @@ -396,21 +323,9 @@ func (r *router) advertiseEvents() error { var events []*Event // collect all events which are not flapping - for key, advert := range adverts { - // process the advert - if err := adverts.process(advert); err != nil { - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Router failed processing advert %d: %v", key, err) - } - continue - } - // if suppressed go to the next advert - if advert.isSuppressed { - continue - } - + for key, event := range adverts { // if we only advertise local routes skip processing anything not link local - if r.options.Advertise == AdvertiseLocal && advert.event.Route.Link != "local" { + if r.options.Advertise == AdvertiseLocal && event.Route.Link != "local" { continue } @@ -418,7 +333,7 @@ func (r *router) advertiseEvents() error { e := new(Event) // this is ok, because router.Event only contains builtin types // and no references so this creates a deep copy of struct Event - *e = *(advert.event) + *e = *event events = append(events, e) // delete the advert from adverts delete(adverts, key) @@ -447,44 +362,22 @@ func (r *router) advertiseEvents() error { continue } - now := time.Now() - if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Router processing table event %s for service %s %s", e.Type, e.Route.Service, e.Route.Address) } // check if we have already registered the route hash := e.Route.Hash() - a, ok := adverts[hash] + ev, ok := adverts[hash] if !ok { - a = &advert{ - event: e, - penalty: Penalty, - lastSeen: now, - } - adverts[hash] = a + ev = e + adverts[hash] = e continue } // override the route event only if the previous event was different - if a.event.Type != e.Type { - a.event = e - } - - // process the advert - if err := adverts.process(a); err != nil { - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Router error processing advert %d: %v", hash, err) - } - continue - } - - // update event penalty and timestamp - a.lastSeen = now - // increment the penalty - a.penalty += Penalty - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Router advert %d for route %s %s event penalty: %f", hash, a.event.Route.Service, a.event.Route.Address, a.penalty) + if ev.Type != e.Type { + ev = e } case <-r.exit: if w != nil { From c831b6c03a14c4b0f5ce9f42f42e76602ddaa8ca Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 16:35:57 +0100 Subject: [PATCH 758/788] Fix --- util/wrapper/wrapper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 285a775f..8b501b12 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -155,7 +155,7 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac // if auth is nil we won't be able to get an access token, so we execute // the request without one. aa := a.auth() - if a == nil { + if aa == nil { return a.Client.Call(ctx, req, rsp, opts...) } From 410fec8ee48a5979e1c66da2faa2f4bba062b2a1 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 16:49:17 +0100 Subject: [PATCH 759/788] Fix auth bug --- service.go | 23 ++++++++++++++++------- store/memory/memory.go | 1 - store/memory/memory_test.go | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/service.go b/service.go index 75de60fa..749f53ae 100644 --- a/service.go +++ b/service.go @@ -53,6 +53,12 @@ func newService(opts ...Option) Service { server.WrapHandler(wrapper.AuthHandler(authFn)), ) + // set the client in the service implementations + options.Auth.Init(auth.WithClient(options.Client)) + options.Registry.Init(registrySrv.WithClient(options.Client)) + options.Runtime.Init(runtime.WithClient(options.Client)) + options.Store.Init(store.WithClient(options.Client)) + // set opts service.opts = options @@ -116,7 +122,10 @@ func (s *service) Init(opts ...Option) { name := s.opts.Cmd.App().Name s.opts.Store.Init(store.Table(name)) - // Set the client for the micro clients + // Reset the clients for the micro services, this is done + // previously in newService for micro (since init is never called) + // however it needs to be done again here since for normal go-micro + // services the implementation may have changed by CLI flags. s.opts.Auth.Init(auth.WithClient(s.Client())) s.opts.Registry.Init(registrySrv.WithClient(s.Client())) s.opts.Runtime.Init(runtime.WithClient(s.Client())) @@ -183,6 +192,11 @@ func (s *service) Stop() error { } func (s *service) Run() error { + // generate an auth account + if err := s.generateAccount(); err != nil { + return err + } + // register the debug handler s.opts.Server.Handle( s.opts.Server.NewHandler( @@ -208,11 +222,6 @@ func (s *service) Run() error { logger.Infof("Starting [service] %s", s.Name()) } - // generate an auth account - if err := s.registerAuthAccount(); err != nil { - return err - } - if err := s.Start(); err != nil { return err } @@ -232,7 +241,7 @@ func (s *service) Run() error { return s.Stop() } -func (s *service) registerAuthAccount() error { +func (s *service) generateAccount() error { // generate a new auth account for the service name := fmt.Sprintf("%v-%v", s.Name(), s.Server().Options().Id) opts := []auth.GenerateOption{ diff --git a/store/memory/memory.go b/store/memory/memory.go index cbe6e38d..33ded427 100644 --- a/store/memory/memory.go +++ b/store/memory/memory.go @@ -134,7 +134,6 @@ func (m *memoryStore) Close() error { } func (m *memoryStore) Init(opts ...store.Option) error { - m.store.Flush() for _, o := range opts { o(&m.options) } diff --git a/store/memory/memory_test.go b/store/memory/memory_test.go index 4598a667..91cd2b12 100644 --- a/store/memory/memory_test.go +++ b/store/memory/memory_test.go @@ -248,7 +248,7 @@ func basictest(s store.Store, t *testing.T) { } } - s.Init() + s.Close() // reset the store for i := 0; i < 10; i++ { s.Write(&store.Record{ Key: fmt.Sprintf("a%d", i), From 2299244332e9ae4ec12f2df8fe2ab3aafc9fb905 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 17:07:46 +0100 Subject: [PATCH 760/788] Auth: Load rules if not present --- auth/service/service.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/auth/service/service.go b/auth/service/service.go index fbec81d0..b8a163b0 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -59,17 +59,14 @@ func (s *svc) Init(opts ...auth.Option) { go func() { ruleTimer := time.NewTicker(time.Second * 30) - // load rules immediately on startup - s.loadRules() - for { - <-ruleTimer.C - // jitter for up to 5 seconds, this stops // all the services calling the auth service // at the exact same time time.Sleep(jitter.Do(time.Second * 5)) s.loadRules() + + <-ruleTimer.C } }() } @@ -132,6 +129,9 @@ func (s *svc) Revoke(role string, res *auth.Resource) error { // Verify an account has access to a resource func (s *svc) Verify(acc *auth.Account, res *auth.Resource) error { + // load the rules if none are loaded + s.loadRulesIfEmpty() + // set the namespace on the resource if len(res.Namespace) == 0 { res.Namespace = s.Options().Namespace @@ -286,6 +286,16 @@ func (s *svc) loadRules() { s.rules = rsp.Rules } +func (s *svc) loadRulesIfEmpty() { + s.Lock() + rules := s.rules + s.Unlock() + + if len(rules) == 0 { + s.loadRules() + } +} + func serializeToken(t *pb.Token) *auth.Token { return &auth.Token{ AccessToken: t.AccessToken, From bba8c254d730da138eda7d2625f5cf2606183980 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 13 May 2020 17:35:57 +0100 Subject: [PATCH 761/788] fix auth initialisation (#1630) --- auth/service/service.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/auth/service/service.go b/auth/service/service.go index b8a163b0..90291257 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -17,11 +17,6 @@ import ( "github.com/micro/go-micro/v2/util/jitter" ) -// NewAuth returns a new instance of the Auth service -func NewAuth(opts ...auth.Option) auth.Auth { - return &svc{options: auth.NewOptions(opts...)} -} - // svc is the service implementation of the Auth interface type svc struct { options auth.Options @@ -45,6 +40,7 @@ func (s *svc) Init(opts ...auth.Option) { if s.options.Client == nil { s.options.Client = client.DefaultClient } + s.auth = pb.NewAuthService("go.micro.auth", s.options.Client) s.rule = pb.NewRulesService("go.micro.auth", s.options.Client) @@ -315,3 +311,18 @@ func serializeAccount(a *pb.Account) *auth.Account { Namespace: a.Namespace, } } + +// NewAuth returns a new instance of the Auth service +func NewAuth(opts ...auth.Option) auth.Auth { + options := auth.NewOptions(opts...) + + if options.Client == nil { + options.Client = client.DefaultClient + } + + return &svc{ + auth: pb.NewAuthService("go.micro.auth", options.Client), + rule: pb.NewRulesService("go.micro.auth", options.Client), + options: options, + } +} From 366fb228e509915b3f1b685b3f7266524645ebb6 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 17:54:47 +0100 Subject: [PATCH 762/788] Auth: Set address --- auth/options.go | 9 ++++++++ auth/service/service.go | 50 +++++++++++++++++++++++------------------ 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/auth/options.go b/auth/options.go index da0982b7..bb120241 100644 --- a/auth/options.go +++ b/auth/options.go @@ -44,10 +44,19 @@ type Options struct { Store store.Store // Client to use for RPC Client client.Client + // Addrs sets the addresses of auth + Addrs []string } type Option func(o *Options) +// Addrs is the auth addresses to use +func Addrs(addrs ...string) Option { + return func(o *Options) { + o.Addrs = addrs + } +} + // Namespace the service belongs to func Namespace(n string) Option { return func(o *Options) { diff --git a/auth/service/service.go b/auth/service/service.go index b8a163b0..b6b886fc 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -19,7 +19,27 @@ import ( // NewAuth returns a new instance of the Auth service func NewAuth(opts ...auth.Option) auth.Auth { - return &svc{options: auth.NewOptions(opts...)} + options := auth.NewOptions(opts...) + + addrs := options.Addrs + if len(addrs) == 0 { + addrs = []string{"127.0.0.1:8010"} + } + + svc := &svc{options: options, addrs: addrs} + + // load rules periodically from the auth service + go func() { + ruleTimer := time.NewTicker(time.Second * 30) + + for { + time.Sleep(jitter.Do(time.Second * 5)) + svc.loadRules() + <-ruleTimer.C + } + }() + + return svc } // svc is the service implementation of the Auth interface @@ -28,6 +48,7 @@ type svc struct { auth pb.AuthService rule pb.RulesService jwt token.Provider + addrs []string rules []*pb.Rule sync.Mutex @@ -54,21 +75,6 @@ func (s *svc) Init(opts ...auth.Option) { if key := s.options.PublicKey; len(key) > 0 { s.jwt = jwt.NewTokenProvider(token.WithPublicKey(key)) } - - // load rules periodically from the auth service - go func() { - ruleTimer := time.NewTicker(time.Second * 30) - - for { - // jitter for up to 5 seconds, this stops - // all the services calling the auth service - // at the exact same time - time.Sleep(jitter.Do(time.Second * 5)) - s.loadRules() - - <-ruleTimer.C - } - }() } func (s *svc) Options() auth.Options { @@ -89,7 +95,7 @@ func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e Metadata: options.Metadata, Provider: options.Provider, Namespace: options.Namespace, - }) + }, client.WithAddress(s.addrs...)) if err != nil { return nil, err } @@ -108,7 +114,7 @@ func (s *svc) Grant(role string, res *auth.Resource) error { Name: res.Name, Endpoint: res.Endpoint, }, - }) + }, client.WithAddress(s.addrs...)) return err } @@ -123,7 +129,7 @@ func (s *svc) Revoke(role string, res *auth.Resource) error { Name: res.Name, Endpoint: res.Endpoint, }, - }) + }, client.WithAddress(s.addrs...)) return err } @@ -193,7 +199,7 @@ func (s *svc) Inspect(token string) (*auth.Account, error) { // the token is not a JWT or we do not have the keys to decode it, // fall back to the auth service - rsp, err := s.auth.Inspect(context.TODO(), &pb.InspectRequest{Token: token}) + rsp, err := s.auth.Inspect(context.TODO(), &pb.InspectRequest{Token: token}, client.WithAddress(s.addrs...)) if err != nil { return nil, err } @@ -209,7 +215,7 @@ func (s *svc) Token(opts ...auth.TokenOption) (*auth.Token, error) { Secret: options.Secret, RefreshToken: options.RefreshToken, TokenExpiry: int64(options.Expiry.Seconds()), - }) + }, client.WithAddress(s.addrs...)) if err != nil { return nil, err } @@ -274,7 +280,7 @@ func (s *svc) listRules(filters ...string) []*pb.Rule { // loadRules retrieves the rules from the auth service func (s *svc) loadRules() { - rsp, err := s.rule.List(context.TODO(), &pb.ListRequest{}) + rsp, err := s.rule.List(context.TODO(), &pb.ListRequest{}, client.WithAddress(s.addrs...)) s.Lock() defer s.Unlock() From 1ca1fd411a3e7cd5ab50e6704961f0b915a7ea87 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 18:17:04 +0100 Subject: [PATCH 763/788] Auth: Fix recursive bug --- util/wrapper/wrapper.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 8b501b12..6de4a663 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -171,6 +171,12 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac return callWithToken(aaOpts.Token.AccessToken) } + // check to ensure we're not calling auth, since this will result in + // an endless loop + if req.Service() == "go.micro.auth" { + return a.Client.Call(ctx, req, rsp, opts...) + } + // if we have a refresh token we can use this to generate another access token if aaOpts.Token != nil { tok, err := aa.Token(auth.WithToken(aaOpts.Token.RefreshToken)) From 05858b746c5bb002a571e915c98014ef683113c4 Mon Sep 17 00:00:00 2001 From: Dominic Wong Date: Wed, 13 May 2020 18:36:45 +0100 Subject: [PATCH 764/788] kill all processes correctly for micro kill command (#1633) --- runtime/default.go | 2 +- runtime/local/process/os/os.go | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index fa75ec8f..869070fa 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -536,7 +536,7 @@ func (r *runtime) Delete(s *Service, opts ...DeleteOption) error { } if s, ok := r.services[serviceKey(s)]; ok { // check if running - if s.Running() { + if !s.Running() { delete(r.services, s.key()) return nil } diff --git a/runtime/local/process/os/os.go b/runtime/local/process/os/os.go index a35d0b79..a37c5cba 100644 --- a/runtime/local/process/os/os.go +++ b/runtime/local/process/os/os.go @@ -20,6 +20,7 @@ func (p *Process) Exec(exe *process.Executable) error { } func (p *Process) Fork(exe *process.Executable) (*process.PID, error) { + // create command cmd := exec.Command(exe.Package.Path, exe.Args...) @@ -43,7 +44,6 @@ func (p *Process) Fork(exe *process.Executable) (*process.PID, error) { if err != nil { return nil, err } - // start the process if err := cmd.Start(); err != nil { return nil, err @@ -62,22 +62,14 @@ func (p *Process) Kill(pid *process.PID) error { if err != nil { return err } - - pr, err := os.FindProcess(id) - if err != nil { + if _, err := os.FindProcess(id); err != nil { return err } // now kill it - err = pr.Kill() + // using -ve PID kills the process group which we created in Fork() + return syscall.Kill(-id, syscall.SIGKILL) - // kill the group - if pgid, err := syscall.Getpgid(id); err == nil { - syscall.Kill(-pgid, syscall.SIGKILL) - } - - // return the kill error - return err } func (p *Process) Wait(pid *process.PID) error { From ca791d7e8d8f2363e8a9dcfe76fe811cfae6e476 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 18:47:53 +0100 Subject: [PATCH 765/788] Disable Clients --- service.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/service.go b/service.go index 749f53ae..84347084 100644 --- a/service.go +++ b/service.go @@ -16,8 +16,6 @@ import ( "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/plugin" - registrySrv "github.com/micro/go-micro/v2/registry/service" - "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/store" signalutil "github.com/micro/go-micro/v2/util/signal" @@ -54,10 +52,10 @@ func newService(opts ...Option) Service { ) // set the client in the service implementations - options.Auth.Init(auth.WithClient(options.Client)) - options.Registry.Init(registrySrv.WithClient(options.Client)) - options.Runtime.Init(runtime.WithClient(options.Client)) - options.Store.Init(store.WithClient(options.Client)) + // options.Auth.Init(auth.WithClient(options.Client)) + // options.Registry.Init(registrySrv.WithClient(options.Client)) + // options.Runtime.Init(runtime.WithClient(options.Client)) + // options.Store.Init(store.WithClient(options.Client)) // set opts service.opts = options @@ -126,10 +124,10 @@ func (s *service) Init(opts ...Option) { // previously in newService for micro (since init is never called) // however it needs to be done again here since for normal go-micro // services the implementation may have changed by CLI flags. - s.opts.Auth.Init(auth.WithClient(s.Client())) - s.opts.Registry.Init(registrySrv.WithClient(s.Client())) - s.opts.Runtime.Init(runtime.WithClient(s.Client())) - s.opts.Store.Init(store.WithClient(s.Client())) + // s.opts.Auth.Init(auth.WithClient(s.Client())) + // s.opts.Registry.Init(registrySrv.WithClient(s.Client())) + // s.opts.Runtime.Init(runtime.WithClient(s.Client())) + // s.opts.Store.Init(store.WithClient(s.Client())) }) } From 57b060bac5adfab097139fa572c85b11164484c7 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 13 May 2020 18:49:36 +0100 Subject: [PATCH 766/788] Disable Addresses --- auth/service/service.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/auth/service/service.go b/auth/service/service.go index 197462a2..ccf2999b 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -307,9 +307,9 @@ func NewAuth(opts ...auth.Option) auth.Auth { } addrs := options.Addrs - if len(addrs) == 0 { - addrs = []string{"127.0.0.1:8010"} - } + // if len(addrs) == 0 { + // addrs = []string{"127.0.0.1:8010"} + // } service := &svc{ auth: pb.NewAuthService("go.micro.auth", options.Client), From 5764519f5b21ca108f543f5f7243f5599308a1c2 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 14 May 2020 11:06:22 +0100 Subject: [PATCH 767/788] Refactor auth to load token outside wrappers --- auth/service/service.go | 19 +++------ config/cmd/cmd.go | 42 +++++++++---------- go.mod | 1 + go.sum | 2 + service.go | 89 +++++++++++++++++++++++++++------------- util/config/config.go | 90 ----------------------------------------- util/wrapper/wrapper.go | 40 +----------------- 7 files changed, 91 insertions(+), 192 deletions(-) delete mode 100644 util/config/config.go diff --git a/auth/service/service.go b/auth/service/service.go index ccf2999b..be316525 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -23,7 +23,6 @@ type svc struct { auth pb.AuthService rule pb.RulesService jwt token.Provider - addrs []string rules []*pb.Rule sync.Mutex @@ -71,7 +70,7 @@ func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, e Metadata: options.Metadata, Provider: options.Provider, Namespace: options.Namespace, - }, client.WithAddress(s.addrs...)) + }) if err != nil { return nil, err } @@ -90,7 +89,7 @@ func (s *svc) Grant(role string, res *auth.Resource) error { Name: res.Name, Endpoint: res.Endpoint, }, - }, client.WithAddress(s.addrs...)) + }) return err } @@ -105,7 +104,7 @@ func (s *svc) Revoke(role string, res *auth.Resource) error { Name: res.Name, Endpoint: res.Endpoint, }, - }, client.WithAddress(s.addrs...)) + }) return err } @@ -175,7 +174,7 @@ func (s *svc) Inspect(token string) (*auth.Account, error) { // the token is not a JWT or we do not have the keys to decode it, // fall back to the auth service - rsp, err := s.auth.Inspect(context.TODO(), &pb.InspectRequest{Token: token}, client.WithAddress(s.addrs...)) + rsp, err := s.auth.Inspect(context.TODO(), &pb.InspectRequest{Token: token}) if err != nil { return nil, err } @@ -191,7 +190,7 @@ func (s *svc) Token(opts ...auth.TokenOption) (*auth.Token, error) { Secret: options.Secret, RefreshToken: options.RefreshToken, TokenExpiry: int64(options.Expiry.Seconds()), - }, client.WithAddress(s.addrs...)) + }) if err != nil { return nil, err } @@ -256,7 +255,7 @@ func (s *svc) listRules(filters ...string) []*pb.Rule { // loadRules retrieves the rules from the auth service func (s *svc) loadRules() { - rsp, err := s.rule.List(context.TODO(), &pb.ListRequest{}, client.WithAddress(s.addrs...)) + rsp, err := s.rule.List(context.TODO(), &pb.ListRequest{}) s.Lock() defer s.Unlock() @@ -306,16 +305,10 @@ func NewAuth(opts ...auth.Option) auth.Auth { options.Client = client.DefaultClient } - addrs := options.Addrs - // if len(addrs) == 0 { - // addrs = []string{"127.0.0.1:8010"} - // } - service := &svc{ auth: pb.NewAuthService("go.micro.auth", options.Client), rule: pb.NewRulesService("go.micro.auth", options.Client), options: options, - addrs: addrs, } // load rules periodically from the auth service diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 1dfd87c5..de805f6c 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -21,6 +21,7 @@ import ( "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" + registrySrv "github.com/micro/go-micro/v2/registry/service" "github.com/micro/go-micro/v2/runtime" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/store" @@ -468,6 +469,22 @@ func (c *cmd) Before(ctx *cli.Context) error { var serverOpts []server.Option var clientOpts []client.Option + // Set the client. This must be first since we use the client below + if name := ctx.String("client"); len(name) > 0 { + // only change if we have the client and type differs + if cl, ok := c.opts.Clients[name]; ok && (*c.opts.Client).String() != name { + *c.opts.Client = cl() + } + } + + // Set the server + if name := ctx.String("server"); len(name) > 0 { + // only change if we have the server and type differs + if s, ok := c.opts.Servers[name]; ok && (*c.opts.Server).String() != name { + *c.opts.Server = s() + } + } + // Set the store if name := ctx.String("store"); len(name) > 0 { s, ok := c.opts.Stores[name] @@ -475,7 +492,7 @@ func (c *cmd) Before(ctx *cli.Context) error { return fmt.Errorf("Unsupported store: %s", name) } - *c.opts.Store = s() + *c.opts.Store = s(store.WithClient(*c.opts.Client)) } // Set the runtime @@ -485,7 +502,7 @@ func (c *cmd) Before(ctx *cli.Context) error { return fmt.Errorf("Unsupported runtime: %s", name) } - *c.opts.Runtime = r() + *c.opts.Runtime = r(runtime.WithClient(*c.opts.Client)) } // Set the tracer @@ -504,8 +521,7 @@ func (c *cmd) Before(ctx *cli.Context) error { if !ok { return fmt.Errorf("Unsupported auth: %s", name) } - - *c.opts.Auth = a() + *c.opts.Auth = a(auth.WithClient(*c.opts.Client)) serverOpts = append(serverOpts, server.Auth(*c.opts.Auth)) } @@ -519,22 +535,6 @@ func (c *cmd) Before(ctx *cli.Context) error { *c.opts.Profile = p() } - // Set the client - if name := ctx.String("client"); len(name) > 0 { - // only change if we have the client and type differs - if cl, ok := c.opts.Clients[name]; ok && (*c.opts.Client).String() != name { - *c.opts.Client = cl() - } - } - - // Set the server - if name := ctx.String("server"); len(name) > 0 { - // only change if we have the server and type differs - if s, ok := c.opts.Servers[name]; ok && (*c.opts.Server).String() != name { - *c.opts.Server = s() - } - } - // Set the broker if name := ctx.String("broker"); len(name) > 0 && (*c.opts.Broker).String() != name { b, ok := c.opts.Brokers[name] @@ -554,7 +554,7 @@ func (c *cmd) Before(ctx *cli.Context) error { return fmt.Errorf("Registry %s not found", name) } - *c.opts.Registry = r() + *c.opts.Registry = r(registrySrv.WithClient(*c.opts.Client)) serverOpts = append(serverOpts, server.Registry(*c.opts.Registry)) clientOpts = append(clientOpts, client.Registry(*c.opts.Registry)) diff --git a/go.mod b/go.mod index 4baf1ac9..f549d7df 100644 --- a/go.mod +++ b/go.mod @@ -47,6 +47,7 @@ require ( github.com/stretchr/testify v1.4.0 github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect go.etcd.io/bbolt v1.3.4 + go.etcd.io/etcd v3.3.20+incompatible go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 golang.org/x/net v0.0.0-20200301022130-244492dfa37a diff --git a/go.sum b/go.sum index 345168c5..b1a34536 100644 --- a/go.sum +++ b/go.sum @@ -499,6 +499,8 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg= go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= +go.etcd.io/etcd v3.3.20+incompatible h1:EyOVslCepyFB2JcbYXvqcYdBTh7cyBKU2NYdKfgTSC0= +go.etcd.io/etcd v3.3.20+incompatible/go.mod h1:yaeTdrJi5lOmYerz05bd8+V7KubZs8YSFZfzsF9A6aI= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= diff --git a/service.go b/service.go index 84347084..ecbd6422 100644 --- a/service.go +++ b/service.go @@ -7,6 +7,7 @@ import ( rtime "runtime" "strings" "sync" + "time" "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/client" @@ -51,12 +52,6 @@ func newService(opts ...Option) Service { server.WrapHandler(wrapper.AuthHandler(authFn)), ) - // set the client in the service implementations - // options.Auth.Init(auth.WithClient(options.Client)) - // options.Registry.Init(registrySrv.WithClient(options.Client)) - // options.Runtime.Init(runtime.WithClient(options.Client)) - // options.Store.Init(store.WithClient(options.Client)) - // set opts service.opts = options @@ -119,15 +114,6 @@ func (s *service) Init(opts ...Option) { // Explicitly set the table name to the service name name := s.opts.Cmd.App().Name s.opts.Store.Init(store.Table(name)) - - // Reset the clients for the micro services, this is done - // previously in newService for micro (since init is never called) - // however it needs to be done again here since for normal go-micro - // services the implementation may have changed by CLI flags. - // s.opts.Auth.Init(auth.WithClient(s.Client())) - // s.opts.Registry.Init(registrySrv.WithClient(s.Client())) - // s.opts.Runtime.Init(runtime.WithClient(s.Client())) - // s.opts.Store.Init(store.WithClient(s.Client())) }) } @@ -240,25 +226,70 @@ func (s *service) Run() error { } func (s *service) generateAccount() error { - // generate a new auth account for the service - name := fmt.Sprintf("%v-%v", s.Name(), s.Server().Options().Id) - opts := []auth.GenerateOption{ - auth.WithType("service"), - auth.WithRoles("service"), - auth.WithNamespace(s.Options().Auth.Options().Namespace), + // extract the account creds from options, these can be set by flags + accID := s.Options().Auth.Options().ID + accSecret := s.Options().Auth.Options().Secret + + // if no credentials were provided, generate an account + if len(accID) == 0 || len(accSecret) == 0 { + name := fmt.Sprintf("%v-%v", s.Name(), s.Server().Options().Id) + opts := []auth.GenerateOption{ + auth.WithType("service"), + auth.WithRoles("service"), + auth.WithNamespace(s.Options().Auth.Options().Namespace), + } + + acc, err := s.Options().Auth.Generate(name, opts...) + if err != nil { + return err + } + logger.Infof("Auth [%v] Authenticated as %v", s.Options().Auth, name) + + accID = acc.ID + accSecret = acc.Secret } - acc, err := s.Options().Auth.Generate(name, opts...) + + // generate the first token + token, err := s.Options().Auth.Token( + auth.WithCredentials(accID, accSecret), + auth.WithExpiry(time.Minute*15), + ) if err != nil { return err } - // generate a token - token, err := s.Options().Auth.Token(auth.WithCredentials(acc.ID, acc.Secret)) - if err != nil { - return err - } + // set the credentials and token in auth options + s.Options().Auth.Init( + auth.ClientToken(token), + auth.Credentials(accID, accSecret), + ) + + // periodically check to see if the token needs refreshing + go func() { + timer := time.NewTicker(time.Second * 15) + + for { + <-timer.C + + // don't refresh the token if it's not close to expiring + if token.Expiry.Unix() > time.Now().Add(time.Minute).Unix() { + continue + } + + // generate the first token + token, err := s.Options().Auth.Token( + auth.WithCredentials(accID, accSecret), + auth.WithExpiry(time.Minute*15), + ) + if err != nil { + logger.Warnf("[Auth] Error refreshing token: %v", err) + continue + } + + // set the token + s.Options().Auth.Init(auth.ClientToken(token)) + } + }() - s.Options().Auth.Init(auth.ClientToken(token), auth.Credentials(acc.ID, acc.Secret)) - logger.Infof("Auth [%v] Authenticated as %v", s.Options().Auth, name) return nil } diff --git a/util/config/config.go b/util/config/config.go deleted file mode 100644 index a15eade7..00000000 --- a/util/config/config.go +++ /dev/null @@ -1,90 +0,0 @@ -package config - -import ( - "io/ioutil" - "os" - "os/user" - "path/filepath" - "strings" - - conf "github.com/micro/go-micro/v2/config" - "github.com/micro/go-micro/v2/config/source/file" - "github.com/micro/go-micro/v2/util/log" -) - -// FileName for global micro config -const FileName = ".micro" - -// config is a singleton which is required to ensure -// each function call doesn't load the .micro file -// from disk -var config = newConfig() - -// Get a value from the .micro file -func Get(path ...string) (string, error) { - tk := config.Get(path...).String("") - return strings.TrimSpace(tk), nil -} - -// Set a value in the .micro file -func Set(value string, path ...string) error { - // get the filepath - fp, err := filePath() - if err != nil { - return err - } - - // set the value - config.Set(value, path...) - - // write to the file - return ioutil.WriteFile(fp, config.Bytes(), 0644) -} - -func filePath() (string, error) { - usr, err := user.Current() - if err != nil { - return "", err - } - return filepath.Join(usr.HomeDir, FileName), nil -} - -// newConfig returns a loaded config -func newConfig() conf.Config { - // get the filepath - fp, err := filePath() - if err != nil { - log.Error(err) - return conf.DefaultConfig - } - - // write the file if it does not exist - if _, err := os.Stat(fp); os.IsNotExist(err) { - ioutil.WriteFile(fp, []byte{}, 0644) - } else if err != nil { - log.Error(err) - return conf.DefaultConfig - } - - // create a new config - c, err := conf.NewConfig( - conf.WithSource( - file.NewSource( - file.WithPath(fp), - ), - ), - ) - if err != nil { - log.Error(err) - return conf.DefaultConfig - } - - // load the config - if err := c.Load(); err != nil { - log.Error(err) - return conf.DefaultConfig - } - - // return the conf - return c -} diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 6de4a663..041feedd 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -12,7 +12,6 @@ import ( "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/server" - "github.com/micro/go-micro/v2/util/config" ) type fromServiceWrapper struct { @@ -159,50 +158,13 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac return a.Client.Call(ctx, req, rsp, opts...) } - // performs the call with the authorization token provided - callWithToken := func(token string) error { - ctx := metadata.Set(ctx, "Authorization", auth.BearerScheme+token) - return a.Client.Call(ctx, req, rsp, opts...) - } - // check to see if we have a valid access token aaOpts := aa.Options() if aaOpts.Token != nil && aaOpts.Token.Expiry.Unix() > time.Now().Unix() { - return callWithToken(aaOpts.Token.AccessToken) - } - - // check to ensure we're not calling auth, since this will result in - // an endless loop - if req.Service() == "go.micro.auth" { + ctx = metadata.Set(ctx, "Authorization", auth.BearerScheme+aaOpts.Token.AccessToken) return a.Client.Call(ctx, req, rsp, opts...) } - // if we have a refresh token we can use this to generate another access token - if aaOpts.Token != nil { - tok, err := aa.Token(auth.WithToken(aaOpts.Token.RefreshToken)) - if err != nil { - return err - } - aa.Init(auth.ClientToken(tok)) - return callWithToken(tok.AccessToken) - } - - // generate a new token if we have credentials - if len(aaOpts.ID) > 0 && len(aaOpts.Secret) > 0 { - tok, err := aa.Token(auth.WithCredentials(aaOpts.ID, aaOpts.Secret)) - if err != nil { - return err - } - aa.Init(auth.ClientToken(tok)) - return callWithToken(tok.AccessToken) - } - - // check to see if a token was provided in config, this is normally used for - // setting the token when calling via the cli - if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 { - return callWithToken(token) - } - // call without an auth token return a.Client.Call(ctx, req, rsp, opts...) } From 1b18730d5433e00e97f44370736506220a64aece Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 14 May 2020 11:25:19 +0100 Subject: [PATCH 768/788] Custom micro client --- auth/service/service.go | 1 - config/cmd/cmd.go | 46 +++++++++++++++++++++++------------------ service.go | 2 +- util/wrapper/wrapper.go | 6 ++---- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/auth/service/service.go b/auth/service/service.go index be316525..ecb605f4 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -300,7 +300,6 @@ func serializeAccount(a *pb.Account) *auth.Account { // NewAuth returns a new instance of the Auth service func NewAuth(opts ...auth.Option) auth.Auth { options := auth.NewOptions(opts...) - if options.Client == nil { options.Client = client.DefaultClient } diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index de805f6c..8886994c 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -11,6 +11,7 @@ import ( "github.com/micro/go-micro/v2/auth/provider" "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/client/grpc" "github.com/micro/go-micro/v2/client/selector" "github.com/micro/go-micro/v2/config" configSrc "github.com/micro/go-micro/v2/config/source" @@ -26,6 +27,7 @@ import ( "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/store" "github.com/micro/go-micro/v2/transport" + "github.com/micro/go-micro/v2/util/wrapper" // clients cgrpc "github.com/micro/go-micro/v2/client/grpc" @@ -469,21 +471,9 @@ func (c *cmd) Before(ctx *cli.Context) error { var serverOpts []server.Option var clientOpts []client.Option - // Set the client. This must be first since we use the client below - if name := ctx.String("client"); len(name) > 0 { - // only change if we have the client and type differs - if cl, ok := c.opts.Clients[name]; ok && (*c.opts.Client).String() != name { - *c.opts.Client = cl() - } - } - - // Set the server - if name := ctx.String("server"); len(name) > 0 { - // only change if we have the server and type differs - if s, ok := c.opts.Servers[name]; ok && (*c.opts.Server).String() != name { - *c.opts.Server = s() - } - } + // setup a client to use when calling the runtime + authFn := func() auth.Auth { return *c.opts.Auth } + microClient := wrapper.AuthClient(authFn, grpc.NewClient()) // Set the store if name := ctx.String("store"); len(name) > 0 { @@ -492,7 +482,7 @@ func (c *cmd) Before(ctx *cli.Context) error { return fmt.Errorf("Unsupported store: %s", name) } - *c.opts.Store = s(store.WithClient(*c.opts.Client)) + *c.opts.Store = s(store.WithClient(microClient)) } // Set the runtime @@ -502,7 +492,7 @@ func (c *cmd) Before(ctx *cli.Context) error { return fmt.Errorf("Unsupported runtime: %s", name) } - *c.opts.Runtime = r(runtime.WithClient(*c.opts.Client)) + *c.opts.Runtime = r(runtime.WithClient(microClient)) } // Set the tracer @@ -521,7 +511,7 @@ func (c *cmd) Before(ctx *cli.Context) error { if !ok { return fmt.Errorf("Unsupported auth: %s", name) } - *c.opts.Auth = a(auth.WithClient(*c.opts.Client)) + *c.opts.Auth = a(auth.WithClient(microClient)) serverOpts = append(serverOpts, server.Auth(*c.opts.Auth)) } @@ -554,7 +544,7 @@ func (c *cmd) Before(ctx *cli.Context) error { return fmt.Errorf("Registry %s not found", name) } - *c.opts.Registry = r(registrySrv.WithClient(*c.opts.Client)) + *c.opts.Registry = r(registrySrv.WithClient(microClient)) serverOpts = append(serverOpts, server.Registry(*c.opts.Registry)) clientOpts = append(clientOpts, client.Registry(*c.opts.Registry)) @@ -594,6 +584,22 @@ func (c *cmd) Before(ctx *cli.Context) error { clientOpts = append(clientOpts, client.Transport(*c.opts.Transport)) } + // Set the client + if name := ctx.String("client"); len(name) > 0 { + // only change if we have the client and type differs + if cl, ok := c.opts.Clients[name]; ok && (*c.opts.Client).String() != name { + *c.opts.Client = cl() + } + } + + // Set the server + if name := ctx.String("server"); len(name) > 0 { + // only change if we have the server and type differs + if s, ok := c.opts.Servers[name]; ok && (*c.opts.Server).String() != name { + *c.opts.Server = s() + } + } + // Parse the server options metadata := make(map[string]string) for _, d := range ctx.StringSlice("server_metadata") { @@ -725,7 +731,7 @@ func (c *cmd) Before(ctx *cli.Context) error { (*c.opts.Auth).Init(authOpts...) if ctx.String("config") == "service" { - opt := config.WithSource(configSrv.NewSource(configSrc.WithClient(*c.opts.Client))) + opt := config.WithSource(configSrv.NewSource(configSrc.WithClient(microClient))) if err := (*c.opts.Config).Init(opt); err != nil { logger.Fatalf("Error configuring config: %v", err) } diff --git a/service.go b/service.go index ecbd6422..b3ebc1ae 100644 --- a/service.go +++ b/service.go @@ -43,7 +43,7 @@ func newService(opts ...Option) Service { // wrap client to inject From-Service header on any calls options.Client = wrapper.FromService(serviceName, options.Client) options.Client = wrapper.TraceCall(serviceName, trace.DefaultTracer, options.Client) - options.Client = wrapper.AuthClient(serviceName, options.Server.Options().Id, authFn, options.Client) + options.Client = wrapper.AuthClient(authFn, options.Client) // wrap the server to provide handler stats options.Server.Init( diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 041feedd..51672f0a 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -132,8 +132,6 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper { type authWrapper struct { client.Client - name string - id string auth func() auth.Auth } @@ -170,8 +168,8 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac } // AuthClient wraps requests with the auth header -func AuthClient(name string, id string, auth func() auth.Auth, c client.Client) client.Client { - return &authWrapper{c, name, id, auth} +func AuthClient(auth func() auth.Auth, c client.Client) client.Client { + return &authWrapper{c, auth} } // AuthHandler wraps a server handler to perform auth From c220686c29f04f327de48ef43e6d515b480c9169 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 14 May 2020 13:30:21 +0100 Subject: [PATCH 769/788] Fix token bug --- auth/service/service.go | 2 +- service.go | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/auth/service/service.go b/auth/service/service.go index ecb605f4..482b488f 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -315,9 +315,9 @@ func NewAuth(opts ...auth.Option) auth.Auth { ruleTimer := time.NewTicker(time.Second * 30) for { + <-ruleTimer.C time.Sleep(jitter.Do(time.Second * 5)) service.loadRules() - <-ruleTimer.C } }() diff --git a/service.go b/service.go index b3ebc1ae..f37dc83b 100644 --- a/service.go +++ b/service.go @@ -252,7 +252,7 @@ func (s *service) generateAccount() error { // generate the first token token, err := s.Options().Auth.Token( auth.WithCredentials(accID, accSecret), - auth.WithExpiry(time.Minute*15), + auth.WithExpiry(time.Minute*10), ) if err != nil { return err @@ -272,14 +272,15 @@ func (s *service) generateAccount() error { <-timer.C // don't refresh the token if it's not close to expiring - if token.Expiry.Unix() > time.Now().Add(time.Minute).Unix() { + tok := s.Options().Auth.Options().Token + if tok.Expiry.Unix() > time.Now().Add(time.Minute).Unix() { continue } // generate the first token - token, err := s.Options().Auth.Token( + tok, err := s.Options().Auth.Token( auth.WithCredentials(accID, accSecret), - auth.WithExpiry(time.Minute*15), + auth.WithExpiry(time.Minute*10), ) if err != nil { logger.Warnf("[Auth] Error refreshing token: %v", err) @@ -287,7 +288,7 @@ func (s *service) generateAccount() error { } // set the token - s.Options().Auth.Init(auth.ClientToken(token)) + s.Options().Auth.Init(auth.ClientToken(tok)) } }() From 83e9c1fad2e92d452ed854f9c95c68166ba53c7c Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 14 May 2020 13:32:42 +0100 Subject: [PATCH 770/788] Remove unnecessary change --- config/cmd/cmd.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/config/cmd/cmd.go b/config/cmd/cmd.go index 8886994c..6ee8bd92 100644 --- a/config/cmd/cmd.go +++ b/config/cmd/cmd.go @@ -525,6 +525,22 @@ func (c *cmd) Before(ctx *cli.Context) error { *c.opts.Profile = p() } + // Set the client + if name := ctx.String("client"); len(name) > 0 { + // only change if we have the client and type differs + if cl, ok := c.opts.Clients[name]; ok && (*c.opts.Client).String() != name { + *c.opts.Client = cl() + } + } + + // Set the server + if name := ctx.String("server"); len(name) > 0 { + // only change if we have the server and type differs + if s, ok := c.opts.Servers[name]; ok && (*c.opts.Server).String() != name { + *c.opts.Server = s() + } + } + // Set the broker if name := ctx.String("broker"); len(name) > 0 && (*c.opts.Broker).String() != name { b, ok := c.opts.Brokers[name] @@ -584,22 +600,6 @@ func (c *cmd) Before(ctx *cli.Context) error { clientOpts = append(clientOpts, client.Transport(*c.opts.Transport)) } - // Set the client - if name := ctx.String("client"); len(name) > 0 { - // only change if we have the client and type differs - if cl, ok := c.opts.Clients[name]; ok && (*c.opts.Client).String() != name { - *c.opts.Client = cl() - } - } - - // Set the server - if name := ctx.String("server"); len(name) > 0 { - // only change if we have the server and type differs - if s, ok := c.opts.Servers[name]; ok && (*c.opts.Server).String() != name { - *c.opts.Server = s() - } - } - // Parse the server options metadata := make(map[string]string) for _, d := range ctx.StringSlice("server_metadata") { From f549e20fa25f042237162e87f9e63e646a9217bb Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 14 May 2020 13:33:11 +0100 Subject: [PATCH 771/788] tidy go mdo --- go.mod | 1 - go.sum | 2 -- 2 files changed, 3 deletions(-) diff --git a/go.mod b/go.mod index f549d7df..4baf1ac9 100644 --- a/go.mod +++ b/go.mod @@ -47,7 +47,6 @@ require ( github.com/stretchr/testify v1.4.0 github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc // indirect go.etcd.io/bbolt v1.3.4 - go.etcd.io/etcd v3.3.20+incompatible go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 golang.org/x/net v0.0.0-20200301022130-244492dfa37a diff --git a/go.sum b/go.sum index b1a34536..345168c5 100644 --- a/go.sum +++ b/go.sum @@ -499,8 +499,6 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg= go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= -go.etcd.io/etcd v3.3.20+incompatible h1:EyOVslCepyFB2JcbYXvqcYdBTh7cyBKU2NYdKfgTSC0= -go.etcd.io/etcd v3.3.20+incompatible/go.mod h1:yaeTdrJi5lOmYerz05bd8+V7KubZs8YSFZfzsF9A6aI= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= From 16af265e8b857df10939883b4e800d45427c7aa7 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 14 May 2020 13:56:51 +0100 Subject: [PATCH 772/788] Seperate JWT refresh / access tokens --- auth/jwt/jwt.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/auth/jwt/jwt.go b/auth/jwt/jwt.go index 86815bce..9c118e1a 100644 --- a/auth/jwt/jwt.go +++ b/auth/jwt/jwt.go @@ -2,6 +2,7 @@ package jwt import ( "sync" + "time" "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/auth/token" @@ -176,15 +177,20 @@ func (j *jwt) Token(opts ...auth.TokenOption) (*auth.Token, error) { return nil, err } - tok, err := j.jwt.Generate(account, token.WithExpiry(options.Expiry)) + access, err := j.jwt.Generate(account, token.WithExpiry(options.Expiry)) + if err != nil { + return nil, err + } + + refresh, err := j.jwt.Generate(account, token.WithExpiry(options.Expiry+time.Hour)) if err != nil { return nil, err } return &auth.Token{ - Created: tok.Created, - Expiry: tok.Expiry, - AccessToken: tok.Token, - RefreshToken: tok.Token, + Created: access.Created, + Expiry: access.Expiry, + AccessToken: access.Token, + RefreshToken: refresh.Token, }, nil } From 6b451a2197314726f43a0973aa0858ba12e5fc5e Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 14 May 2020 16:10:14 +0100 Subject: [PATCH 773/788] Refactor auth setup to util/auth --- service.go | 75 ++----------------------------------------- util/auth/auth.go | 81 +++++++++++++++++++++++++++++++++++++++++++++++ web/service.go | 8 +++++ 3 files changed, 91 insertions(+), 73 deletions(-) create mode 100644 util/auth/auth.go diff --git a/service.go b/service.go index f37dc83b..9c414654 100644 --- a/service.go +++ b/service.go @@ -1,13 +1,11 @@ package micro import ( - "fmt" "os" "os/signal" rtime "runtime" "strings" "sync" - "time" "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/client" @@ -19,6 +17,7 @@ import ( "github.com/micro/go-micro/v2/plugin" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/store" + authutil "github.com/micro/go-micro/v2/util/auth" signalutil "github.com/micro/go-micro/v2/util/signal" "github.com/micro/go-micro/v2/util/wrapper" ) @@ -177,7 +176,7 @@ func (s *service) Stop() error { func (s *service) Run() error { // generate an auth account - if err := s.generateAccount(); err != nil { + if err := authutil.Generate(s.Server().Options().Id, s.Name(), s.Options().Auth); err != nil { return err } @@ -224,73 +223,3 @@ func (s *service) Run() error { return s.Stop() } - -func (s *service) generateAccount() error { - // extract the account creds from options, these can be set by flags - accID := s.Options().Auth.Options().ID - accSecret := s.Options().Auth.Options().Secret - - // if no credentials were provided, generate an account - if len(accID) == 0 || len(accSecret) == 0 { - name := fmt.Sprintf("%v-%v", s.Name(), s.Server().Options().Id) - opts := []auth.GenerateOption{ - auth.WithType("service"), - auth.WithRoles("service"), - auth.WithNamespace(s.Options().Auth.Options().Namespace), - } - - acc, err := s.Options().Auth.Generate(name, opts...) - if err != nil { - return err - } - logger.Infof("Auth [%v] Authenticated as %v", s.Options().Auth, name) - - accID = acc.ID - accSecret = acc.Secret - } - - // generate the first token - token, err := s.Options().Auth.Token( - auth.WithCredentials(accID, accSecret), - auth.WithExpiry(time.Minute*10), - ) - if err != nil { - return err - } - - // set the credentials and token in auth options - s.Options().Auth.Init( - auth.ClientToken(token), - auth.Credentials(accID, accSecret), - ) - - // periodically check to see if the token needs refreshing - go func() { - timer := time.NewTicker(time.Second * 15) - - for { - <-timer.C - - // don't refresh the token if it's not close to expiring - tok := s.Options().Auth.Options().Token - if tok.Expiry.Unix() > time.Now().Add(time.Minute).Unix() { - continue - } - - // generate the first token - tok, err := s.Options().Auth.Token( - auth.WithCredentials(accID, accSecret), - auth.WithExpiry(time.Minute*10), - ) - if err != nil { - logger.Warnf("[Auth] Error refreshing token: %v", err) - continue - } - - // set the token - s.Options().Auth.Init(auth.ClientToken(tok)) - } - }() - - return nil -} diff --git a/util/auth/auth.go b/util/auth/auth.go new file mode 100644 index 00000000..454c5e9e --- /dev/null +++ b/util/auth/auth.go @@ -0,0 +1,81 @@ +package auth + +import ( + "fmt" + "time" + + "github.com/micro/go-micro/v2/auth" + "github.com/micro/go-micro/v2/logger" +) + +// Generate generates a service account for and continually +// refreshes the access token. +func Generate(id string, name string, a auth.Auth) error { + // extract the account creds from options, these can be set by flags + accID := a.Options().ID + accSecret := a.Options().Secret + + // if no credentials were provided, generate an account + if len(accID) == 0 || len(accSecret) == 0 { + name := fmt.Sprintf("%v-%v", name, id) + opts := []auth.GenerateOption{ + auth.WithType("service"), + auth.WithRoles("service"), + auth.WithNamespace(a.Options().Namespace), + } + + acc, err := a.Generate(name, opts...) + if err != nil { + return err + } + logger.Infof("Auth [%v] Authenticated as %v in the %v namespace", a, name, acc.Namespace) + + accID = acc.ID + accSecret = acc.Secret + } + + // generate the first token + token, err := a.Token( + auth.WithCredentials(accID, accSecret), + auth.WithExpiry(time.Minute*10), + ) + if err != nil { + return err + } + + // set the credentials and token in auth options + a.Init( + auth.ClientToken(token), + auth.Credentials(accID, accSecret), + ) + + // periodically check to see if the token needs refreshing + go func() { + timer := time.NewTicker(time.Second * 15) + + for { + <-timer.C + + // don't refresh the token if it's not close to expiring + tok := a.Options().Token + if tok.Expiry.Unix() > time.Now().Add(time.Minute).Unix() { + continue + } + + // generate the first token + tok, err := a.Token( + auth.WithCredentials(accID, accSecret), + auth.WithExpiry(time.Minute*10), + ) + if err != nil { + logger.Warnf("[Auth] Error refreshing token: %v", err) + continue + } + + // set the token + a.Init(auth.ClientToken(tok)) + } + }() + + return nil +} diff --git a/web/service.go b/web/service.go index 4ca54f88..c9efc25a 100644 --- a/web/service.go +++ b/web/service.go @@ -17,6 +17,7 @@ import ( "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" maddr "github.com/micro/go-micro/v2/util/addr" + authutil "github.com/micro/go-micro/v2/util/auth" mhttp "github.com/micro/go-micro/v2/util/http" mnet "github.com/micro/go-micro/v2/util/net" signalutil "github.com/micro/go-micro/v2/util/signal" @@ -421,6 +422,13 @@ func (s *service) Init(opts ...Option) error { } func (s *service) Run() error { + // generate an auth account + srvID := s.opts.Service.Server().Options().Id + srvName := s.opts.Service.Name() + if err := authutil.Generate(srvID, srvName, s.opts.Service.Options().Auth); err != nil { + return err + } + if err := s.start(); err != nil { return err } From 8a802d8f7afc0191f994051c94e9630d0a528a18 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 14 May 2020 18:00:13 +0100 Subject: [PATCH 774/788] Fix registry address option unused --- registry/service/service.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/registry/service/service.go b/registry/service/service.go index ddf6fd00..894c74c2 100644 --- a/registry/service/service.go +++ b/registry/service/service.go @@ -47,6 +47,10 @@ func (s *serviceRegistry) Init(opts ...registry.Option) error { o(&s.opts) } + if len(s.opts.Addrs) > 0 { + s.address = s.opts.Addrs + } + // extract the client from the context, fallback to grpc var cli client.Client if c, ok := s.opts.Context.Value(clientKey{}).(client.Client); ok { From 0d7250352f16c72e15daa8aa1fc5701540e19129 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Thu, 14 May 2020 19:38:56 +0100 Subject: [PATCH 775/788] Registry service: return not found error --- registry/service/service.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/registry/service/service.go b/registry/service/service.go index ddf6fd00..7c264977 100644 --- a/registry/service/service.go +++ b/registry/service/service.go @@ -7,6 +7,7 @@ import ( "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/grpc" + "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/registry" pb "github.com/micro/go-micro/v2/registry/service/proto" ) @@ -116,7 +117,9 @@ func (s *serviceRegistry) GetService(name string, opts ...registry.GetOption) ([ Service: name, }, s.callOpts()...) - if err != nil { + if verr, ok := err.(*errors.Error); ok && verr.Code == 404 { + return nil, registry.ErrNotFound + } else if err != nil { return nil, err } From 4d2de923cda221d3c1af0cfa3bb5e151dabf1d3e Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Fri, 15 May 2020 10:24:30 +0100 Subject: [PATCH 776/788] Auth: setup a public rule --- auth/service/service.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/auth/service/service.go b/auth/service/service.go index 482b488f..733244a6 100644 --- a/auth/service/service.go +++ b/auth/service/service.go @@ -203,7 +203,13 @@ var ruleJoinKey = ":" // accessForRule returns a rule status, indicating if a rule permits access to a // resource for a given account func accessForRule(rule *pb.Rule, acc *auth.Account, res *auth.Resource) pb.Access { - if rule.Role == "*" { + // a blank role permits access to the public + if rule.Role == "" { + return rule.Access + } + + // a * role permits access to any user + if rule.Role == "*" && acc != nil { return rule.Access } From 56a7897c919b3799cde12b88377cbf27d990210b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 17 May 2020 12:39:20 +0100 Subject: [PATCH 777/788] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 491c42db..0359e027 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Go Micro [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/micro/go-micro?tab=doc) [![Travis CI](https://api.travis-ci.org/micro/go-micro.svg?branch=master)](https://travis-ci.org/micro/go-micro) [![Go Report Card](https://goreportcard.com/badge/micro/go-micro)](https://goreportcard.com/report/github.com/micro/go-micro) +# Go Micro [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/micro/go-micro?tab=doc) [![Travis CI](https://api.travis-ci.org/micro/go-micro.svg?branch=master)](https://travis-ci.org/micro/go-micro) [![Go Report Card](https://goreportcard.com/badge/micro/go-micro)](https://goreportcard.com/report/github.com/micro/go-micro) Slack Widget Go Micro is a framework for distributed systems development. From 3d36398818f4f9f646b2e2f0268eec27922a1ccb Mon Sep 17 00:00:00 2001 From: Maarten Bezemer Date: Mon, 18 May 2020 18:22:33 +0200 Subject: [PATCH 778/788] Fix client RPC stream close mutex (#1643) --- client/rpc_stream.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/rpc_stream.go b/client/rpc_stream.go index 7c880d88..426aafc4 100644 --- a/client/rpc_stream.go +++ b/client/rpc_stream.go @@ -130,15 +130,15 @@ func (r *rpcStream) Error() error { } func (r *rpcStream) Close() error { - r.RLock() + r.Lock() select { case <-r.closed: - r.RUnlock() + r.Unlock() return nil default: close(r.closed) - r.RUnlock() + r.Unlock() // send the end of stream message if r.sendEOS { From 14155c7e02ab1b1a34e7353dfcebd9de80ab3947 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 19 May 2020 09:28:00 +0100 Subject: [PATCH 779/788] Add runtime ErrNotFound --- runtime/runtime.go | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/runtime.go b/runtime/runtime.go index 567e8c3b..62813973 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -12,6 +12,7 @@ var ( // DefaultName is default runtime service name DefaultName = "go.micro.runtime" + ErrNotFound = errors.New("not found") ErrAlreadyExists = errors.New("already exists") ) From c19b349e961366de7495931c548bd120828c235b Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 19 May 2020 10:14:07 +0100 Subject: [PATCH 780/788] Update runtime.Event struct --- runtime/default.go | 4 ++-- runtime/kubernetes/kubernetes.go | 8 ++++---- runtime/runtime.go | 10 ++++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index 869070fa..1be03e2f 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -260,9 +260,9 @@ func (r *runtime) run(events <-chan Event) { // NOTE: we only handle Update events for now switch event.Type { case Update: - if len(event.Service) > 0 { + if event.Service != nil { r.RLock() - service, ok := r.services[fmt.Sprintf("%v:%v", event.Service, event.Version)] + service, ok := r.services[fmt.Sprintf("%v:%v", event.Service.Name, event.Service.Version)] r.RUnlock() if !ok { if logger.V(logger.DebugLevel, logger.DefaultLogger) { diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 01f61769..5ce110c6 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -252,12 +252,12 @@ func (k *kubernetes) run(events <-chan runtime.Event) { case runtime.Update: // only process if there's an actual service // we do not update all the things individually - if len(event.Service) == 0 { + if event.Service == nil { continue } // format the name - name := client.Format(event.Service) + name := client.Format(event.Service.Name) // set the default labels labels := map[string]string{ @@ -265,8 +265,8 @@ func (k *kubernetes) run(events <-chan runtime.Event) { "name": name, } - if len(event.Version) > 0 { - labels["version"] = event.Version + if len(event.Service.Version) > 0 { + labels["version"] = event.Service.Version } // get the deployment status diff --git a/runtime/runtime.go b/runtime/runtime.go index 62813973..288604ba 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -86,14 +86,16 @@ func (t EventType) String() string { // Event is notification event type Event struct { + // ID of the event + ID string // Type is event type Type EventType // Timestamp is event timestamp Timestamp time.Time - // Service is the name of the service - Service string - // Version of the build - Version string + // Service the event relates to + Service *Service + // Options to use when processing the event + Options *CreateOptions } // Service is runtime service From 8875719619808b626df005f7a156c04b2807cb91 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 19 May 2020 11:01:06 +0100 Subject: [PATCH 781/788] Default Runtime multi-tenancy --- runtime/default.go | 182 ++++++++++++++++++++++++++++++--------------- runtime/runtime.go | 1 - 2 files changed, 124 insertions(+), 59 deletions(-) diff --git a/runtime/default.go b/runtime/default.go index 1be03e2f..61a1f562 100644 --- a/runtime/default.go +++ b/runtime/default.go @@ -18,6 +18,9 @@ import ( "github.com/micro/go-micro/v2/runtime/local/git" ) +// defaultNamespace to use if not provided as an option +const defaultNamespace = "default" + type runtime struct { sync.RWMutex // options configure runtime @@ -28,9 +31,9 @@ type runtime struct { start chan *service // indicates if we're running running bool - // the service map - // TODO: track different versions of the same service - services map[string]*service + // namespaces stores services grouped by namespace, e.g. namespaces["foo"]["go.micro.auth:latest"] + // would return the latest version of go.micro.auth from the foo namespace + namespaces map[string]map[string]*service } // NewRuntime creates new local runtime and returns it @@ -48,10 +51,10 @@ func NewRuntime(opts ...Option) Runtime { _ = os.MkdirAll(path, 0755) return &runtime{ - options: options, - closed: make(chan bool), - start: make(chan *service, 128), - services: make(map[string]*service), + options: options, + closed: make(chan bool), + start: make(chan *service, 128), + namespaces: make(map[string]map[string]*service), } } @@ -190,7 +193,7 @@ func (r *runtime) run(events <-chan Event) { defer t.Stop() // process event processes an incoming event - processEvent := func(event Event, service *service) error { + processEvent := func(event Event, service *service, ns string) error { // get current vals r.RLock() name := service.Name @@ -203,11 +206,11 @@ func (r *runtime) run(events <-chan Event) { } if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime updating service %s", name) + logger.Debugf("Runtime updating service %s in %v namespace", name, ns) } // this will cause a delete followed by created - if err := r.Update(service.Service); err != nil { + if err := r.Update(service.Service, UpdateNamespace(ns)); err != nil { return err } @@ -224,18 +227,20 @@ func (r *runtime) run(events <-chan Event) { case <-t.C: // check running services r.RLock() - for _, service := range r.services { - if !service.ShouldStart() { - continue - } + for _, sevices := range r.namespaces { + for _, service := range sevices { + if !service.ShouldStart() { + continue + } - // TODO: check service error - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime starting %s", service.Name) - } - if err := service.Start(); err != nil { + // TODO: check service error if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime error starting %s: %v", service.Name, err) + logger.Debugf("Runtime starting %s", service.Name) + } + if err := service.Start(); err != nil { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime error starting %s: %v", service.Name, err) + } } } } @@ -261,16 +266,26 @@ func (r *runtime) run(events <-chan Event) { switch event.Type { case Update: if event.Service != nil { + ns := defaultNamespace + if event.Options != nil && len(event.Options.Namespace) > 0 { + ns = event.Options.Namespace + } + r.RLock() - service, ok := r.services[fmt.Sprintf("%v:%v", event.Service.Name, event.Service.Version)] - r.RUnlock() - if !ok { + if _, ok := r.namespaces[ns]; !ok { if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime unknown service: %s", event.Service) + logger.Debugf("Runtime unknown namespace: %s", ns) } + r.RUnlock() continue } - if err := processEvent(event, service); err != nil { + service, ok := r.namespaces[ns][fmt.Sprintf("%v:%v", event.Service.Name, event.Service.Version)] + r.RUnlock() + if !ok { + logger.Debugf("Runtime unknown service: %s", event.Service) + } + + if err := processEvent(event, service, ns); err != nil { if logger.V(logger.DebugLevel, logger.DefaultLogger) { logger.Debugf("Runtime error updating service %s: %v", event.Service, err) } @@ -279,14 +294,16 @@ func (r *runtime) run(events <-chan Event) { } r.RLock() - services := r.services + namespaces := r.namespaces r.RUnlock() // if blank service was received we update all services - for _, service := range services { - if err := processEvent(event, service); err != nil { - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime error updating service %s: %v", service.Name, err) + for ns, services := range namespaces { + for _, service := range services { + if err := processEvent(event, service, ns); err != nil { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime error updating service %s: %v", service.Name, err) + } } } } @@ -320,20 +337,25 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error { r.Lock() defer r.Unlock() - if _, ok := r.services[serviceKey(s)]; ok { - return errors.New("service already running") - } - var options CreateOptions for _, o := range opts { o(&options) } - + if len(options.Namespace) == 0 { + options.Namespace = defaultNamespace + } if len(options.Command) == 0 { options.Command = []string{"go"} options.Args = []string{"run", "."} } + if _, ok := r.namespaces[options.Namespace]; !ok { + r.namespaces[options.Namespace] = make(map[string]*service) + } + if _, ok := r.namespaces[options.Namespace][serviceKey(s)]; ok { + return errors.New("service already running") + } + // create new service service := newService(s, options) @@ -353,7 +375,7 @@ func (r *runtime) Create(s *Service, opts ...CreateOption) error { } // save service - r.services[serviceKey(s)] = service + r.namespaces[options.Namespace][serviceKey(s)] = service return nil } @@ -481,6 +503,9 @@ func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) { for _, o := range opts { o(&gopts) } + if len(gopts.Namespace) == 0 { + gopts.Namespace = defaultNamespace + } save := func(k, v string) bool { if len(k) == 0 { @@ -492,7 +517,11 @@ func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) { //nolint:prealloc var services []*Service - for _, service := range r.services { + if _, ok := r.namespaces[gopts.Namespace]; !ok { + return make([]*Service, 0), nil + } + + for _, service := range r.namespaces[gopts.Namespace] { if !save(gopts.Service, service.Name) { continue } @@ -509,20 +538,37 @@ func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) { // Update attemps to update the service func (r *runtime) Update(s *Service, opts ...UpdateOption) error { + var options UpdateOptions + for _, o := range opts { + o(&options) + } + if len(options.Namespace) == 0 { + options.Namespace = defaultNamespace + } + err := r.checkoutSourceIfNeeded(s) if err != nil { return err } + r.Lock() - service, ok := r.services[serviceKey(s)] + srvs, ok := r.namespaces[options.Namespace] r.Unlock() if !ok { return errors.New("Service not found") } - err = service.Stop() - if err != nil { + + r.Lock() + service, ok := srvs[serviceKey(s)] + r.Unlock() + if !ok { + return errors.New("Service not found") + } + + if err := service.Stop(); err != nil { return err } + return service.Start() } @@ -531,24 +577,41 @@ func (r *runtime) Delete(s *Service, opts ...DeleteOption) error { r.Lock() defer r.Unlock() - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime deleting service %s", s.Name) + var options DeleteOptions + for _, o := range opts { + o(&options) } - if s, ok := r.services[serviceKey(s)]; ok { - // check if running - if !s.Running() { - delete(r.services, s.key()) - return nil - } - // otherwise stop it - if err := s.Stop(); err != nil { - return err - } - // delete it - delete(r.services, s.key()) + if len(options.Namespace) == 0 { + options.Namespace = defaultNamespace + } + + srvs, ok := r.namespaces[options.Namespace] + if !ok { return nil } + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime deleting service %s", s.Name) + } + + service, ok := srvs[serviceKey(s)] + if !ok { + return nil + } + + // check if running + if !service.Running() { + delete(srvs, service.key()) + r.namespaces[options.Namespace] = srvs + return nil + } + // otherwise stop it + if err := service.Stop(); err != nil { + return err + } + // delete it + delete(srvs, service.key()) + r.namespaces[options.Namespace] = srvs return nil } @@ -602,12 +665,15 @@ func (r *runtime) Stop() error { r.running = false // stop all the services - for _, service := range r.services { - if logger.V(logger.DebugLevel, logger.DefaultLogger) { - logger.Debugf("Runtime stopping %s", service.Name) + for _, services := range r.namespaces { + for _, service := range services { + if logger.V(logger.DebugLevel, logger.DefaultLogger) { + logger.Debugf("Runtime stopping %s", service.Name) + } + service.Stop() } - service.Stop() } + // stop the scheduler if r.options.Scheduler != nil { return r.options.Scheduler.Close() diff --git a/runtime/runtime.go b/runtime/runtime.go index 288604ba..1299baf5 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -12,7 +12,6 @@ var ( // DefaultName is default runtime service name DefaultName = "go.micro.runtime" - ErrNotFound = errors.New("not found") ErrAlreadyExists = errors.New("already exists") ) From f0c0f3d4c45f49ec8586051a1bd9e1794e523fed Mon Sep 17 00:00:00 2001 From: Patrik Lindahl Date: Tue, 19 May 2020 19:11:26 +0800 Subject: [PATCH 782/788] Fixes for #1560 (#1644) close #1560 This fixes one of the reported data races and also allows for having a different name on the micro.Service and web.Service. This makes it possible to discover the two service variants separately. Co-authored-by: Vasiliy Tolstov --- web/service.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/web/service.go b/web/service.go index c9efc25a..aed52eda 100644 --- a/web/service.go +++ b/web/service.go @@ -112,8 +112,8 @@ func (s *service) run(exit chan bool) { } func (s *service) register() error { - s.RLock() - defer s.RUnlock() + s.Lock() + defer s.Unlock() if s.srv == nil { return nil @@ -142,8 +142,8 @@ func (s *service) register() error { } func (s *service) deregister() error { - s.RLock() - defer s.RUnlock() + s.Lock() + defer s.Unlock() if s.srv == nil { return nil @@ -406,7 +406,9 @@ func (s *service) Init(opts ...Option) error { s.RLock() // pass in own name and version - serviceOpts = append(serviceOpts, micro.Name(s.opts.Name)) + if s.opts.Service.Name() == "" { + serviceOpts = append(serviceOpts, micro.Name(s.opts.Name)) + } serviceOpts = append(serviceOpts, micro.Version(s.opts.Version)) s.RUnlock() From 9216a47724b8bf1b6e362f36a57723355db19a02 Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 19 May 2020 14:44:46 +0100 Subject: [PATCH 783/788] fix client race (#1647) --- client/rpc_client.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client/rpc_client.go b/client/rpc_client.go index d66a918a..20d07546 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -114,8 +114,7 @@ func (r *rpcClient) call(ctx context.Context, node *registry.Node, req Request, return errors.InternalServerError("go.micro.client", "connection error: %v", err) } - seq := atomic.LoadUint64(&r.seq) - atomic.AddUint64(&r.seq, 1) + seq := atomic.AddUint64(&r.seq, 1) - 1 codec := newRpcCodec(msg, c, cf, "") rsp := &rpcResponse{ @@ -232,8 +231,7 @@ func (r *rpcClient) stream(ctx context.Context, node *registry.Node, req Request } // increment the sequence number - seq := atomic.LoadUint64(&r.seq) - atomic.AddUint64(&r.seq, 1) + seq := atomic.AddUint64(&r.seq, 1) - 1 id := fmt.Sprintf("%v", seq) // create codec with stream id From a29676b86a540f2efa2c9b4cda95a8cb21d36346 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 20 May 2020 11:49:09 +0100 Subject: [PATCH 784/788] Registration Retry / Interval (#1651) * Change the default ttl to 90 seconds * add retries to registration * Add retry to web register --- server/grpc/grpc.go | 33 ++++++++++++++++++++++++++------- server/rpc_server.go | 36 ++++++++++++++++++++++++++++-------- server/server.go | 4 ++-- web/service.go | 20 +++++++++++++++++++- web/web.go | 2 +- 5 files changed, 76 insertions(+), 19 deletions(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index a4501c05..1123fba8 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -22,6 +22,7 @@ import ( "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/server" "github.com/micro/go-micro/v2/util/addr" + "github.com/micro/go-micro/v2/util/backoff" mgrpc "github.com/micro/go-micro/v2/util/grpc" mnet "github.com/micro/go-micro/v2/util/net" "golang.org/x/net/netutil" @@ -566,16 +567,36 @@ func (g *grpcServer) Subscribe(sb server.Subscriber) error { } func (g *grpcServer) Register() error { - g.RLock() rsvc := g.rsvc config := g.opts g.RUnlock() + regFunc := func(service *registry.Service) error { + var regErr error + + for i := 0; i < 3; i++ { + // set the ttl + rOpts := []registry.RegisterOption{registry.RegisterTTL(config.RegisterTTL)} + // attempt to register + if err := config.Registry.Register(service, rOpts...); err != nil { + // set the error + regErr = err + // backoff then retry + time.Sleep(backoff.Do(i + 1)) + continue + } + // success so nil error + regErr = nil + break + } + + return regErr + } + // if service already filled, reuse it and return early if rsvc != nil { - rOpts := []registry.RegisterOption{registry.RegisterTTL(config.RegisterTTL)} - if err := config.Registry.Register(rsvc, rOpts...); err != nil { + if err := regFunc(rsvc); err != nil { return err } return nil @@ -677,10 +698,8 @@ func (g *grpcServer) Register() error { } } - // create registry options - rOpts := []registry.RegisterOption{registry.RegisterTTL(config.RegisterTTL)} - - if err := config.Registry.Register(service, rOpts...); err != nil { + // register the service + if err := regFunc(service); err != nil { return err } diff --git a/server/rpc_server.go b/server/rpc_server.go index f1ce3ebb..212d539a 100644 --- a/server/rpc_server.go +++ b/server/rpc_server.go @@ -20,6 +20,7 @@ import ( "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/transport" "github.com/micro/go-micro/v2/util/addr" + "github.com/micro/go-micro/v2/util/backoff" mnet "github.com/micro/go-micro/v2/util/net" "github.com/micro/go-micro/v2/util/socket" ) @@ -514,18 +515,39 @@ func (s *rpcServer) Subscribe(sb Subscriber) error { } func (s *rpcServer) Register() error { - s.RLock() rsvc := s.rsvc config := s.Options() s.RUnlock() - if rsvc != nil { + regFunc := func(service *registry.Service) error { + // create registry options rOpts := []registry.RegisterOption{registry.RegisterTTL(config.RegisterTTL)} - if err := config.Registry.Register(rsvc, rOpts...); err != nil { - return err + + var regErr error + + for i := 0; i < 3; i++ { + // attempt to register + if err := config.Registry.Register(service, rOpts...); err != nil { + // set the error + regErr = err + // backoff then retry + time.Sleep(backoff.Do(i + 1)) + continue + } + // success so nil error + regErr = nil + break } + return regErr + } + + // have we registered before? + if rsvc != nil { + if err := regFunc(rsvc); err != nil { + return err + } return nil } @@ -635,10 +657,8 @@ func (s *rpcServer) Register() error { } } - // create registry options - rOpts := []registry.RegisterOption{registry.RegisterTTL(config.RegisterTTL)} - - if err := config.Registry.Register(service, rOpts...); err != nil { + // register the service + if err := regFunc(service); err != nil { return err } diff --git a/server/server.go b/server/server.go index 136ae6f9..a7c00fca 100644 --- a/server/server.go +++ b/server/server.go @@ -125,7 +125,7 @@ type Handler interface { } // Subscriber interface represents a subscription to a given topic using -// a specific subscriber function or object with endpoints. It mirrors +// a specific subscriber function or object with endpoints. It mirrors // the handler in its behaviour. type Subscriber interface { Topic() string @@ -145,7 +145,7 @@ var ( DefaultRouter = newRpcRouter() DefaultRegisterCheck = func(context.Context) error { return nil } DefaultRegisterInterval = time.Second * 30 - DefaultRegisterTTL = time.Minute + DefaultRegisterTTL = time.Second * 90 // NewServer creates a new server NewServer func(...Option) Server = newRpcServer diff --git a/web/service.go b/web/service.go index aed52eda..bee94814 100644 --- a/web/service.go +++ b/web/service.go @@ -18,6 +18,7 @@ import ( "github.com/micro/go-micro/v2/registry" maddr "github.com/micro/go-micro/v2/util/addr" authutil "github.com/micro/go-micro/v2/util/auth" + "github.com/micro/go-micro/v2/util/backoff" mhttp "github.com/micro/go-micro/v2/util/http" mnet "github.com/micro/go-micro/v2/util/net" signalutil "github.com/micro/go-micro/v2/util/signal" @@ -138,7 +139,24 @@ func (s *service) register() error { return err } - return r.Register(s.srv, registry.RegisterTTL(s.opts.RegisterTTL)) + var regErr error + + // try three times if necessary + for i := 0; i < 3; i++ { + // attempt to register + if err := r.Register(s.srv, registry.RegisterTTL(s.opts.RegisterTTL)); err != nil { + // set the error + regErr = err + // backoff then retry + time.Sleep(backoff.Do(i + 1)) + continue + } + // success so nil error + regErr = nil + break + } + + return regErr } func (s *service) deregister() error { diff --git a/web/web.go b/web/web.go index 72f653b9..6bd9c82b 100644 --- a/web/web.go +++ b/web/web.go @@ -31,7 +31,7 @@ var ( DefaultAddress = ":0" // for registration - DefaultRegisterTTL = time.Minute + DefaultRegisterTTL = time.Second * 90 DefaultRegisterInterval = time.Second * 30 // static directory From 6a661fd08cbac5e955b2087bc9de6949b96f4af5 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 20 May 2020 14:03:38 +0100 Subject: [PATCH 785/788] check if the db conn is nil before doing anything (#1652) --- store/cockroach/cockroach.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/store/cockroach/cockroach.go b/store/cockroach/cockroach.go index 13b12d9d..bd6ae34f 100644 --- a/store/cockroach/cockroach.go +++ b/store/cockroach/cockroach.go @@ -11,6 +11,7 @@ import ( "time" "github.com/lib/pq" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/store" "github.com/pkg/errors" ) @@ -87,6 +88,10 @@ func (s *sqlStore) createDB(database, table string) error { } func (s *sqlStore) initDB(database, table string) error { + if s.db == nil { + return errors.New("Database connection not initialised") + } + // Create the namespace's database _, err := s.db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s;", database)) if err != nil { @@ -456,7 +461,11 @@ func NewStore(opts ...store.Option) store.Store { // mark known databases s.databases = make(map[string]bool) // best-effort configure the store - s.configure() + if err := s.configure(); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Error("Error configuring store ", err) + } + } // return store return s From 0615fe825faaa3e23a5e6607705b908a357426b7 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Wed, 20 May 2020 16:18:05 +0200 Subject: [PATCH 786/788] Auth invalid token fix (#1650) --- util/auth/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/auth/auth.go b/util/auth/auth.go index 454c5e9e..cb292c5e 100644 --- a/util/auth/auth.go +++ b/util/auth/auth.go @@ -64,7 +64,7 @@ func Generate(id string, name string, a auth.Auth) error { // generate the first token tok, err := a.Token( - auth.WithCredentials(accID, accSecret), + auth.WithToken(tok.RefreshToken), auth.WithExpiry(time.Minute*10), ) if err != nil { From ffd89599a06e44de68c7ff6f3c252b10be69be67 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 23 May 2020 16:46:50 +0100 Subject: [PATCH 787/788] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0359e027..8d6421da 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Go Micro is a framework for distributed systems development. ## Overview Go Micro provides the core requirements for distributed systems development including RPC and Event driven communication. -The **micro** philosophy is sane defaults with a pluggable architecture. We provide defaults to get you started quickly +The **Micro** philosophy is sane defaults with a pluggable architecture. We provide defaults to get you started quickly but everything can be easily swapped out. From bd049a51e6373e707e3219c5ebfe10f3fde5984a Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 23 May 2020 16:47:23 +0100 Subject: [PATCH 788/788] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d6421da..e95d2276 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ but everything can be easily swapped out. Plugins are available at [github.com/micro/go-plugins](https://github.com/micro/go-plugins). -Follow us on [Twitter](https://twitter.com/microhq) or join the [Community](https://micro.mu/slack). +Follow us on [Twitter](https://twitter.com/microhq) or join the [Community](https://slack.micro.mu). ## Features