Commit graph

27 commits

Author SHA1 Message Date
Ondřej Benkovský
c2dbb7141a
add golangci-lint linter (#5499) 2022-07-10 11:06:33 -07:00
Yong Tang
a1429e1445
[plugin/rewrite] Refactor to satisfy security scan (#5214)
this PR re-arrange the logic to avoid a false positive DAST scan.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2022-03-01 14:33:52 -05:00
Uwe Krueger
40edf1e566
plugin/rewrite: streamline the ResponseRule handling. (#4473)
* plugin/rewrite: streamline the ResponseRule handling.

The functionality of a response rule is now completely encapsulated behind
a `ResponseRule` interface. This significantly simplifies the complete
processing flow, it enables more flexible response handling and it is possible
to eliminate lots of state flags, ifs and switches.

Based on the new flexibility the pull request also enables to support a
response name rewrite for all name rewrite types.
To be compatible, an explicit `answer auto` option is added to support
a best effort response rewrite (name and value).
Additionally now all name rewrite rules support additional name and value
reponse rewrite options.

Using this feature it is also possible now to rewrite a complete sub domain
hierarchy to a single domain name combined with a correct rewrite (#2389).

Signed-off-by: Uwe Krueger <uwe.krueger@sap.com>

* revert policy

Signed-off-by: Uwe Krueger <uwe.krueger@sap.com>

Co-authored-by: Miek Gieben <miek@miek.nl>
2021-05-04 10:05:45 +02:00
coredns-auto-go-fmt[bot]
ff9b4bcb98 auto go fmt 2021-02-24 10:22:15 +00:00
slick-nic
0103931263
Rewrite SRV targets and additional names in response (#4287)
* Rewrite plugin - rewrite SRV targets and names in response answer and additional records

Signed-off-by: Nic Colledge <nic@njcolledge.net>

* Added README content to describe new behaviour

Signed-off-by: Nic Colledge <nic@njcolledge.net>

* Added more record types to rewrite handling based on PR/Issue feedback

Signed-off-by: Nic Colledge <nic@njcolledge.net>

* Updated README.md for plugin

Signed-off-by: Nic Colledge <nic@njcolledge.net>

* Updated unit tests.
Small refactor of getTarget... function.

Signed-off-by: Nic Colledge <nic@njcolledge.net>

* Refactor to add response value rewrite as answer value option

Signed-off-by: Nic Colledge <nic@njcolledge.net>

* Removed TODO comment, added test for NAPTR record.

Signed-off-by: Nic Colledge <nic@njcolledge.net>
2021-02-23 10:12:40 +01:00
Hu Shuai
e233f59ee8
Fix some typos in comments. (#4100)
Signed-off-by: Hu Shuai <hus.fnst@cn.fujitsu.com>
2020-09-01 09:10:45 +02:00
Miek Gieben
dbd1c047cb
Run gostaticheck (#3325)
* Run gostaticheck

Run gostaticcheck on the codebase and fix almost all flagged items.

Only keep

* coremain/run.go:192:2: var appVersion is unused (U1000)
* plugin/chaos/setup.go:54:3: the surrounding loop is unconditionally terminated (SA4004)
* plugin/etcd/setup.go:103:3: the surrounding loop is unconditionally terminated (SA4004)
* plugin/pkg/replacer/replacer.go:274:13: argument should be pointer-like to avoid allocations (SA6002)
* plugin/route53/setup.go:124:28: session.New is deprecated: Use NewSession functions to create sessions instead. NewSession has the same functionality as New except an error can be returned when the func is called instead of waiting to receive an error until a request is made.  (SA1019)
* test/grpc_test.go:25:69: grpc.WithTimeout is deprecated: use DialContext and context.WithTimeout instead.  Will be supported throughout 1.x.  (SA1019)

The first one isn't true, as this is set via ldflags. The rest is
minor. The deprecation should be fixed at some point; I'll file some
issues.

Signed-off-by: Miek Gieben <miek@miek.nl>

* Make sure to plug in the plugins

import the plugins, that file that did this was removed, put it in the
reload test as this requires an almost complete coredns server.

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-10-01 07:41:29 +01:00
Guangming Wang
8af4685587 cleanup code by lint (#3312)
Signed-off-by: Guangming Wang <guangming.wang@daocloud.io>
2019-09-27 11:10:34 +01:00
Ruslan Drozhdzh
69a2397bf5 plugin/rewrite: fix domain length validation (#2995)
* unit test

* fix domain length validation

* code optimization

* remove unit test
2019-07-12 12:22:45 +00:00
Nguyen Quang Huy
42cf6606fc Fix error string should not be capitalized (#2608)
From [Golang coding convention](https://github.com/golang/go/wiki/CodeReviewComments#error-strings)

Co-Authored-By: Nguyen Van Trung [trungnvfet@outlook.com](mailto:trungnvfet@outlook.com)
Signed-off-by: Nguyen Quang Huy [huynq0911@gmail.com](mailto:huynq0911@gmail.com)
2019-02-27 08:25:02 -05:00
Daniel Garcia
4a3f5cc41e Use Trim(Prefix/Suffix) instead of Trim(Left/Right) in rewrite prefix plugin (#2364) (#2372) 2018-12-06 22:10:46 +00:00
Daniel Garcia
f51c110511 Use TrimPrefix instead of TrimLeft in rewrite prefix plugin (#2364) (#2370) 2018-12-06 21:02:07 +00:00
Paul G
a9ce35ae4e
plugin/rewrite: add closing dot for suffix rewrite rule (#2070)
* add closing dot for suffix rewrite rule
* improve rule syntax checks

Resolves: #1881
2018-10-23 16:59:59 -04:00
Paul G
38051b9089
plugin/rewrite: add handling of TTL field rewrites (#2048)
Resolves: #1981

Signed-off-by: Paul Greenberg <greenpau@outlook.com>
2018-08-29 10:41:03 -04:00
Karsten Weiss
6d8a078704 Typo fixes (#2031) 2018-08-14 08:55:55 -07:00
Miek Gieben
d9b9a955ba plugin/rewrite: prevent illegal names (#1972)
Log and returns an error when the name rewrite creates a name that is
illegal. Add test in name_test.go to see if an error is returned.

Possible followup could be the only check this if a name-rewrite is
done.

Fixes: #1638

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-13 09:32:07 -04:00
Francois Tur
7745462430 plugin/rewrite - extend edns0 local variable support with metadata (#1928)
* - add support of metadata values for edns0 local variables

* - comments from review.

* - simplify label check. Add UT

* - enhance check for Labels, add UT
- remove IsMetadataSet

* - edns0 variable - if variable is not found just ignore the rewrite.
2018-07-08 08:18:01 +01:00
Miek Gieben
6dd2cf8c4b plugin/rewrite: use request.Request and other cleanups (#1920)
This was done anyway, but only deep in the functions, just do this
everywhere; allows for shorter code and request.Request allows for
caching as well.

Cleanups, make it more Go like.
* remove unneeded switches
* remove testdir (why was this there??)
* simplify the logic
* remove unneeded variables
* put short functions on a single line
* fix documentation.
* spin off wire funcs in wire.go, make them functions.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-02 07:39:50 -07:00
Miek Gieben
99800a687c
plugin/metadata: metadata is just label=value (#1914)
This revert 17d807f0 and re-adds the metadata plugin as a plugin that
just sets a label to a value function.

Add package documentation on how to use the metadata package. Make it
clear that any caching is up to the Func implemented.

There are now - no in tree users. We could add the request metadata by
default under names that copy request.Request, i.e

request/ip - remote IP
request/port - remote port

Variables.go has been deleted.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-01 20:01:17 +01:00
Miek Gieben
0a43306871
plugin/rewrite: cleanup (#1916)
delete unused tests and fix import lines.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-06-30 21:55:38 +01:00
Eugen Kleiner
17d807f05f plugin/metadata: add metadata plugin (#1894)
* plugin/metadata: add metadata plugin

* plugin/metadata: Add MD struct, refactor code, fix doc

* plugin/metadata: simplify metadata key

* plugin/metadata: improve setup_test

* Support of metadata by rewrite plugin. Move calculated variables to metadata.

* Move variables from metadata to pkg, add UTs, READMEs change, metadata small fixes

* Add client port validation to variables_test

* plugin/metadata: improve README

* plugin/metadata: rename methods

* plugin/metadata: Update Metadataer interface, update doc, cosmetic code changes

* plugin/metadata: move colllisions check to OnStartup(). Fix default variables metadataer.

* plugin/metadata: Fix comment for method setValue

* plugin/metadata: change variables order to fix linter warning

* plugin/metadata: rename Metadataer to Provider
2018-06-29 10:44:16 +01:00
Chris O'Haver
5e06687ee5 plugin/rewrite: tweak parse error messaging, add tests (#1737)
* tweak parse error messaging, add tests

* looser err msg checking
2018-04-25 20:48:32 +01:00
Yong Tang
4e63d0be35 Enable goimports check, and fixes several imports format (#1525)
This fix enables goimports check and fixes several imports format
so that the import sections are prettier, e.g.:
```
 import (
-       "github.com/miekg/dns"
        "regexp"
        "strconv"
        "strings"
+
+       "github.com/miekg/dns"
 )
```

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2018-02-14 10:00:04 -05:00
Paul Greenberg
258c163bb0 feature: plugin/rewrite: rewrite ANSWER SECTION (#1318)
Resolves: #1313
2018-01-18 10:41:14 -05:00
Paul Greenberg
d35f2c73ec plugin/rewrite: regular expression and substring match/replace (#1296) (#1297) 2017-12-13 11:31:19 -05:00
Thong Huynh
ec21f83425 Modify the rewrite plugin to write multiple EDNS0 options (#936) (#1096)
* Add processing mode

* Add processing mode

* Update UTs

* Update README.md

* Change to use the constant Stop

* Fix README per review comments
2017-09-20 16:06:53 -04:00
Miek Gieben
d8714e64e4 Remove the word middleware (#1067)
* Rename middleware to plugin

first pass; mostly used 'sed', few spots where I manually changed
text.

This still builds a coredns binary.

* fmt error

* Rename AddMiddleware to AddPlugin

* Readd AddMiddleware to remain backwards compat
2017-09-14 09:36:06 +01:00
Renamed from middleware/rewrite/name.go (Browse further)