diff --git a/client.go b/client.go index e784c2ad..0a632248 100644 --- a/client.go +++ b/client.go @@ -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. @@ -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:, 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) diff --git a/providers.go b/providers.go index b7051303..ffe6f93e 100644 --- a/providers.go +++ b/providers.go @@ -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() +} diff --git a/test/integration/fixture_image_simple_test.go b/test/integration/fixture_image_simple_test.go index 3ab0dfaf..fef0fbbb 100644 --- a/test/integration/fixture_image_simple_test.go +++ b/test/integration/fixture_image_simple_test.go @@ -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, }, {