Skip to content

Commit

Permalink
✨ Remove repository visibility field
Browse files Browse the repository at this point in the history
  • Loading branch information
tosone committed Nov 29, 2023
1 parent d8a5494 commit f37ad5f
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 134 deletions.
6 changes: 3 additions & 3 deletions pkg/dal/dao/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestArtifactServiceAssociateArtifact(t *testing.T) {
assert.NoError(t, err)

repositoryService := repositoryServiceFactory.New(tx)
repositoryObj = &models.Repository{Name: "test/busybox", NamespaceID: namespaceObj.ID, Visibility: enums.VisibilityPrivate}
repositoryObj = &models.Repository{Name: "test/busybox", NamespaceID: namespaceObj.ID}
err = repositoryService.Create(ctx, repositoryObj, dao.AutoCreateNamespace{UserID: userObj.ID})
assert.NoError(t, err)
return nil
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestArtifactService(t *testing.T) {
assert.NoError(t, err)

repositoryService := repositoryServiceFactory.New(tx)
repositoryObj := &models.Repository{Name: "test/busybox", NamespaceID: namespaceObj.ID, Visibility: enums.VisibilityPrivate}
repositoryObj := &models.Repository{Name: "test/busybox", NamespaceID: namespaceObj.ID}
err = repositoryService.Create(ctx, repositoryObj, dao.AutoCreateNamespace{UserID: userObj.ID})
assert.NoError(t, err)

Expand Down Expand Up @@ -275,7 +275,7 @@ func TestArtifactService(t *testing.T) {
assert.NoError(t, err)

repositoryService := repositoryServiceFactory.New(tx)
repositoryObj := &models.Repository{Name: "test1/busybox", NamespaceID: namespaceObj.ID, Visibility: enums.VisibilityPrivate}
repositoryObj := &models.Repository{Name: "test1/busybox", NamespaceID: namespaceObj.ID}
err = repositoryService.Create(ctx, repositoryObj, dao.AutoCreateNamespace{UserID: userObj.ID})
assert.NoError(t, err)

Expand Down
3 changes: 0 additions & 3 deletions pkg/dal/dao/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ func (s *repositoryService) Create(ctx context.Context, repositoryObj *models.Re
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
if !repositoryObj.Visibility.IsValid() {
repositoryObj.Visibility = namespaceObj.Visibility
}
err = s.tx.Repository.WithContext(ctx).Create(repositoryObj)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/dal/dao/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ func TestRepositoryService(t *testing.T) {
assert.NoError(t, err)

repositoryService := repositoryServiceFactory.New(tx)
repositoryObj := &models.Repository{Name: "test/busybox", NamespaceID: namespaceObj.ID, Visibility: enums.VisibilityPrivate}
repositoryObj := &models.Repository{Name: "test/busybox", NamespaceID: namespaceObj.ID}
err = repositoryService.Create(ctx, repositoryObj, dao.AutoCreateNamespace{UserID: userObj.ID})
assert.NoError(t, err)

namespaceObj1 := &models.Namespace{Name: "test1", Visibility: enums.VisibilityPrivate}
err = namespaceService.Create(ctx, namespaceObj1)
assert.NoError(t, err)
err = repositoryService.Create(ctx, &models.Repository{Name: "test1/busybox", Visibility: enums.VisibilityPrivate}, dao.AutoCreateNamespace{UserID: userObj.ID})
err = repositoryService.Create(ctx, &models.Repository{Name: "test1/busybox"}, dao.AutoCreateNamespace{UserID: userObj.ID})
assert.NoError(t, err)

count1, err := repositoryService.CountRepository(ctx, namespaceObj.ID, nil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/dal/dao/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestTagService(t *testing.T) {
assert.NoError(t, err)

repositoryService := repositoryServiceFactory.New(tx)
repositoryObj := &models.Repository{Name: "test/busybox", NamespaceID: namespaceObj.ID, Visibility: enums.VisibilityPrivate}
repositoryObj := &models.Repository{Name: "test/busybox", NamespaceID: namespaceObj.ID}
err = repositoryService.Create(ctx, repositoryObj, dao.AutoCreateNamespace{UserID: userObj.ID})
assert.NoError(t, err)

Expand Down
1 change: 0 additions & 1 deletion pkg/dal/migrations/mysql/0001_initialize.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ CREATE TABLE IF NOT EXISTS `repositories` (
`name` varchar(64) NOT NULL,
`description` varchar(255),
`overview` BLOB,
`visibility` ENUM ('public', 'private') NOT NULL DEFAULT 'private',
`size_limit` bigint NOT NULL DEFAULT 0,
`size` bigint NOT NULL DEFAULT 0,
`tag_limit` bigint NOT NULL DEFAULT 0,
Expand Down
1 change: 0 additions & 1 deletion pkg/dal/migrations/postgresql/0001_initialize.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ CREATE TABLE IF NOT EXISTS "repositories" (
"name" varchar(64) NOT NULL,
"description" varchar(255),
"overview" bytea,
"visibility" visibility NOT NULL DEFAULT 'private',
"size_limit" bigint NOT NULL DEFAULT 0,
"size" bigint NOT NULL DEFAULT 0,
"tag_limit" bigint NOT NULL DEFAULT 0,
Expand Down
1 change: 0 additions & 1 deletion pkg/dal/migrations/sqlite3/0001_initialize.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ CREATE TABLE IF NOT EXISTS `repositories` (
`name` varchar(64) NOT NULL,
`description` varchar(255),
`overview` BLOB,
`visibility` text CHECK (`visibility` IN ('public', 'private')) NOT NULL DEFAULT 'private',
`size_limit` integer NOT NULL DEFAULT 0,
`size` integer NOT NULL DEFAULT 0,
`tag_limit` integer NOT NULL DEFAULT 0,
Expand Down
10 changes: 4 additions & 6 deletions pkg/dal/models/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"

"github.com/go-sigma/sigma/pkg/types/enums"
"github.com/go-sigma/sigma/pkg/xerrors"
)

Expand All @@ -33,11 +32,10 @@ type Repository struct {
Name string
Description *string
Overview []byte
Visibility enums.Visibility `gorm:"default:public"`
TagLimit int64 `gorm:"default:0"`
TagCount int64 `gorm:"default:0"`
SizeLimit int64 `gorm:"default:0"`
Size int64 `gorm:"default:0"`
TagLimit int64 `gorm:"default:0"`
TagCount int64 `gorm:"default:0"`
SizeLimit int64 `gorm:"default:0"`
Size int64 `gorm:"default:0"`

Namespace Namespace
Builder *Builder
Expand Down
6 changes: 1 addition & 5 deletions pkg/dal/query/repositories.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/handlers/artifacts/artifacts_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestDeleteArtifact(t *testing.T) {
log.Info().Interface("namespace", namespaceObj).Msg("namespace created")
repositoryServiceFactory := dao.NewRepositoryServiceFactory()
repositoryService := repositoryServiceFactory.New(tx)
repositoryObj := &models.Repository{Name: repositoryName, NamespaceID: namespaceObj.ID, Visibility: enums.VisibilityPrivate}
repositoryObj := &models.Repository{Name: repositoryName, NamespaceID: namespaceObj.ID}
err = repositoryService.Create(ctx, repositoryObj, dao.AutoCreateNamespace{UserID: userObj.ID})
assert.NoError(t, err)
artifactServiceFactory := dao.NewArtifactServiceFactory()
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/artifacts/artifacts_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestGetArtifact(t *testing.T) {
log.Info().Interface("namespace", namespaceObj).Msg("namespace created")
repositoryServiceFactory := dao.NewRepositoryServiceFactory()
repositoryService := repositoryServiceFactory.New(tx)
repositoryObj := &models.Repository{Name: namespaceName + "/" + repositoryName, NamespaceID: namespaceObj.ID, Visibility: enums.VisibilityPrivate}
repositoryObj := &models.Repository{Name: namespaceName + "/" + repositoryName, NamespaceID: namespaceObj.ID}
err = repositoryService.Create(ctx, repositoryObj, dao.AutoCreateNamespace{UserID: userObj.ID})
assert.NoError(t, err)
artifactServiceFactory := dao.NewArtifactServiceFactory()
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/artifacts/artifacts_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestListArtifact(t *testing.T) {
log.Info().Interface("namespace", namespaceObj).Msg("namespace created")
repositoryServiceFactory := dao.NewRepositoryServiceFactory()
repositoryService := repositoryServiceFactory.New(tx)
repositoryObj := &models.Repository{Name: namespaceName + "/" + repositoryName, NamespaceID: namespaceObj.ID, Visibility: enums.VisibilityPrivate}
repositoryObj := &models.Repository{Name: namespaceName + "/" + repositoryName, NamespaceID: namespaceObj.ID}
err = repositoryService.Create(ctx, repositoryObj, dao.AutoCreateNamespace{UserID: userObj.ID})
assert.NoError(t, err)
artifactServiceFactory := dao.NewArtifactServiceFactory()
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/distribution/base/repository_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestListRepositories(t *testing.T) {
assert.NoError(t, dao.NewUserServiceFactory().New().Create(ctx, userObj))
namespaceObj := &models.Namespace{Name: namespaceName, Visibility: enums.VisibilityPrivate}
assert.NoError(t, dao.NewNamespaceServiceFactory().New().Create(ctx, namespaceObj))
repositoryObj := &models.Repository{Name: repositoryName, NamespaceID: namespaceObj.ID, Visibility: enums.VisibilityPrivate}
repositoryObj := &models.Repository{Name: repositoryName, NamespaceID: namespaceObj.ID}
assert.NoError(t, dao.NewRepositoryServiceFactory().New().Create(ctx, repositoryObj, dao.AutoCreateNamespace{UserID: userObj.ID}))
artifactObj := &models.Artifact{RepositoryID: repositoryObj.ID, Digest: "sha256:1234567890", Size: 1234, ContentType: "application/octet-stream", Raw: []byte("test"), PushedAt: time.Now()}
assert.NoError(t, dao.NewArtifactServiceFactory().New().Create(ctx, artifactObj))
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/distribution/base/tags_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestListTags(t *testing.T) {
assert.NoError(t, dao.NewNamespaceServiceFactory().New().Create(ctx, namespaceObj))
_, err := dao.NewNamespaceMemberServiceFactory().New().AddNamespaceMember(ctx, userObj.ID, ptr.To(namespaceObj), enums.NamespaceRoleAdmin)
assert.NoError(t, err)
repositoryObj := &models.Repository{Name: repositoryName, NamespaceID: namespaceObj.ID, Visibility: enums.VisibilityPrivate}
repositoryObj := &models.Repository{Name: repositoryName, NamespaceID: namespaceObj.ID}
assert.NoError(t, dao.NewRepositoryServiceFactory().New().Create(ctx, repositoryObj, dao.AutoCreateNamespace{UserID: userObj.ID}))
artifactObj := &models.Artifact{RepositoryID: repositoryObj.ID, Digest: "sha256:1234567890", Size: 1234, ContentType: "application/octet-stream", Raw: []byte("test"), PushedAt: time.Now()}
assert.NoError(t, dao.NewArtifactServiceFactory().New().Create(ctx, artifactObj))
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/distribution/manifest/manifest_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestDeleteManifest(t *testing.T) {
namespaceObj := &models.Namespace{Name: namespaceName, Visibility: enums.VisibilityPrivate}
assert.NoError(t, dao.NewNamespaceServiceFactory().New().Create(ctx, namespaceObj))

repositoryObj := &models.Repository{NamespaceID: namespaceObj.ID, Name: repositoryName, Visibility: enums.VisibilityPrivate}
repositoryObj := &models.Repository{NamespaceID: namespaceObj.ID, Name: repositoryName}
assert.NoError(t, dao.NewRepositoryServiceFactory().New().Create(ctx, repositoryObj, dao.AutoCreateNamespace{UserID: userObj.ID}))

artifactObj := &models.Artifact{RepositoryID: repositoryObj.ID, Digest: digestName, Size: 123, ContentType: "application/vnd.oci.image.manifest.v1+json", Raw: []byte(`{"schemaVersion":2,"config":{"mediaType":"application/vnd.cncf.helm.config.v1+json","digest":"sha256:a61fd63bebd559934a60e30d1e7b832a136ac6bae3a11ca97ade20bfb3645796","size":800},"layers":[{"mediaType":"application/vnd.cncf.helm.chart.content.v1.tar+gzip","digest":"sha256:e45dd3e880e94bdb52cc88d6b4e0fbaec6876856f39a1a89f76e64d0739c2904","size":37869}],"annotations":{"category":"Infrastructure","licenses":"Apache-2.0","org.opencontainers.image.authors":"VMware, Inc.","org.opencontainers.image.description":"NGINX Open Source is a web server that can be also used as a reverse proxy, load balancer, and HTTP cache. Recommended for high-demanding sites due to its ability to provide faster content.","org.opencontainers.image.source":"https://github.com/bitnami/charts/tree/main/bitnami/nginx","org.opencontainers.image.title":"nginx","org.opencontainers.image.url":"https://bitnami.com","org.opencontainers.image.version":"15.0.2"}}`)}
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/distribution/manifest/manifest_head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestHeadManifest(t *testing.T) {
assert.NoError(t, dao.NewUserServiceFactory().New().Create(ctx, userObj))
namespaceObj := &models.Namespace{Name: namespaceName, Visibility: enums.VisibilityPrivate}
assert.NoError(t, dao.NewNamespaceServiceFactory().New().Create(ctx, namespaceObj))
repositoryObj := &models.Repository{NamespaceID: namespaceObj.ID, Name: repositoryName, Visibility: enums.VisibilityPrivate}
repositoryObj := &models.Repository{NamespaceID: namespaceObj.ID, Name: repositoryName}
assert.NoError(t, dao.NewRepositoryServiceFactory().New().Create(ctx, repositoryObj, dao.AutoCreateNamespace{UserID: userObj.ID}))
artifactObj := &models.Artifact{RepositoryID: repositoryObj.ID, Digest: digestName, Size: 123, ContentType: "application/vnd.oci.image.manifest.v1+json", Raw: []byte(`{"schemaVersion":2,"config":{"mediaType":"application/vnd.cncf.helm.config.v1+json","digest":"sha256:a61fd63bebd559934a60e30d1e7b832a136ac6bae3a11ca97ade20bfb3645796","size":800},"layers":[{"mediaType":"application/vnd.cncf.helm.chart.content.v1.tar+gzip","digest":"sha256:e45dd3e880e94bdb52cc88d6b4e0fbaec6876856f39a1a89f76e64d0739c2904","size":37869}],"annotations":{"category":"Infrastructure","licenses":"Apache-2.0","org.opencontainers.image.authors":"VMware, Inc.","org.opencontainers.image.description":"NGINX Open Source is a web server that can be also used as a reverse proxy, load balancer, and HTTP cache. Recommended for high-demanding sites due to its ability to provide faster content.","org.opencontainers.image.source":"https://github.com/bitnami/charts/tree/main/bitnami/nginx","org.opencontainers.image.title":"nginx","org.opencontainers.image.url":"https://bitnami.com","org.opencontainers.image.version":"15.0.2"}}`)}
assert.NoError(t, dao.NewArtifactServiceFactory().New().Create(ctx, artifactObj))
Expand Down
5 changes: 1 addition & 4 deletions pkg/handlers/distribution/manifest/manifest_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ func (h *handler) PutManifest(c echo.Context) error {
refs := h.parseRef(ref)

repositoryService := h.repositoryServiceFactory.New()
repositoryObj := &models.Repository{
Name: repository,
Visibility: enums.VisibilityPrivate,
}
repositoryObj := &models.Repository{Name: repository}
err = repositoryService.Create(ctx, repositoryObj, dao.AutoCreateNamespace{
AutoCreate: h.config.Namespace.AutoCreate,
Visibility: h.config.Namespace.Visibility,
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/distribution/manifest/manifest_put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestPutManifest(t *testing.T) {
namespaceObj := &models.Namespace{Name: namespaceName, Visibility: enums.VisibilityPrivate}
assert.NoError(t, dao.NewNamespaceServiceFactory().New().Create(ctx, namespaceObj))

repositoryObj := &models.Repository{NamespaceID: namespaceObj.ID, Name: repositoryName, Visibility: enums.VisibilityPrivate}
repositoryObj := &models.Repository{NamespaceID: namespaceObj.ID, Name: repositoryName}
assert.NoError(t, dao.NewRepositoryServiceFactory().New().Create(ctx, repositoryObj, dao.AutoCreateNamespace{AutoCreate: false, Visibility: enums.VisibilityPrivate, UserID: userObj.ID}))

blobService := dao.NewBlobServiceFactory().New()
Expand Down
1 change: 0 additions & 1 deletion pkg/handlers/repositories/repositories_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (h *handler) CreateRepository(c echo.Context) error {
Name: req.Name,
Description: req.Description,
Overview: []byte(ptr.To(req.Overview)),
Visibility: ptr.To(req.Visibility),
TagLimit: ptr.To(req.TagLimit),
SizeLimit: ptr.To(req.SizeLimit),
}
Expand Down
1 change: 0 additions & 1 deletion pkg/handlers/repositories/repositories_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func (h *handler) GetRepository(c echo.Context) error {
Name: repositoryObj.Name,
Description: repositoryObj.Description,
Overview: ptr.Of(string(repositoryObj.Overview)),
Visibility: repositoryObj.Visibility,
SizeLimit: ptr.Of(repositoryObj.SizeLimit),
Size: ptr.Of(repositoryObj.Size),
TagCount: repositoryObj.TagCount,
Expand Down
1 change: 0 additions & 1 deletion pkg/handlers/repositories/repositories_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func (h *handler) ListRepositories(c echo.Context) error {
Name: repository.Name,
Description: repository.Description,
Overview: ptr.Of(string(repository.Overview)),
Visibility: repository.Visibility,
SizeLimit: ptr.Of(repository.SizeLimit),
Size: ptr.Of(repository.Size),
TagCount: repository.TagCount,
Expand Down
10 changes: 5 additions & 5 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
"monaco-editor": "^0.44.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet-async": "^1.3.0",
"react-helmet-async": "^2.0.1",
"react-hot-toast": "^2.4.1",
"react-icons": "^4.12.0",
"react-router-dom": "^6.20.0",
"react-toastify": "^9.1.3",
"react-use": "^17.4.0",
"react-use": "^17.4.1",
"xterm": "^5.3.0",
"xterm-addon-attach": "^0.9.0",
"xterm-addon-fit": "^0.8.0"
},
"devDependencies": {
"@types/node": "^20.9.5",
"@types/react": "^18.2.38",
"@types/node": "^20.10.0",
"@types/react": "^18.2.39",
"@types/react-dom": "^18.2.17",
"@vitejs/plugin-react-swc": "^3.5.0",
"autoprefixer": "^10.4.16",
Expand All @@ -51,7 +51,7 @@
"postcss": "^8.4.31",
"tailwindcss": "^3.3.5",
"typescript": "^5.3.2",
"vite": "^5.0.2"
"vite": "^5.0.3"
},
"packageManager": "[email protected]"
}
1 change: 0 additions & 1 deletion web/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export interface IRepositoryItem {
name: string;
description: string;
overview: string;
visibility: string;
tag_count: number;
tag_limit: number;
size_limit: number;
Expand Down
Loading

0 comments on commit f37ad5f

Please sign in to comment.