mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #50787 from austinvazquez/move-registry-search-options-to-client
api/types/registry: move registry search options to client
This commit is contained in:
@@ -1,26 +1,5 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/moby/moby/api/types/filters"
|
||||
)
|
||||
|
||||
// SearchOptions holds parameters to search images with.
|
||||
type SearchOptions struct {
|
||||
RegistryAuth string
|
||||
|
||||
// PrivilegeFunc is a function that clients can supply to retry operations
|
||||
// after getting an authorization error. This function returns the registry
|
||||
// authentication header value in base64 encoded format, or an error if the
|
||||
// privilege request fails.
|
||||
//
|
||||
// For details, refer to [github.com/moby/moby/api/types/registry.RequestAuthConfig].
|
||||
PrivilegeFunc func(context.Context) (string, error)
|
||||
Filters filters.Args
|
||||
Limit int
|
||||
}
|
||||
|
||||
// SearchResult describes a search result returned from a registry
|
||||
type SearchResult struct {
|
||||
// StarCount indicates the number of stars this repository has
|
||||
|
||||
@@ -116,7 +116,7 @@ type ImageAPIClient interface {
|
||||
ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error)
|
||||
ImagePush(ctx context.Context, ref string, options image.PushOptions) (io.ReadCloser, error)
|
||||
ImageRemove(ctx context.Context, image string, options image.RemoveOptions) ([]image.DeleteResponse, error)
|
||||
ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error)
|
||||
ImageSearch(ctx context.Context, term string, options ImageSearchOptions) ([]registry.SearchResult, error)
|
||||
ImageTag(ctx context.Context, image, ref string) error
|
||||
ImagesPrune(ctx context.Context, pruneFilter filters.Args) (image.PruneReport, error)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
// ImageSearch makes the docker host search by a term in a remote registry.
|
||||
// The list of results is not sorted in any fashion.
|
||||
func (cli *Client) ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) {
|
||||
func (cli *Client) ImageSearch(ctx context.Context, term string, options ImageSearchOptions) ([]registry.SearchResult, error) {
|
||||
var results []registry.SearchResult
|
||||
query := url.Values{}
|
||||
query.Set("term", term)
|
||||
|
||||
22
client/image_search_opts.go
Normal file
22
client/image_search_opts.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/moby/moby/api/types/filters"
|
||||
)
|
||||
|
||||
// ImageSearchOptions holds parameters to search images with.
|
||||
type ImageSearchOptions struct {
|
||||
RegistryAuth string
|
||||
|
||||
// PrivilegeFunc is a function that clients can supply to retry operations
|
||||
// after getting an authorization error. This function returns the registry
|
||||
// authentication header value in base64 encoded format, or an error if the
|
||||
// privilege request fails.
|
||||
//
|
||||
// For details, refer to [github.com/moby/moby/api/types/registry.RequestAuthConfig].
|
||||
PrivilegeFunc func(context.Context) (string, error)
|
||||
Filters filters.Args
|
||||
Limit int
|
||||
}
|
||||
@@ -22,7 +22,7 @@ func TestImageSearchAnyError(t *testing.T) {
|
||||
client := &Client{
|
||||
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
|
||||
}
|
||||
_, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{})
|
||||
_, err := client.ImageSearch(context.Background(), "some-image", ImageSearchOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestImageSearchStatusUnauthorizedError(t *testing.T) {
|
||||
client := &Client{
|
||||
client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")),
|
||||
}
|
||||
_, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{})
|
||||
_, err := client.ImageSearch(context.Background(), "some-image", ImageSearchOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsUnauthorized))
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestImageSearchWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
|
||||
privilegeFunc := func(_ context.Context) (string, error) {
|
||||
return "", errors.New("Error requesting privilege")
|
||||
}
|
||||
_, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
|
||||
_, err := client.ImageSearch(context.Background(), "some-image", ImageSearchOptions{
|
||||
PrivilegeFunc: privilegeFunc,
|
||||
})
|
||||
assert.Check(t, is.Error(err, "Error requesting privilege"))
|
||||
@@ -54,7 +54,7 @@ func TestImageSearchWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.
|
||||
privilegeFunc := func(_ context.Context) (string, error) {
|
||||
return "a-auth-header", nil
|
||||
}
|
||||
_, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
|
||||
_, err := client.ImageSearch(context.Background(), "some-image", ImageSearchOptions{
|
||||
PrivilegeFunc: privilegeFunc,
|
||||
})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsUnauthorized))
|
||||
@@ -99,7 +99,7 @@ func TestImageSearchWithPrivilegedFuncNoError(t *testing.T) {
|
||||
privilegeFunc := func(_ context.Context) (string, error) {
|
||||
return "IAmValid", nil
|
||||
}
|
||||
results, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
|
||||
results, err := client.ImageSearch(context.Background(), "some-image", ImageSearchOptions{
|
||||
RegistryAuth: "NotValid",
|
||||
PrivilegeFunc: privilegeFunc,
|
||||
})
|
||||
@@ -139,7 +139,7 @@ func TestImageSearchWithoutErrors(t *testing.T) {
|
||||
}, nil
|
||||
}),
|
||||
}
|
||||
results, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
|
||||
results, err := client.ImageSearch(context.Background(), "some-image", ImageSearchOptions{
|
||||
Filters: filters.NewArgs(
|
||||
filters.Arg("is-automated", "true"),
|
||||
filters.Arg("stars", "3"),
|
||||
|
||||
21
vendor/github.com/moby/moby/api/types/registry/search.go
generated
vendored
21
vendor/github.com/moby/moby/api/types/registry/search.go
generated
vendored
@@ -1,26 +1,5 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/moby/moby/api/types/filters"
|
||||
)
|
||||
|
||||
// SearchOptions holds parameters to search images with.
|
||||
type SearchOptions struct {
|
||||
RegistryAuth string
|
||||
|
||||
// PrivilegeFunc is a function that clients can supply to retry operations
|
||||
// after getting an authorization error. This function returns the registry
|
||||
// authentication header value in base64 encoded format, or an error if the
|
||||
// privilege request fails.
|
||||
//
|
||||
// For details, refer to [github.com/moby/moby/api/types/registry.RequestAuthConfig].
|
||||
PrivilegeFunc func(context.Context) (string, error)
|
||||
Filters filters.Args
|
||||
Limit int
|
||||
}
|
||||
|
||||
// SearchResult describes a search result returned from a registry
|
||||
type SearchResult struct {
|
||||
// StarCount indicates the number of stars this repository has
|
||||
|
||||
2
vendor/github.com/moby/moby/client/client_interfaces.go
generated
vendored
2
vendor/github.com/moby/moby/client/client_interfaces.go
generated
vendored
@@ -116,7 +116,7 @@ type ImageAPIClient interface {
|
||||
ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error)
|
||||
ImagePush(ctx context.Context, ref string, options image.PushOptions) (io.ReadCloser, error)
|
||||
ImageRemove(ctx context.Context, image string, options image.RemoveOptions) ([]image.DeleteResponse, error)
|
||||
ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error)
|
||||
ImageSearch(ctx context.Context, term string, options ImageSearchOptions) ([]registry.SearchResult, error)
|
||||
ImageTag(ctx context.Context, image, ref string) error
|
||||
ImagesPrune(ctx context.Context, pruneFilter filters.Args) (image.PruneReport, error)
|
||||
|
||||
|
||||
2
vendor/github.com/moby/moby/client/image_search.go
generated
vendored
2
vendor/github.com/moby/moby/client/image_search.go
generated
vendored
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
// ImageSearch makes the docker host search by a term in a remote registry.
|
||||
// The list of results is not sorted in any fashion.
|
||||
func (cli *Client) ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) {
|
||||
func (cli *Client) ImageSearch(ctx context.Context, term string, options ImageSearchOptions) ([]registry.SearchResult, error) {
|
||||
var results []registry.SearchResult
|
||||
query := url.Values{}
|
||||
query.Set("term", term)
|
||||
|
||||
22
vendor/github.com/moby/moby/client/image_search_opts.go
generated
vendored
Normal file
22
vendor/github.com/moby/moby/client/image_search_opts.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/moby/moby/api/types/filters"
|
||||
)
|
||||
|
||||
// ImageSearchOptions holds parameters to search images with.
|
||||
type ImageSearchOptions struct {
|
||||
RegistryAuth string
|
||||
|
||||
// PrivilegeFunc is a function that clients can supply to retry operations
|
||||
// after getting an authorization error. This function returns the registry
|
||||
// authentication header value in base64 encoded format, or an error if the
|
||||
// privilege request fails.
|
||||
//
|
||||
// For details, refer to [github.com/moby/moby/api/types/registry.RequestAuthConfig].
|
||||
PrivilegeFunc func(context.Context) (string, error)
|
||||
Filters filters.Args
|
||||
Limit int
|
||||
}
|
||||
Reference in New Issue
Block a user