forked from TrueCloudLab/frostfs-node
[#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:
parent
3a44010180
commit
cd545f0160
11 changed files with 39 additions and 53 deletions
|
@ -2,7 +2,6 @@ package internal
|
|||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
|
@ -19,11 +18,7 @@ func GetSDKClient(key *ecdsa.PrivateKey, addr network.Address) (*client.Client,
|
|||
|
||||
prmInit.SetDefaultPrivateKey(*key)
|
||||
prmInit.ResolveNeoFSFailures()
|
||||
prmDial.SetServerURI(addr.HostAddr())
|
||||
|
||||
if addr.TLSEnabled() {
|
||||
prmDial.SetTLSConfig(&tls.Config{})
|
||||
}
|
||||
prmDial.SetServerURI(addr.URIAddr())
|
||||
|
||||
c.Init(prmInit)
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package cmd
|
|||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
|
||||
"github.com/mr-tron/base58"
|
||||
|
@ -457,30 +456,9 @@ func listShards(cmd *cobra.Command, _ []string) {
|
|||
prettyPrintShards(cmd, resp.GetBody().GetShards())
|
||||
}
|
||||
|
||||
// getControlSDKClient is the same getSDKClient but with
|
||||
// another RPC endpoint flag.
|
||||
// getControlSDKClient calls getSDKClientFlag with "endpoint" flag.
|
||||
func getControlSDKClient(key *ecdsa.PrivateKey) (*client.Client, error) {
|
||||
var (
|
||||
c client.Client
|
||||
prmInit client.PrmInit
|
||||
prmDial client.PrmDial
|
||||
)
|
||||
|
||||
netAddr, err := getEndpointAddress(controlRPC)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prmInit.SetDefaultPrivateKey(*key)
|
||||
prmDial.SetServerURI(netAddr.HostAddr())
|
||||
|
||||
if netAddr.TLSEnabled() {
|
||||
prmDial.SetTLSConfig(&tls.Config{})
|
||||
}
|
||||
|
||||
c.Init(prmInit)
|
||||
|
||||
return &c, c.Dial(prmDial)
|
||||
return getSDKClientFlag(key, controlRPC)
|
||||
}
|
||||
|
||||
func prettyPrintShards(cmd *cobra.Command, ii []*control.ShardInfo) {
|
||||
|
|
|
@ -188,7 +188,7 @@ func getEndpointAddress(endpointFlag string) (addr network.Address, err error) {
|
|||
|
||||
err = addr.FromString(endpoint)
|
||||
if err != nil {
|
||||
err = errInvalidEndpoint
|
||||
err = fmt.Errorf("%v: %w", errInvalidEndpoint, err)
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -227,13 +227,19 @@ func prepareBearerPrm(cmd *cobra.Command, prm bearerPrm) {
|
|||
prm.SetBearerToken(btok)
|
||||
}
|
||||
|
||||
// getSDKClient returns default neofs-api-go sdk client. Consider using
|
||||
// opts... to provide TTL or other global configuration flags.
|
||||
// getSDKClient calls getSDKGClientFlag with "rpc-endpoint" flag.
|
||||
func getSDKClient(key *ecdsa.PrivateKey) (*client.Client, error) {
|
||||
netAddr, err := getEndpointAddress(rpc)
|
||||
return getSDKClientFlag(key, rpc)
|
||||
}
|
||||
|
||||
// getSDKClientFlag returns NeoFS API client connection to the network address
|
||||
// set by the given flag.
|
||||
func getSDKClientFlag(key *ecdsa.PrivateKey, endpointFlag string) (*client.Client, error) {
|
||||
netAddr, err := getEndpointAddress(endpointFlag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return internalclient.GetSDKClient(key, netAddr)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue