Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
| ... | ... |
@@ -1,26 +1,5 @@ |
| 1 | 1 |
package registry |
| 2 | 2 |
|
| 3 |
-import ( |
|
| 4 |
- "context" |
|
| 5 |
- |
|
| 6 |
- "github.com/moby/moby/api/types/filters" |
|
| 7 |
-) |
|
| 8 |
- |
|
| 9 |
-// SearchOptions holds parameters to search images with. |
|
| 10 |
-type SearchOptions struct {
|
|
| 11 |
- RegistryAuth string |
|
| 12 |
- |
|
| 13 |
- // PrivilegeFunc is a function that clients can supply to retry operations |
|
| 14 |
- // after getting an authorization error. This function returns the registry |
|
| 15 |
- // authentication header value in base64 encoded format, or an error if the |
|
| 16 |
- // privilege request fails. |
|
| 17 |
- // |
|
| 18 |
- // For details, refer to [github.com/moby/moby/api/types/registry.RequestAuthConfig]. |
|
| 19 |
- PrivilegeFunc func(context.Context) (string, error) |
|
| 20 |
- Filters filters.Args |
|
| 21 |
- Limit int |
|
| 22 |
-} |
|
| 23 |
- |
|
| 24 | 3 |
// SearchResult describes a search result returned from a registry |
| 25 | 4 |
type SearchResult struct {
|
| 26 | 5 |
// StarCount indicates the number of stars this repository has |
| ... | ... |
@@ -116,7 +116,7 @@ type ImageAPIClient interface {
|
| 116 | 116 |
ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) |
| 117 | 117 |
ImagePush(ctx context.Context, ref string, options image.PushOptions) (io.ReadCloser, error) |
| 118 | 118 |
ImageRemove(ctx context.Context, image string, options image.RemoveOptions) ([]image.DeleteResponse, error) |
| 119 |
- ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) |
|
| 119 |
+ ImageSearch(ctx context.Context, term string, options SearchOptions) ([]registry.SearchResult, error) |
|
| 120 | 120 |
ImageTag(ctx context.Context, image, ref string) error |
| 121 | 121 |
ImagesPrune(ctx context.Context, pruneFilter filters.Args) (image.PruneReport, error) |
| 122 | 122 |
|
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
|
| 15 | 15 |
// ImageSearch makes the docker host search by a term in a remote registry. |
| 16 | 16 |
// The list of results is not sorted in any fashion. |
| 17 |
-func (cli *Client) ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) {
|
|
| 17 |
+func (cli *Client) ImageSearch(ctx context.Context, term string, options SearchOptions) ([]registry.SearchResult, error) {
|
|
| 18 | 18 |
var results []registry.SearchResult |
| 19 | 19 |
query := url.Values{}
|
| 20 | 20 |
query.Set("term", term)
|
| 21 | 21 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,22 @@ |
| 0 |
+package client |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "context" |
|
| 4 |
+ |
|
| 5 |
+ "github.com/moby/moby/api/types/filters" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+// SearchOptions holds parameters to search images with. |
|
| 9 |
+type SearchOptions struct {
|
|
| 10 |
+ RegistryAuth string |
|
| 11 |
+ |
|
| 12 |
+ // PrivilegeFunc is a function that clients can supply to retry operations |
|
| 13 |
+ // after getting an authorization error. This function returns the registry |
|
| 14 |
+ // authentication header value in base64 encoded format, or an error if the |
|
| 15 |
+ // privilege request fails. |
|
| 16 |
+ // |
|
| 17 |
+ // For details, refer to [github.com/moby/moby/api/types/registry.RequestAuthConfig]. |
|
| 18 |
+ PrivilegeFunc func(context.Context) (string, error) |
|
| 19 |
+ Filters filters.Args |
|
| 20 |
+ Limit int |
|
| 21 |
+} |
| ... | ... |
@@ -22,7 +22,7 @@ func TestImageSearchAnyError(t *testing.T) {
|
| 22 | 22 |
client := &Client{
|
| 23 | 23 |
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
| 24 | 24 |
} |
| 25 |
- _, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{})
|
|
| 25 |
+ _, err := client.ImageSearch(context.Background(), "some-image", SearchOptions{})
|
|
| 26 | 26 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal)) |
| 27 | 27 |
} |
| 28 | 28 |
|
| ... | ... |
@@ -30,7 +30,7 @@ func TestImageSearchStatusUnauthorizedError(t *testing.T) {
|
| 30 | 30 |
client := &Client{
|
| 31 | 31 |
client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), |
| 32 | 32 |
} |
| 33 |
- _, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{})
|
|
| 33 |
+ _, err := client.ImageSearch(context.Background(), "some-image", SearchOptions{})
|
|
| 34 | 34 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsUnauthorized)) |
| 35 | 35 |
} |
| 36 | 36 |
|
| ... | ... |
@@ -41,7 +41,7 @@ func TestImageSearchWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
|
| 41 | 41 |
privilegeFunc := func(_ context.Context) (string, error) {
|
| 42 | 42 |
return "", errors.New("Error requesting privilege")
|
| 43 | 43 |
} |
| 44 |
- _, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
|
|
| 44 |
+ _, err := client.ImageSearch(context.Background(), "some-image", SearchOptions{
|
|
| 45 | 45 |
PrivilegeFunc: privilegeFunc, |
| 46 | 46 |
}) |
| 47 | 47 |
assert.Check(t, is.Error(err, "Error requesting privilege")) |
| ... | ... |
@@ -54,7 +54,7 @@ func TestImageSearchWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing. |
| 54 | 54 |
privilegeFunc := func(_ context.Context) (string, error) {
|
| 55 | 55 |
return "a-auth-header", nil |
| 56 | 56 |
} |
| 57 |
- _, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
|
|
| 57 |
+ _, err := client.ImageSearch(context.Background(), "some-image", SearchOptions{
|
|
| 58 | 58 |
PrivilegeFunc: privilegeFunc, |
| 59 | 59 |
}) |
| 60 | 60 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsUnauthorized)) |
| ... | ... |
@@ -99,7 +99,7 @@ func TestImageSearchWithPrivilegedFuncNoError(t *testing.T) {
|
| 99 | 99 |
privilegeFunc := func(_ context.Context) (string, error) {
|
| 100 | 100 |
return "IAmValid", nil |
| 101 | 101 |
} |
| 102 |
- results, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
|
|
| 102 |
+ results, err := client.ImageSearch(context.Background(), "some-image", SearchOptions{
|
|
| 103 | 103 |
RegistryAuth: "NotValid", |
| 104 | 104 |
PrivilegeFunc: privilegeFunc, |
| 105 | 105 |
}) |
| ... | ... |
@@ -139,7 +139,7 @@ func TestImageSearchWithoutErrors(t *testing.T) {
|
| 139 | 139 |
}, nil |
| 140 | 140 |
}), |
| 141 | 141 |
} |
| 142 |
- results, err := client.ImageSearch(context.Background(), "some-image", registry.SearchOptions{
|
|
| 142 |
+ results, err := client.ImageSearch(context.Background(), "some-image", SearchOptions{
|
|
| 143 | 143 |
Filters: filters.NewArgs( |
| 144 | 144 |
filters.Arg("is-automated", "true"),
|
| 145 | 145 |
filters.Arg("stars", "3"),
|
| ... | ... |
@@ -1,26 +1,5 @@ |
| 1 | 1 |
package registry |
| 2 | 2 |
|
| 3 |
-import ( |
|
| 4 |
- "context" |
|
| 5 |
- |
|
| 6 |
- "github.com/moby/moby/api/types/filters" |
|
| 7 |
-) |
|
| 8 |
- |
|
| 9 |
-// SearchOptions holds parameters to search images with. |
|
| 10 |
-type SearchOptions struct {
|
|
| 11 |
- RegistryAuth string |
|
| 12 |
- |
|
| 13 |
- // PrivilegeFunc is a function that clients can supply to retry operations |
|
| 14 |
- // after getting an authorization error. This function returns the registry |
|
| 15 |
- // authentication header value in base64 encoded format, or an error if the |
|
| 16 |
- // privilege request fails. |
|
| 17 |
- // |
|
| 18 |
- // For details, refer to [github.com/moby/moby/api/types/registry.RequestAuthConfig]. |
|
| 19 |
- PrivilegeFunc func(context.Context) (string, error) |
|
| 20 |
- Filters filters.Args |
|
| 21 |
- Limit int |
|
| 22 |
-} |
|
| 23 |
- |
|
| 24 | 3 |
// SearchResult describes a search result returned from a registry |
| 25 | 4 |
type SearchResult struct {
|
| 26 | 5 |
// StarCount indicates the number of stars this repository has |
| ... | ... |
@@ -116,7 +116,7 @@ type ImageAPIClient interface {
|
| 116 | 116 |
ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) |
| 117 | 117 |
ImagePush(ctx context.Context, ref string, options image.PushOptions) (io.ReadCloser, error) |
| 118 | 118 |
ImageRemove(ctx context.Context, image string, options image.RemoveOptions) ([]image.DeleteResponse, error) |
| 119 |
- ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) |
|
| 119 |
+ ImageSearch(ctx context.Context, term string, options SearchOptions) ([]registry.SearchResult, error) |
|
| 120 | 120 |
ImageTag(ctx context.Context, image, ref string) error |
| 121 | 121 |
ImagesPrune(ctx context.Context, pruneFilter filters.Args) (image.PruneReport, error) |
| 122 | 122 |
|
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
|
| 15 | 15 |
// ImageSearch makes the docker host search by a term in a remote registry. |
| 16 | 16 |
// The list of results is not sorted in any fashion. |
| 17 |
-func (cli *Client) ImageSearch(ctx context.Context, term string, options registry.SearchOptions) ([]registry.SearchResult, error) {
|
|
| 17 |
+func (cli *Client) ImageSearch(ctx context.Context, term string, options SearchOptions) ([]registry.SearchResult, error) {
|
|
| 18 | 18 |
var results []registry.SearchResult |
| 19 | 19 |
query := url.Values{}
|
| 20 | 20 |
query.Set("term", term)
|
| 21 | 21 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,22 @@ |
| 0 |
+package client |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "context" |
|
| 4 |
+ |
|
| 5 |
+ "github.com/moby/moby/api/types/filters" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+// SearchOptions holds parameters to search images with. |
|
| 9 |
+type SearchOptions struct {
|
|
| 10 |
+ RegistryAuth string |
|
| 11 |
+ |
|
| 12 |
+ // PrivilegeFunc is a function that clients can supply to retry operations |
|
| 13 |
+ // after getting an authorization error. This function returns the registry |
|
| 14 |
+ // authentication header value in base64 encoded format, or an error if the |
|
| 15 |
+ // privilege request fails. |
|
| 16 |
+ // |
|
| 17 |
+ // For details, refer to [github.com/moby/moby/api/types/registry.RequestAuthConfig]. |
|
| 18 |
+ PrivilegeFunc func(context.Context) (string, error) |
|
| 19 |
+ Filters filters.Args |
|
| 20 |
+ Limit int |
|
| 21 |
+} |