/
mutator_noop.go
54 lines (43 loc) · 1.16 KB
/
mutator_noop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package mutate
import (
"encoding/json"
"net/http"
"github.com/ory/oathkeeper/driver/configuration"
"github.com/ory/oathkeeper/pipeline"
"github.com/ory/oathkeeper/pipeline/authn"
)
type MutatorNoop struct{ c configuration.Provider }
func NewMutatorNoop(c configuration.Provider) *MutatorNoop {
return &MutatorNoop{c: c}
}
func (a *MutatorNoop) GetID() string {
return "noop"
}
func (a *MutatorNoop) Mutate(r *http.Request, session *authn.AuthenticationSession, config json.RawMessage, _ pipeline.Rule) error {
currentSessionHeaders := session.Header.Clone()
session.Header = r.Header
if session.Header == nil {
session.Header = make(map[string][]string)
}
for k, v := range currentSessionHeaders {
var val string
if len(v) == 0 {
val = ""
} else {
val = v[0]
}
session.SetHeader(k, val)
}
return nil
}
func (a *MutatorNoop) Validate(config json.RawMessage) error {
if !a.c.MutatorIsEnabled(a.GetID()) {
return NewErrMutatorNotEnabled(a)
}
if err := a.c.MutatorConfig(a.GetID(), config, nil); err != nil {
return NewErrMutatorMisconfigured(a, err)
}
return nil
}