2024-01-10 16:19:20 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
package discovery
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"sync/atomic"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/config"
|
|
|
|
)
|
|
|
|
|
2024-01-17 23:46:18 +00:00
|
|
|
// v2DataFetcherDynamicConfig is used to store the dynamic configuration of the V2 data fetcher.
|
2024-01-10 16:19:20 +00:00
|
|
|
type v2DataFetcherDynamicConfig struct {
|
|
|
|
onlyPassing bool
|
|
|
|
}
|
|
|
|
|
2024-01-17 23:46:18 +00:00
|
|
|
// V2DataFetcher is used to fetch data from the V2 catalog.
|
2024-01-10 16:19:20 +00:00
|
|
|
type V2DataFetcher struct {
|
|
|
|
dynamicConfig atomic.Value
|
|
|
|
}
|
|
|
|
|
2024-01-17 23:46:18 +00:00
|
|
|
// NewV2DataFetcher creates a new V2 data fetcher.
|
2024-01-10 16:19:20 +00:00
|
|
|
func NewV2DataFetcher(config *config.RuntimeConfig) *V2DataFetcher {
|
|
|
|
f := &V2DataFetcher{}
|
|
|
|
f.LoadConfig(config)
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
2024-01-17 23:46:18 +00:00
|
|
|
// LoadConfig loads the configuration for the V2 data fetcher.
|
2024-01-10 16:19:20 +00:00
|
|
|
func (f *V2DataFetcher) LoadConfig(config *config.RuntimeConfig) {
|
|
|
|
dynamicConfig := &v2DataFetcherDynamicConfig{
|
|
|
|
onlyPassing: config.DNSOnlyPassing,
|
|
|
|
}
|
|
|
|
f.dynamicConfig.Store(dynamicConfig)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO (v2-dns): Implementation of the V2 data fetcher
|
|
|
|
|
2024-01-17 23:46:18 +00:00
|
|
|
// FetchNodes fetches A/AAAA/CNAME
|
2024-01-10 16:19:20 +00:00
|
|
|
func (f *V2DataFetcher) FetchNodes(ctx Context, req *QueryPayload) ([]*Result, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2024-01-17 23:46:18 +00:00
|
|
|
// FetchEndpoints fetches records for A/AAAA/CNAME or SRV requests for services
|
2024-01-10 16:19:20 +00:00
|
|
|
func (f *V2DataFetcher) FetchEndpoints(ctx Context, req *QueryPayload, lookupType LookupType) ([]*Result, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2024-01-17 23:46:18 +00:00
|
|
|
// FetchVirtualIP fetches A/AAAA records for virtual IPs
|
2024-01-10 16:19:20 +00:00
|
|
|
func (f *V2DataFetcher) FetchVirtualIP(ctx Context, req *QueryPayload) (*Result, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2024-01-17 23:46:18 +00:00
|
|
|
// FetchRecordsByIp is used for PTR requests to look up a service/node from an IP.
|
2024-01-10 16:19:20 +00:00
|
|
|
func (f *V2DataFetcher) FetchRecordsByIp(ctx Context, ip net.IP) ([]*Result, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2024-01-17 23:46:18 +00:00
|
|
|
// FetchWorkload is used to fetch a single workload from the V2 catalog.
|
|
|
|
// V2-only.
|
2024-01-10 16:19:20 +00:00
|
|
|
func (f *V2DataFetcher) FetchWorkload(ctx Context, req *QueryPayload) (*Result, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2024-01-17 23:46:18 +00:00
|
|
|
// FetchPreparedQuery is used to fetch a prepared query from the V2 catalog.
|
|
|
|
// Deprecated in V2.
|
2024-01-10 16:19:20 +00:00
|
|
|
func (f *V2DataFetcher) FetchPreparedQuery(ctx Context, req *QueryPayload) ([]*Result, error) {
|
2024-01-29 16:40:10 +00:00
|
|
|
return nil, ErrNotSupported
|
2024-01-10 16:19:20 +00:00
|
|
|
}
|