Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parameters and fix linting issues #18

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"path"
"time"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd"

"github.com/edwarnicke/grpcfd"

"github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig"
Expand All @@ -42,7 +44,6 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/memif"
"github.com/networkservicemesh/cmd-nsc/pkg/config"
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/client"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
"github.com/networkservicemesh/sdk/pkg/tools/spiffejwt"

Expand Down Expand Up @@ -147,7 +148,7 @@ func NewNSMClient(ctx context.Context, rootConf *config.Config) networkservice.N
logrus.Infof("NSC: Connecting to Network Service Manager %v", rootConf.ConnectTo.String())
var clientCC *grpc.ClientConn
clientCC, err = grpc.DialContext(ctx,
grpcutils.URLToTarget(rootConf.ConnectTo),
grpcutils.URLToTarget(&rootConf.ConnectTo),
grpc.WithTransportCredentials(
grpcfd.TransportCredentials(
credentials.NewTLS(
Expand Down Expand Up @@ -177,7 +178,7 @@ func NewNSMClient(ctx context.Context, rootConf *config.Config) networkservice.N
// RunClient - runs a client application with passed configuration over a client to Network Service Manager
func RunClient(ctx context.Context, rootConf *config.Config, nsmClient networkservice.NetworkServiceClient) ([]*networkservice.Connection, error) {
// Validate config parameters
if err := rootConf.Validate(); err != nil {
if err := rootConf.IsValid(); err != nil {
return []*networkservice.Connection{}, err
}

Expand Down
6 changes: 3 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestConnectNSM(t *testing.T) {
testClient := &nsmTestClient{}
cfg := &config.Config{
Name: "nsc",
ConnectTo: &url.URL{
ConnectTo: url.URL{
Scheme: "unix",
Path: "/file.sock",
},
Expand All @@ -143,7 +143,7 @@ func TestConnectNSMGRPC(t *testing.T) {
testClient := &nsmTestClient{}
cfg := &config.Config{
Name: "nsc",
ConnectTo: &url.URL{
ConnectTo: url.URL{
Scheme: "unix",
Path: "/file.sock",
},
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestSendFd(t *testing.T) {

cfg := &config.Config{
Name: "nsc",
ConnectTo: &url.URL{Scheme: "tcp", Host: "127.0.0.1:0"},
ConnectTo: url.URL{Scheme: "tcp", Host: "127.0.0.1:0"},
NetworkServices: []*config.NetworkServiceConfig{
parse(t, "kernel://my-service/nsmKernel?"),
},
Expand Down
14 changes: 7 additions & 7 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var configMechanisms = map[string]string{
// Config - configuration for cmd-nsmgr
type Config struct {
Name string `default:"nsc" desc:"Name of Network Service Client"`
ConnectTo *url.URL `default:"unix:///var/lib/networkservicemesh/nsm.io.sock" desc:"url to connect to NSM" split_words:"true"`
ConnectTo url.URL `default:"unix:///var/lib/networkservicemesh/nsm.io.sock" desc:"url to connect to NSM" split_words:"true"`
MaxTokenLifetime time.Duration `default:"24h" desc:"maximum lifetime of tokens" split_words:"true"`

Routes []string `default:"" desc:"A list of routes asked by client" split_words:"true"`
Expand All @@ -46,15 +46,15 @@ type Config struct {
NetworkServices []*NetworkServiceConfig `default:"" desc:"A list of Network Service Requests with format [{mechanism}]?:${nsName}[@domainName]?/${interfaceName/memIfSocketName}?${label1}=${value1}&${label2}=${value2}" split_words:"true"`
}

// Validate - check if configuration is valid
func (c *Config) Validate() error {
// IsValid - check if configuration is valid
func (c *Config) IsValid() error {
if len(c.NetworkServices) == 0 {
return errors.New("no network services are specified")
}
if c.Name == "" {
return errors.New("no cleint name specified")
}
if c.ConnectTo == nil {
if c.ConnectTo.String() == "" {
return errors.New("no NSMGr ConnectTO URL are sepecified")
}
return nil
Expand Down Expand Up @@ -100,8 +100,8 @@ func (cfg *NetworkServiceConfig) UnmarshalBinary(text []byte) error {
return nil
}

// Validate - check if network service request is correct.
func (cfg *NetworkServiceConfig) Validate() error {
// IsValid - check if network service request is correct.
func (cfg *NetworkServiceConfig) IsValid() error {
if cfg.Mechanism == "" {
return errors.New("invalid mechanism specified")
}
Expand Down Expand Up @@ -149,5 +149,5 @@ func (cfg *NetworkServiceConfig) MergeWithConfigOptions(conf *Config) error {
cfg.Labels[key] = strings.Trim(keyValue[1], " ")
}
}
return cfg.Validate()
return cfg.IsValid()
}