-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecs_socket.go
More file actions
34 lines (31 loc) · 1.06 KB
/
Copy pathecs_socket.go
File metadata and controls
34 lines (31 loc) · 1.06 KB
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
package main
import (
"context"
"errors"
"net"
"net/http"
"os"
"path/filepath"
"time"
)
// Private IPC adapter; all IAM/signature/lease logic lives in ecslogagent.
// Logical sink stays HTTPS, preserving the durable source/sink binding.
type ecsSocketTransport struct{ socket string }
func (t ecsSocketTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if req.URL.Scheme != "https" || !filepath.IsAbs(t.socket) {
return nil, errors.New("invalid private ECS transport")
}
info, err := os.Lstat(t.socket)
if err != nil || info.Mode()&os.ModeSocket == 0 || info.Mode().Perm()&0077 != 0 {
return nil, errors.New("private ECS agent socket unavailable")
}
clone := req.Clone(req.Context())
clone.Header.Set("X-Monitor-Archive-Ack", "1")
urlCopy := *req.URL
urlCopy.Scheme = "http"
clone.URL = &urlCopy
transport := &http.Transport{DisableKeepAlives: true, DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
return (&net.Dialer{Timeout: 3 * time.Second}).DialContext(ctx, "unix", t.socket)
}}
return transport.RoundTrip(clone)
}