github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/util/image/image.go (about)

     1  /*
     2   * Copyright contributors to the Hyperledger Fabric Operator project
     3   *
     4   * SPDX-License-Identifier: Apache-2.0
     5   *
     6   * Licensed under the Apache License, Version 2.0 (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at:
     9   *
    10   * 	  http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an "AS IS" BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   */
    18  
    19  package image
    20  
    21  import (
    22  	"fmt"
    23  	"strings"
    24  )
    25  
    26  func Format(image, tag string) string {
    27  	if !strings.HasPrefix(tag, "sha256:") {
    28  		return fmt.Sprintf("%s:%s", image, tag)
    29  	} else {
    30  		return fmt.Sprintf("%s@%s", image, tag)
    31  	}
    32  }
    33  
    34  func GetImage(registryURL, image, requestedImage string) string {
    35  	// if requested image is passed use it
    36  	// else fallback to using default image
    37  	if requestedImage != "" {
    38  		image = requestedImage
    39  	}
    40  
    41  	if image != "" {
    42  		// if registry url is empty or set to `no-registry-url` return image as is
    43  		if registryURL == "" || registryURL == "no-registry-url" || registryURL == "no-registry-url/" {
    44  			// use the image as is
    45  			return image
    46  		}
    47  		// else pre-pend registry url to image
    48  		image = registryURL + image
    49  	}
    50  
    51  	return image
    52  }
    53  
    54  func GetTag(arch, tag, requestedTag string) string {
    55  	// if override is passed return it
    56  	// else return default
    57  	if requestedTag != "" {
    58  		return requestedTag
    59  	}
    60  
    61  	return tag
    62  }