-
Notifications
You must be signed in to change notification settings - Fork 278
/
zmsclient.go
43 lines (39 loc) · 985 Bytes
/
zmsclient.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
// Copyright The Athenz Authors
// Licensed under the terms of the Apache version 2.0 license. See LICENSE file for terms.
package athenzutils
import (
"net/http"
"os"
"github.com/AthenZ/athenz/clients/go/zms"
"github.com/AthenZ/athenz/libs/go/tls/config"
)
// ZmsClient creates and returns a ZMS client instance.
func ZmsClient(zmsURL, keyFile, certFile, caCertFile string, proxy bool) (*zms.ZMSClient, error) {
keypem, err := os.ReadFile(keyFile)
if err != nil {
return nil, err
}
certpem, err := os.ReadFile(certFile)
if err != nil {
return nil, err
}
var cacertpem []byte
if caCertFile != "" {
cacertpem, err = os.ReadFile(caCertFile)
if err != nil {
return nil, err
}
}
config, err := config.ClientTLSConfigFromPEM(keypem, certpem, cacertpem)
if err != nil {
return nil, err
}
tr := &http.Transport{
TLSClientConfig: config,
}
if proxy {
tr.Proxy = http.ProxyFromEnvironment
}
client := zms.NewClient(zmsURL, tr)
return &client, nil
}