func (s *APIServer) upsertServer(role teleport.Role, w http.ResponseWriter, r *http.Request, p httprouter.Params) (interface{}, error) {
	var req upsertServerReq
	if err := httplib.ReadJSON(r, &req); err != nil {
		return nil, trace.Wrap(err)
	}
	// if server sent "local" IP address to us, replace the ip/host part with the remote address we see
	// on the socket, but keep the original port:
	req.Server.Addr = utils.ReplaceLocalhost(req.Server.Addr, r.RemoteAddr)

	switch role {
	case teleport.RoleNode:
		if err := s.a.UpsertNode(req.Server, req.TTL); err != nil {
			return nil, trace.Wrap(err)
		}
	case teleport.RoleAuth:
		if err := s.a.UpsertAuthServer(req.Server, req.TTL); err != nil {
			return nil, trace.Wrap(err)
		}
	case teleport.RoleProxy:
		if err := s.a.UpsertProxy(req.Server, req.TTL); err != nil {
			return nil, trace.Wrap(err)
		}
	}
	return message("ok"), nil
}
// upsertNode is called by remote SSH nodes when they ping back into the auth service
upsertNode is called by remote SSH nodes when they ping back into the auth service
// upsertNode is called by remote SSH nodes when they ping back into the auth service
func (s *APIServer) upsertServer(role teleport.Role, w http.ResponseWriter, r *http.Request, p httprouter.Params) (interface{}, error) {
	var req upsertServerReq
	if err := httplib.ReadJSON(r, &req); err != nil {
		return nil, trace.Wrap(err)
	}
	req.Server.Addr = utils.ReplaceLocalhost(req.Server.Addr, r.RemoteAddr)
	switch role {
	case teleport.RoleNode:
		if err := s.a.UpsertNode(req.Server, req.TTL); err != nil {
			return nil, trace.Wrap(err)
		}
	case teleport.RoleAuth:
		if err := s.a.UpsertAuthServer(req.Server, req.TTL); err != nil {
			return nil, trace.Wrap(err)
		}
	case teleport.RoleProxy:
		if err := s.a.UpsertProxy(req.Server, req.TTL); err != nil {
			return nil, trace.Wrap(err)
		}
	}
	return message("ok"), nil
}
func ( s * APIServer ) upsertServer ( role teleport . Role , w http . ResponseWriter , r * http . Request , p httprouter . Params ) ( interface { } , error ) { var req upsertServerReq if err := httplib . ReadJSON ( r , & req ) ; err != nil { return nil , trace . Wrap ( err ) } req . Server . Addr = utils . ReplaceLocalhost ( req . Server . Addr , r . RemoteAddr ) switch role { case teleport . RoleNode : if err := s . a . UpsertNode ( req . Server , req . TTL ) ; err != nil { return nil , trace . Wrap ( err ) } case teleport . RoleAuth : if err := s . a . UpsertAuthServer ( req . Server , req . TTL ) ; err != nil { return nil , trace . Wrap ( err ) } case teleport . RoleProxy : if err := s . a . UpsertProxy ( req . Server , req . TTL ) ; err != nil { return nil , trace . Wrap ( err ) } } return message ( " " ) , nil }
upsertNode is called by remote SSH nodes when they ping back into the auth service
upsertNode is called by remote SSH nodes when they ping back into the auth service
// if server sent "local" IP address to us, replace the ip/host part with the remote address we see // on the socket, but keep the original port: