code: def get_url_for_service(service, region, endpoint_type):
      if 'type' not in service:
          return None
  
      identity_version = get_version_from_service(service)
      service_endpoints = service.get('endpoints', [])
      available_endpoints = [endpoint for endpoint in service_endpoints
                             if region == _get_endpoint_region(endpoint)]
      
      if service['type'] == 'identity' and not available_endpoints:
          available_endpoints = [endpoint for endpoint in service_endpoints]
  
      for endpoint in available_endpoints:
          try:
              if identity_version < 3:
                  return endpoint.get(endpoint_type)
              else:
                  interface = \
                      ENDPOINT_TYPE_TO_INTERFACE.get(endpoint_type, '')
                  if endpoint.get('interface') == interface:
                      return endpoint.get('url')
          except (IndexError, KeyError):
              # it could be that the current endpoint just doesn't match the
              # type, continue trying the next one
              pass
      return None
docs: if we are dealing with the identity service and there is no endpoint
      in the current region, it is okay to use the first endpoint for any
      identity service endpoints and we can assume that it is global