Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <[email protected]>
  • Loading branch information
kzantow committed Feb 13, 2024
1 parent 707581e commit 9958a84
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
20 changes: 4 additions & 16 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func WithPlatform(platform string) Option {
// GetImage parses the user provided image string and provides an image object;
// note: the source where the image should be referenced from is automatically inferred.
func GetImage(ctx context.Context, imgStr string, options ...Option) (*image.Image, error) {
return getImageFromSource(ctx, imgStr, "", options...)
// look for a known source scheme like docker:
source, imgStr := ExtractSchemeSource(imgStr, allProviderTags()...)
return getImageFromSource(ctx, imgStr, source, options...)
}

// GetImageFromSource returns an image from the explicitly provided source.
Expand Down Expand Up @@ -88,22 +90,8 @@ func getImageFromSource(ctx context.Context, imgStr string, source image.Source,
Registry: cfg.Registry,
})...,
)
source = strings.ToLower(strings.TrimSpace(source))
if source == "" {
// if no source is explicitly specified, look for a known scheme like docker:
source, imgStr = ExtractSchemeSource(imgStr, providers.Tags()...)
if source != "" {
// a source was specified in the string, so imgStr was something like docker:<image-ref>, reconfigure the providers with the right image ref
providers = tagged.ValueSet[image.Provider]{}.Join(
ImageProviders(ImageProviderConfig{
UserInput: imgStr,
Platform: cfg.Platform,
Registry: cfg.Registry,
})...,
)
}
}
if source != "" {
source = strings.ToLower(strings.TrimSpace(source))
providers = providers.Select(source)
if len(providers) == 0 {
return nil, fmt.Errorf("unable to find image providers matching: '%s'", source)
Expand Down
4 changes: 4 additions & 0 deletions providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ func ImageProviders(cfg ImageProviderConfig) []tagged.Value[image.Provider] {
func taggedProvider(provider image.Provider, tags ...string) tagged.Value[image.Provider] {
return tagged.New[image.Provider](provider, append([]string{provider.Name()}, tags...)...)
}

func allProviderTags() []string {
return tagged.ValueSet[image.Provider]{}.Join(ImageProviders(ImageProviderConfig{})...).Tags()
}
2 changes: 1 addition & 1 deletion test/integration/fixture_image_simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var simpleImageTestCases = []testCase{
imageMediaType: v1Types.DockerManifestSchema2,
layerMediaType: v1Types.DockerLayer,
layers: simpleImageLayers,
tagCount: 1, // this uses a docker image save, which does not include the latest tag
tagCount: 2,
size: 65,
},
{
Expand Down

0 comments on commit 9958a84

Please sign in to comment.