Skip to content

Commit

Permalink
extract function
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyer committed Oct 10, 2023
1 parent 85148c2 commit 14263bd
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions agent/consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,31 +589,11 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server,
return nil, fmt.Errorf("cannot initialize server with a nil RPC request recorder")
}

isV1CatalogRPC := func(name string) bool {
switch {
case strings.HasPrefix(name, "Catalog."),
strings.HasPrefix(name, "Health."),
strings.HasPrefix(name, "ConfigEntry."):
return true
}

switch name {
case "Internal.EventFire", "Internal.KeyringOperation", "Internal.OIDCAuthMethods":
return false
default:
if strings.HasPrefix(name, "Internal.") {
return true
}
}

return false
}

rpcServerOpts := []func(*rpc.Server){
rpc.WithPreBodyInterceptor(
middleware.ChainedRPCPreBodyInterceptor(
func(reqServiceMethod string, sourceAddr net.Addr) error {
if s.useV2Resources && isV1CatalogRPC(reqServiceMethod) {
if s.useV2Resources && isV1CatalogRequest(reqServiceMethod) {
return structs.ErrUsingV2CatalogExperiment
}
return nil
Expand Down Expand Up @@ -929,6 +909,25 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server,
return s, nil
}

func isV1CatalogRequest(rpcName string) bool {
switch {
case strings.HasPrefix(rpcName, "Catalog."),
strings.HasPrefix(rpcName, "Health."),
strings.HasPrefix(rpcName, "ConfigEntry."):
return true
}

switch rpcName {
case "Internal.EventFire", "Internal.KeyringOperation", "Internal.OIDCAuthMethods":
return false
default:
if strings.HasPrefix(rpcName, "Internal.") {
return true
}
return false
}
}

func (s *Server) registerControllers(deps Deps, proxyUpdater ProxyUpdater) error {
if stringslice.Contains(deps.Experiments, CatalogResourceExperimentName) {
s.useV2Resources = true
Expand Down

0 comments on commit 14263bd

Please sign in to comment.