Commit Graph

11 Commits

Author SHA1 Message Date
Kazuyoshi Kato
b497e64143 Fuzz filter package with Go 1.18's fuzzer
Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2022-04-18 20:49:29 +00:00
Derek McGowan
986f294187
Merge pull request #3942 from hs0210/work
Add unit test for func in filter.go
2020-02-18 12:05:22 -08:00
Derek McGowan
3af3a76026
Fix filter errors
Prevent error messages from being output to stderr.
Return illegal token when a quoted string is invalid and
capture the error.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2020-01-08 18:07:50 -08:00
Hu Shuai
7b52bc506c Add unit test for func in filter.go
Signed-off-by: Hu Shuai <hus.fnst@cn.fujitsu.com>
2020-01-09 09:11:37 +08:00
Kunal Kushwaha
b12c3215a0 Licence header added
Signed-off-by: Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
2018-02-19 10:32:26 +09:00
Daniel Nephin
49fffe8ec7 Less verbose tests
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
2017-12-14 11:00:40 -05:00
Stephen J Day
4dfcf60bec
filters: supporting alternative characters for quote
The regexp syntax can have some nasty characters to handle quoting
correctly, in practice. In certain scenarios a double quote works well,
but it can affect readability for certain regexps. This introduces a
quoting mode that treats `/` and `|` as a double quote to make the
quoting in regular expressions more familiar and readable.

This change is introduced in a backwards compatible manner, so existing
regexp quoting is not affected.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-12-04 20:06:19 -08:00
Michael Crosby
f43b7acfd2 Update files based on go lint
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-10-02 10:15:28 -04:00
Stephen J Day
1921173569 filters: handle presence syntax correctly
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-06-28 10:56:01 -07:00
Stephen J Day
3d5ee9e8b8
filters: clean up implementation
Address a few cleanup items in the parser. Currently, we don't handle
compound values and we remove a panic when part of the input is not
consumed.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-06-20 18:02:52 -07:00
Stephen J Day
d69ef98bfd
filters: add package for filter syntax
With this PR, we add the syntax to use for filtration of items over the
containerd API. This package defines a syntax and parser that can be
used across types and use cases in a uniform manner.

The syntax is fairly familiar, if you've used container ecosystem
projects.  At the core, we base it on the concept of protobuf field
paths, augmenting with the ability to quote portions of the field path
to match arbitrary labels. These "selectors" come in the following
syntax:

```
<fieldpath>[<operator><value>]
```

A basic example is as follows:

```
name=foo
```

This would match all objects that have a field `name` with the value
`foo`. If we only want to test if the field is present, we can omit the
operator. This is most useful for matching labels in containerd. The
following will match objects that has the field labels and have the
label "foo" defined:

```
labels.foo
```

We also allow for quoting of parts of the field path to allow matching
of arbitrary items:

```
labels."very complex label"==something
```

We also define `!=` and `~=` as operators. The `!=` operator will match
all objects that don't match the value for a field and `~=` will compile
the target value as a regular expression and match the field value
against that.

Selectors can be combined using a comma, such that the resulting
selector will require all selectors are matched for the object to match.
The following example will match objects that are named `foo` and have
the label `bar`:

```
name==foo,labels.bar
```

This filter syntax will be used across all APIs that allow listing of
objects and for filtering which event a cleint see. By using a common
syntax, we hope to keep API access uniform.

For the most part, this takes inspiration from docker, swarm and k8s,
but has the limitation that it only allows selection of an inner
product. We may expand to operators that implement `or`, `in` or
`notin`, but it is not clear that this is useful at this level of the
stack.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-06-20 13:03:35 -07:00