Skip to content

Commit

Permalink
fix: hide preset pipelines in GET /pipelines endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
donch1989 committed Oct 12, 2024
1 parent 3d1c053 commit 81f8588
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 50 deletions.
7 changes: 6 additions & 1 deletion cmd/init/presetdownloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/instill-ai/x/zapadapter"

database "github.com/instill-ai/pipeline-backend/pkg/db"
mgmtpb "github.com/instill-ai/protogen-go/core/mgmt/v1beta"
pipelinepb "github.com/instill-ai/protogen-go/vdp/pipeline/v1beta"
)

Expand Down Expand Up @@ -98,6 +99,10 @@ func DownloadPresetPipelines(ctx context.Context, repo repository.Repository) er
if mgmtPrivateServiceClientConn != nil {
defer mgmtPrivateServiceClientConn.Close()
}
presetOrgResp, err := mgmtPrivateServiceClient.GetOrganizationAdmin(ctx, &mgmtpb.GetOrganizationAdminRequest{OrganizationId: constant.PresetNamespaceID})
if err != nil {
return err
}

converter := service.NewConverter(mgmtPrivateServiceClient, redisClient, &aclClient, repo, "")

Expand All @@ -120,7 +125,7 @@ func DownloadPresetPipelines(ctx context.Context, repo repository.Repository) er
ns := resource.Namespace{
NsType: resource.Organization,
NsID: constant.PresetNamespaceID,
NsUID: uuid.FromStringOrNil(constant.PresetNamespaceUID),
NsUID: uuid.FromStringOrNil(presetOrgResp.Organization.Uid),
}
pageToken := ""
for {
Expand Down
5 changes: 2 additions & 3 deletions pkg/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ const ContentTypeJSON = "application/json"
// with its global secret when it finds this keyword.
const GlobalSecretKey = "INSTILL_SECRET"

// The ID and UID within the preset namespace must consistently match between
// The ID within the preset namespace must consistently match between
// mgmt and pipeline-backend.
const (
PresetNamespaceID = "preset"
PresetNamespaceUID = "63196cec-1c95-49e8-9bf6-9f9497a15f72"
PresetNamespaceID = "preset"
)
115 changes: 73 additions & 42 deletions pkg/mock/repository_mock.gen.go

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

6 changes: 3 additions & 3 deletions pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Repository interface {
CheckPinnedUser(_ context.Context, _ *gorm.DB, table string) *gorm.DB

GetHubStats(uidAllowList []uuid.UUID) (*datamodel.HubStats, error)
ListPipelines(ctx context.Context, pageSize int64, pageToken string, isBasicView bool, filter filtering.Filter, uidAllowList []uuid.UUID, showDeleted bool, embedReleases bool, order ordering.OrderBy) ([]*datamodel.Pipeline, int64, string, error)
ListPipelines(ctx context.Context, pageSize int64, pageToken string, isBasicView bool, filter filtering.Filter, uidAllowList []uuid.UUID, showDeleted bool, embedReleases bool, order ordering.OrderBy, presetNamespaceUID uuid.UUID) ([]*datamodel.Pipeline, int64, string, error)
GetPipelineByUID(ctx context.Context, uid uuid.UUID, isBasicView bool, embedReleases bool) (*datamodel.Pipeline, error)

CreateNamespacePipeline(ctx context.Context, pipeline *datamodel.Pipeline) error
Expand Down Expand Up @@ -397,13 +397,13 @@ func (r *repository) listPipelines(ctx context.Context, where string, whereArgs
return pipelines, totalSize, nextPageToken, nil
}

func (r *repository) ListPipelines(ctx context.Context, pageSize int64, pageToken string, isBasicView bool, filter filtering.Filter, uidAllowList []uuid.UUID, showDeleted bool, embedReleases bool, order ordering.OrderBy) ([]*datamodel.Pipeline, int64, string, error) {
func (r *repository) ListPipelines(ctx context.Context, pageSize int64, pageToken string, isBasicView bool, filter filtering.Filter, uidAllowList []uuid.UUID, showDeleted bool, embedReleases bool, order ordering.OrderBy, presetNamespaceUID uuid.UUID) ([]*datamodel.Pipeline, int64, string, error) {
// Note: Preset pipelines are ignored in `GET /pipelines` requests. These
// pipelines are used by the artifact backend and should not be directly
// exposed to users.
return r.listPipelines(ctx,
"(owner != ?)",
[]interface{}{fmt.Sprintf("organizations/%s", constant.PresetNamespaceUID)},
[]interface{}{fmt.Sprintf("organizations/%s", presetNamespaceUID)},
pageSize, pageToken, isBasicView, filter, uidAllowList, showDeleted, embedReleases, order)
}
func (r *repository) ListNamespacePipelines(ctx context.Context, ownerPermalink string, pageSize int64, pageToken string, isBasicView bool, filter filtering.Filter, uidAllowList []uuid.UUID, showDeleted bool, embedReleases bool, order ordering.OrderBy) ([]*datamodel.Pipeline, int64, string, error) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/service/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ func (s *service) ListPipelines(ctx context.Context, pageSize int32, pageToken s
}
}

dbPipelines, totalSize, nextPageToken, err := s.repository.ListPipelines(ctx, int64(pageSize), pageToken, view <= pipelinepb.Pipeline_VIEW_BASIC, filter, uidAllowList, showDeleted, true, order)
presetOrgResp, err := s.mgmtPrivateServiceClient.GetOrganizationAdmin(ctx, &mgmtpb.GetOrganizationAdminRequest{OrganizationId: constant.PresetNamespaceID})
if err != nil {
return nil, 0, "", err
}
presetNamespaceUID := uuid.FromStringOrNil(presetOrgResp.Organization.Uid)
dbPipelines, totalSize, nextPageToken, err := s.repository.ListPipelines(ctx, int64(pageSize), pageToken, view <= pipelinepb.Pipeline_VIEW_BASIC, filter, uidAllowList, showDeleted, true, order, presetNamespaceUID)
if err != nil {
return nil, 0, "", err
}
Expand Down

0 comments on commit 81f8588

Please sign in to comment.