containerx

package
v0.0.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 4 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetImageURL

func GetImageURL(opts *NewBaseContainerOpts) (string, error)

GetImageURL constructs the full image URL from the provided options.

This function takes a pointer to NewBaseContainerOpts and constructs a Docker image URL by combining the image name and version. If the provided image name or version is empty, it uses fallback values. If both the provided and fallback values are empty, it uses default values.

Parameters:

  • opts (*NewBaseContainerOpts): A pointer to a NewBaseContainerOpts struct containing the image name, version, fallback image name, and fallback version.

Returns:

  • (string, error): Returns the constructed image URL as a string and an error if the options pointer is nil.

Example:

opts := &NewBaseContainerOpts{
    Image:         "myimage",
    Version:       "1.0",
    FallbackImage: "fallbackimage",
    FallBackVersion: "latest",
}
imageURL, err := GetImageURL(opts)
if err != nil {
    log.Fatalf("Error: %v", err)
}
fmt.Println(imageURL) // Output: myimage:1.0

func SetDefaultImageNameIfEmpty added in v0.0.10

func SetDefaultImageNameIfEmpty(image, fallbackImage string) string

SetDefaultImageNameIfEmpty returns a fallback image if the provided image is empty. If both the provided image and the fallback image are empty, it returns the default image from fixtures.

func SetDefaultImageVersionIfEmpty added in v0.0.10

func SetDefaultImageVersionIfEmpty(version, fallbackVersion string) string

SetDefaultImageVersionIfEmpty returns a fallback version if the provided version is empty. If both the provided version and the fallback version are empty, it returns "latest".

func ValidateImageURL added in v0.0.17

func ValidateImageURL(imageURL string) (bool, error)

ValidateImageURL verifies the correctness and validity of a given Docker image URL.

This function performs several validation steps to ensure the image URL adheres to expected formats and does not contain any invalid characters or components. The validation includes:

  1. **Empty Check**: Ensures that the `imageURL` is not an empty string.
  2. **Structure Validation**: Splits the `imageURL` into segments using the '/' delimiter and checks that the number of components does not exceed four, which could indicate an improperly formatted URL.
  3. **Repository Name Validation**: Iterates through all repository components except the last one to verify that they do not contain the '@' character, which is reserved for specifying digests.
  4. **Registry Validation**: If a registry is present in the URL, it validates the registry's format to ensure it conforms to expected naming conventions.
  5. **Namespace and Repository Validation**: Checks that each namespace and repository name within the URL adheres to valid naming rules, preventing the inclusion of invalid characters or formats.
  6. **Tag and Digest Validation**: Examines the last part of the URL to ensure that any specified tag or digest is correctly formatted. Specifically, if a digest is present, it must start with a supported hashing algorithm prefix like `sha256:` or `sha512:`.

**Parameters:** - `imageURL` (string): The Docker image URL to be validated.

**Returns:** - `bool`: Returns `true` if the `imageURL` passes all validation checks; otherwise, returns `false`. - `error`: Provides an error detailing the reason for validation failure, if any.

Types

type NewBaseContainerOpts

type NewBaseContainerOpts struct {
	// Image is the name of the image to use.
	Image string
	// Version is the version of the image to use.
	Version string
	// FallbackImage is the name of the fallback image to use if the primary image is empty.
	FallbackImage string
	// FallBackVersion is the version of the fallback image to use if the primary image is empty.
	FallBackVersion string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL