cmd/uplink/cmd: remove port detection when selecting satellite while
setup We don't have default ports as a part of configuration anymore because satellite-addr flag was removed. Change-Id: Ibf9fc4b399beaf51ebb9461de2d8994a322f9686
This commit is contained in:
parent
2fbb34c3ea
commit
a4c19b3359
@ -5,10 +5,8 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -53,17 +51,6 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
return Error.Wrap(err)
|
||||
}
|
||||
|
||||
// apply helpful default host and port to the address
|
||||
vip, err := process.Viper(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
satelliteAddress, err = ApplyDefaultHostAndPortToAddr(
|
||||
satelliteAddress, vip.GetString("satellite-addr"))
|
||||
if err != nil {
|
||||
return Error.Wrap(err)
|
||||
}
|
||||
|
||||
var (
|
||||
accessName string
|
||||
defaultSerializedAccessExists bool
|
||||
@ -165,40 +152,3 @@ Some things to try next:
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ApplyDefaultHostAndPortToAddr applies the default host and/or port if either is missing in the specified address.
|
||||
func ApplyDefaultHostAndPortToAddr(address, defaultAddress string) (string, error) {
|
||||
defaultHost, defaultPort, err := net.SplitHostPort(defaultAddress)
|
||||
if err != nil {
|
||||
return "", Error.Wrap(err)
|
||||
}
|
||||
|
||||
addressParts := strings.Split(address, ":")
|
||||
numberOfParts := len(addressParts)
|
||||
|
||||
if numberOfParts > 1 && len(addressParts[0]) > 0 && len(addressParts[1]) > 0 {
|
||||
// address is host:port so skip applying any defaults.
|
||||
return address, nil
|
||||
}
|
||||
|
||||
// We are missing a host:port part. Figure out which part we are missing.
|
||||
indexOfPortSeparator := strings.Index(address, ":")
|
||||
lengthOfFirstPart := len(addressParts[0])
|
||||
|
||||
if indexOfPortSeparator < 0 {
|
||||
if lengthOfFirstPart == 0 {
|
||||
// address is blank.
|
||||
return defaultAddress, nil
|
||||
}
|
||||
// address is host
|
||||
return net.JoinHostPort(addressParts[0], defaultPort), nil
|
||||
}
|
||||
|
||||
if indexOfPortSeparator == 0 {
|
||||
// address is :1234
|
||||
return net.JoinHostPort(defaultHost, addressParts[1]), nil
|
||||
}
|
||||
|
||||
// address is host:
|
||||
return net.JoinHostPort(addressParts[0], defaultPort), nil
|
||||
}
|
||||
|
@ -1,49 +0,0 @@
|
||||
// Copyright (C) 2019 Storj Labs, Inc.
|
||||
// See LICENSE for copying information
|
||||
|
||||
package cmd_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"storj.io/storj/cmd/uplink/cmd"
|
||||
)
|
||||
|
||||
func TestApplyDefaultHostAndPortToAddr(t *testing.T) {
|
||||
{
|
||||
got, err := cmd.ApplyDefaultHostAndPortToAddr("", "localhost:7777")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "localhost:7777", got,
|
||||
"satellite-addr should contain default port when no port specified")
|
||||
}
|
||||
|
||||
{
|
||||
got, err := cmd.ApplyDefaultHostAndPortToAddr("ahost", "localhost:7777")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "ahost:7777", got,
|
||||
"satellite-addr should contain default port when no port specified")
|
||||
}
|
||||
|
||||
{
|
||||
got, err := cmd.ApplyDefaultHostAndPortToAddr("ahost:7778", "localhost:7777")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "ahost:7778", got,
|
||||
"satellite-addr should contain default port when no port specified")
|
||||
}
|
||||
|
||||
{
|
||||
got, err := cmd.ApplyDefaultHostAndPortToAddr(":7778", "localhost:7777")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "localhost:7778", got,
|
||||
"satellite-addr should contain default port when no port specified")
|
||||
}
|
||||
|
||||
{
|
||||
got, err := cmd.ApplyDefaultHostAndPortToAddr("ahost:", "localhost:7777")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "ahost:7777", got,
|
||||
"satellite-addr should contain default port when no port specified")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user