original_docstring: Converts current service to a replica of a primary specified in a ticket.
  
    Args:
      ticket: replication_pb2.ServiceLinkTicket passed from a primary.
      initiated_by: Identity of a user that accepted linking request, for logging.
  
    Raises:
      ProtocolError in case the request to primary fails.
    
docstring: Converts current service to a replica of a primary specified in a ticket.
  Args:
  ticket: replication_pb2.ServiceLinkTicket passed from a primary.
  initiated_by: Identity of a user that accepted linking request, for logging.
  
  ProtocolError in case the request to primary fails.
docstring_tokens: Converts current service to a replica of a primary specified in a ticket . Args : ticket : replication_pb2 . ServiceLinkTicket passed from a primary . initiated_by : Identity of a user that accepted linking request for logging . ProtocolError in case the request to primary fails .
code: def become_replica(ticket, initiated_by):
    """Converts current service to a replica of a primary specified in a ticket.
  
    Args:
      ticket: replication_pb2.ServiceLinkTicket passed from a primary.
      initiated_by: Identity of a user that accepted linking request, for logging.
  
    Raises:
      ProtocolError in case the request to primary fails.
    """
    assert model.is_standalone()
  
    # On dev appserver emulate X-Appengine-Inbound-Appid header.
    headers = {'Content-Type': 'application/octet-stream'}
    protocol = 'https'
    if utils.is_local_dev_server():
      headers['X-Appengine-Inbound-Appid'] = app_identity.get_application_id()
      protocol = 'http'
    headers['X-URLFetch-Service-Id'] = utils.get_urlfetch_service_id()
  
    # Pass back the ticket for primary to verify it, tell the primary to use
    # default version hostname to talk to us.
    link_request = replication_pb2.ServiceLinkRequest()
    link_request.ticket = ticket.ticket
    link_request.replica_url = (
        '%s://%s' % (protocol, app_identity.get_default_version_hostname()))
    link_request.initiated_by = initiated_by.to_bytes()
  
    # Primary will look at X-Appengine-Inbound-Appid and compare it to what's in
    # the ticket.
    try:
      result = urlfetch.fetch(
          url='%s/auth_service/api/v1/internal/link_replica' % ticket.primary_url,
          payload=link_request.SerializeToString(),
          method='POST',
          headers=headers,
          follow_redirects=False,
          deadline=30,
          validate_certificate=True)
    except urlfetch.Error as exc:
      raise ProtocolError(
          replication_pb2.ServiceLinkResponse.TRANSPORT_ERROR,
          'URLFetch error (%s): %s' % (exc.__class__.__name__, exc))
  
    # Protobuf based protocol is not using HTTP codes (handler always replies with
    # HTTP 200, providing error details if needed in protobuf serialized body).
    # So any other status code here means there was a transport level error.
    if result.status_code != 200:
      raise ProtocolError(
          replication_pb2.ServiceLinkResponse.TRANSPORT_ERROR,
          'Request to the primary failed with HTTP %d.' % result.status_code)
  
    link_response = replication_pb2.ServiceLinkResponse.FromString(result.content)
    if link_response.status != replication_pb2.ServiceLinkResponse.SUCCESS:
      message = LINKING_ERRORS.get(
          link_response.status,
          'Request to the primary failed with status %d.' % link_response.status)
      raise ProtocolError(link_response.status, message)
  
    # Become replica. Auth DB will be overwritten on a first push from Primary.
    state = model.AuthReplicationState(
        key=model.replication_state_key(),
        primary_id=ticket.primary_id,
        primary_url=ticket.primary_url)
    state.put()
code_tokens: def become_replica ( ticket , initiated_by ) : assert model . is_standalone ( ) headers = { 'Content-Type' : 'application/octet-stream' } protocol = 'https' if utils . is_local_dev_server ( ) : headers [ 'X-Appengine-Inbound-Appid' ] = app_identity . get_application_id ( ) protocol = 'http' headers [ 'X-URLFetch-Service-Id' ] = utils . get_urlfetch_service_id ( ) link_request = replication_pb2 . ServiceLinkRequest ( ) link_request . ticket = ticket . ticket link_request . replica_url = ( '%s://%s' % ( protocol , app_identity . get_default_version_hostname ( ) ) ) link_request . initiated_by = initiated_by . to_bytes ( ) try : result = urlfetch . fetch ( url = '%s/auth_service/api/v1/internal/link_replica' % ticket . primary_url , payload = link_request . SerializeToString ( ) , method = 'POST' , headers = headers , follow_redirects = False , deadline = 30 , validate_certificate = True ) except urlfetch . Error as exc : raise ProtocolError ( replication_pb2 . ServiceLinkResponse . TRANSPORT_ERROR , 'URLFetch error (%s): %s' % ( exc . __class__ . __name__ , exc ) ) if result . status_code != 200 : raise ProtocolError ( replication_pb2 . ServiceLinkResponse . TRANSPORT_ERROR , 'Request to the primary failed with HTTP %d.' % result . status_code ) link_response = replication_pb2 . ServiceLinkResponse . FromString ( result . content ) if link_response . status != replication_pb2 . ServiceLinkResponse . SUCCESS : message = LINKING_ERRORS . get ( link_response . status , 'Request to the primary failed with status %d.' % link_response . status ) raise ProtocolError ( link_response . status , message ) state = model . AuthReplicationState ( key = model . replication_state_key ( ) , primary_id = ticket . primary_id , primary_url = ticket . primary_url ) state . put ( )
short_docstring: Converts current service to a replica of a primary specified in a ticket.
short_docstring_tokens: Converts current service to a replica of a primary specified in a ticket .
comment: """Converts current service to a replica of a primary specified in a ticket.
  
    Args:
      ticket: replication_pb2.ServiceLinkTicket passed from a primary.
      initiated_by: Identity of a user that accepted linking request, for logging.
  
    Raises:
      ProtocolError in case the request to primary fails.
    """$SEP$# On dev appserver emulate X-Appengine-Inbound-Appid header.$SEP$# Pass back the ticket for primary to verify it, tell the primary to use$SEP$# default version hostname to talk to us.$SEP$# Primary will look at X-Appengine-Inbound-Appid and compare it to what's in$SEP$# the ticket.$SEP$# Protobuf based protocol is not using HTTP codes (handler always replies with$SEP$# HTTP 200, providing error details if needed in protobuf serialized body).$SEP$# So any other status code here means there was a transport level error.$SEP$# Become replica. Auth DB will be overwritten on a first push from Primary.