Skip to content

Commit

Permalink
Addressed PR comments
Browse files Browse the repository at this point in the history
Documented new functions
Fixed authcodec permission list
Removed unused event code
  • Loading branch information
Ed Cranford committed Mar 6, 2018
1 parent ee0f573 commit 4a2007b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cli/api/host.go
Expand Up @@ -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.
Expand Down
18 changes: 9 additions & 9 deletions cli/cmd/host.go
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/key.go
Expand Up @@ -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)
Expand Down
11 changes: 1 addition & 10 deletions facade/host.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion rpc/master/hosts_client.go
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion rpc/rpcutils/authcodec.go
Expand Up @@ -32,7 +32,6 @@ var (
"Master.AuthenticateHost",
"Agent.BuildHost",
"ControlCenterAgent.Ping",
"Agent.AddHostPrivate",
"Master.AddHostPrivate",
}
// RPC calls that do not require admin access:
Expand Down

0 comments on commit 4a2007b

Please sign in to comment.