This repository was archived by the owner on Oct 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient_factory.go
More file actions
60 lines (57 loc) · 1.58 KB
/
client_factory.go
File metadata and controls
60 lines (57 loc) · 1.58 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
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 auth
import (
"fmt"
"github.com/containerssh/http"
"github.com/containerssh/log"
"github.com/containerssh/metrics"
)
// NewHttpAuthClient creates a new HTTP authentication client
//goland:noinspection GoUnusedExportedFunction
func NewHttpAuthClient(
config ClientConfig,
logger log.Logger,
metrics metrics.Collector,
) (Client, error) {
if config.URL == "" {
return nil, fmt.Errorf("no authentication server URL provided")
}
realClient, err := http.NewClient(
config.ClientConfiguration,
logger,
)
if err != nil {
return nil, err
}
backendRequestsMetric := metrics.MustCreateCounter(
MetricNameAuthBackendRequests,
"requests",
"The number of requests sent to the configuration server.",
)
backendFailureMetric := metrics.MustCreateCounter(
MetricNameAuthBackendFailure,
"requests",
"The number of request failures to the configuration server.",
)
authSuccessMetric := metrics.MustCreateCounterGeo(
MetricNameAuthSuccess,
"requests",
"The number of successful authentications.",
)
authFailureMetric := metrics.MustCreateCounterGeo(
MetricNameAuthFailure,
"requests",
"The number of failed authentications.",
)
return &httpAuthClient{
enablePassword: config.Password,
enablePubKey: config.PubKey,
timeout: config.AuthTimeout,
httpClient: realClient,
logger: logger,
metrics: metrics,
backendRequestsMetric: backendRequestsMetric,
backendFailureMetric: backendFailureMetric,
authSuccessMetric: authSuccessMetric,
authFailureMetric: authFailureMetric,
}, nil
}