2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2020-09-08 21:31:47 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
2020-10-02 15:58:18 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
2020-09-08 21:31:47 +00:00
|
|
|
"github.com/hashicorp/consul/acl"
|
|
|
|
"github.com/hashicorp/consul/agent/consul/stream"
|
2022-07-13 15:33:48 +00:00
|
|
|
"github.com/hashicorp/consul/agent/grpc-internal/services/subscribe"
|
2020-10-21 20:41:22 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2020-09-08 21:31:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type subscribeBackend struct {
|
|
|
|
srv *Server
|
2021-04-20 22:14:46 +00:00
|
|
|
connPool GRPCClientConner
|
2020-09-08 21:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: refactor Resolve methods to an ACLBackend that can be used by all
|
|
|
|
// the endpoints.
|
2020-10-21 20:08:33 +00:00
|
|
|
func (s subscribeBackend) ResolveTokenAndDefaultMeta(
|
|
|
|
token string,
|
2022-04-05 21:10:06 +00:00
|
|
|
entMeta *acl.EnterpriseMeta,
|
2020-10-21 20:08:33 +00:00
|
|
|
authzContext *acl.AuthorizerContext,
|
|
|
|
) (acl.Authorizer, error) {
|
|
|
|
return s.srv.ResolveTokenAndDefaultMeta(token, entMeta, authzContext)
|
2020-09-08 21:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ subscribe.Backend = (*subscribeBackend)(nil)
|
|
|
|
|
2021-09-22 18:14:26 +00:00
|
|
|
func (s subscribeBackend) Forward(info structs.RPCInfo, f func(*grpc.ClientConn) error) (handled bool, err error) {
|
|
|
|
return s.srv.ForwardGRPC(s.connPool, info, f)
|
2020-09-08 21:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s subscribeBackend) Subscribe(req *stream.SubscribeRequest) (*stream.Subscription, error) {
|
2022-04-12 13:47:42 +00:00
|
|
|
return s.srv.publisher.Subscribe(req)
|
2020-09-08 21:31:47 +00:00
|
|
|
}
|