Skip to content

Commit

Permalink
refactor: Internal UUID package references
Browse files Browse the repository at this point in the history
Signed-off-by: jay-dee7 <[email protected]>
  • Loading branch information
jay-dee7 committed Dec 22, 2023
1 parent 9284141 commit e13204c
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 43 deletions.
3 changes: 1 addition & 2 deletions dfs/filebase/filebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/containerish/OpenRegistry/config"
"github.com/containerish/OpenRegistry/dfs"
"github.com/containerish/OpenRegistry/store/v1/types"
core_types "github.com/containerish/OpenRegistry/types"
oci_digest "github.com/opencontainers/go-digest"
)

Expand Down Expand Up @@ -225,7 +224,7 @@ func (fb *filebase) Metadata(layer *types.ContainerImageLayer) (*types.ObjectMet
var resp *s3.HeadObjectOutput
var err error

identifier := core_types.GetLayerIdentifier(layer.ID)
identifier := types.GetLayerIdentifier(layer.ID)
for i := 3; i > 0; i-- {
resp, err = fb.client.HeadObject(context.Background(), &s3.HeadObjectInput{
Bucket: &fb.bucket,
Expand Down
3 changes: 1 addition & 2 deletions dfs/mock/memMappedSystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/containerish/OpenRegistry/dfs"
types "github.com/containerish/OpenRegistry/store/v1/types"
"github.com/containerish/OpenRegistry/telemetry"
core_types "github.com/containerish/OpenRegistry/types"
"github.com/fatih/color"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -151,7 +150,7 @@ func (ms *memMappedMockStorage) Metadata(layer *types.ContainerImageLayer) (*typ
err error
)

identifier := core_types.GetLayerIdentifier(layer.ID)
identifier := types.GetLayerIdentifier(layer.ID)
parts := strings.Split(identifier, "/")
if len(parts) > 1 {
fd, err = ms.memFs.Open(parts[1])
Expand Down
3 changes: 1 addition & 2 deletions dfs/mock/mockFileSystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/containerish/OpenRegistry/dfs"
types "github.com/containerish/OpenRegistry/store/v1/types"
"github.com/containerish/OpenRegistry/telemetry"
core_types "github.com/containerish/OpenRegistry/types"
"github.com/fatih/color"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -168,7 +167,7 @@ func (ms *fileBasedMockStorage) Metadata(layer *types.ContainerImageLayer) (*typ
err error
)

identifier := core_types.GetLayerIdentifier(layer.ID)
identifier := types.GetLayerIdentifier(layer.ID)
parts := strings.Split(identifier, "/")
if len(parts) > 1 {
fd, err = ms.fs.Open(parts[1])
Expand Down
3 changes: 1 addition & 2 deletions dfs/storj/storj.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/containerish/OpenRegistry/config"
"github.com/containerish/OpenRegistry/dfs"
"github.com/containerish/OpenRegistry/store/v1/types"
core_types "github.com/containerish/OpenRegistry/types"
oci_digest "github.com/opencontainers/go-digest"
)

Expand Down Expand Up @@ -203,7 +202,7 @@ func (sj *storj) AddImage(ns string, mf, l map[string][]byte) (string, error) {
func (sj *storj) Metadata(layer *types.ContainerImageLayer) (*types.ObjectMetadata, error) {
var resp *s3.HeadObjectOutput
var err error
id := core_types.GetLayerIdentifier(layer.ID)
id := types.GetLayerIdentifier(layer.ID)
for i := 3; i > 0; i-- {
resp, err = sj.client.HeadObject(context.Background(), &s3.HeadObjectInput{
Bucket: &sj.bucket,
Expand Down
3 changes: 1 addition & 2 deletions dfs/storj/uplink/uplink.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/containerish/OpenRegistry/config"
"github.com/containerish/OpenRegistry/dfs"
"github.com/containerish/OpenRegistry/store/v1/types"
core_types "github.com/containerish/OpenRegistry/types"
"github.com/fatih/color"
"storj.io/uplink"
"storj.io/uplink/edge"
Expand Down Expand Up @@ -172,7 +171,7 @@ func (u *storjUplink) GetUploadProgress(identifier string, uploadID string) (*ty

// Metadata implements dfs.DFS
func (u *storjUplink) Metadata(layer *types.ContainerImageLayer) (*types.ObjectMetadata, error) {
identifier := core_types.GetLayerIdentifier(layer.ID)
identifier := types.GetLayerIdentifier(layer.ID)

metadata, err := u.client.StatObject(context.Background(), u.bucket, identifier)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion registry/v2/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/containerish/OpenRegistry/types"
"github.com/containerish/OpenRegistry/store/v1/types"
"github.com/fatih/color"
"github.com/labstack/echo/v4"
oci_digest "github.com/opencontainers/go-digest"
Expand Down
16 changes: 7 additions & 9 deletions registry/v2/extensions/catalog_detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,13 @@ func (ext *extension) GetUserCatalog(ctx echo.Context) error {
visibility = types.RepositoryVisibilityPrivate
}

repositories, total, err := ext.
store.
GetUserRepositories(
ctx.Request().Context(),
user.ID,
visibility,
pageSize,
offset,
)
repositories, total, err := ext.store.GetUserRepositories(
ctx.Request().Context(),
user.ID,
visibility,
pageSize,
offset,
)
if err != nil {
return ctx.JSON(http.StatusInternalServerError, echo.Map{
"error": err.Error(),
Expand Down
37 changes: 21 additions & 16 deletions registry/v2/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (
"github.com/containerish/OpenRegistry/config"
dfsImpl "github.com/containerish/OpenRegistry/dfs"
store_v2 "github.com/containerish/OpenRegistry/store/v1/registry"
types_v2 "github.com/containerish/OpenRegistry/store/v1/types"
"github.com/containerish/OpenRegistry/store/v1/types"
"github.com/containerish/OpenRegistry/telemetry"
"github.com/containerish/OpenRegistry/types"
"github.com/labstack/echo/v4"
oci_digest "github.com/opencontainers/go-digest"
img_spec_v1 "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -359,7 +358,7 @@ func (r *registry) MonolithicUpload(ctx echo.Context) error {
return echoErr
}

layerV2 := &types_v2.ContainerImageLayer{
layerV2 := &types.ContainerImageLayer{
MediaType: ctx.Request().Header.Get("content-type"),
Digest: imageDigest,
DFSLink: dfsLink,
Expand Down Expand Up @@ -551,7 +550,7 @@ func (r *registry) MonolithicPut(ctx echo.Context) error {
return echoErr
}

layer := &types_v2.ContainerImageLayer{
layer := &types.ContainerImageLayer{
CreatedAt: time.Now(),
ID: layerKey,
Digest: digest,
Expand Down Expand Up @@ -682,7 +681,7 @@ func (r *registry) CompleteUpload(ctx echo.Context) error {
return echoErr
}

layer := &types_v2.ContainerImageLayer{
layer := &types.ContainerImageLayer{
MediaType: ctx.Request().Header.Get("content-type"),
Digest: digest,
DFSLink: dfsLink,
Expand Down Expand Up @@ -765,17 +764,17 @@ func (r *registry) PushManifest(ctx echo.Context) error {

}

repository = &types_v2.ContainerImageRepository{
repository = &types.ContainerImageRepository{
CreatedAt: time.Now(),
OwnerID: user.ID,
ID: repositoryID,
Name: strings.Split(namespace, "/")[1],
Visibility: types_v2.RepositoryVisibilityPrivate,
Visibility: types.RepositoryVisibilityPrivate,
}

// IPFS P2P repositories are public
if user.Username == types_v2.SystemUsernameIPFS {
repository.Visibility = types_v2.RepositoryVisibilityPublic
if user.Username == types.SystemUsernameIPFS {
repository.Visibility = types.RepositoryVisibilityPublic
}

idErr = r.store.CreateRepository(ctx.Request().Context(), repository)
Expand Down Expand Up @@ -811,7 +810,7 @@ func (r *registry) PushManifest(ctx echo.Context) error {
return echoErr
}

manifest := types_v2.ImageManifest{
manifest := types.ImageManifest{
CreatedAt: time.Now(),
ID: uuid,
RepositoryID: repository.ID,
Expand Down Expand Up @@ -883,7 +882,7 @@ func (r *registry) PushManifest(ctx echo.Context) error {
func (r *registry) setPushManifestHaeders(
ctx echo.Context,
namespace, ref, digest string,
manifest *types_v2.ImageManifest,
manifest *types.ImageManifest,
) {
locationHeader := fmt.Sprintf("%s/v2/%s/manifests/%s", r.config.Endpoint(), namespace, ref)
ctx.Response().Header().Set("Location", locationHeader)
Expand Down Expand Up @@ -1012,7 +1011,13 @@ func (r *registry) GetImageNamespace(ctx echo.Context) error {
r.logger.Log(ctx, errMsg).Send()
return echoErr
}
result, err := r.store.GetImageNamespace(ctx.Request().Context(), searchQuery)

var visibility types.RepositoryVisibility
if ctx.QueryParam("public") == "true" {
visibility = types.RepositoryVisibilityPublic
}

result, err := r.store.GetImageNamespace(ctx.Request().Context(), searchQuery, visibility)
if err != nil {
echoErr := ctx.JSON(http.StatusInternalServerError, echo.Map{
"error": err.Error(),
Expand Down Expand Up @@ -1042,17 +1047,17 @@ func (r *registry) GetImageNamespace(ctx echo.Context) error {
return echoErr
}

func (r *registry) GetUserFromCtx(ctx echo.Context) (*types_v2.User, error) {
user, ok := ctx.Get(string(types_v2.UserContextKey)).(*types_v2.User)
func (r *registry) GetUserFromCtx(ctx echo.Context) (*types.User, error) {
user, ok := ctx.Get(string(types.UserContextKey)).(*types.User)
if !ok {
return nil, fmt.Errorf("ERR_USER_NOT_PRESENT_IN_REQUEST_CTX")
}

return user, nil
}

func (r *registry) GetRepositoryFromCtx(ctx echo.Context) *types_v2.ContainerImageRepository {
if repository, ok := ctx.Get(string(types_v2.UserRepositoryContextKey)).(*types_v2.ContainerImageRepository); ok {
func (r *registry) GetRepositoryFromCtx(ctx echo.Context) *types.ContainerImageRepository {
if repository, ok := ctx.Get(string(types.UserRepositoryContextKey)).(*types.ContainerImageRepository); ok {
return repository
}
return nil
Expand Down
20 changes: 15 additions & 5 deletions store/v1/registry/registry_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ func (s *registryStore) GetUserRepositories(
db.
NewSelect().
Model(&repositories).
Relation("User", func(sq *bun.SelectQuery) *bun.SelectQuery {
return sq.ExcludeColumn("password").ExcludeColumn("github_connected").ExcludeColumn("webauthn_connected")
}).
WhereGroup(" AND ", func(q *bun.SelectQuery) *bun.SelectQuery {
if visibility != "" {
return q.Where("visibility = ?", visibility)
Expand Down Expand Up @@ -369,26 +372,33 @@ func (s *registryStore) GetContentHashById(ctx context.Context, uuid string) (st
}

// GetImageNamespace implements registry.RegistryStore.
func (s *registryStore) GetImageNamespace(ctx context.Context, search string) ([]*types.ImageManifest, error) {
func (s *registryStore) GetImageNamespace(
ctx context.Context,
search string,
visibility types.RepositoryVisibility,
) ([]*types.ContainerImageRepository, error) {
logEvent := s.logger.Debug().Str("method", "GetImageNamespace").Str("search_query", search)
var manifests []*types.ImageManifest
var repos []*types.ContainerImageRepository

q := s.
db.
NewSelect().
Model(&manifests).
Model(&repos).
Relation("User").
Relation("Repository").
WhereOr("substr(username, 1, 50) ILIKE ?", search).
WhereOr("substr(name, 1, 50) ILIKE ?", search)

if visibility == types.RepositoryVisibilityPublic {
q.Where("visibility = ? ", visibility.String())
}

if err := q.Scan(ctx); err != nil {
logEvent.Err(err).Send()
return nil, v1.WrapDatabaseError(err, v1.DatabaseOperationRead)
}

logEvent.Bool("success", true).Send()
return manifests, nil
return repos, nil
}

// GetImageTags implements registry.RegistryStore.
Expand Down
6 changes: 5 additions & 1 deletion store/v1/registry/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ type RegistryStore interface {
offset int,
) (*types.ContainerImageRepository, error)
GetCatalogCount(ctx context.Context, ns string) (int64, error)
GetImageNamespace(ctx context.Context, search string) ([]*types.ImageManifest, error)
GetImageNamespace(
ctx context.Context,
search string,
visibility types.RepositoryVisibility,
) ([]*types.ContainerImageRepository, error)
DeleteLayerByDigest(ctx context.Context, digest string) error
GetPublicRepositories(ctx context.Context, pageSize int, offset int) ([]*types.ContainerImageRepository, int, error)
GetUserRepositories(
Expand Down
2 changes: 1 addition & 1 deletion store/v1/types/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type (

CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
UpdatedAt time.Time `bun:"updated_at,nullzero" json:"updatedAt"`
Repository *ContainerImageRepository `bun:"rel:belongs-to,join:repository_id=id" json:"-"`
Repository *ContainerImageRepository `bun:"rel:belongs-to,join:repository_id=id" json:"repository"`
User *User `bun:"rel:belongs-to,join:owner_id=id" json:"-"`
Subject *img_spec_v1.Descriptor `bun:"embed:subject_" json:"subject,omitempty"`
Config *img_spec_v1.Descriptor `bun:"embed:config_" json:"config"`
Expand Down
File renamed without changes.

0 comments on commit e13204c

Please sign in to comment.