Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use GCS object update time instead of creation time #2454

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ def convert_blob_to_vuln(blob: storage.Blob) -> Optional[Tuple[str, str]]:
if not _is_vulnerability_file(source_repo, blob.name):
return None
if not ignore_last_import_time and \
not blob.time_created > utc_last_update_date:
blob.updated is not None and \
not blob.updated > utc_last_update_date:
return None

logging.info('Bucket entry triggered for %s/%s', source_repo.bucket,
Expand Down
18 changes: 5 additions & 13 deletions tools/datafix/reimport_gcs_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,19 @@ def bucket_for_source(client: datastore.Client, source: str) -> str:
return result[0]['bucket']


def reset_object_creation(bucket_name: str,
blob_name: str,
tmpdir="/tmp") -> None:
def reset_object_modification(bucket_name: str, blob_name: str) -> None:
"""Resets a GCS object's creation time.

Copies the object locally and uploads it again.
Makes a no-op patch ("gcloud object storage objects update" equivalent)

Args:
bucket_name: the name of the GCS bucket.
blob_name: the name of the object in the bucket.
tmpdir: a preexisting directory in the local filesystem to copy the object
to/from.
"""
local_tmp_file = os.path.join(tmpdir, os.path.basename(blob_name))
gcs_client = storage.Client()
bucket = gcs_client.bucket(bucket_name)
blob = bucket.blob(blob_name)
blob.download_to_filename(local_tmp_file)
blob.upload_from_filename(local_tmp_file, retry=retry.DEFAULT_RETRY)
os.unlink(local_tmp_file)
blob.patch(retry=retry.DEFAULT_RETRY)


def main() -> None:
Expand Down Expand Up @@ -178,11 +171,10 @@ def main() -> None:
print(f"Skipping {bug['db_id']}, got {e}\n")
continue
if args.verbose:
print(f"Resetting creation time for {bug_in_gcs['uri']}")
print(f"Resetting modification time for {bug_in_gcs['uri']}")
if not args.dryrun:
try:
reset_object_creation(bug_in_gcs["bucket"], bug_in_gcs["path"],
args.tmpdir)
reset_object_modification(bug_in_gcs["bucket"], bug_in_gcs["path"])
except NotFound as e:
if args.verbose:
print(f"Skipping, got {e}\n")
Expand Down
2 changes: 1 addition & 1 deletion vulnfeeds/cmd/combine-to-osv/run_combine_to_osv_convert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ echo "Override"
gcloud --no-user-output-enabled storage rsync "gs://${INPUT_BUCKET}/osv-output-overrides/" $OSV_OUTPUT

echo "Begin syncing output to GCS bucket ${OUTPUT_BUCKET}"
gcloud --no-user-output-enabled storage rsync "$OSV_OUTPUT" "gs://${OUTPUT_BUCKET}/osv-output/" --checksums-only -c --delete-unmatched-destination-objects -q
gsutil -q -m rsync -c -d "${OSV_OUTPUT}" "gs://${OUTPUT_BUCKET}/osv-output/"
echo "Successfully synced to GCS bucket"
Loading