Make Image.HasShaInInputName to an independent local function

The functionality only depends on Image.InputName, and we will want
to make the only user of this independent of the fairly complex Image type.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Closes: #1112
Approved by: rhatdan
This commit is contained in:
Miloslav Trmač
2018-07-19 00:11:15 +02:00
committed by Atomic Bot
parent 347ba2cc25
commit 3b964a4d9a
2 changed files with 9 additions and 9 deletions

View File

@ -264,6 +264,12 @@ func (i *Image) pullImage(ctx context.Context, writer io.Writer, authfile, signa
return images, nil
}
// hasShaInInputName returns a bool as to whether the user provided an image name that includes
// a reference to a specific sha
func hasShaInInputName(inputName string) bool {
return strings.Contains(inputName, "@sha256:")
}
// refNamesFromPossiblyUnqualifiedName looks at a decomposed image and determines the possible
// image names to try pulling in combination with the registries.conf file as well
func (i *Image) refNamesFromPossiblyUnqualifiedName() ([]*pullRefName, error) {
@ -277,7 +283,7 @@ func (i *Image) refNamesFromPossiblyUnqualifiedName() ([]*pullRefName, error) {
return nil, err
}
if decomposedImage.hasRegistry {
if i.HasShaInInputName() {
if hasShaInInputName(i.InputName) {
imageName = fmt.Sprintf("%s%s", decomposedImage.transport, i.InputName)
} else {
imageName = decomposedImage.assembleWithTransport()
@ -290,7 +296,7 @@ func (i *Image) refNamesFromPossiblyUnqualifiedName() ([]*pullRefName, error) {
image: i.InputName,
srcRef: srcRef,
}
if i.HasShaInInputName() {
if hasShaInInputName(i.InputName) {
ps.dstName = decomposedImage.assemble()
} else {
ps.dstName = ps.image
@ -305,7 +311,7 @@ func (i *Image) refNamesFromPossiblyUnqualifiedName() ([]*pullRefName, error) {
for _, registry := range searchRegistries {
decomposedImage.registry = registry
imageName := decomposedImage.assembleWithTransport()
if i.HasShaInInputName() {
if hasShaInInputName(i.InputName) {
imageName = fmt.Sprintf("%s%s/%s", decomposedImage.transport, registry, i.InputName)
}
srcRef, err := alltransports.ParseImageName(imageName)