Skip to content

Commit 4fb3117

Browse files
committed
Error when using both include and exclude types
1 parent d21490c commit 4fb3117

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/pkg/ingress/bindings/binding_config.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package bindings
22

33
import (
4+
"errors"
45
"net/url"
56
"strings"
67

@@ -36,7 +37,10 @@ func (d *DrainParamParser) FetchBindings() ([]syslog.Binding, error) {
3637
b.OmitMetadata = getOmitMetadata(urlParsed, d.defaultDrainMetadata)
3738
b.InternalTls = getInternalTLS(urlParsed)
3839
b.DrainData = getBindingType(urlParsed)
39-
b.LogFilter = getLogFilter(urlParsed)
40+
b.LogFilter, err = getLogFilter(urlParsed)
41+
if err != nil {
42+
return nil, err
43+
}
4044

4145
processed = append(processed, b)
4246
}
@@ -138,18 +142,18 @@ func NewLogTypeSet(logTypeList string, isExclude bool) *syslog.LogTypeSet {
138142
return &set
139143
}
140144

141-
func getLogFilter(u *url.URL) *syslog.LogTypeSet {
145+
func getLogFilter(u *url.URL) (*syslog.LogTypeSet, error) {
142146
includeLogTypes := u.Query().Get("include-log-types")
143147
excludeLogTypes := u.Query().Get("exclude-log-types")
144148

145149
if excludeLogTypes != "" && includeLogTypes != "" {
146-
// TODO return errors.New("include-log-types and exclude-log-types can not be used at the same time")
150+
return nil, errors.New("include-log-types and exclude-log-types can not be used at the same time")
147151
} else if excludeLogTypes != "" {
148-
return NewLogTypeSet(excludeLogTypes, true)
152+
return NewLogTypeSet(excludeLogTypes, true), nil
149153
} else if includeLogTypes != "" {
150-
return NewLogTypeSet(includeLogTypes, false)
154+
return NewLogTypeSet(includeLogTypes, false), nil
151155
}
152-
return NewLogTypeSet("", false)
156+
return NewLogTypeSet("", false), nil
153157
}
154158

155159
func getRemoveMetadataQuery(u *url.URL) string {

src/pkg/ingress/bindings/binding_config_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ var _ = Describe("Drain Param Config", func() {
107107
Expect(configedBindings[4].LogFilter).To(Equal(NewLogTypeSet(syslog.API, syslog.STG, syslog.LGR, syslog.APP, syslog.SSH, syslog.CELL)))
108108
})
109109

110+
It("returns an error when both include-log-types and exclude-log-types are specified", func() {
111+
bs := []syslog.Binding{
112+
{Drain: syslog.Drain{Url: "https://test.org/drain?include-log-types=app&exclude-log-types=rtr"}},
113+
}
114+
f := newStubFetcher(bs, nil)
115+
wf := bindings.NewDrainParamParser(f, true)
116+
117+
configedBindings, err := wf.FetchBindings()
118+
Expect(err).To(HaveOccurred())
119+
Expect(configedBindings).To(HaveLen(0))
120+
})
121+
110122
It("sets drain data for old parameter appropriately'", func() {
111123
bs := []syslog.Binding{
112124
{Drain: syslog.Drain{Url: "https://test.org/drain?drain-type=metrics"}},

0 commit comments

Comments
 (0)