def GET(self, uri): """Perform HTTP GET of catalog metadata. """ content_type = data.negotiated_content_type(self.supported_types, self.default_content_type) def body(conn, cur): self.enforce_read(cur, uri) return self.catalog.manager.get_meta(cur, self.key, self.value) def post_commit(meta): web.header('Content-Type', content_type) web.ctx.ermrest_request_content_type = content_type response = json.dumps(list(meta)) + '\n' web.header('Content-Length', len(response)) return response return self.perform(body, post_commit)
def POST(self, uri='catalog'): """Perform HTTP POST of catalogs. """ # content negotiation content_type = data.negotiated_content_type(self.supported_types, self.default_content_type) # registry acl enforcement allowed = web.ctx.ermrest_registry.can_create( web.ctx.webauthn2_context.attributes) if not allowed: raise rest.Forbidden(uri) # create the catalog instance catalog = web.ctx.ermrest_catalog_factory.create() # initialize the catalog instance pc = sanepg2.PooledConnection(catalog.dsn) try: pc.perform(lambda conn, cur: catalog.init_meta( conn, cur, web.ctx.webauthn2_context.client)).next() finally: pc.final() # register the catalog descriptor entry = web.ctx.ermrest_registry.register(catalog.descriptor) catalog_id = entry['id'] web.header('Content-Type', content_type) web.ctx.ermrest_request_content_type = content_type # set location header and status location = '/ermrest/catalog/%s' % catalog_id web.header('Location', location) web.ctx.status = '201 Created' if content_type == _text_plain: return str(catalog_id) else: assert content_type == _application_json return json.dumps(dict(id=catalog_id))
def POST(self, uri='catalog'): """Perform HTTP POST of catalogs. """ # content negotiation content_type = data.negotiated_content_type(self.supported_types, self.default_content_type) # registry acl enforcement allowed = web.ctx.ermrest_registry.can_create(web.ctx.webauthn2_context.attributes) if not allowed: raise rest.Forbidden(uri) # create the catalog instance catalog = web.ctx.ermrest_catalog_factory.create() # initialize the catalog instance pc = sanepg2.PooledConnection(catalog.dsn) try: pc.perform(lambda conn, cur: catalog.init_meta(conn, cur, web.ctx.webauthn2_context.client)).next() finally: pc.final() # register the catalog descriptor entry = web.ctx.ermrest_registry.register(catalog.descriptor) catalog_id = entry['id'] web.header('Content-Type', content_type) web.ctx.ermrest_request_content_type = content_type # set location header and status location = '/ermrest/catalog/%s' % catalog_id web.header('Location', location) web.ctx.status = '201 Created' if content_type == _text_plain: return str(catalog_id) else: assert content_type == _application_json return json.dumps(dict(id=catalog_id))
def GET(self, uri): """Perform HTTP GET of catalog. """ # content negotiation content_type = data.negotiated_content_type(self.supported_types, self.default_content_type) web.header('Content-Type', content_type) web.ctx.ermrest_request_content_type = content_type def body(conn, cur): return list(self.manager.get_meta(cur)) def post_commit(meta): # note that the 'descriptor' includes private system information such # as the dbname (and potentially connection credentials) which should # not ever be shared. resource = dict(id=self.catalog_id, meta=list(meta)) response = json.dumps(resource) + '\n' web.header('Content-Length', len(response)) return response return self.perform(body, post_commit)