From 4a2007b8dd369d904be1f2478814fdf06b3e5787 Mon Sep 17 00:00:00 2001 From: Ed Cranford Date: Tue, 6 Mar 2018 14:56:55 -0600 Subject: [PATCH] Addressed PR comments Documented new functions Fixed authcodec permission list Removed unused event code --- cli/api/host.go | 2 +- cli/cmd/host.go | 18 +++++++++--------- cli/cmd/key.go | 1 + facade/host.go | 11 +---------- rpc/master/hosts_client.go | 2 +- rpc/rpcutils/authcodec.go | 1 - 6 files changed, 13 insertions(+), 22 deletions(-) diff --git a/cli/api/host.go b/cli/api/host.go index 1a70a90978..2ff2e4095f 100644 --- a/cli/api/host.go +++ b/cli/api/host.go @@ -172,7 +172,7 @@ func (a *api) AddHost(config HostConfig) (*host.Host, []byte, error) { } } -// Adds a new host and uses a common key to register it. +// Adds a new host and uses a common key to register it. Returns the host and the master's public key. func (a *api) AddHostPrivate(config HostConfig) (*host.Host, []byte, error) { // if a nat is configured then we connect rpc to the nat, otherwise // connect to the host address. diff --git a/cli/cmd/host.go b/cli/cmd/host.go index 3ac6aa0288..1e0abf14a2 100644 --- a/cli/cmd/host.go +++ b/cli/cmd/host.go @@ -323,25 +323,25 @@ func (c *ServicedCli) cmdHostAddPrivate(ctx *cli.Context) { if len(args) < 2 { fmt.Printf("Incorrect Usage.\n\n") cli.ShowCommandHelp(ctx, "add-private") - return + os.Exit(1) } var address utils.URL if err := address.Set(args[0]); err != nil { fmt.Println(err) - return + os.Exit(1) } if ip := net.ParseIP(address.Host); ip == nil { // Host did not parse, try resolving addr, err := net.ResolveTCPAddr("tcp", args[0]) if err != nil { fmt.Printf("Could not resolve %s.\n\n", args[0]) - return + os.Exit(1) } address.Host = addr.IP.String() if strings.HasPrefix(address.Host, "127.") { fmt.Printf("%s must not resolve to a loopback address\n\n", args[0]) - return + os.Exit(1) } } @@ -351,20 +351,20 @@ func (c *ServicedCli) cmdHostAddPrivate(ctx *cli.Context) { if len(natString) > 0 { if err := nat.Set(natString); err != nil { fmt.Println(err) - return + os.Exit(1) } if natip := net.ParseIP(nat.Host); natip == nil { // NAT did not parse, try resolving addr, err := net.ResolveTCPAddr("tcp", natString) if err != nil { fmt.Printf("Could not resolve nat address (%s): %s\n", natString, err) - return + os.Exit(1) } nat.Host = addr.IP.String() } if strings.HasPrefix(nat.Host, "127.") { fmt.Printf("The nat address %s must not resolve to a loopback address\n", natString) - return + os.Exit(1) } } @@ -378,10 +378,10 @@ func (c *ServicedCli) cmdHostAddPrivate(ctx *cli.Context) { host, keyblock, err := c.driver.AddHostPrivate(cfg) if err != nil { fmt.Fprintln(os.Stderr, err) - return + os.Exit(1) } else if keyblock == nil { fmt.Fprintln(os.Stderr, "received nil key") - return + os.Exit(1) } c.outputCommonKey(host, nat, keyblock) diff --git a/cli/cmd/key.go b/cli/cmd/key.go index 6d10880b0b..8a6bf57fe4 100644 --- a/cli/cmd/key.go +++ b/cli/cmd/key.go @@ -172,6 +172,7 @@ func (c *ServicedCli) outputDelegateKey(host *host.Host, nat utils.URL, keyData fmt.Println(host.ID) } +// Registers a host with the given keydata, and stores the key at the location designated by auth.DelegateKeyFileName func (c *ServicedCli) outputCommonKey(host *host.Host, nat utils.URL, keyData []byte) { keyfileName := filepath.Join(config.GetOptions().EtcPath, auth.DelegateKeyFileName) c.outputDelegateKey(host, nat, keyData, keyfileName, true) diff --git a/facade/host.go b/facade/host.go index 198341838b..56eae623db 100644 --- a/facade/host.go +++ b/facade/host.go @@ -65,7 +65,7 @@ func (f *Facade) AddHost(ctx datastore.Context, entity *host.Host) ([]byte, erro // Returns an error if host already exists or if the host's IP is a virtual IP. func (f *Facade) AddHostPrivate(ctx datastore.Context, entity *host.Host) ([]byte, error) { defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.AddHostPrivate")) - alog := f.auditLogger.Message(ctx, "Adding Host").Action(audit.Add).Entity(entity) + alog := f.auditLogger.Message(ctx, "Adding Host with common key").Action(audit.Add).Entity(entity) glog.V(2).Infof("Facade.AddHostPrivate: %v", entity) if err := f.DFSLock(ctx).LockWithTimeout("add host", userLockTimeout); err != nil { glog.Warningf("Cannot add host: %s", err) @@ -149,15 +149,6 @@ func (f *Facade) addHostPrivate(ctx datastore.Context, entity *host.Host) ([]byt } } - /* - ec := newEventCtx() - err = nil - defer f.afterEvent(afterHostAdd, ec, entity, err) - if err = f.beforeEvent(beforeHostAdd, ec, entity); err != nil { - return nil, err - } - */ - // Load the shared key. commonPEMBlock, err := f.useCommonKey(ctx, entity) if err != nil { diff --git a/rpc/master/hosts_client.go b/rpc/master/hosts_client.go index f59d5c087a..020ad9f3f5 100644 --- a/rpc/master/hosts_client.go +++ b/rpc/master/hosts_client.go @@ -56,7 +56,7 @@ func (c *Client) AddHost(host host.Host) ([]byte, error) { return response, nil } -//AddHost adds and registers a host with an agreed-upon shared secret keypair +//AddHost adds and registers a host with an agreed-upon shared secret keypair. Returns master's public key. func (c *Client) AddHostPrivate(host host.Host) ([]byte, error) { response := []byte{} if err := c.call("AddHostPrivate", host, &response); err != nil { diff --git a/rpc/rpcutils/authcodec.go b/rpc/rpcutils/authcodec.go index ba9041c152..7444840e13 100644 --- a/rpc/rpcutils/authcodec.go +++ b/rpc/rpcutils/authcodec.go @@ -32,7 +32,6 @@ var ( "Master.AuthenticateHost", "Agent.BuildHost", "ControlCenterAgent.Ping", - "Agent.AddHostPrivate", "Master.AddHostPrivate", } // RPC calls that do not require admin access: