Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions db/migrations/000004_create_config_table.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ CREATE TABLE "config" (
PRIMARY KEY(namespace, reference)
);

CREATE INDEX on config (substr(namespace,1,20) text_pattern_ops);
17 changes: 17 additions & 0 deletions registry/v2/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,3 +829,20 @@ func (r *registry) ApiVersion(ctx echo.Context) error {

return ctx.String(http.StatusOK, "OK\n")
}

func (r *registry) GetImageNamespace(ctx echo.Context) error {
searchQuery := ctx.QueryParam("search_query")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guacamole can we check for emptiness here?

if searchQuery == "" {
return ctx.JSON(http.StatusBadRequest, echo.Map{
"error": "search query must not be empty",
})
}
result, err := r.store.GetImageNamespace(ctx.Request().Context(), searchQuery)
if err != nil {
return ctx.JSON(http.StatusInternalServerError, echo.Map{
"error": err.Error(),
"message": "error getting image namespace",
})
}
return ctx.JSON(http.StatusOK, result)
}
1 change: 1 addition & 0 deletions registry/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,5 @@ type Registry interface {
DeleteTagOrManifest(ctx echo.Context) error
//The list of available repositories is made available through the catalog
Catalog(ctx echo.Context) error
GetImageNamespace(ctx echo.Context) error
}
1 change: 1 addition & 0 deletions router/route_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ const (

// JWT based auth endpoint
TokenAuth = "/token"
Search = "/catalog/search"
)
8 changes: 5 additions & 3 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Register(
RegisterAuthRoutes(authRouter, authSvc)
RegisterBetaRoutes(betaRouter, localCache)
InternalRoutes(internal, localCache)
Docker(v2Router, reg)
Extensions(v2Router, reg)
}

// RegisterNSRoutes is one of the helper functions to Register
Expand Down Expand Up @@ -109,9 +109,11 @@ func RegisterNSRoutes(nsRouter *echo.Group, reg registry.Registry) {
nsRouter.Add(http.MethodDelete, ManifestsReference, reg.DeleteTagOrManifest)
}

// Docker is used for Catalog api
func Docker(group *echo.Group, reg registry.Registry) {
// Extensions for teh OCI dist spec
func Extensions(group *echo.Group, reg registry.Registry) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also worth noting that the Function here called Docker can totally be called Extensions

// GET /v2/_catalog
group.Add(http.MethodGet, Catalog, reg.Catalog)
group.Add(http.MethodGet, Search, reg.GetImageNamespace)

}
20 changes: 20 additions & 0 deletions store/postgres/container_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,23 @@ func (p *pg) Metadata(ctx echo.Context) error {

return ctx.JSON(http.StatusOK, imageManifestList)
}

func (p *pg) GetImageNamespace(ctx context.Context, search string) ([]string, error) {
childCtx, cancel := context.WithTimeout(context.Background(), time.Minute*30)
defer cancel()
rows, err := p.conn.Query(childCtx, queries.GetImageNamespace, "%"+search+"%")
if err != nil {
return nil, fmt.Errorf("ERR_QUERY_GET_IMAGE_NAMESPACE: %w", err)
}
defer rows.Close()

var result []string
for rows.Next() {
var ns string
if err := rows.Scan(&ns); err != nil {
return nil, fmt.Errorf("ERR_IMAGE_NAMESPACE_SCAN: %w", err)
}
result = append(result, ns)
}
return result, nil
}
1 change: 1 addition & 0 deletions store/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type RegistryStore interface {
GetImageTags(ctx context.Context, namespace string) ([]string, error)
GetCatalog(ctx context.Context, namespace string, pageSize int64, offset int64) ([]*types.ConfigV2, error)
GetCatalogCount(ctx context.Context) (int64, error)
GetImageNamespace(ctx context.Context, search string) ([]string, error)
DeleteLayerV2(ctx context.Context, txn pgx.Tx, digest string) error
DeleteBlobV2(ctx context.Context, txn pgx.Tx, digest string) error
DeleteManifestOrTag(ctx context.Context, txn pgx.Tx, reference string) error
Expand Down
1 change: 1 addition & 0 deletions store/postgres/queries/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
GetCatalog = `select uuid,namespace,reference,digest from config;`
GetCatalogWithPagination = `select uuid,namespace,reference,digest from config limit $1 offset $2;`
GetUserCatalogWithPagination = `select uuid,namespace,reference,digest from config where namespace like $1 limit $2 offset $3;`
GetImageNamespace = `select namespace from config where substr(namespace, 1, 50) like $1;`
)

// delete queries
Expand Down