Exemplo n.º 1
0
def process_vault(vault):
  """
  vault should be a dictionary returned from list_vaults (from amazon).
  returns the newly created vault object
  """
  #Check if it already exists
  tmp=Vault.query.filter_by(name = vault["VaultName"]).first()
  #Add it if not
  if tmp is None:
    tmp=Vault(vault["VaultName"],vault["VaultARN"].split(":")[3])
  tmp.creation_date = str_to_dt(vault["CreationDate"])
  tmp.ARN = vault['VaultARN']
  tmp.last_inventory_date = str_to_dt(vault["LastInventoryDate"])
  tmp.no_of_archives=vault["NumberOfArchives"]
  tmp.size=vault["SizeInBytes"]
  WG.db.session.add(tmp)
  WG.db.session.commit()
  return tmp
Exemplo n.º 2
0
def process_job(job,vault):
  """
  job should be a dictionary returned by amazon with all the pertinent info.
  vault is a vault object
  returns the newly created/updated job object created
  """
  #Check if it exists
  tmp=Job.query.filter_by(job_id = job['JobId']).first()
  #If it doesn't add it first
  if tmp is None:
    if job['Action']==u'InventoryRetrieval':
      tmp = Job(action='list',job_id = job['JobId'],vault=vault)
    elif job['Action']==u'ArchiveRetrieval':
      archive = Archive.query.filter_by(archive_id = job["ArchiveId"]).first()
      if archive is None:
        #Archive either not added, or deleted
        if WG.app.config.get("VERBOSE",False):
          print "Job points at unknown archive."
      tmp = Job(action='download',job_id = job['JobId'],vault=vault,archive=archive)
  else:
    #Ensure archive is set correctly
    if tmp.archive is None:
      archive = Archive.query.filter_by(archive_id = job["ArchiveId"]).first()
      if archive is None:
        #Archive either not added, or deleted
        if WG.app.config.get("VERBOSE",False):
          print "Job points at unknown archive."
      else:
        tmp.archive=archive
  #Now add all the little extras we may have
  tmp.completed = job['Completed']
  tmp.completion_date = str_to_dt(job['CompletionDate'])
  tmp.creation_date = str_to_dt(job['CreationDate'])
  tmp.inventory_size = job['InventorySizeInBytes']
  tmp.description = job['JobDescription']
  tmp.retrieval_range = job['RetrievalByteRange']
  tmp.SHA256_tree_hash = job['SHA256TreeHash']
  tmp.SNS_topic = job['SNSTopic']
  tmp.status_code = job['StatusCode']
  tmp.status_message = job['StatusMessage']
  WG.db.session.add(tmp)
  WG.db.session.commit()
  return tmp
Exemplo n.º 3
0
def process_archive(archive,vault):
  """
  Like above
  """
  #Check if it exists
  tmp = Archive.query.filter_by(archive_id = archive["ArchiveId"]).first()
  #If it doesn't, first thing is to add it
  if tmp is None:
    tmp = Archive(archive["ArchiveId"],archive["ArchiveDescription"],vault)
  #Now make everything what it should be...
  tmp.description = archive["ArchiveDescription"]
  tmp.insertion_date = str_to_dt(archive["CreationDate"])
  tmp.SHA256_tree_hash = archive["SHA256TreeHash"]
  tmp.filesize = archive["Size"]
  #Try and fill in metadata from the description if possible
  tmp.populate_from_description()
  WG.db.session.add(tmp)
  WG.db.session.commit()
  return tmp