@@ -14,6 +14,7 @@ import (
14
14
15
15
"github.com/google/uuid"
16
16
"github.com/microcosm-cc/bluemonday"
17
+ "github.com/open-feature/go-sdk/openfeature"
17
18
"github.com/yuin/goldmark"
18
19
"github.com/yuin/goldmark/extension"
19
20
"github.com/yuin/goldmark/parser"
@@ -23,6 +24,7 @@ import (
23
24
24
25
"github.com/mindersec/minder/internal/db"
25
26
"github.com/mindersec/minder/internal/engine/engcontext"
27
+ "github.com/mindersec/minder/internal/engine/ingester/git"
26
28
"github.com/mindersec/minder/internal/flags"
27
29
"github.com/mindersec/minder/internal/logger"
28
30
"github.com/mindersec/minder/internal/util"
@@ -175,14 +177,9 @@ func (s *Server) CreateRuleType(
175
177
return nil , util .UserVisibleError (codes .InvalidArgument , "%s" , err )
176
178
}
177
179
178
- ruleDS := crt .GetRuleType ().GetDef ().GetEval ().GetDataSources ()
179
- if len (ruleDS ) > 0 && ! flags .Bool (ctx , s .featureFlags , flags .DataSources ) {
180
- return nil , util .UserVisibleError (codes .InvalidArgument , "DataSources feature is disabled" )
181
- }
182
-
183
- prCommentAlert := crt .GetRuleType ().GetDef ().GetAlert ().GetPullRequestComment ()
184
- if prCommentAlert != nil && ! flags .Bool (ctx , s .featureFlags , flags .PRCommentAlert ) {
185
- return nil , util .UserVisibleError (codes .InvalidArgument , "Pull request comment alert type is disabled" )
180
+ ruleDef := crt .GetRuleType ().GetDef ()
181
+ if err := checkRuleDefinitionFlags (ctx , s .featureFlags , ruleDef ); err != nil {
182
+ return nil , err
186
183
}
187
184
188
185
newRuleType , err := db .WithTransaction (s .store , func (qtx db.ExtendQuerier ) (* minderv1.RuleType , error ) {
@@ -204,6 +201,27 @@ func (s *Server) CreateRuleType(
204
201
}, nil
205
202
}
206
203
204
+ func checkRuleDefinitionFlags (
205
+ ctx context.Context , featureFlags openfeature.IClient , ruleDef * minderv1.RuleType_Definition ) * util.NiceStatus {
206
+ ruleDS := ruleDef .GetEval ().GetDataSources ()
207
+ if len (ruleDS ) > 0 && ! flags .Bool (ctx , featureFlags , flags .DataSources ) {
208
+ return util .UserVisibleError (codes .InvalidArgument , "DataSources feature is disabled" )
209
+ }
210
+
211
+ prCommentAlert := ruleDef .GetAlert ().GetPullRequestComment ()
212
+ if prCommentAlert != nil && ! flags .Bool (ctx , featureFlags , flags .PRCommentAlert ) {
213
+ return util .UserVisibleError (codes .InvalidArgument , "Pull request comment alert type is disabled" )
214
+ }
215
+
216
+ usesGitPR := ruleDef .GetIngest ().GetType () == git .GitRuleDataIngestType &&
217
+ ruleDef .GetInEntity () == minderv1 .PullRequestEntity .String ()
218
+ if usesGitPR && ! flags .Bool (ctx , featureFlags , flags .GitPRDiffs ) {
219
+ return util .UserVisibleError (codes .InvalidArgument , "Git pull request ingest is disabled" )
220
+ }
221
+
222
+ return nil
223
+ }
224
+
207
225
// UpdateRuleType is a method to update a rule type
208
226
func (s * Server ) UpdateRuleType (
209
227
ctx context.Context ,
@@ -227,9 +245,9 @@ func (s *Server) UpdateRuleType(
227
245
return nil , util .UserVisibleError (codes .InvalidArgument , "%s" , err )
228
246
}
229
247
230
- ruleDS := urt .GetRuleType ().GetDef (). GetEval (). GetDataSources ()
231
- if len ( ruleDS ) > 0 && ! flags . Bool (ctx , s .featureFlags , flags . DataSources ) {
232
- return nil , util . UserVisibleError ( codes . InvalidArgument , "DataSources feature is disabled" )
248
+ ruleDef := urt .GetRuleType ().GetDef ()
249
+ if err := checkRuleDefinitionFlags (ctx , s .featureFlags , ruleDef ); err != nil {
250
+ return nil , err
233
251
}
234
252
235
253
updatedRuleType , err := db .WithTransaction (s .store , func (qtx db.ExtendQuerier ) (* minderv1.RuleType , error ) {
0 commit comments