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
17 changes: 16 additions & 1 deletion central/resourcecollection/service/service_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
"/v1.CollectionService/GetCollection",
"/v1.CollectionService/GetCollectionCount",
"/v1.CollectionService/ListCollections",
// "/v1.CollectionService/ListCollectionSelectors", TODO ROX-12612
"/v1.CollectionService/ListCollectionSelectors",
},
user.With(permissions.Modify(resources.WorkflowAdministration)): {
// "/v1.CollectionService/AutoCompleteCollection", TODO ROX-12616
Expand Down Expand Up @@ -75,6 +75,21 @@ func (s *serviceImpl) AuthFuncOverride(ctx context.Context, fullMethodName strin
return ctx, authorizer.Authorized(ctx, fullMethodName)
}

// ListCollectionSelectors returns all supported selectors
func (s *serviceImpl) ListCollectionSelectors(_ context.Context, _ *v1.Empty) (*v1.ListCollectionSelectorsResponse, error) {
if !features.ObjectCollections.Enabled() {
return nil, errors.Errorf("%s env var is not enabled", features.ObjectCollections.EnvVar())
}
selectors := datastore.GetSupportedFieldLabels()
selectorStrings := make([]string, 0, len(selectors))
for _, selector := range selectors {
selectorStrings = append(selectorStrings, selector.String())
}
return &v1.ListCollectionSelectorsResponse{
Selectors: selectorStrings,
}, nil
}

// GetCollection returns a collection for the given request
func (s *serviceImpl) GetCollection(ctx context.Context, request *v1.GetCollectionRequest) (*v1.GetCollectionResponse, error) {
if !features.ObjectCollections.Enabled() {
Expand Down
22 changes: 22 additions & 0 deletions central/resourcecollection/service/service_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ func (suite *CollectionServiceTestSuite) TearDownSuite() {
suite.mockCtrl.Finish()
}

func (suite *CollectionServiceTestSuite) TestListCollectionSelectors() {
if !features.ObjectCollections.Enabled() {
suite.T().Skip("skipping because env var is not set")
}

selectorsResponse, err := suite.collectionService.ListCollectionSelectors(context.Background(), &v1.Empty{})
suite.NoError(err)

supportedLabelStrings := []string{
search.Cluster.String(),
search.ClusterLabel.String(),
search.Namespace.String(),
search.NamespaceLabel.String(),
search.NamespaceAnnotation.String(),
search.DeploymentName.String(),
search.DeploymentLabel.String(),
search.DeploymentAnnotation.String(),
}

suite.ElementsMatch(supportedLabelStrings, selectorsResponse.GetSelectors())
}

func (suite *CollectionServiceTestSuite) TestGetCollection() {
if !features.ObjectCollections.Enabled() {
suite.T().Skip("skipping because env var is not set")
Expand Down
Loading