2023-03-28 19:39:22 +01:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 09:12:13 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 19:39:22 +01:00
|
|
|
|
2022-04-21 12:56:18 -04:00
|
|
|
package serverdiscovery
|
|
|
|
|
|
|
|
import (
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-hclog"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/acl"
|
2022-06-17 10:24:43 +01:00
|
|
|
"github.com/hashicorp/consul/acl/resolver"
|
2022-04-21 12:56:18 -04:00
|
|
|
"github.com/hashicorp/consul/agent/consul/stream"
|
|
|
|
"github.com/hashicorp/consul/proto-public/pbserverdiscovery"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Server struct {
|
|
|
|
Config
|
|
|
|
}
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Publisher EventPublisher
|
|
|
|
Logger hclog.Logger
|
|
|
|
ACLResolver ACLResolver
|
|
|
|
}
|
|
|
|
|
|
|
|
type EventPublisher interface {
|
|
|
|
Subscribe(*stream.SubscribeRequest) (*stream.Subscription, error)
|
|
|
|
}
|
|
|
|
|
2022-06-17 10:24:43 +01:00
|
|
|
//go:generate mockery --name ACLResolver --inpackage
|
2022-04-21 12:56:18 -04:00
|
|
|
type ACLResolver interface {
|
2022-06-17 10:24:43 +01:00
|
|
|
ResolveTokenAndDefaultMeta(string, *acl.EnterpriseMeta, *acl.AuthorizerContext) (resolver.Result, error)
|
2022-04-21 12:56:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewServer(cfg Config) *Server {
|
|
|
|
return &Server{cfg}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) Register(grpcServer *grpc.Server) {
|
|
|
|
pbserverdiscovery.RegisterServerDiscoveryServiceServer(grpcServer, s)
|
|
|
|
}
|