cmd-remote-prune: pass gcp credentials when pruning
import argparse
import sys
+import os
from cosalib.builds import Builds
from cosalib.prune import fetch_build_meta, get_unreferenced_s3_builds, delete_build
@@ -14,6 +15,10 @@ parser = argparse.ArgumentParser(prog="coreos-assembler remote-prune")
parser.add_argument("--workdir", default='.', help="Path to workdir")
parser.add_argument("--dry-run", help="Don't actually delete anything",
action='store_true')
+parser.add_argument("--gcp-json-key", help="GCP Service Account JSON Auth",
+ default=os.environ.get("GCP_JSON_AUTH"))
+parser.add_argument("--gcp-project", help="GCP Project name",
+ default=os.environ.get("GCP_PROJECT_NAME"))
subparsers = parser.add_subparsers(dest='cmd', title='subcommands')
subparsers.required = True
@@ -44,13 +49,20 @@ if args.dry_run:
print("Not removing anything: in dry-run mode")
sys.exit(0)
+cloud_config = {
+ 'gcp': {
+ 'json-key': args.gcp_json_key,
+ 'project': args.gcp_project,
+ }
+}
+
error_during_pruning = False
for unmatched_build_id in unreferenced_s3_builds:
# TODO: fetch arches from s3
build = fetch_build_meta(builds, unmatched_build_id, 'x86_64', args.bucket, args.prefix)
if build:
try:
- delete_build(build, args.bucket, args.prefix)
+ delete_build(build, args.bucket, args.prefix, cloud_config)
except Exception as e:
error_during_pruning = True
print(f"{e}")
