MCPcopy
hub / github.com/grpc/grpc-go / initAuthority

Method initAuthority

clientconn.go:1955–1989  ·  view source on GitHub ↗

Determine channel authority. The order of precedence is as follows: - user specified authority override using `WithAuthority` dial option - creds' notion of server name for the authentication handshake - endpoint from dial target of the form "scheme://[authority]/endpoint" Stores the determined aut

()

Source from the content-addressed store, hash-verified

1953//
1954// Doesn't grab cc.mu as this method is expected to be called only at Dial time.
1955func (cc *ClientConn) initAuthority() error {
1956 dopts := cc.dopts
1957 // Historically, we had two options for users to specify the serverName or
1958 // authority for a channel. One was through the transport credentials
1959 // (either in its constructor, or through the OverrideServerName() method).
1960 // The other option (for cases where WithInsecure() dial option was used)
1961 // was to use the WithAuthority() dial option.
1962 //
1963 // A few things have changed since:
1964 // - `insecure` package with an implementation of the `TransportCredentials`
1965 // interface for the insecure case
1966 // - WithAuthority() dial option support for secure credentials
1967 authorityFromCreds := ""
1968 if creds := dopts.copts.TransportCredentials; creds != nil && creds.Info().ServerName != "" {
1969 authorityFromCreds = creds.Info().ServerName
1970 }
1971 authorityFromDialOption := dopts.authority
1972 if (authorityFromCreds != "" && authorityFromDialOption != "") && authorityFromCreds != authorityFromDialOption {
1973 return fmt.Errorf("ClientConn's authority from transport creds %q and dial option %q don't match", authorityFromCreds, authorityFromDialOption)
1974 }
1975
1976 endpoint := cc.parsedTarget.Endpoint()
1977 if authorityFromDialOption != "" {
1978 cc.authority = authorityFromDialOption
1979 } else if authorityFromCreds != "" {
1980 cc.authority = authorityFromCreds
1981 } else if auth, ok := cc.resolverBuilder.(resolver.AuthorityOverrider); ok {
1982 cc.authority = auth.OverrideAuthority(cc.parsedTarget)
1983 } else if strings.HasPrefix(endpoint, ":") {
1984 cc.authority = "localhost" + encodeAuthority(endpoint)
1985 } else {
1986 cc.authority = encodeAuthority(endpoint)
1987 }
1988 return nil
1989}

Callers 1

NewClientFunction · 0.95

Calls 5

encodeAuthorityFunction · 0.85
EndpointMethod · 0.80
InfoMethod · 0.65
ErrorfMethod · 0.65
OverrideAuthorityMethod · 0.65

Tested by

no test coverage detected