-
Notifications
You must be signed in to change notification settings - Fork 4
/
opts.go
84 lines (73 loc) · 2.43 KB
/
opts.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Copyright 2018- The Pixie Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package pxapi
import (
"log"
"os"
"strings"
)
// ClientOption configures options on the client.
type ClientOption func(client *Client)
// WithCloudAddr is the option to specify cloud address to use.
func WithCloudAddr(cloudAddr string) ClientOption {
return func(c *Client) {
c.vzAddr = cloudAddr
}
}
// Allows disabling TLS verification if the `PX_DISABLE_TLS` env var is set and the cloud address is a cluster domain (cluster.local).
func WithDisableTLSVerification(cloudAddr string) ClientOption {
return func(c *Client) {
isInternal := strings.Contains(cloudAddr, "cluster.local")
tlsDisabled := os.Getenv("PX_DISABLE_TLS") == "1"
insecureSkipVerify := tlsDisabled && isInternal
if !tlsDisabled && isInternal {
log.Fatalf("The `PX_DISABLE_TLS` environment variable must be set to \"1\" when making cloud connections that do not support TLS.\n")
}
c.disableTLSVerification = insecureSkipVerify
}
}
// WithDirectAddr is the option to specify direct address to use for data from standalone pem.
func WithDirectAddr(directAddr string) ClientOption {
return func(c *Client) {
c.vzAddr = directAddr
}
}
// WithBearerAuth is the option to specify bearer auth to use.
func WithBearerAuth(auth string) ClientOption {
return func(c *Client) {
c.bearerAuth = auth
}
}
// WithAPIKey is the option to specify the API key to use.
func WithAPIKey(auth string) ClientOption {
return func(c *Client) {
c.apiKey = auth
}
}
// WithE2EEncryption is the option to enable E2E ecnryption for table data.
func WithE2EEncryption(enabled bool) ClientOption {
return func(c *Client) {
c.useEncryption = enabled
}
}
// WithDirectCredsInsecure is the option to setup insecure credentials for direct connections.
func WithDirectCredsInsecure() ClientOption {
return func(c *Client) {
c.insecureDirect = true
}
}