Add source auth to image push
Add source username and password cli parameters to the `openstack tripleo container image push` command. Change-Id: Idb6b97167b00aee24f173926a1e1822ccb0b92bd Closes-Bug: #1864700
This commit is contained in:
parent
7aeba8f51a
commit
8526ad0d3f
|
@ -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',
|
||||
|
|
|
@ -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://'):
|
||||
|
|
Loading…
Reference in New Issue