This repository was archived by the owner on Sep 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
OSAC-58: filter unpublished catalog items from public API #595
Merged
openshift-merge-bot
merged 9 commits into
osac-project:main
from
tzvatot:OSAC-58/filter-unpublished-catalog-items
Jun 1, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
97aef7c
OSAC-58: filter unpublished catalog items from public API
tzvatot 3c238d8
OSAC-58: address code review findings for unpublished filter
tzvatot 943c831
OSAC-58: set Published: false explicitly in unpublished test case
tzvatot 403b091
OSAC-58: address Juan's review findings for published filter
tzvatot adeabc3
OSAC-58: cache CEL env and add OR composition test
tzvatot 035ed85
OSAC-58: allow creators to see their own unpublished catalog items
tzvatot 784ae80
OSAC-58: revert creator-based visibility, add direct validateCELSynta…
tzvatot f67ff20
OSAC-58: allow Get of unpublished catalog item referenced by existing…
tzvatot 57633d6
OSAC-58: allow Get of unpublished catalog item referenced by existing…
tzvatot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| Copyright (c) 2025 Red Hat Inc. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | ||
| License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific | ||
| language governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package servers | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| grpccodes "google.golang.org/grpc/codes" | ||
| grpcstatus "google.golang.org/grpc/status" | ||
|
|
||
| "github.com/osac-project/fulfillment-service/internal/database/dao" | ||
| ) | ||
|
|
||
| // catalogItemReferenceChecker checks whether the caller has any resources that reference a catalog item. | ||
| type catalogItemReferenceChecker interface { | ||
| hasReference(ctx context.Context, catalogItemID string) (bool, error) | ||
| } | ||
|
|
||
| // daoReferenceChecker implements catalogItemReferenceChecker using a GenericDAO. | ||
| type daoReferenceChecker[Resource dao.Object] struct { | ||
| resourceDao *dao.GenericDAO[Resource] | ||
| } | ||
|
|
||
| func (c *daoReferenceChecker[Resource]) hasReference(ctx context.Context, catalogItemID string) (bool, error) { | ||
| filter := fmt.Sprintf("this.spec.catalog_item == %q", catalogItemID) | ||
| response, err := c.resourceDao.List(). | ||
| SetFilter(filter). | ||
| SetLimit(1). | ||
| Do(ctx) | ||
| if err != nil { | ||
| return false, grpcstatus.Errorf(grpccodes.Internal, "failed to check resource references") | ||
| } | ||
| return response.GetTotal() > 0, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| Copyright (c) 2025 Red Hat Inc. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | ||
| License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific | ||
| language governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package servers | ||
|
|
||
| import ( | ||
| "context" | ||
| "reflect" | ||
|
|
||
| "go.uber.org/mock/gomock" | ||
| ) | ||
|
|
||
| type MockCatalogItemReferenceChecker struct { | ||
| ctrl *gomock.Controller | ||
| recorder *MockCatalogItemReferenceCheckerMockRecorder | ||
| isgomock struct{} | ||
| } | ||
|
|
||
| type MockCatalogItemReferenceCheckerMockRecorder struct { | ||
| mock *MockCatalogItemReferenceChecker | ||
| } | ||
|
|
||
| func NewMockCatalogItemReferenceChecker(ctrl *gomock.Controller) *MockCatalogItemReferenceChecker { | ||
| mock := &MockCatalogItemReferenceChecker{ctrl: ctrl} | ||
| mock.recorder = &MockCatalogItemReferenceCheckerMockRecorder{mock} | ||
| return mock | ||
| } | ||
|
|
||
| func (m *MockCatalogItemReferenceChecker) EXPECT() *MockCatalogItemReferenceCheckerMockRecorder { | ||
| return m.recorder | ||
| } | ||
|
|
||
| func (m *MockCatalogItemReferenceChecker) hasReference(ctx context.Context, catalogItemID string) (bool, error) { | ||
| m.ctrl.T.Helper() | ||
| ret := m.ctrl.Call(m, "hasReference", ctx, catalogItemID) | ||
| ret0, _ := ret[0].(bool) | ||
| ret1, _ := ret[1].(error) | ||
| return ret0, ret1 | ||
| } | ||
|
|
||
| func (mr *MockCatalogItemReferenceCheckerMockRecorder) hasReference(ctx, catalogItemID any) *gomock.Call { | ||
| mr.mock.ctrl.T.Helper() | ||
| return mr.mock.ctrl.RecordCallWithMethodType( | ||
| mr.mock, "hasReference", | ||
| reflect.TypeOf((*MockCatalogItemReferenceChecker)(nil).hasReference), | ||
| ctx, catalogItemID, | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| Copyright (c) 2025 Red Hat Inc. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | ||
| License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific | ||
| language governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package servers | ||
|
|
||
| import ( | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| var _ = Describe("addPublishedFilter", func() { | ||
| var server *ClusterCatalogItemsServer | ||
|
|
||
| BeforeEach(func() { | ||
| server = &ClusterCatalogItemsServer{} | ||
| }) | ||
|
|
||
| DescribeTable("composes filter correctly", | ||
| func(input string, expected string) { | ||
| result, err := server.addPublishedFilter(input) | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| Expect(result).To(Equal(expected)) | ||
| }, | ||
| Entry("empty filter", "", "this.published"), | ||
| Entry("simple filter", "this.id == '123'", "(this.id == '123') && this.published"), | ||
| Entry("compound filter", "this.title == 'a' && this.template == 'b'", | ||
| "(this.title == 'a' && this.template == 'b') && this.published"), | ||
| Entry("valid filter with OR is safely composed", "true || true", | ||
| "(true || true) && this.published"), | ||
| ) | ||
|
|
||
| DescribeTable("rejects malformed filters", | ||
| func(input string) { | ||
| _, err := server.addPublishedFilter(input) | ||
| Expect(err).To(HaveOccurred()) | ||
| Expect(status.Code(err)).To(Equal(codes.InvalidArgument)) | ||
| }, | ||
| Entry("unbalanced parens to bypass published", `true) || (true`), | ||
| Entry("unbalanced closing paren", `true)`), | ||
| Entry("unbalanced opening paren", `(true`), | ||
| ) | ||
|
|
||
| DescribeTable("validateCELSyntax", | ||
| func(input string, shouldPass bool) { | ||
| err := validateCELSyntax(input) | ||
| if shouldPass { | ||
| Expect(err).ToNot(HaveOccurred()) | ||
| } else { | ||
| Expect(err).To(HaveOccurred()) | ||
| } | ||
| }, | ||
| Entry("valid simple expression", "true", true), | ||
| Entry("valid field reference", "this.published", true), | ||
| Entry("valid comparison", "this.id == '123'", true), | ||
| Entry("valid compound", "this.a && this.b || this.c", true), | ||
| Entry("unbalanced closing paren", "true)", false), | ||
| Entry("unbalanced opening paren", "(true", false), | ||
| Entry("injection attempt", `true) || (true`, false), | ||
| Entry("empty string is not valid CEL", "", false), | ||
| ) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.