function discoverEndpoint(request, done) {
  var service = request.service || {};
  if (hasCustomEndpoint(service) || request.isPresigned()) return done();

  if (!isEndpointDiscoveryApplicable(request)) return done();

  request.httpRequest.appendToUserAgent('endpoint-discovery');

  var operations = service.api.operations || {};
  var operationModel = operations[request.operation];
  var isEndpointDiscoveryRequired = operationModel ? operationModel.endpointDiscoveryRequired : 'NULL';
  switch (isEndpointDiscoveryRequired) {
    case 'OPTIONAL':
      optionalDiscoverEndpoint(request);
      request.addNamedListener('INVALIDATE_CACHED_ENDPOINTS', 'extractError', invalidateCachedEndpoints);
      done();
      break;
    case 'REQUIRED':
      request.addNamedListener('INVALIDATE_CACHED_ENDPOINTS', 'extractError', invalidateCachedEndpoints);
      requiredDiscoverEndpoint(request, done);
      break;
    case 'NULL':
    default:
      done();
      break;
  }
}
function discoverEndpoint(request, done) {
  var service = request.service || {};
  if (hasCustomEndpoint(service) || request.isPresigned()) return done();

  if (!isEndpointDiscoveryApplicable(request)) return done();

  request.httpRequest.appendToUserAgent('endpoint-discovery');

  var operations = service.api.operations || {};
  var operationModel = operations[request.operation];
  var isEndpointDiscoveryRequired = operationModel ? operationModel.endpointDiscoveryRequired : 'NULL';
  switch (isEndpointDiscoveryRequired) {
    case 'OPTIONAL':
      optionalDiscoverEndpoint(request);
      request.addNamedListener('INVALIDATE_CACHED_ENDPOINTS', 'extractError', invalidateCachedEndpoints);
      done();
      break;
    case 'REQUIRED':
      request.addNamedListener('INVALIDATE_CACHED_ENDPOINTS', 'extractError', invalidateCachedEndpoints);
      requiredDiscoverEndpoint(request, done);
      break;
    case 'NULL':
    default:
      done();
      break;
  }
}
function discoverEndpoint ( request , done ) { var service = request . service || { } ; if ( hasCustomEndpoint ( service ) || request . isPresigned ( ) ) return done ( ) ; if ( ! isEndpointDiscoveryApplicable ( request ) ) return done ( ) ; request . httpRequest . appendToUserAgent ( 'endpoint-discovery' ) ; var operations = service . api . operations || { } ; var operationModel = operations [ request . operation ] ; var isEndpointDiscoveryRequired = operationModel ? operationModel . endpointDiscoveryRequired : 'NULL' ; switch ( isEndpointDiscoveryRequired ) { case 'OPTIONAL' : optionalDiscoverEndpoint ( request ) ; request . addNamedListener ( 'INVALIDATE_CACHED_ENDPOINTS' , 'extractError' , invalidateCachedEndpoints ) ; done ( ) ; break ; case 'REQUIRED' : request . addNamedListener ( 'INVALIDATE_CACHED_ENDPOINTS' , 'extractError' , invalidateCachedEndpoints ) ; requiredDiscoverEndpoint ( request , done ) ; break ; case 'NULL' : default : done ( ) ; break ; } }
attach endpoint discovery logic to request object
@param [object] request
@api private
attach endpoint discovery logic to request object
Discover an endpoint