mirror of https://github.com/grpc/grpc-go.git
grpc: optional interface to provide channel authority (#6752)
This commit is contained in:
parent
5d7453e661
commit
0866ce06ba
|
|
@ -1860,27 +1860,15 @@ func (cc *ClientConn) determineAuthority() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint := cc.parsedTarget.Endpoint()
|
endpoint := cc.parsedTarget.Endpoint()
|
||||||
target := cc.target
|
if authorityFromDialOption != "" {
|
||||||
switch {
|
|
||||||
case authorityFromDialOption != "":
|
|
||||||
cc.authority = authorityFromDialOption
|
cc.authority = authorityFromDialOption
|
||||||
case authorityFromCreds != "":
|
} else if authorityFromCreds != "" {
|
||||||
cc.authority = authorityFromCreds
|
cc.authority = authorityFromCreds
|
||||||
case strings.HasPrefix(target, "unix:") || strings.HasPrefix(target, "unix-abstract:"):
|
} else if auth, ok := cc.resolverBuilder.(resolver.AuthorityOverrider); ok {
|
||||||
// TODO: remove when the unix resolver implements optional interface to
|
cc.authority = auth.OverrideAuthority(cc.parsedTarget)
|
||||||
// return channel authority.
|
} else if strings.HasPrefix(endpoint, ":") {
|
||||||
cc.authority = "localhost"
|
|
||||||
case strings.HasPrefix(endpoint, ":"):
|
|
||||||
cc.authority = "localhost" + endpoint
|
cc.authority = "localhost" + endpoint
|
||||||
default:
|
} else {
|
||||||
// TODO: Define an optional interface on the resolver builder to return
|
|
||||||
// the channel authority given the user's dial target. For resolvers
|
|
||||||
// which don't implement this interface, we will use the endpoint from
|
|
||||||
// "scheme://authority/endpoint" as the default authority.
|
|
||||||
// Escape the endpoint to handle use cases where the endpoint
|
|
||||||
// might not be a valid authority by default.
|
|
||||||
// For example an endpoint which has multiple paths like
|
|
||||||
// 'a/b/c', which is not a valid authority by default.
|
|
||||||
cc.authority = encodeAuthority(endpoint)
|
cc.authority = encodeAuthority(endpoint)
|
||||||
}
|
}
|
||||||
channelz.Infof(logger, cc.channelzID, "Channel authority set to %q", cc.authority)
|
channelz.Infof(logger, cc.channelzID, "Channel authority set to %q", cc.authority)
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,10 @@ func (b *builder) Scheme() string {
|
||||||
return b.scheme
|
return b.scheme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *builder) OverrideAuthority(resolver.Target) string {
|
||||||
|
return "localhost"
|
||||||
|
}
|
||||||
|
|
||||||
type nopResolver struct {
|
type nopResolver struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -314,3 +314,13 @@ type Resolver interface {
|
||||||
// Close closes the resolver.
|
// Close closes the resolver.
|
||||||
Close()
|
Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuthorityOverrider is implemented by Builders that wish to override the
|
||||||
|
// default authority for the ClientConn.
|
||||||
|
// By default, the authority used is target.Endpoint().
|
||||||
|
type AuthorityOverrider interface {
|
||||||
|
// OverrideAuthority returns the authority to use for a ClientConn with the
|
||||||
|
// given target. The implementation must generate it without blocking,
|
||||||
|
// typically in line, and must keep it unchanged.
|
||||||
|
OverrideAuthority(Target) string
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue