def restore_records(self, manifest: ArchiveManifest): """ Re-create the catalog_image and catalog_image_docker records. :return: """ with session_scope() as session: img_record_str = manifest.metadata.get('image_record') if not img_record_str: raise Exception('Cannot restore missing image record') else: img_record = json.loads(img_record_str) details = img_record.pop('image_detail') if not details: details = [] c = CatalogImage() img_record['userId'] = self.account c.update(img_record) session.add(c) for detail in details: detail['userId'] = self.account tr = CatalogImageDocker() tr.update(detail) session.add(tr) return True
def add(imageDigest, userId, image_type, dbobj={}, image_data={}, session=None): if not session: session = db.Session dbobj.pop('created_at', None) dbobj.pop('last_updated', None) our_result = session.query(CatalogImage).filter_by( imageDigest=imageDigest, userId=userId, image_type=image_type).first() if not our_result: if image_type == 'docker' and image_data: rc = db.db_catalog_image_docker.add( imageDigest, userId, image_data['tag'], registry=image_data['registry'], user=image_data['user'], repo=image_data['repo'], digest=image_data['digest'], imageId=image_data['imageId'], dockerfile=image_data['dockerfile'], session=session) our_result = CatalogImage(imageDigest=imageDigest, userId=userId, image_type=image_type) our_result.update(dbobj) session.add(our_result) else: our_result.update(dbobj) if image_type == 'docker' and image_data: rc = db.db_catalog_image_docker.update( imageDigest, userId, image_data['tag'], registry=image_data['registry'], user=image_data['user'], repo=image_data['repo'], digest=image_data['digest'], imageId=image_data['imageId'], dockerfile=image_data['dockerfile'], session=session) return (True)