2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-05-27 11:38:52 +00:00
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
2023-01-18 18:33:21 +00:00
|
|
|
"github.com/hashicorp/consul/agent/grpc-external/limiter"
|
2022-05-27 11:38:52 +00:00
|
|
|
"github.com/hashicorp/consul/agent/proxycfg"
|
|
|
|
structs "github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ConfigSource wraps a proxycfg.Manager to create watches on services
|
|
|
|
// local to the agent (pre-registered by Sync).
|
|
|
|
type ConfigSource struct {
|
|
|
|
manager ConfigManager
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewConfigSource builds a ConfigSource with the given proxycfg.Manager.
|
|
|
|
func NewConfigSource(cfgMgr ConfigManager) *ConfigSource {
|
|
|
|
return &ConfigSource{cfgMgr}
|
|
|
|
}
|
|
|
|
|
2023-01-18 18:33:21 +00:00
|
|
|
func (m *ConfigSource) Watch(serviceID structs.ServiceID, nodeName string, _ string) (<-chan *proxycfg.ConfigSnapshot, limiter.SessionTerminatedChan, proxycfg.CancelFunc, error) {
|
2022-05-27 11:38:52 +00:00
|
|
|
watchCh, cancelWatch := m.manager.Watch(proxycfg.ProxyID{
|
|
|
|
ServiceID: serviceID,
|
|
|
|
NodeName: nodeName,
|
|
|
|
|
|
|
|
// Note: we *intentionally* don't set Token here. All watches on local
|
|
|
|
// services use the same ACL token, regardless of whatever token is
|
|
|
|
// presented in the xDS stream (the token presented to the xDS server
|
|
|
|
// is checked before the watch is created).
|
|
|
|
Token: "",
|
|
|
|
})
|
2023-01-18 18:33:21 +00:00
|
|
|
return watchCh, nil, cancelWatch, nil
|
2022-05-27 11:38:52 +00:00
|
|
|
}
|