-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
server_ipc.go
51 lines (39 loc) · 1.37 KB
/
server_ipc.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package apiimpl
import (
"crypto/tls"
"net"
"net/http"
"time"
configendpoint "github.com/DataDog/datadog-agent/comp/api/api/apiimpl/internal/config"
apiutils "github.com/DataDog/datadog-agent/comp/api/api/apiimpl/utils"
"github.com/DataDog/datadog-agent/pkg/config"
)
const ipcServerName string = "IPC API Server"
var ipcListener net.Listener
func startIPCServer(ipcServerAddr string, tlsConfig *tls.Config) (err error) {
ipcListener, err = getListener(ipcServerAddr)
if err != nil {
return err
}
configEndpointMux := configendpoint.GetConfigEndpointMuxCore()
configEndpointMux.Use(validateToken)
ipcMux := http.NewServeMux()
ipcMux.Handle(
"/config/v1/",
http.StripPrefix("/config/v1", configEndpointMux))
ipcMuxHandler := apiutils.LogResponseHandler(ipcServerName)(ipcMux)
ipcServer := &http.Server{
Addr: ipcServerAddr,
Handler: http.TimeoutHandler(ipcMuxHandler, time.Duration(config.Datadog.GetInt64("server_timeout"))*time.Second, "timeout"),
TLSConfig: tlsConfig,
}
startServer(ipcListener, ipcServer, ipcServerName)
return nil
}
func stopIPCServer() {
stopServer(ipcListener, ipcServerName)
}