-
Notifications
You must be signed in to change notification settings - Fork 140
CBG-4412: Add ability to pass custom import filter into diagnostic API #7935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 10 commits
ef36319
ba04a67
51c2252
47f555e
b8e7403
33de478
bbc67b1
f09f031
6bf370d
1e8d8ef
786b9fc
4fd3879
0584eb8
7451981
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -545,20 +545,43 @@ func (i *ImportFilterFunction) EvaluateFunction(ctx context.Context, doc Body, d | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false, errors.New("Import filter function returned non-boolean value.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (db *DatabaseCollectionWithUser) ImportFilterDryRun(ctx context.Context, doc Body, docid string) (bool, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| importFilter := db.importFilter() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if docid != "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| docInBucket, err := db.GetDocument(ctx, docid, DocUnmarshalAll) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if doc == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doc = docInBucket.Body(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ImportFilterDryRun Runs a document through the import filter and returns a boolean and error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (db *DatabaseCollectionWithUser) ImportFilterDryRun(ctx context.Context, doc Body, importFn string) (bool, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var shouldImport bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if importFn == "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| importFilter := db.importFilter() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if importFilter == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false, base.HTTPErrorf(http.StatusBadRequest, "No import filter specified") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| output, err := importFilter.EvaluateFunction(ctx, doc, true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RIT3shSapata marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false, &base.ImportFilterDryRunError{Err: err} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shouldImport = output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jsTimeout := time.Duration(base.DefaultJavascriptTimeoutSecs) * time.Second | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| importRunner, err := newImportFilterRunner(ctx, importFn, jsTimeout) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false, errors.New("failed to create import filter runner: " + err.Error()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| importOuput, err := importRunner.Call(ctx, doc) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RIT3shSapata marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch result := importOuput.(type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| importOuput, err := importRunner.Call(ctx, doc) | |
| switch result := importOuput.(type) { | |
| importOutput, err := importRunner.Call(ctx, doc) | |
| switch result := importOutput.(type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Outdated
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The break statements are unnecessary in a switch statement in Go. The break is implicit at the end of each case unless a fallthrough is explicitly used.
| break | |
| case string: | |
| boolResult, err := strconv.ParseBool(result) | |
| if err != nil { | |
| return false, err | |
| } | |
| } else { | |
| return false, err | |
| shouldImport = boolResult | |
| break | |
| case string: | |
| boolResult, err := strconv.ParseBool(result) | |
| if err != nil { | |
| return false, err | |
| } | |
| shouldImport = boolResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Outdated
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The break statements are unnecessary in a switch statement in Go. The break is implicit at the end of each case unless a fallthrough is explicitly used.
| break | |
| case string: | |
| boolResult, err := strconv.ParseBool(result) | |
| if err != nil { | |
| return false, err | |
| } | |
| } else { | |
| return false, err | |
| shouldImport = boolResult | |
| break | |
| case string: | |
| boolResult, err := strconv.ParseBool(result) | |
| if err != nil { | |
| return false, err | |
| } | |
| shouldImport = boolResult |
Outdated
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error err may be nil at this point since it's only assigned in the string case. This would result in wrapping a nil error. Consider returning an explicit error message indicating that the import filter returned a non-boolean value.
| return false, &base.ImportFilterDryRunError{Err: err} | |
| wrappedErr := err | |
| if wrappedErr == nil { | |
| wrappedErr = errors.New("import filter function returned non-boolean value") | |
| } | |
| return false, &base.ImportFilterDryRunError{Err: wrappedErr} |
Uh oh!
There was an error while loading. Please reload this page.