Skip to content

Commit

Permalink
Check if file exists on S3
Browse files Browse the repository at this point in the history
  • Loading branch information
blagojabozinovski committed May 28, 2024
1 parent e155141 commit 8de9359
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ckanext/qa/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ckan.lib.helpers as ckan_helpers
from ckanext.qa.sniff_format import sniff_file_format
from ckanext.archiver.model import Archival, Status
from google.cloud import storage

import logging

Expand Down Expand Up @@ -295,15 +296,26 @@ def score_by_sniffing_data(archival, resource, score_reasons):
score_reasons.append(_('This file had not been downloaded at the time of scoring it.'))
return (None, None)
# Analyse the cached file
cloudstorage_enabled = config.get('ckanext.qa.cloudstorage_enabled', True)
cloudstorage_enabled = config.get('ckanext.qa.cloudstorage_enabled', False)

if cloudstorage_enabled:

# check if blob exists
pass
# check if blob exists in cloudstorage
path_to_json = config.get(
'ckanext.cloudstorage.google_service_account_json')
bucket_name = config.get('ckanext.cloudstorage.container_name')
storage_client = storage.Client.from_service_account_json(path_to_json)
bucket = storage_client.bucket(bucket_name)
s3_filepath = "resources/" + resource.id + "/" + resource.url
blob = bucket.blob(s3_filepath)
if blob.exists():
return (None, None)
else:
score_reasons.append(_('File does not exists on S3: "%s".') % s3_filepath)
return (None, None)

else:

# check if file exists in filestore
filepath = archival.cache_filepath
if not os.path.exists(filepath):
score_reasons.append(_('Cache filepath does not exist: "%s".') % filepath)
Expand Down

0 comments on commit 8de9359

Please sign in to comment.