forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
accesslog.go
98 lines (83 loc) · 2.4 KB
/
accesslog.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2018 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package envoy
import (
"fmt"
"net/http"
"net/url"
"strings"
"github.com/cilium/cilium/pkg/proxy/accesslog"
"github.com/cilium/proxy/go/cilium/api"
)
// ParseURL returns the URL as *net.url.URL
func ParseURL(scheme, host, path string) *url.URL {
u, err := url.Parse(fmt.Sprintf("%s://%s/%s", scheme, host, strings.TrimPrefix(path, "/")))
if err != nil {
u = &url.URL{
Scheme: scheme,
Host: host,
Path: path,
}
}
return u
}
// getNetHttpHeaders returns the Headers as net.http.Header
func GetNetHttpHeaders(httpHeaders []*cilium.KeyValue) http.Header {
headers := make(http.Header)
for _, header := range httpHeaders {
headers.Add(header.Key, header.Value)
}
return headers
}
// getProtocol returns the HTTP protocol in the format that Cilium understands
func GetProtocol(httpProtocol cilium.HttpProtocol) string {
switch httpProtocol {
case cilium.HttpProtocol_HTTP10:
return "HTTP/1"
case cilium.HttpProtocol_HTTP11:
return "HTTP/1.1"
case cilium.HttpProtocol_HTTP2:
return "HTTP/2"
default:
return "Unknown"
}
}
// GetFlowType returns the type of flow (request|response)
func GetFlowType(m *cilium.LogEntry) accesslog.FlowType {
// the fall back type is request
result := accesslog.TypeRequest
if m != nil {
switch m.EntryType {
case cilium.EntryType_Denied:
result = accesslog.TypeRequest
case cilium.EntryType_Request:
result = accesslog.TypeRequest
case cilium.EntryType_Response:
result = accesslog.TypeResponse
}
}
return result
}
// GetVerdict returns the verdict performed on the flow (forwarded|denied)
func GetVerdict(m *cilium.LogEntry) accesslog.FlowVerdict {
// the default verdict is forwarded
result := accesslog.VerdictForwarded
if m != nil {
switch m.EntryType {
case cilium.EntryType_Denied:
result = accesslog.VerdictDenied
}
}
return result
}