11/**
22 * INTERNAL use only. This is an experimental API subject to change without notice.
33 *
4- * Provides classes and predicates for dealing with flow models specified in CSV format.
4+ * Provides classes and predicates for dealing with flow models specified
5+ * in data extension files.
56 *
6- * The CSV specification has the following columns:
7+ * The extensible relations have the following columns:
78 * - Sources:
89 * `namespace; type; subtypes; name; signature; ext; output; kind`
910 * - Sinks:
@@ -104,117 +105,9 @@ private import internal.FlowSummaryImpl::Private
104105private import internal.FlowSummaryImpl:: Private:: External
105106private import internal.ExternalFlowExtensions:: Extensions as Extensions
106107private import codeql.mad.ModelValidation as SharedModelVal
107- private import codeql.util.Unit
108108private import codeql.mad.static.ModelsAsData as SharedMaD
109109
110- /**
111- * A unit class for adding additional source model rows.
112- *
113- * Extend this class to add additional source definitions.
114- */
115- class SourceModelCsv extends Unit {
116- /** Holds if `row` specifies a source definition. */
117- abstract predicate row ( string row ) ;
118- }
119-
120- /**
121- * A unit class for adding additional sink model rows.
122- *
123- * Extend this class to add additional sink definitions.
124- */
125- class SinkModelCsv extends Unit {
126- /** Holds if `row` specifies a sink definition. */
127- abstract predicate row ( string row ) ;
128- }
129-
130- /**
131- * A unit class for adding additional summary model rows.
132- *
133- * Extend this class to add additional flow summary definitions.
134- */
135- class SummaryModelCsv extends Unit {
136- /** Holds if `row` specifies a summary definition. */
137- abstract predicate row ( string row ) ;
138- }
139-
140- /** Holds if `row` is a source model. */
141- predicate sourceModel ( string row ) { any ( SourceModelCsv s ) .row ( row ) }
142-
143- /** Holds if `row` is a sink model. */
144- predicate sinkModel ( string row ) { any ( SinkModelCsv s ) .row ( row ) }
145-
146- /** Holds if `row` is a summary model. */
147- predicate summaryModel ( string row ) { any ( SummaryModelCsv s ) .row ( row ) }
148-
149110private module MadInput implements SharedMaD:: InputSig {
150- /** Holds if a source model exists for the given parameters. */
151- predicate additionalSourceModel (
152- string namespace , string type , boolean subtypes , string name , string signature , string ext ,
153- string output , string kind , string provenance , string model
154- ) {
155- exists ( string row |
156- sourceModel ( row ) and
157- row .splitAt ( ";" , 0 ) = namespace and
158- row .splitAt ( ";" , 1 ) = type and
159- row .splitAt ( ";" , 2 ) = subtypes .toString ( ) and
160- subtypes = [ true , false ] and
161- row .splitAt ( ";" , 3 ) = name and
162- row .splitAt ( ";" , 4 ) = signature and
163- row .splitAt ( ";" , 5 ) = ext and
164- row .splitAt ( ";" , 6 ) = output and
165- row .splitAt ( ";" , 7 ) = kind
166- ) and
167- provenance = "manual" and
168- model = ""
169- }
170-
171- /** Holds if a sink model exists for the given parameters. */
172- predicate additionalSinkModel (
173- string namespace , string type , boolean subtypes , string name , string signature , string ext ,
174- string input , string kind , string provenance , string model
175- ) {
176- exists ( string row |
177- sinkModel ( row ) and
178- row .splitAt ( ";" , 0 ) = namespace and
179- row .splitAt ( ";" , 1 ) = type and
180- row .splitAt ( ";" , 2 ) = subtypes .toString ( ) and
181- subtypes = [ true , false ] and
182- row .splitAt ( ";" , 3 ) = name and
183- row .splitAt ( ";" , 4 ) = signature and
184- row .splitAt ( ";" , 5 ) = ext and
185- row .splitAt ( ";" , 6 ) = input and
186- row .splitAt ( ";" , 7 ) = kind
187- ) and
188- provenance = "manual" and
189- model = ""
190- }
191-
192- /**
193- * Holds if a summary model exists for the given parameters.
194- *
195- * This predicate does not expand `@` to `*`s.
196- */
197- predicate additionalSummaryModel (
198- string namespace , string type , boolean subtypes , string name , string signature , string ext ,
199- string input , string output , string kind , string provenance , string model
200- ) {
201- exists ( string row |
202- summaryModel ( row ) and
203- row .splitAt ( ";" , 0 ) = namespace and
204- row .splitAt ( ";" , 1 ) = type and
205- row .splitAt ( ";" , 2 ) = subtypes .toString ( ) and
206- subtypes = [ true , false ] and
207- row .splitAt ( ";" , 3 ) = name and
208- row .splitAt ( ";" , 4 ) = signature and
209- row .splitAt ( ";" , 5 ) = ext and
210- row .splitAt ( ";" , 6 ) = input and
211- row .splitAt ( ";" , 7 ) = output and
212- row .splitAt ( ";" , 8 ) = kind
213- ) and
214- provenance = "manual" and
215- model = ""
216- }
217-
218111 string namespaceSegmentSeparator ( ) { result = "::" }
219112}
220113
@@ -250,8 +143,8 @@ predicate summaryModel(
250143 )
251144}
252145
253- /** Provides a query predicate to check the CSV data for validation errors. */
254- module CsvValidation {
146+ /** Provides a query predicate to check the data for validation errors. */
147+ module ModelValidation {
255148 private string getInvalidModelInput ( ) {
256149 exists ( string pred , AccessPath input , string part |
257150 sinkModel ( _, _, _, _, _, _, input , _, _, _) and pred = "sink"
@@ -294,40 +187,6 @@ module CsvValidation {
294187
295188 private module KindVal = SharedModelVal:: KindValidation< KindValConfig > ;
296189
297- private string getInvalidModelSubtype ( ) {
298- exists ( string pred , string row |
299- sourceModel ( row ) and pred = "source"
300- or
301- sinkModel ( row ) and pred = "sink"
302- or
303- summaryModel ( row ) and pred = "summary"
304- |
305- exists ( string b |
306- b = row .splitAt ( ";" , 2 ) and
307- not b = [ "true" , "false" ] and
308- result = "Invalid boolean \"" + b + "\" in " + pred + " model."
309- )
310- )
311- }
312-
313- private string getInvalidModelColumnCount ( ) {
314- exists ( string pred , string row , int expect |
315- sourceModel ( row ) and expect = 8 and pred = "source"
316- or
317- sinkModel ( row ) and expect = 8 and pred = "sink"
318- or
319- summaryModel ( row ) and expect = 9 and pred = "summary"
320- |
321- exists ( int cols |
322- cols = 1 + max ( int n | exists ( row .splitAt ( ";" , n ) ) ) and
323- cols != expect and
324- result =
325- "Wrong number of columns in " + pred + " model row, expected " + expect + ", got " + cols +
326- "."
327- )
328- )
329- }
330-
331190 private string getInvalidModelSignature ( ) {
332191 exists ( string pred , string namespace , string type , string name , string signature , string ext |
333192 sourceModel ( namespace , type , _, name , signature , ext , _, _, _, _) and pred = "source"
@@ -366,13 +225,12 @@ module CsvValidation {
366225 )
367226 }
368227
369- /** Holds if some row in a CSV-based flow model appears to contain typos. */
228+ /** Holds if some row in a MaD flow model appears to contain typos. */
370229 query predicate invalidModelRow ( string msg ) {
371230 msg =
372231 [
373232 getInvalidModelSignature ( ) , getInvalidModelInput ( ) , getInvalidModelOutput ( ) ,
374- getInvalidModelSubtype ( ) , getInvalidModelColumnCount ( ) , KindVal:: getInvalidModelKind ( ) ,
375- getIncorrectConstructorSummaryOutput ( )
233+ KindVal:: getInvalidModelKind ( ) , getIncorrectConstructorSummaryOutput ( )
376234 ]
377235 }
378236}
@@ -1026,7 +884,7 @@ private module Cached {
1026884 }
1027885
1028886 /**
1029- * Holds if `node` is specified as a source with the given kind in a CSV flow
887+ * Holds if `node` is specified as a source with the given kind in a MaD flow
1030888 * model.
1031889 */
1032890 cached
@@ -1037,7 +895,7 @@ private module Cached {
1037895 }
1038896
1039897 /**
1040- * Holds if `node` is specified as a sink with the given kind in a CSV flow
898+ * Holds if `node` is specified as a sink with the given kind in a MaD flow
1041899 * model.
1042900 */
1043901 cached
0 commit comments