code: def create_and_write_saml_metadata(proxy_conf, key, cert, dir, valid, split_frontend_metadata=False,
                                     split_backend_metadata=False):
      
      satosa_config = SATOSAConfig(proxy_conf)
      secc = _get_security_context(key, cert)
      frontend_entities, backend_entities = create_entity_descriptors(satosa_config)
  
      output = []
      if frontend_entities:
          if split_frontend_metadata:
              output.extend(_create_split_entity_descriptors(frontend_entities, secc, valid))
          else:
              output.extend(_create_merged_entities_descriptors(frontend_entities, secc, valid, "frontend.xml"))
      if backend_entities:
          if split_backend_metadata:
              output.extend(_create_split_entity_descriptors(backend_entities, secc, valid))
          else:
              output.extend(_create_merged_entities_descriptors(backend_entities, secc, valid, "backend.xml"))
  
      for metadata, filename in output:
          path = os.path.join(dir, filename)
          print("Writing metadata to '{}'".format(path))
          with open(path, "w") as f:
              f.write(metadata)
docs: Generates SAML metadata for the given PROXY_CONF, signed with the given KEY and associated CERT.