Skip to content
This repository was archived by the owner on Oct 10, 2020. It is now read-only.

Commit 1c877c5

Browse files
giusepperh-atomic-bot
authored andcommitted
syscontainers: support credentials for accessing the source registry
Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1505744 Signed-off-by: Giuseppe Scrivano <[email protected]> Closes: #1120 Approved by: ashcrow
1 parent 24e1a61 commit 1c877c5

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

Atomic/backends/_ostree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def get_containers(self):
110110
return [self._make_container(x) for x in self.syscontainers.get_containers()]
111111

112112
def pull_image(self, image, remote_image_obj=None, **kwargs):
113-
return self.syscontainers.pull_image(image)
113+
return self.syscontainers.pull_image(image, **kwargs)
114114

115115
def delete_image(self, image, force=False):
116116
return self.syscontainers.delete_image(image)

Atomic/syscontainers.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _split_set_args(setvalues):
158158
values[key] = val
159159
return values
160160

161-
def _pull_image_to_ostree(self, repo, image, upgrade):
161+
def _pull_image_to_ostree(self, repo, image, upgrade, src_creds=None):
162162
if not repo:
163163
raise ValueError("Cannot find a configured OSTree repo")
164164
if image.startswith("ostree:") and image.count(':') > 1:
@@ -169,17 +169,21 @@ def _pull_image_to_ostree(self, repo, image, upgrade):
169169
tarpath = image.replace("dockertar:/", "", 1)
170170
image = self._pull_docker_tar(repo, tarpath, os.path.basename(tarpath).replace(".tar", ""))
171171
else: # Assume "oci:"
172-
self._check_system_oci_image(repo, image, upgrade)
172+
self._check_system_oci_image(repo, image, upgrade, src_creds=src_creds)
173173
return image
174174

175-
def pull_image(self, image=None):
175+
def pull_image(self, image=None, **kwargs):
176176
"""
177177
Public method for pulling an image from an external location into ostree.
178178
179179
:param image: Name of the image to pull. If not provided self.args.image is used.
180180
:type image: str or None
181+
182+
:param kwargs: Arguments to pass to the pull
183+
:type kwargs: dict or None
181184
"""
182-
self._pull_image_to_ostree(self._get_ostree_repo(), image or self.args.image, True)
185+
src_creds = kwargs.get('src_creds')
186+
self._pull_image_to_ostree(self._get_ostree_repo(), image or self.args.image, True, src_creds=src_creds)
183187

184188
def install_user_container(self, image, name):
185189
"""
@@ -1933,7 +1937,7 @@ def _check_system_ostree_image(self, repo, img, upgrade):
19331937
remote, branch = imagebranch.split(":")
19341938
return repo.pull(remote, [branch], 0, None)
19351939

1936-
def _check_system_oci_image(self, repo, img, upgrade):
1940+
def _check_system_oci_image(self, repo, img, upgrade, src_creds=None):
19371941
imagebranch = "%s%s" % (OSTREE_OCIIMAGE_PREFIX, SystemContainers._encode_to_ostree_ref(img))
19381942
current_rev = repo.resolve_rev(imagebranch, True)
19391943
if not current_rev:
@@ -1953,10 +1957,10 @@ def _check_system_oci_image(self, repo, img, upgrade):
19531957
can_use_skopeo_copy = util.check_output([util.SKOPEO_PATH, "copy", "--help"]).decode().find("ostree") >= 0
19541958

19551959
if can_use_skopeo_copy:
1956-
return self._check_system_oci_image_skopeo_copy(repo, img)
1960+
return self._check_system_oci_image_skopeo_copy(repo, img, src_creds=src_creds)
19571961
return self._check_system_oci_image_no_skopeo_copy(repo, img, imagebranch)
19581962

1959-
def _check_system_oci_image_skopeo_copy(self, repo, img):
1963+
def _check_system_oci_image_skopeo_copy(self, repo, img, src_creds=None):
19601964
repo = self.get_ostree_repo_location()
19611965

19621966
checkout = self._get_system_checkout_path()
@@ -1968,7 +1972,7 @@ def _check_system_oci_image_skopeo_copy(self, repo, img):
19681972

19691973
destination = "ostree:{}@{}".format(img, repo)
19701974
try:
1971-
util.skopeo_copy("docker://" + img, destination, dest_ostree_tmp_dir=temp_dir, insecure=insecure)
1975+
util.skopeo_copy("docker://" + img, destination, dest_ostree_tmp_dir=temp_dir, insecure=insecure, src_creds=src_creds)
19721976
finally:
19731977
shutil.rmtree(temp_dir, ignore_errors=True)
19741978
return True

0 commit comments

Comments
 (0)