code: def validate_context(context):
    
    # Service must exist in service registry
    if not context.service_registry.service_record(context.service_name):
      fail("service: {} not found in service registry: {}".format(
           context.service_name, context.service_registry.filespec))
    service_type = context.service_registry.service_record(context.service_name)["type"]
  
    # Key must be valid
    if context.key not in EFConfig.VERSION_KEYS:
      fail("invalid key: {}; see VERSION_KEYS in ef_config for supported keys".format(context.key))
  
    # Lookup allowed key for service type
    if "allowed_types" in EFConfig.VERSION_KEYS[context.key] and \
            service_type not in EFConfig.VERSION_KEYS[context.key]["allowed_types"]:
      fail("service_type: {} is not allowed for key {}; see VERSION_KEYS[KEY]['allowed_types']"
           "in ef_config and validate service registry entry".format(service_type, context.key))
  
    return True
docs: Set the key for the current context.
      Args:
        context: a populated EFVersionContext object