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_record(record, session=None): if not session: session = db.Session our_result = session.query(CatalogImageDocker).filter_by(imageDigest=record['imageDigest'], userId=record['userId'], tag=record['tag'], repo=record['repo'], registry=record['registry']).first() if not our_result: our_result = CatalogImageDocker(**record) session.add(our_result) return(True)
def add(imageDigest, userId, tag, registry=None, user=None, repo=None, digest=None, imageId=None, dockerfile=None, tag_detected_at=None, session=None): if not session: session = db.Session dbobj = { 'registry':registry, 'user':user, 'repo':repo, 'digest':digest, 'imageId':imageId, 'dockerfile':dockerfile } if tag_detected_at: dbobj['tag_detected_at'] = tag_detected_at our_result = session.query(CatalogImageDocker).filter_by(imageDigest=imageDigest, userId=userId, tag=tag).first() if not our_result: our_result = CatalogImageDocker(imageDigest=imageDigest, userId=userId, tag=tag) #dbobj['created_at'] = int(time.time()) our_result.update(dbobj) session.add(our_result) else: our_result.update(dbobj) return(True)
def add_record(record, session=None): if not session: session = db.Session our_result = (session.query(CatalogImageDocker).filter_by( imageDigest=record["imageDigest"], userId=record["userId"], tag=record["tag"], repo=record["repo"], registry=record["registry"], ).first()) if not our_result: our_result = CatalogImageDocker(**record) session.add(our_result) return True
def add( imageDigest, userId, tag, registry=None, user=None, repo=None, digest=None, imageId=None, dockerfile=None, tag_detected_at=None, session=None, ): if not session: session = db.Session dbobj = { "registry": registry, "user": user, "repo": repo, "digest": digest, "imageId": imageId, "dockerfile": dockerfile, } if tag_detected_at: dbobj["tag_detected_at"] = tag_detected_at our_result = (session.query(CatalogImageDocker).filter_by( imageDigest=imageDigest, userId=userId, tag=tag).first()) if not our_result: our_result = CatalogImageDocker(imageDigest=imageDigest, userId=userId, tag=tag) our_result.update(dbobj) session.add(our_result) else: our_result.update(dbobj) return True