-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
forwarder_overwrite.go
60 lines (54 loc) · 1.91 KB
/
forwarder_overwrite.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
package application
import (
"context"
"errors"
"fmt"
gohttp "net/http"
"github.com/argoproj/argo-cd/v2/util/kube"
"github.com/argoproj/pkg/grpc/http"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
// nolint:staticcheck
"github.com/golang/protobuf/proto"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
)
func init() {
logsForwarder := func(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w gohttp.ResponseWriter, req *gohttp.Request, recv func() (proto.Message, error), opts ...func(context.Context, gohttp.ResponseWriter, proto.Message) error) {
if req.URL.Query().Get("download") == "true" {
w.Header().Set("Content-Type", "application/octet-stream")
fileName := "log"
if container := req.URL.Query().Get("container"); len(container) > 0 && kube.IsValidResourceName(container) {
fileName = container
}
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment;filename="%s.txt"`, fileName))
for {
msg, err := recv()
if err != nil {
_, _ = w.Write([]byte(err.Error()))
return
}
if logEntry, ok := msg.(*LogEntry); ok {
if logEntry.GetLast() {
return
}
if _, err = w.Write([]byte(logEntry.GetContent() + "\n")); err != nil {
return
}
}
}
} else {
http.StreamForwarder(ctx, mux, marshaler, w, req, recv, opts...)
}
}
forward_ApplicationService_PodLogs_0 = logsForwarder
forward_ApplicationService_PodLogs_1 = logsForwarder
forward_ApplicationService_WatchResourceTree_0 = http.StreamForwarder
forward_ApplicationService_Watch_0 = http.NewStreamForwarder(func(message proto.Message) (string, error) {
event, ok := message.(*v1alpha1.ApplicationWatchEvent)
if !ok {
return "", errors.New("unexpected message type")
}
return event.Application.Name, nil
})
forward_ApplicationService_List_0 = http.UnaryForwarder
forward_ApplicationService_ManagedResources_0 = http.UnaryForwarder
}