205
}
206
207
>
stmts, e := task.parseSQLStmts(fsys, dirPath, m)
updatetask.go
208
>
if e != nil {
209
return nil, e
210
}
211
213
>
if e != nil {
214
return nil, fmt.Errorf("error processing version %v:%v", vd, e.Error())
215
}
216
218
>
cs.manifest = m
219
>
cs.cqlStmts = stmts
220
>
cs.version = m.CurrVersion
221
>
result = append(result, cs)
222
}
223
225
}
226
227
>
func (task *UpdateTask) parseSQLStmts(fsys fs.FS, dir string, manifest *manifest) ([]string, error) {
updatetask.go
228
>
result := make([]string, 0, 4)
229
>
230
>
for _, file := range manifest.SchemaUpdateCqlFiles {
231
>
schemaPath := path.Join(dir, file)
232
>
task.logger.Info("Processing schema file: " + schemaPath)
233
>
schemaBuf, err := fs.ReadFile(fsys, schemaPath)
234
>
if err != nil {
235
return nil, fmt.Errorf("error reading file %s: %w", schemaPath, err)
236
}
237
>
stmts, err := persistence.LoadAndSplitQueryFromReaders([]io.Reader{bytes.NewBuffer(schemaBuf)})
updatetask.go
238
>
if err != nil {
239
return nil, fmt.Errorf("error parsing file %v, err=%v", schemaPath, err)
240
}
242
}
243
244
>
if len(result) == 0 && !manifest.AllowNoCqlFiles {
updatetask.go
245
return nil, fmt.Errorf("found 0 updates in dir %v", dir)
246
}
247
249
}
250
251
>
func validateCQLStmts(stmts []string) error {
updatetask.go
252
>
for _, stmt := range stmts {
253
>
valid := false
254
>
for _, prefix := range whitelistedCQLPrefixes {
255
>
if strings.HasPrefix(stmt, prefix) {
256
>
valid = true
257
>
break
258
}
259
}
261
return fmt.Errorf("CQL prefix not in whitelist, stmt=%v", stmt)
262
}
263
}
265
}
266