|
| 1 | +package application |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "errors" |
| 6 | + "fmt" |
| 7 | + gohttp "net/http" |
| 8 | + |
| 9 | + "github.com/argoproj/argo-cd/v2/util/kube" |
| 10 | + |
| 11 | + "github.com/argoproj/pkg/grpc/http" |
| 12 | + "github.com/grpc-ecosystem/grpc-gateway/runtime" |
| 13 | + |
| 14 | + // nolint:staticcheck |
| 15 | + "github.com/golang/protobuf/proto" |
| 16 | + |
| 17 | + "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" |
| 18 | +) |
| 19 | + |
| 20 | +func init() { |
| 21 | + 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) { |
| 22 | + if req.URL.Query().Get("download") == "true" { |
| 23 | + w.Header().Set("Content-Type", "application/octet-stream") |
| 24 | + fileName := "log" |
| 25 | + if container := req.URL.Query().Get("container"); len(container) > 0 && kube.IsValidResourceName(container) { |
| 26 | + fileName = container |
| 27 | + } |
| 28 | + w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment;filename="%s.txt"`, fileName)) |
| 29 | + for { |
| 30 | + msg, err := recv() |
| 31 | + if err != nil { |
| 32 | + _, _ = w.Write([]byte(err.Error())) |
| 33 | + return |
| 34 | + } |
| 35 | + if logEntry, ok := msg.(*LogEntry); ok { |
| 36 | + if logEntry.GetLast() { |
| 37 | + return |
| 38 | + } |
| 39 | + if _, err = w.Write([]byte(logEntry.GetContent() + "\n")); err != nil { |
| 40 | + return |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + } else { |
| 45 | + http.StreamForwarder(ctx, mux, marshaler, w, req, recv, opts...) |
| 46 | + } |
| 47 | + } |
| 48 | + forward_ApplicationService_PodLogs_0 = logsForwarder |
| 49 | + forward_ApplicationService_PodLogs_1 = logsForwarder |
| 50 | + forward_ApplicationService_WatchResourceTree_0 = http.StreamForwarder |
| 51 | + forward_ApplicationService_Watch_0 = http.NewStreamForwarder(func(message proto.Message) (string, error) { |
| 52 | + event, ok := message.(*v1alpha1.ApplicationWatchEvent) |
| 53 | + if !ok { |
| 54 | + return "", errors.New("unexpected message type") |
| 55 | + } |
| 56 | + return event.Application.Name, nil |
| 57 | + }) |
| 58 | + forward_ApplicationService_List_0 = http.UnaryForwarder |
| 59 | + forward_ApplicationService_ManagedResources_0 = http.UnaryForwarder |
| 60 | +} |
0 commit comments