Skip to content

Commit 1f556ec

Browse files
authored
Merge pull request #4 from Ryang20718/user/ryang/s3_versioning
[feat] add optional versioning id for s3 archive
2 parents 46844cc + bab5aaf commit 1f556ec

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cloud_archive.bzl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def cloud_archive_download(
7676
build_file = "",
7777
build_file_contents = "",
7878
profile = "",
79-
patch_cmds = []):
79+
patch_cmds = [],
80+
file_version = ""):
8081
""" Securely downloads and unpacks an archive from Minio, then places a
8182
BUILD file inside. """
8283
filename = repo_ctx.path(file_path).basename
@@ -95,8 +96,11 @@ def cloud_archive_download(
9596
elif provider == "s3":
9697
tool_path = repo_ctx.which("aws")
9798
extra_flags = ["--profile", profile] if profile else []
98-
src_url = "s3://{}/{}".format(bucket, file_path)
99-
cmd = [tool_path] + extra_flags + ["s3", "cp", src_url, "."]
99+
bucket_arg = ["--bucket", bucket]
100+
file_arg = ["--key", file_path]
101+
file_version_arg = ["--version-id", file_version] if file_version else []
102+
src_url = filename
103+
cmd = [tool_path] + extra_flags + ["s3api", "get-object"] + bucket_arg + file_arg + file_version_arg + [filename]
100104
elif provider == "backblaze":
101105
# NOTE: currently untested, as I don't have a B2 account.
102106
tool_path = repo_ctx.which("b2")
@@ -168,6 +172,7 @@ def _cloud_archive_impl(ctx):
168172
build_file_contents = ctx.attr.build_file_contents,
169173
profile = ctx.attr.profile if hasattr(ctx.attr, "profile") else "",
170174
bucket = ctx.attr.bucket if hasattr(ctx.attr, "bucket") else "",
175+
file_version = ctx.attr.file_version if hasattr(ctx.attr, "file_version") else "",
171176
)
172177

173178
minio_archive = repository_rule(
@@ -210,6 +215,7 @@ s3_archive = repository_rule(
210215
"patch_args": attr.string_list(doc = "Arguments to use when applying patches."),
211216
"patch_cmds": attr.string_list(doc = "Sequence of Bash commands to be applied after patches are applied."),
212217
"strip_prefix": attr.string(doc = "Prefix to strip when archive is unpacked"),
218+
"file_version": attr.string(doc = "file version id of object if bucket is versioned"),
213219
"_provider": attr.string(default = "s3"),
214220
},
215221
)

0 commit comments

Comments
 (0)