diff --git a/pkg/updater/resultstore/query/query.go b/pkg/updater/resultstore/query/query.go index 3bb941bb..db524177 100644 --- a/pkg/updater/resultstore/query/query.go +++ b/pkg/updater/resultstore/query/query.go @@ -17,47 +17,76 @@ limitations under the License. package query import ( + "errors" "fmt" "regexp" "strings" ) -func translateAtom(simpleAtom string) (string, error) { - if simpleAtom == "" { - return "", nil +type keyValue struct { + key string + value string +} + +func translateAtom(simpleAtom keyValue, queryTarget bool) (string, error) { + if simpleAtom.key == "" { + return "", errors.New("missing key") } - // For now, we expect an atom with the exact form `target:""` - // Split the `key:value` atom. - parts := strings.SplitN(simpleAtom, ":", 2) - if len(parts) != 2 { - return "", fmt.Errorf("unrecognized atom %q", simpleAtom) + if simpleAtom.value == "" { + return "", errors.New("missing value") } - key := strings.TrimSpace(parts[0]) - val := strings.Trim(strings.TrimSpace(parts[1]), `"`) - switch { - case key == "target": - return fmt.Sprintf(`id.target_id="%s"`, val), nil + case simpleAtom.key == "label" && queryTarget: + return fmt.Sprintf(`invocation.invocation_attributes.labels:"%s"`, simpleAtom.value), nil + case simpleAtom.key == "label": + return fmt.Sprintf(`invocation_attributes.labels:"%s"`, simpleAtom.value), nil + case simpleAtom.key == "target": + return fmt.Sprintf(`id.target_id="%s"`, simpleAtom.value), nil default: - return "", fmt.Errorf("unrecognized atom key %q", key) + return "", fmt.Errorf("unknown type of atom %q", simpleAtom.key) } } var ( - queryRe = regexp.MustCompile(`^target:".*"$`) + // Captures any atoms of the form `label:"