Merge "Add source auth to image push"

This commit is contained in:
Zuul 2020-02-26 18:45:21 +00:00 committed by Gerrit Code Review
commit 8a0f1cacd5
2 changed files with 36 additions and 2 deletions

View File

@ -311,6 +311,8 @@ class TestContainerImagePush(TestPluginV1):
mock_get_uc_registry):
arglist = ['--registry-url', '127.0.0.1:8787',
'--append-tag', 'test',
'--source-username', 'sourceuser',
'--source-password', 'sourcepassword',
'--username', 'user',
'--password', 'password',
'--dry-run',
@ -355,9 +357,15 @@ class TestContainerImagePush(TestPluginV1):
self.cmd.take_action(parsed_args)
source_url = parse.urlparse("docker://docker.io/namespace/foo:tag")
registry_url = parse.urlparse("docker://127.0.0.1:8787")
mock_uploader.authenticate.assert_called_once_with(
registry_url, parsed_args.username, parsed_args.password)
auth_calls = [mock.call(source_url,
parsed_args.source_username,
parsed_args.source_password),
mock.call(registry_url,
parsed_args.username,
parsed_args.password)]
mock_uploader.authenticate.assert_has_calls(auth_calls)
mock_task.assert_called_once_with(
image_name='namespace/foo:tag',

View File

@ -581,6 +581,19 @@ class TripleOContainerImagePush(command.Command):
metavar='<password>',
help=_("Password for the destination image registry.")
)
parser.add_argument(
"--source-username",
dest="source_username",
metavar='<source_username>',
help=_("Username for the source image registry.")
)
parser.add_argument(
"--source-password",
dest="source_password",
metavar='<source_password>',
help=_("Password for the source image registry.")
)
parser.add_argument(
"--dry-run",
dest="dry_run",
@ -630,6 +643,8 @@ class TripleOContainerImagePush(command.Command):
source_url = parse.urlparse(source_image)
image_name = source_url.geturl()
image_source = None
if parsed_args.source_username or parsed_args.source_password:
self.log.warning('Source credentials ignored for local images')
else:
storage = 'docker://'
if not source_image.startswith(storage):
@ -642,6 +657,17 @@ class TripleOContainerImagePush(command.Command):
'container image should be '
'<registry>/<namespace>/<name>:'
'<tag>')
if parsed_args.source_username or parsed_args.source_password:
if not parsed_args.source_username:
self.log.warning('Skipping authentication - missing source'
' username')
elif not parsed_args.source_password:
self.log.warning('Skipping authentication - missing source'
' password')
else:
uploader.authenticate(source_url,
parsed_args.source_username,
parsed_args.source_password)
registry_url = parsed_args.registry_url
if not registry_url.startswith('docker://'):