code: func (m *Manager) newProxy(mp *local.ManagedProxy) (Proxy, error) {
  	// Defensive because the alternative is to panic which is not desired
  	if mp == nil || mp.Proxy == nil {
  		return nil, fmt.Errorf("internal error: nil *local.ManagedProxy or Proxy field")
  	}
  	p := mp.Proxy
  
  	// We reuse the service ID a few times
  	id := p.ProxyService.ID
  
  	// Create the Proxy. We could just as easily switch on p.ExecMode
  	// but I wanted there to be only location where ExecMode => Proxy so
  	// it lowers the chance that is wrong.
  	proxy, err := m.newProxyFromMode(p.ExecMode, id)
  	if err != nil {
  		return nil, err
  	}
  
  	// Depending on the proxy type we configure the rest from our ManagedProxy
  	switch proxy := proxy.(type) {
  	case *Daemon:
  		command := p.Command
  
  		// This should never happen since validation should happen upstream
  		// but verify it because the alternative is to panic below.
  		if len(command) == 0 {
  			return nil, fmt.Errorf("daemon mode managed proxy requires command")
  		}
  
  		// Build the command to execute.
  		var cmd exec.Cmd
  		cmd.Path = command[0]
  		cmd.Args = command // idx 0 is path but preserved since it should be
  		if err := m.configureLogDir(id, &cmd); err != nil {
  			return nil, fmt.Errorf("error configuring proxy logs: %s", err)
  		}
  
  		// Pass in the environmental variables for the proxy process
  		cmd.Env = append(m.ProxyEnv, os.Environ()...)
  
  		// Build the daemon structure
  		proxy.Command = &cmd
  		proxy.ProxyID = id
  		proxy.ProxyToken = mp.ProxyToken
  		return proxy, nil
  
  	default:
  		return nil, fmt.Errorf("unsupported managed proxy type: %q", p.ExecMode)
  	}
  }
docs: // newProxy creates the proper Proxy implementation for the configured
  // local managed proxy.