mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-10-12 01:58:46 +02:00
ctrld keeps a second log file, ctrld-journal.log, next to ctrld.log. The journal holds all warnings and errors and each event with the field journal=true. It stays on disk after a start of the service and after a self-upgrade. Each log file starts with a Log header line. Each log send upload starts with the same line, made at send time, and has a limit of about 16 MB.
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type controlClient struct {
|
|
c *http.Client
|
|
}
|
|
|
|
func newControlClient(addr string) *controlClient {
|
|
return &controlClient{c: &http.Client{
|
|
Transport: &http.Transport{
|
|
DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
|
|
d := net.Dialer{}
|
|
return d.DialContext(ctx, "unix", addr)
|
|
},
|
|
},
|
|
Timeout: time.Second * 30,
|
|
}}
|
|
}
|
|
|
|
func (c *controlClient) post(path string, data io.Reader) (*http.Response, error) {
|
|
// A log send uploads many megabytes, so it needs more time than the other
|
|
// calls.
|
|
if isSendLogsPath(path) {
|
|
c.c.Timeout = time.Minute * 5
|
|
}
|
|
return c.c.Post("http://unix"+path, contentTypeJson, data)
|
|
}
|
|
|
|
// isSendLogsPath reports whether path addresses the log send handler. The path
|
|
// can carry a query, so the comparison takes the path alone. A path that does
|
|
// not parse keeps the prefix rule, because it still reaches that handler.
|
|
func isSendLogsPath(path string) bool {
|
|
parsed, err := url.Parse(path)
|
|
if err != nil {
|
|
return strings.HasPrefix(path, sendLogsPath)
|
|
}
|
|
return parsed.Path == sendLogsPath
|
|
}
|
|
|
|
// postStream sends a POST request with no timeout, suitable for long-lived streaming connections.
|
|
func (c *controlClient) postStream(path string, data io.Reader) (*http.Response, error) {
|
|
c.c.Timeout = 0
|
|
return c.c.Post("http://unix"+path, contentTypeJson, data)
|
|
}
|
|
|
|
// deactivationRequest represents request for validating deactivation pin.
|
|
type deactivationRequest struct {
|
|
Pin int64 `json:"pin"`
|
|
}
|