[#1351] cli: Fix connection scheme loss during endpoint parsing

In previous implementation NeoFS CLI app used `network.Address.HostAddr`
as a server URI, which caused scheme loss since host address doesn't
contain it.

Rename `HostAddr` to `URIAddr` and make it to return URI address with
`grpcs` scheme if TLS is enabled. Make `TLSEnabled` unexported since it
was used to provide default `tls.Config` only (it is used by default in
SDK).

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-05-04 15:34:26 +03:00 committed by LeL
parent 3a44010180
commit cd545f0160
11 changed files with 39 additions and 53 deletions

View file

@ -3,6 +3,7 @@ package network
import (
"fmt"
"net"
"net/url"
"strings"
"github.com/multiformats/go-multiaddr"
@ -33,10 +34,12 @@ func (a Address) equal(addr Address) bool {
return a.ma.Equal(addr.ma)
}
// HostAddr returns host address in string format.
// URIAddr returns Address as a URI.
//
// Panics if host address cannot be fetched from Address.
func (a Address) HostAddr() string {
//
// See also FromString.
func (a Address) URIAddr() string {
_, host, err := manet.DialArgs(a.ma)
if err != nil {
// the only correct way to construct Address is AddressFromString
@ -44,7 +47,14 @@ func (a Address) HostAddr() string {
panic(fmt.Errorf("could not get host addr: %w", err))
}
return host
if !a.isTLSEnabled() {
return host
}
return (&url.URL{
Scheme: "grpcs",
Host: host,
}).String()
}
// FromString restores Address from a string representation.